The Process Stack
Notes
- This is from Chapter 9 of Jorgensen.
- Draw the memory of a process on the board.
- A stack is the best solution we have found so far for function management.
- When we call a function, we place local variables on the stack.
- Along with other record keeping information
- When we return from a function, we remove this from the stack.
- The stack grows down from higher memory to lower memory
- So the data at the bottom of the stack have a higher address then the data at the top of the stack.
- This is upside down, but live with it.
- Intel assembly supports the stack with
-
push operand -
pop operand- Register or memory or address only, no immediate.
- Quadwords (8 bytes) only
- So push will move the top of the stack by -8 bytes
- And pop will move the top of the stack by 8 bytes.
-
- The
rspandrbpregisters are associated with the stack.- rsp holds the address of the top of the stack.
- push operand
-
rsp-= 8 memory[rsp] = operand
-
- We need to be exceedingly careful when using the stack.
- The linux calling convention expects the stack to be 16 byte aligned.
- Ie rsp % 16 = 0
- So we need to push a multiple of two if we are going to call a function
- Let's use the stack to reverse a string. (reverse.asm).