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.

Jester
  • 56,577
  • 4
  • 81
  • 125
InYourDreams
  • 33
  • 1
  • 5
  • 4
    Your code has been compiled as position independent executable, probably due to a compiler default. You can try using the `-no-pie` switch. – Jester Jan 01 '18 at 00:25
  • 3
    Different versions of the compiler, different distros (different default options) will generate different code. If you want it to be exact you would have to use the exact version they did with the same version of the distro. – Michael Petch Jan 01 '18 at 00:25
  • If there were only one way to compile a program, there would be no need for benchmarking. – Raymond Chen Jan 01 '18 at 00:54
  • 1
    default-PIE sucks a lot for 32-bit code, because it can't use RIP-relative addressing modes. It has to use `__x86.get_pc_thunk.bx` to set EBX = EIP and use that as a base for PC-relative addressing of static data. See https://stackoverflow.com/questions/43367427/32-bit-absolute-addresses-no-longer-allowed-in-x86-64-linux for more about default-PIE (in 64-bit code). – Peter Cordes Jan 01 '18 at 01:00
  • Right okay. Thanks guys. Bit of a pain because the book explains what the stack pointer (esp) is doing at various parts. But in my case it's different. – InYourDreams Jan 01 '18 at 01:09

0 Answers0