文档详情

函数调用过程分析.pdf

发布:2017-06-08约字共11页下载文档
文本预览下载声明
1. 函数调用过程分析 1. 函数调用 我们用下面的代码来研究函数调用的过程。 例 19.1. 研究函数的调用过程 int bar(int c, int d) { int e = c + d; return e; } int foo(int a, int b) { return bar(a, b); } int main(void) { foo(2, 3); return 0; } 如果在编译时加上-g 选项(在第 10 章 gdb 讲过-g 选项),那么用objdump 反汇编时可以把C 代 码和汇编代码穿插起来显示,这样C 代码和汇编代码的对应关系看得更清楚。反汇编的结果很长, 以下只列出我们关心的部分。 $ gcc main.c -g $ objdump -dS a.out ... bar: int bar(int c, int d) { 8048394: 55 push %ebp 8048395: 89 e5 mov %esp,%ebp 8048397: 83 ec 10 sub $0x10,%esp int e = c + d; 804839a: 8b 55 0c mov 0xc(%ebp),%edx 804839d: 8b 45 08 mov 0x8(%ebp),%eax 80483a0: 01 d0 add %edx,%eax 80483a2: 89 45 fc mov %eax,-0x4(%ebp) return e; 80483a5: 8b 45 fc mov -0x4(%ebp),%eax } 80483a8: c9 leave 80483a9: c3 ret 080483aa foo: int foo(int a, int b) { 80483aa: 55 push %ebp 80483ab: 89 e5 mov %esp,%ebp 80483ad: 83 ec 08 sub $0x8,%esp return bar(a, b); 80483b0: 8b 45 0c mov 0xc(%ebp),%eax 80483b3: 89 44 24 04 mov %eax,0x4(%esp) 80483b7: 8b 45 08 mov 0x8(%ebp),%eax 80483ba: 89 04 24 mov %eax,(%esp) 80483bd: e8 d2 ff ff ff call 8048394 bar } 80483c2: c9 leave 80483c3: c3 ret 080483c4 main: int main(void) { 80483c4: 8d 4c 24 04 lea 0x4(%esp),%ecx 804
显示全部
相似文档