现在 的gcc -g 编译后objdump反汇编看的结果怎么是乱的?
int add_not_inline(int a, int b)
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 28 sub $0x28,%esp
int i, ret;
for (i = 0; i < 100; i++)
6: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
d: eb 19 jmp 28 <add_not_inline+0x28>
{
ret = ret*a + i*b;
f: 8b 45 f4 mov -0xc(%ebp),%eax
12: 0f af 45 08 imul 0x8(%ebp),%eax
16: 89 c2 mov %eax,%edx
18: 8b 45 f0 mov -0x10(%ebp),%eax
1b: 0f af 45 0c imul 0xc(%ebp),%eax
1f: 01 d0 add %edx,%eax
21: 89 45 f4 mov %eax,-0xc(%ebp)
int add_not_inline(int a, int b)
{
int i, ret;
for (i = 0; i < 100; i++)
24: 83 45 f0 01 addl $0x1,-0x10(%ebp)
28: 83 7d f0 63 cmpl $0x63,-0x10(%ebp)
2c: 7e e1 jle f <add_not_inline+0xf>
{
ret = ret*a + i*b;
}
printf ("ret = %u\r\n", ret);
2e: 8b 45 f4 mov -0xc(%ebp),%eax
31: 89 44 24 04 mov %eax,0x4(%esp)
35: c7 04 24 00 00 00 00 movl $0x0,(%esp)
3c: e8 fc ff ff ff call 3d <add_not_inline+0x3d>
return ret;
41: 8b 45 f4 mov -0xc(%ebp),%eax
}
44: c9 leave
45: c3 ret
00000046 <add_inline>:
int add_inline(int a, int b)
{
46: 55 push %ebp
47: 89 e5 mov %esp,%ebp
49: 83 ec 28 sub $0x28,%esp
int i, ret;
for (i = 0; i < 100; i++)
4c: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
53: eb 19 jmp 6e <add_inline+0x28>
{
ret = ret*a + i*b;
55: 8b 45 f4 mov -0xc(%ebp),%eax
58: 0f af 45 08 imul 0x8(%ebp),%eax
5c: 89 c2 mov %eax,%edx
5e: 8b 45 f0 mov -0x10(%ebp),%eax
61: 0f af 45 0c imul 0xc(%ebp),%eax
65: 01 d0 add %edx,%eax
67: 89 45 f4 mov %eax,-0xc(%ebp)
int add_inline(int a, int b)
{
int i, ret;
for (i = 0; i < 100; i++)
6a: 83 45 f0 01 addl $0x1,-0x10(%ebp)
6e: 83 7d f0 63 cmpl $0x63,-0x10(%ebp)
72: 7e e1 jle 55 <add_inline+0xf>
{
ret = ret*a + i*b;
}
printf ("ret = %u\r\n", ret);
74: 8b 45 f4 mov -0xc(%ebp),%eax
77: 89 44 24 04 mov %eax,0x4(%esp)
7b: c7 04 24 00 00 00 00 movl $0x0,(%esp)
82: e8 fc ff ff ff call 83 <add_inline+0x3d>
return ret;
87: 8b 45 f4 mov -0xc(%ebp),%eax
}
8a: c9 leave
8b: c3 ret
0000008c <main>:
int main(int cc, char *v[])
{
8c: 55 push %ebp
8d: 89 e5 mov %esp,%ebp
8f: 83 e4 f0 and $0xfffffff0,%esp
92: 83 ec 20 sub $0x20,%esp
int a, b;
int c, d;
a = 1;
95: c7 44 24 10 01 00 00 movl $0x1,0x10(%esp)
9c: 00
b = a*cc;
9d: 8b 44 24 10 mov 0x10(%esp),%eax
a1: 0f af 45 08 imul 0x8(%ebp),%eax
a5: 89 44 24 14 mov %eax,0x14(%esp)
printf ("b = %u\r\n", b);
a9: 8b 44 24 14 mov 0x14(%esp),%eax
ad: 89 44 24 04 mov %eax,0x4(%esp)
b1: c7 04 24 0b 00 00 00 movl $0xb,(%esp)
b8: e8 fc ff ff ff call b9 <main+0x2d>
c = 3;
bd: c7 44 24 18 03 00 00 movl $0x3,0x18(%esp)
c4: 00
d = a*cc;
c5: 8b 44 24 10 mov 0x10(%esp),%eax
c9: 0f af 45 08 imul 0x8(%ebp),%eax
cd: 89 44 24 1c mov %eax,0x1c(%esp)
c = add_not_inline(a, b);
d1: 8b 44 24 14 mov 0x14(%esp),%eax
d5: 89 44 24 04 mov %eax,0x4(%esp)
d9: 8b 44 24 10 mov 0x10(%esp),%eax
dd: 89 04 24 mov %eax,(%esp)
e0: e8 fc ff ff ff call e1 <main+0x55>
e5: 89 44 24 18 mov %eax,0x18(%esp)
d = add_inline(a, b);
e9: 8b 44 24 14 mov 0x14(%esp),%eax
ed: 89 44 24 04 mov %eax,0x4(%esp)
f1: 8b 44 24 10 mov 0x10(%esp),%eax
f5: 89 04 24 mov %e
源码
#include "stdio.h"
int add_not_inline(int a, int b)
{
int i, ret;
for (i = 0; i < 100; i++)
{
ret = ret*a + i*b;
}
printf ("ret = %u\r\n", ret);
return ret;
}
int add_inline(int a, int b)
{
int i, ret;
for (i = 0; i < 100; i++)
{
ret = ret*a + i*b;
}
printf ("ret = %u\r\n", ret);
return ret;
}
int main(int cc, char *v[])
{
int a, b;
int c, d;
a = 1;
b = a*cc;
printf ("b = %u\r\n", b);
c = 3;
d = a*cc;
c = add_not_inline(a, b);
d = add_inline(a, b);
printf ("d = %u %u\r\n", d, c);
return 0;
}
页:
[1]