i have this c code:
#include <stdio.h>
int main()
{
int x = 10;
int y = 20;
int z = 30;
return 0;
}
when i compile it using gcc v4.8.5 & disassemble it using gdb
it gives
0x00000000004004f3 <+0>: push %rbp
0x00000000004004f4 <+1>: mov %rsp,%rbp
0x00000000004004f7 <+4>: movl $0xa,-0xc(%rbp)
0x00000000004004fe <+11>: movl $0x14,-0x8(%rbp)
0x0000000000400505 <+18>: movl $0x1e,-0x4(%rbp)
0x000000000040050c <+25>: mov $0x0,%eax
0x0000000000400511 <+30>: pop %rbp
0x0000000000400512 <+31>: retq
But when i disassemble it using godbolt(here) i get this output.
main:
pushq %rbp
movq %rsp, %rbp
movl $10, -4(%rbp) //---> offset for value 10 was 12 bytes from $rbp in the above version but here it is 4 bytes ?
movl $20, -8(%rbp)
movl $30, -12(%rbp)
movl $0, %eax
popq %rbp
ret
in both the outputs, there is the difference in the offset from $rbp
. addresses for variables in Godbolt assembly seems reversed. why is it so?is it just a compiler thing & machine dependent?