汇编:
gcc -O1 main.c -c -o main.o
$cat main.o
.file "main.c"
.text
.globl sum
.type sum, @function
sum:
pushl %ebp
movl %esp, %ebp
movl 12(%ebp), %eax
addl 8(%ebp), %eax
addl %eax, accum
popl %ebp
ret
.size sum, .-sum
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
movl $0, %eax
popl %ebp
ret
.size main, .-main
.globl accum
.bss
.align 4
.type accum, @object
.size accum, 4
accum:
.zero 4
.ident "GCC: (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3"
.section .note.GNU-stack,"",@progbits
反汇编:
$ objdump -d main.o
对照C源代码 $objdump -S main
main.o: file format elf32-i386
Disassembly of section .text:
00000000 <sum>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 8b 45 0c mov 0xc(%ebp),%eax
6: 03 45 08 add 0x8(%ebp),%eax
9: 01 05 00 00 00 00 add %eax,0x0
f: 5d pop %ebp
10: c3 ret
00000011 <main>:
11: 55 push %ebp
12: 89 e5 mov %esp,%ebp
14: b8 00 00 00 00 mov $0x0,%eax
19: 5d pop %ebp
1a: c3 ret