cd cs31/weeklylab pwd mkdir week04 ls cd week04 pwd cp ~newhall/public/cs31/week04/* . ls Makefile simpleops.c
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 fileTo see the machine code and assembly code mappings in the .o file:
objdump -d simpleops.oYou can compare this to the assembly file:
cat simpleops.sHere is some more information about tools for examining phases of compiling and running C programs.
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.