%esp
contains the stack pointer,%ebp
contains the frame pointer,%eax
contains the return value, and%ebx
, %esi
, and %edi
are callee-save registers.Additionally:
%esp
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 (4 bytes). When the return stack pointer is then pushed onto the stack in the function prologue, the stack then becomes misaligned by two words (8 bytes).
Further pushes should occur in pairs or should be resolved using a sub
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. As the callee removes arguments from the stack upon return, the stack may be misaligned when a function is returned from. It is the responsibility of the caller to re-align the stack if this occurs.
%ebp
onto the stack,%esp
into %ebp
push %ebp mov %esp, %ebp // re-align to 16-bytes sub $0x8, %esp
leave
ret
Arguments are passed on the stack in %ebp+4+(4 * n)
(between the return address and the return frame pointer).