So I tried to debug my first program with gdb on the console. I was able to make sense of what has been put out, but I couldn't figure out why this address gets moved into the rcx register if it starts with bunch of 0's? So I tried to look further down the address line and the actual string appears 14 bytes off from the address that gets moved into the rcx register. But why? I know there is an address from GDB put there "0x404000" and that is actually the place where the string starts, but why doesn't this address get moved into the rcx register? I hope I get an answer here!
The source code:
#include <stdio.h>
int main()
{
int i;
for(i = 0; i < 10; ++i)
{
printf("Hello, world!\n");
}
}
Here is the disassembly of main:
Dump of assembler code for function main():
0x0000000000401550 <+0>: push rbp
0x0000000000401551 <+1>: mov rbp,rsp
0x0000000000401554 <+4>: sub rsp,0x30
0x0000000000401558 <+8>: call 0x401640 <__main>
0x000000000040155d <+13>: mov DWORD PTR [rbp-0x4],0x0
0x0000000000401564 <+20>: cmp DWORD PTR [rbp-0x4],0x9
0x0000000000401568 <+24>: jg 0x40157c <main()+44>
0x000000000040156a <+26>: lea rcx,[rip+0x2a8f] # 0x404000
0x0000000000401571 <+33>: call 0x402a70 <puts>
0x0000000000401576 <+38>: add DWORD PTR [rbp-0x4],0x1
0x000000000040157a <+42>: jmp 0x401564 <main()+20>
0x000000000040157c <+44>: mov eax,0x0
0x0000000000401581 <+49>: add rsp,0x30
0x0000000000401585 <+53>: pop rbp
0x0000000000401586 <+54>: ret
End of assembler dump.
0x403ff3: 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000'
0x403ffb: 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 72 'H' 101 'e' 108 'l'
0x404003: 108 'l' 111 'o' 44 ',' 32 ' ' 119 'w' 111 'o' 114 'r' 108 'l'
0x40400b: 100 'd' 33 '!'