The Runtime Theory

Function Call Stack Lifecycle

The exact machine steps of a function call: argument registers, the call instruction, frame push with rbp and rsp, and the ret that restores the stack.

The Runtime Theory Team08 stages

trace / request.md

ARGUMENTSPLACED PER ABICALL PUSHES THERETURN ADDRESSPROLOGUE:FRAME SETUPBODY RUNSON THE FRAMERESULTWRITTEN TO RAXEPILOGUE:FRAME TEARDOWNRET POPS THERETURN ADDRESSCALLER RESUMES

readyThe caller moves the first six integer arguments into rdi, rsi, rdx, rcx, r8, r9 in ABI order. Extra arguments spill to stack slots above the return address. Nothing on the stack has changed yet.

A function call is a bookkeeping ritual executed by the hardware: arguments are staged in registers, the return address is pushed, a frame is carved out, and — at the end — everything is unwound in reverse. This diagram walks one call frame from the caller's perspective, instruction by instruction, showing rbp and rsp as they move. Each stage is a step a debugger would show you: argument setup, the call instruction, prologue, body, epilogue, ret, and the moment the caller's stack pointer is exactly where it started. The ordering matters because the frame contract depends on it — the callee must tear down precisely what it built, and the return address must be the last thing pushed and the first thing popped. Watch rsp throughout: every push has its matching pop, and the stack is byte-for-byte identical after the call returns.