我的代码如下:
- #include
- int pluss_a_and_b(int a,int b)
- {
- int c = -2;
- return (a + b - c);
- }
- int call_plus(int *a,int *b)
- {
- int c = *a;
- int d = *b;
- *a = d;
- *b = c;
- return pluss_a_and_b(c,d);
- }
- int main()
- {
- int c = 10;
- int d = 20;
- int g = call_plus(&c,&d);
- return 0;
- }
- ...
- 8048393: c3 ret
- 08048394
: - #include
- int pluss_a_and_b(int a,int b)
- {
- 8048394: 55 push %ebp
- 8048395: 89 e5 mov %esp,%ebp
- 8048397: 83 ec 10 sub $0x10,%esp
- int c = -2;
- 804839a: c7 45 fc fe ff ff ff movl $0xfffffffe,-0x4(%ebp)
- return (a + b - c);
- 80483a1: 8b 45 0c mov 0xc(%ebp),%eax
- 80483a4: 8b 55 08 mov 0x8(%ebp),%edx
- 80483a7: 8d 04 02 lea (%edx,%eax,1),%eax
- 80483aa: 2b 45 fc sub -0x4(%ebp),%eax
- }
- 80483ad: c9 leave
- 80483ae: c3 ret
- 080483af
: - int call_plus(int *a,int *b)
- {
- 80483af: 55 push %ebp
- 80483b0: 89 e5 mov %esp,%ebp
- 80483b2: 83 ec 18 sub $0x18,%esp
- int c = *a;
- 80483b5: 8b 45 08 mov 0x8(%ebp),%eax
- 80483b8: 8b 00 mov (%eax),%eax
- 80483ba: 89 45 fc mov %eax,-0x4(%ebp)
- int d = *b;
- 80483bd: 8b 45 0c mov 0xc(%ebp),%eax
- 80483c0: 8b 00 mov (%eax),%eax
- 80483c2: 89 45 f8 mov %eax,-0x8(%ebp)
- *a = d;
- 80483c5: 8b 45 08 mov 0x8(%ebp),%eax
- 80483c8: 8b 55 f8 mov -0x8(%ebp),%edx
- 80483cb: 89 10 mov %edx,(%eax)
- *b = c;
- 80483cd: 8b 45 0c mov 0xc(%ebp),%eax
- 80483d0: 8b 55 fc mov -0x4(%ebp),%edx
- 80483d3: 89 10 mov %edx,(%eax)
- return pluss_a_and_b(c,d);
- 80483d5: 8b 45 f8 mov -0x8(%ebp),%eax
- 80483d8: 89 44 24 04 mov %eax,0x4(%esp)
- 80483dc: 8b 45 fc mov -0x4(%ebp),%eax
- 80483df: 89 04 24 mov %eax,(%esp)
- 80483e2: e8 ad ff ff ff call 8048394
- }
- 80483e7: c9 leave
- 80483e8: c3 ret
- 080483e9
: - int main()
- {
- 80483e9: 55 push %ebp
- 80483ea: 89 e5 mov %esp,%ebp
- 80483ec: 83 ec 18 sub $0x18,%esp
- int c = 10;
- 80483ef: c7 45 f8 0a 00 00 00 movl $0xa,-0x8(%ebp)
- int d = 20;
- 80483f6: c7 45 f4 14 00 00 00 movl $0x14,-0xc(%ebp)
- int g = call_plus(&c,&d);
- 80483fd: 8d 45 f4 lea -0xc(%ebp),%eax
- 8048400: 89 44 24 04 mov %eax,0x4(%esp)
- 8048404: 8d 45 f8 lea -0x8(%ebp),%eax
- 8048407: 89 04 24 mov %eax,(%esp)
- 804840a: e8 a0 ff ff ff call 80483af
- 804840f: 89 45 fc mov %eax,-0x4(%ebp)
- return 0;
- 8048412: b8 00 00 00 00 mov $0x0,%eax
- }
- 8048417: c9 leave
- 8048418: c3 ret
- 8048419: 90 nop
- 804841a: 90 nop
- ...
}
80483e7: c9 leave
80483ea: 89 e5 mov %esp,%ebp
80483ec: 83 ec 18 sub $0x18,%esp
- #include
- typedef struct {
- double d;
- float f;
- int i;
- char c;
- }return_value;
- return_value my_test_of_return()
- {
- return_value rv;
-
- rv.d = 12.56;
- rv.f = 3.1;
- rv.i = 10;
- rv.c = 'a';
- return rv;
- }
- int main()
- {
- return_value local = my_test_of_return();
- return 0;
- }
[gong@Gong-Computer deeplearn]$ objdump -S -d structpass > structpass_s
- ...
- 08048394
: - char c;
- }return_value;
- return_value my_test_of_return()
- {
- 8048394: 55 push %ebp
- 8048395: 89 e5 mov %esp,%ebp
- 8048397: 83 ec 20 sub $0x20,%esp
- 804839a: 8b 45 08 mov 0x8(%ebp),%eax
- return_value rv;
- rv.d = 12.56;
- 804839d: dd 05 d8 84 04 08 fldl 0x80484d8
- 80483a3: dd 5d e8 fstpl -0x18(%ebp)
- rv.f = 3.1;
- 80483a6: ba 66 66 46 40 mov $0x40466666,%edx
- 80483ab: 89 55 f0 mov %edx,-0x10(%ebp)
- rv.i = 10;
- 80483ae: c7 45 f4 0a 00 00 00 movl $0xa,-0xc(%ebp)
- rv.c = 'a';
- 80483b5: c6 45 f8 61 movb $0x61,-0x8(%ebp)
- return rv;
- 80483b9: 8b 55 e8 mov -0x18(%ebp),%edx
- 80483bc: 89 10 mov %edx,(%eax)
- 80483be: 8b 55 ec mov -0x14(%ebp),%edx
- 80483c1: 89 50 04 mov %edx,0x4(%eax)
- 80483c4: 8b 55 f0 mov -0x10(%ebp),%edx
- 80483c7: 89 50 08 mov %edx,0x8(%eax)
- 80483ca: 8b 55 f4 mov -0xc(%ebp),%edx
- 80483cd: 89 50 0c mov %edx,0xc(%eax)
- 80483d0: 8b 55 f8 mov -0x8(%ebp),%edx
- 80483d3: 89 50 10 mov %edx,0x10(%eax)
- }
- 80483d6: c9 leave
- 80483d7: c2 04 00 ret $0x4
- 080483da
: - int main()
- {
- 80483da: 8d 4c 24 04 lea 0x4(%esp),%ecx
- 80483de: 83 e4 f8 and $0xfffffff8,%esp
- 80483e1: ff 71 fc pushl -0x4(%ecx)
- 80483e4: 55 push %ebp
- 80483e5: 89 e5 mov %esp,%ebp
- 80483e7: 51 push %ecx
- 80483e8: 83 ec 2c sub $0x2c,%esp
- return_value local = my_test_of_return();
- 80483eb: 8d 45 e0 lea -0x20(%ebp),%eax
- 80483ee: 89 04 24 mov %eax,(%esp)
- 80483f1: e8 9e ff ff ff call 8048394
- 80483f6: 83 ec 04 sub $0x4,%esp
- return 0;
- 80483f9: b8 00 00 00 00 mov $0x0,%eax
- }
- 80483fe: 8b 4d fc mov -0x4(%ebp),%ecx
- 8048401: c9 leave
- 8048402: 8d 61 fc lea -0x4(%ecx),%esp
- ...
- #include
- typedef struct {
- double d;
- float f;
- int i;
- char c;
- }return_value;
- return_value my_test_pass(return_value pass)
- {
- return_value rv;
- rv.d = pass.d;
- rv.f = pass.f;
- rv.i = pass.i;
- rv.c = pass.c;
- return rv;
- }
- return_value my_test_of_return()
- {
- return_value rv;
-
- rv.d = 12.56;
- rv.f = 3.1;
- rv.i = 10;
- rv.c = 'a';
- return rv;
- }
- int main()
- {
- return_value local = my_test_of_return();
- return_value local1 = my_test_pass(local);
- return 0;
- }
[gong@Gong-Computer deeplearn]$ objdump -S -d structpass > structpass_s
- ...
- int main()
- {
- 804841d: 8d 4c 24 04 lea 0x4(%esp),%ecx
- 8048421: 83 e4 f8 and $0xfffffff8,%esp
- 8048424: ff 71 fc pushl -0x4(%ecx)
- 8048427: 55 push %ebp
- 8048428: 89 e5 mov %esp,%ebp
- 804842a: 51 push %ecx
- 804842b: 83 ec 4c sub $0x4c,%esp
- return_value local = my_test_of_return();
- 804842e: 8d 45 e0 lea -0x20(%ebp),%eax
- 8048431: 89 04 24 mov %eax,(%esp)
- 8048434: e8 9e ff ff ff call 80483d7
- 8048439: 83 ec 04 sub $0x4,%esp
- return_value local1 = my_test_pass(local);
- 804843c: 8d 45 c8 lea -0x38(%ebp),%eax
- 804843f: 8b 55 e0 mov -0x20(%ebp),%edx
- 8048442: 89 54 24 04 mov %edx,0x4(%esp)
- 8048446: 8b 55 e4 mov -0x1c(%ebp),%edx
- 8048449: 89 54 24 08 mov %edx,0x8(%esp)
- 804844d: 8b 55 e8 mov -0x18(%ebp),%edx
- 8048450: 89 54 24 0c mov %edx,0xc(%esp)
- 8048454: 8b 55 ec mov -0x14(%ebp),%edx
- 8048457: 89 54 24 10 mov %edx,0x10(%esp)
- 804845b: 8b 55 f0 mov -0x10(%ebp),%edx
- 804845e: 89 54 24 14 mov %edx,0x14(%esp)
- 8048462: 89 04 24 mov %eax,(%esp)
- 8048465: e8 2a ff ff ff call 8048394
- 804846a: 83 ec 04 sub $0x4,%esp
- return 0;
- 804846d: b8 00 00 00 00 mov $0x0,%eax
- }
从上面的分析我们可以发现汇编代码是非常有用的,建议多参看汇编代码分析具体的问题。
上一篇:C/C++中宏定义的经典运用
下一篇:UCOS操作系统堆栈浅谈
推荐阅读最新更新时间:2024-03-16 14:00