%rsp
contains the stack pointer,%rbp
contains the frame pointer,%rax
contains the return value, and%rbx
and %r12
to %r15
are callee-save registers.Additionally:
%rsp
mod 16 == 0.In order to ensure tha alignment is maintained at a 16-byte alignment, the stack may need to be manually aligned after function entry.
When a function is entered via call
, the return address is implicitly pushed onto the stack, misaligning it by one word (8 bytes). When the return stack pointer is then pushed onto the stack in the function prologue, the stack is re-aligned.
Further pushes should occur in pairs or should be resolved using a subq
instruction to re-align the stack to 16 bytes.
It is also the responsibility of the caller to ensure that when a function is called that the stack remains aligned to 16-bytes up to the call
instruction.
%rbp
onto the stack,%rsp
into %rbp
push %rbp mov %rsp, %rbp // This will already be aligned to 16 bytes due to the empty stack // frame. // subq $0x0, %rsp
leave
ret
Arguments are passed first using registers %rdi
, %rsi
, %rdx
, %rcx
, %r8
, %r9
, %xmm0
–%xmm7
, then on the stack in %rbp+8+(8 * n)