为什么这两个相同的hello world.c反汇编有所不同?

时间:2018-01-01 00:21:53

标签: assembly x86

这些之间的唯一区别是迭代次数。

下面是我的,下面是我正在阅读的书中的汇编代码。我也看过同一个hello世界的其他反汇编代码,它们与本书相同。 我的hello world似乎比其他例子有更多的命令......这些更容易理解。

我一直在使用gcc和gdb。

lubuntu@lubuntu:~/Documents/aoe$ gcc -g helloworld.c
lubuntu@lubuntu:~/Documents/aoe$ gdb -q ./a.out
Reading symbols from ./a.out...done.
warning: File "/home/lubuntu/Documents/aoe/.gdbinit" auto-loading has       
been declined by your auto-load safe-path' set to      
"$debugdir:$datadir/auto-load".
To enable execution of this file add
add-auto-load-safe-path /home/lubuntu/Documents/aoe/.gdbinit
line to your configuration file "/home/lubuntu/.gdbinit".
To completely disable this security protection add
set auto-load safe-path /
line to your configuration file "/home/lubuntu/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the      
shell:
info "(gdb)Auto-loading safe path"
(gdb) list
1   #include <stdio.h>
2   
3   int main()
4   {
5   int i;
6   for(i=0; i < 7; i++)
7   {
8       printf("Hello, world!\n");
9   }
10  return 0;
(gdb) break main
Breakpoint 1 at 0x53a: file helloworld.c, line 6.
(gdb) disass main
Dump of assembler code for function main:
0x0000051d <+0>:    lea    ecx,[esp+0x4]
0x00000521 <+4>:    and    esp,0xfffffff0
0x00000524 <+7>:    push   DWORD PTR [ecx-0x4]
0x00000527 <+10>:   push   ebp
0x00000528 <+11>:   mov    ebp,esp
0x0000052a <+13>:   push   ebx
0x0000052b <+14>:   push   ecx
0x0000052c <+15>:   sub    esp,0x10
0x0000052f <+18>:   call   0x420 <__x86.get_pc_thunk.bx>
0x00000534 <+23>:   add    ebx,0x1aa4
0x0000053a <+29>:   mov    DWORD PTR [ebp-0xc],0x0
0x00000541 <+36>:   jmp    0x559 <main+60>
0x00000543 <+38>:   sub    esp,0xc
0x00000546 <+41>:   lea    eax,[ebx-0x19e8]
0x0000054c <+47>:   push   eax
0x0000054d <+48>:   call   0x3b0 <puts@plt>
0x00000552 <+53>:   add    esp,0x10
0x00000555 <+56>:   add    DWORD PTR [ebp-0xc],0x1
0x00000559 <+60>:   cmp    DWORD PTR [ebp-0xc],0x6 
0x0000055d <+64>:   jle    0x543 <main+38>
0x0000055f <+66>:   mov    eax,0x0
0x00000564 <+71>:   lea    esp,[ebp-0x8]
---Type <return> to continue, or q <return> to quit---Quit
(gdb) Quit
(gdb)`

这是一个与书籍完全相同的例子。 (我显然无法嵌入图像。) 这个有一个指针 - mov DWORD PTR [esp],0x80484b0 我没有这个,但在我见过的所有例子中都有。

hello world assembly

任何帮助将不胜感激。

0 个答案:

没有答案