x86-64 Assembly: Local Variables, Stack Frames & Alignment Explained

x86-64 Assembly: Local Variables, Stack Frames & Alignment Explained

Learn how local variables are allocated on the stack in x86-64 assembly using YASM. See exactly how to reserve space, address variables with offsets, understand downward stack growth, and fix mysterious printf segfaults caused by 16-byte stack misalignment. Includes two alignment solutions and a complete working example with a local integer array.
The Call Stack Explained: Call Frames, Return Addresses, Local Variables

The Call Stack Explained: Call Frames, Return Addresses, Local Variables

The call stack is a special stack data structure that your computer uses to manage function calls. Every time a function is called, a call frame is pushed onto the stack containing the return address, function arguments (beyond what fits in registers), preserved registers, and space for local variables. When the function returns, its call frame is popped and execution jumps back to the return address - this is how your program knows exactly where to continue after a function finishes.