4 ms·
FWIW, the stack grows downwards and push decrements the stack pointer.
by atq2119 4y ago
FWIW, the stack grows downwards and push decrements the stack pointer.
- robocat 4y agoAnd user netch on stack overflow wrote this which explains more: notice also there is a 128-byte space ("red zone") before %rsp that keeps its contents between function calls but preserved by OS during interrupts. So, very temporary values (between function calls) can be used with negative offsets to %rsp. Not all compilers utilize this. About this code (note opposite order of register movement - there are two main styles of displaying x86 assembly code): pushq %rbp movq %rsp, %rbp subq $16, %rsp the comment was: Compiler allocates some space for local values on function enter. That's why it subtracts value from %rsp on enter. This doesn't depend on whether %rbp is used as frame pointer. After that, this place is used with positive offsets upon %rsp. Also, if this function calls another one, %rsp shall be aligned on 16-byte boundary for each call, so, in that case compiler shall subtract 8 from %rsp on each enter.