彙編語言程序設計學習筆記(二)(Linux 版)

彙編:

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    

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章