To give you an example of a "real world", consider this program:
int main() { int i = 0; i += 1; i++; i = i + 1; return 0; }
Compilation with GCC in Darwin 11 with the following flags:
-S stop in assembler-m32 to a 32-bit platform, just to simplify things.
The following program will generate, with the exception of the comments and blank lines that I added. Take a specific look at the comments.
.section __TEXT,__text,regular,pure_instructions .globl _main .align 4, 0x90 _main: pushl %ebp # cdecl function stuff movl %esp, %ebp # subl $12, %esp # get room for variables movl $0, -12(%ebp) # i = 0; ; i += 1 movl -12(%ebp), %eax # load i in register a addl $1, %eax # add 1 to register a movl %eax, -12(%ebp) # store it back in memory ; i++ movl -12(%ebp), %eax # addl $1, %eax # just the same movl %eax, -12(%ebp) # ; i = i + 1 movl -12(%ebp), %eax # addl $1, %eax # just the same movl %eax, -12(%ebp) # movl $0, -8(%ebp) movl -8(%ebp), %eax movl %eax, -4(%ebp) movl -4(%ebp), %eax addl $12, %esp popl %ebp ret .subsections_via_symbols
sidyll Sep 19 '11 at 14:37 2011-09-19 14:37
source share