Ia32 supports a number of operand forms figure 33

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cedure definition: 1 2 3 4 5 6 7 8 int accum = 0; int sum(int x, int y) { int t = x + y; accum += t; return t; } To see the assembly code generated by the C compiler, we can use the “-S” option on the command line: unix> gcc -O2 -S code.c This will cause the compiler to generate an assembly file code.s and go no further. (Normally it would then invoke the assembler to generate an object code file). The assembly-code file contains various declarations including the set of lines: sum: pushl %ebp movl %esp,%ebp movl 12(%ebp),%eax addl 8(%ebp),%eax addl %eax,accum movl %ebp,%esp popl %ebp ret Each indented line in the above code corresponds to a single machine instruction. For example, the pushl instruction indicates that the contents of register %ebp should be pushed onto the program stack. All information about local variable names or data types has been stripped away. We still see a reference to the global variable accum, since the compiler has not yet determined where in memory this variable will be stored. If we use the ’-c’ command line option, GCC will both compile and assemble the code:...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online