Why are these two identical hello world.c disassemblies different?

0

The only difference between these is the number of iterations.

Below is mine and below that is the assembly code from the book I'm reading. I've also seen other disassembly code of the same hello world and they are the same to the book. My hello world seems to have more commands than the other examples...which are easier to understand.

I've been using gcc and 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)`

Here is an example that is exactly the same as the books. (I'm unable to embed images apparently.) This one has a pointer - mov DWORD PTR [esp],0x80484b0 I don't have this in mine, but in all the example I've seen it does.

hello world assembly

any help would be appreciated.

assembly
x86
asked on Stack Overflow Jan 1, 2018 by InYourDreams • edited Jan 1, 2018 by Jester

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0