Reputation:
I'm currently reading following blog to understand how to write assembler programs. I understand everything in a blog, but I can't figure one thing.
https://www.recurse.com/blog/7-understanding-c-by-learning-assembly
Code:
0x0000000100000f50 <main+0>: push %rbp
0x0000000100000f51 <main+1>: mov %rsp,%rbp
0x0000000100000f54 <main+4>: mov $0x0,%eax
0x0000000100000f59 <main+9>: movl $0x0,-0x4(%rbp)
I don't understand why we can write zero to -0x4(%rbp). On the line 1 we pushed pointer saved in register %rbp on a stack. Since %rbp register size is 64-bit I would later expect we would have to write zero to position -0x8(%rbp) in a stack and not -0x4(%rbp), which is only 4 bytes (32-bits).
Can anyone explain that?
Thanks in advance.
Upvotes: 3
Views: 875
Reputation: 33727
Since %rsp
and %rbp
are equal at this point, -0x4(%rbp)
is below the stack pointer, in the red zone. This is an area untouched by signal handlers (and debuggers), so it can be used even though it is below the stack pointer.
And the movl
instruction stores an int
, a 32-bit quantity, not a 64-bit machine word.
Upvotes: 3