The Stack & Calling Conventions
Go deeper into how functions pass arguments, return values, and manage the stack frame, the knowledge that makes disassembled code readable.
The Stack & Calling Conventions is a free Reverse Engineering & Binary Analysis Basics lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Reverse Engineering & Binary Analysis Basics learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Beyond a Single Call
You can read basic x86/x64 instructions and follow control flow. To truly understand function calls you must know the stack and calling conventions.
These rules govern how arguments arrive and how cleanup happens.
What the Stack Is
The stack is a region of memory that grows downward (toward lower addresses). It stores return addresses, saved registers, and local variables.
pushdecrements RSP and writespopreads and increments RSP
push rax ; rsp -= 8, [rsp] = rax
pop rbx ; rbx = [rsp], rsp += 8RSP and RBP
Two registers track the stack:
- RSP (stack pointer) points to the current top
- RBP (base pointer) anchors the current frame
Locals are addressed relative to RBP, like [rbp-8].
The Function Prologue
Most functions begin with a prologue that sets up the frame: save the old base pointer, then point RBP at the new frame.
push rbp
mov rbp, rsp
sub rsp, 0x20 ; reserve 32 bytes for localsThe Function Epilogue
The epilogue reverses the prologue, restoring the caller's frame before returning.
mov rsp, rbp
pop rbp
retCalling Conventions
A calling convention is the contract for passing arguments and returning values.
- Where arguments go (registers or stack)
- Who cleans up the stack
- Which registers must be preserved
System V AMD64 (Linux x64)
On Linux x64 the first six integer arguments go in registers: rdi, rsi, rdx, rcx, r8, r9. The return value comes back in rax.
Extra arguments spill onto the stack.
; foo(1, 2, 3)
mov edi, 1
mov esi, 2
mov edx, 3
call fooMicrosoft x64 Convention
Windows x64 uses different registers: the first four arguments go in rcx, rdx, r8, r9, and the caller reserves 32 bytes of shadow space.
Recognizing the OS tells you which mapping to apply when reading arguments.
; Windows: bar(a, b)
mov rcx, a
mov rdx, b
sub rsp, 0x28 ; shadow space + alignment
call barCaller-Saved vs Callee-Saved
Some registers may be clobbered by a call (caller-saved), others must be preserved (callee-saved).
Seeing a function push rbx, rbp, and r12-r15 in its prologue is a strong hint about which registers it intends to use.
Reading Arguments in Practice
When you land in a function, mapping registers to arguments lets you label them. If the code reads rdi first on Linux, that is argument one.
This is how raw disassembly becomes readable pseudocode like send(sock, buf, len).
Stack-Passed Arguments
When a function has more arguments than the convention allows in registers, the extras are pushed onto the stack by the caller. The callee reads them at positive offsets from RBP, like [rbp+0x10].
Spotting these accesses helps you recover the full argument list.
; 7th System V argument
mov rax, [rbp+0x10]Quick Check
Under the System V AMD64 convention, which register holds the FIRST integer argument?
Recap
You can now decode function calls at the metal level:
- Stack grows down; RSP tops it, RBP anchors the frame
- Prologue/epilogue set up and tear down frames
- Calling conventions map registers to arguments (System V vs Microsoft x64)
This turns opaque disassembly into recognizable function signatures.
Frequently asked questions
Is the “The Stack & Calling Conventions” lesson free?
Yes — the full text of “The Stack & Calling Conventions” is free to read here on the web, and the Reverse Engineering & Binary Analysis Basics course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Reverse Engineering & Binary Analysis Basics course, upgrade to CoddyKit PRO.
What will I learn in “The Stack & Calling Conventions”?
Go deeper into how functions pass arguments, return values, and manage the stack frame, the knowledge that makes disassembled code readable. You practise Reverse Engineering & Binary Analysis Basics with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Reverse Engineering & Binary Analysis Basics?
No prior experience is required. Reverse Engineering & Binary Analysis Basics on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “The Stack & Calling Conventions” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Reverse Engineering & Binary Analysis Basics lesson?
Yes. Every Reverse Engineering & Binary Analysis Basics lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- x86/x64 Assembly Basics
- Registers and Memory Operations
- Control Flow and Function Calls
- The Stack & Calling Conventions