関数呼び出し

doyu@oreo:/tmp$ cat a.c
int func(int a1,int a2,int a3,int a4,int a5,int a6, int a7){ return a1+a2+a3+a4+a5+a6+a7; }
int main() { int rc =  func(1,2,3,4,5,6,7); return rc; }
doyu@oreo:/tmp$ gcc -g -fomit-frame-pointer -c a.c
doyu@oreo:/tmp$ objdump -d -S a.o

a.o:     ファイル形式 elf32-i386

セクション .text の逆アセンブル:

00000000 :
int func(int a1,int a2,int a3,int a4,int a5,int a6, int a7){ return a1+a2+a3+a4+a5+a6+a7; }
   0:   8b 44 24 08             mov    0x8(%esp),%eax         ! 足し算
   4:   03 44 24 04             add    0x4(%esp),%eax
   8:   03 44 24 0c             add    0xc(%esp),%eax
   c:   03 44 24 10             add    0x10(%esp),%eax
  10:   03 44 24 14             add    0x14(%esp),%eax
  14:   03 44 24 18             add    0x18(%esp),%eax
  18:   03 44 24 1c             add    0x1c(%esp),%eax        ! 戻り値は"eax"に格納
  1c:   c3                      ret                           ! 呼び出し元へ戻る

0000001d 
: int main() { int rc = func(1,2,3,4,5,6,7); return rc; } 1d: 55 push %ebp ! 呼び出し元のpcをスタックに保存 1e: 89 e5 mov %esp,%ebp 20: 83 ec 28 sub $0x28,%esp ! 作業領域の確保 23: 83 e4 f0 and $0xfffffff0,%esp 26: b8 00 00 00 00 mov $0x0,%eax 2b: 29 c4 sub %eax,%esp 2d: c7 44 24 18 07 00 00 movl $0x7,0x18(%esp) ! 引数は全てスタックで 34: 00 35: c7 44 24 14 06 00 00 movl $0x6,0x14(%esp) 3c: 00 3d: c7 44 24 10 05 00 00 movl $0x5,0x10(%esp) 44: 00 45: c7 44 24 0c 04 00 00 movl $0x4,0xc(%esp) 4c: 00 4d: c7 44 24 08 03 00 00 movl $0x3,0x8(%esp) 54: 00 55: c7 44 24 04 02 00 00 movl $0x2,0x4(%esp) 5c: 00 5d: c7 04 24 01 00 00 00 movl $0x1,(%esp) 64: e8 fc ff ff ff call 65 ! 関数コール 69: 89 45 fc mov %eax,0xfffffffc(%ebp) ! 戻り値をスタックに保存 6c: 8b 45 fc mov 0xfffffffc(%ebp),%eax ! 戻り値は"eax"に格納 6f: c9 leave ! 呼び出し元へ戻る 70: c3 ret