CS31 Weekly Lab Week 4

IA32 assembly, C stack drawing, machine teardown
Create a week04 subdirectory in your weeklylab subdirectory and copy over some files:
    cd cs31/weeklylab
    pwd
    mkdir week04
    ls
    cd week04
    pwd
    cp ~newhall/public/cs31/week04/* .
    ls
    Makefile simpleops.c

Week 4 lab goals:

  1. C stack drawing, HW1 example.
    Another example (from the C intro for CS31 programmers webpage.)
  2. Condition Code and ALU Lab
  3. Compilation Steps and practice with IA32 assembly code, gcc, objdump
  4. Disassemble a computer and see what parts you can identify.


gcc to generate IA32 assembly
Let's try out gcc to build IA32 assembly files and .o files and look at the results.

Open up simpleops.c in vim.

We are going to look at how to use gcc to create an assembly version of this file, and how to create an object .o file, and how to examine its contents.

If you open up the Makefile you can see the rules for building .s, .o and executable files from simpleops.c. We will be compiling the 32-bit version of instructions, so we will use the -m32 flag. The Makefile also uses a flag -fno-asynchronous-unwind-tables that just makes the assembly code for functions a little easier to read.

gcc -m32 -S simpleops.c   # just runs the assembler to create a .s text file
gcc -m32 -c simpleops.s   # compiles to a relocatable object binary file (.o) 
gcc -m32 -o simpleops simpleops.o  # creates a 32-bit executable file
To see the machine code and assembly code mappings in the .o file:
objdump -d simpleops.o
You can compare this to the assembly file:
cat simpleops.s
Here is some more information about tools for examining phases of compiling and running C programs.
Computer Teardown
Log out, and we are going next door. You have been randomly assigned to one of four groups. Each group is assigned a computer that you can take apart. The goal is to find as many parts of a computer as you can. We have tools available to remove parts from your computer, and here are a few links that may be helpful:

Try to identify some of the following:

Before leaving lab, please clean-up all spare parts, screws, etc. that you have removed by putting them in the boxes. You do not need to put the cases in the boxes, just all loose parts. CPU thermal glue is toxic, so just to be extra safe I'd recommend washing your hands after lab today.