Status: Tags: Links: Computer Memory
Memory Stack
Principles
x86-64 Assembly
- initially empty
- has stack-specific instructions and register
%rsp
- points to address of last used byte on stack
- initialized to “top of stack” at startup
- stack grows towards low memory address
- Should always go back to original position after end of function
push* src
src
can be- imm
- register
- memory
- execution
- get value of operand src
- decrement %rsp by 8 as you need to go down the stack
- store value at (memory adress stored in) %rsp
%rsp
is an implicit register
pop* dest
dest
can be- register
- execution
- read value at (memory adress stored in) %rsp and load this value in operand dest
- increment %rsp by 8
%rsp
is implicit register
Uses
Store local variables Steps:
- Setup code to create space on stack
subq $16, %rsp
- Spill onto stack
- `movq %rax, 8(%rsp)
- Clean-up code (restore stack)
addq $16 %rsp
References:
Created:: 2022-02-12 16:11