#include <stdio.h>
#include <stdlib.h>
int add(int a , int b){
int ret = 0;
ret = a + b;
return ret;
}
int minus(int a , int b){
int ret = 0;
ret = a - b;
return ret;
}
int main(){
int i = 100,j = 20;
printf("add %d\n",add(i,j));
printf("minus %d\n",minus(i,j));
return 0;
}
(gdb) disas add
Dump of assembler code for function add:
0x08048430 <+0>: push %ebp
0x08048431 <+1>: mov %esp,%ebp
0x08048433 <+3>: sub $0x10,%esp
0x08048436 <+6>: movl $0x0,-0x4(%ebp)
0x0804843d <+13>: mov 0xc(%ebp),%eax
0x08048440 <+16>: mov 0x8(%ebp),%edx
0x08048443 <+19>: add %edx,%eax
0x08048445 <+21>: mov %eax,-0x4(%ebp)
0x08048448 <+24>: mov -0x4(%ebp),%eax
0x0804844b <+27>: leave
0x0804844c <+28>: ret
(gdb) x/40x $sp
0xbffff098: 0xbffff000 0x080482bd 0x00008000 0x00000078
0xbffff0a8: 0xbffff0d8 0x0804849b 0x00000064 0x00000014
0xbffff0b8: 0xbffff17c 0x4e93a1ad 0x4eaba3c4 0x00001000
0xbffff0c8: 0x00000014 0x00000064 0x080484e0 0x00000000
0xbffff0d8: 0x00000000 0x4e921865 0x00000001 0xbffff174
0xbffff0e8: 0xbffff17c 0xb7ffe6b0 0x00000001 0x00000001
$sp = 0xbffff098
$fp = 0xbffff0a8
几个参数说明
$fp-4 本地参数
$fp 父函数fp
$fp+4 返回地址
$fp+8 传入参数