AsAssembly · Lesson 6 of 10
The Stack & Functions
The stack is how functions store local variables and return addresses. `push` and `pop` move data on and off it. Understanding the stack is the key to understanding function calls, recursion, and most security vulnerabilities.
⚠ Warning
The stack must be 16-byte aligned before any `call` instruction — the ABI requires it for SSE/AVX instructions. A `call` pushes 8 bytes (return address), so rsp becomes misaligned by 8 inside a function. The standard prologue (`push rbp; mov rbp, rsp`) restores alignment because push is another 8 bytes (8+8=16). If you skip the prologue, align manually: `sub rsp, 8` before calling external functions.
The stack must be 16-byte aligned before any `call` instruction — the ABI requires it for SSE/AVX instructions. A `call` pushes 8 bytes (return address), so rsp becomes misaligned by 8 inside a function. The standard prologue (`push rbp; mov rbp, rsp`) restores alignment because push is another 8 bytes (8+8=16). If you skip the prologue, align manually: `sub rsp, 8` before calling external functions.