Quiz Entry - updated: 2026.07.10
How does IA-32 pass arguments through the stack?
The caller pushes arguments onto the stack right-to-left just before the call, so the first argument ends up nearest the top (and at the lowest offset inside the callee).
In IA-32 there are no argument registers, so the caller stages every argument in memory. Pushing right-to-left means the first argument is pushed last and therefore sits closest to the return address.
void call_swap() { swap(&course1, &course2); }
call_swap:
subl $8, %esp # reserve space for 2 args
movl $course2, 4(%esp) # 2nd arg (pushed "higher")
movl $course1, (%esp) # 1st arg (lowest, nearest call)
call swap
Inside swap, after its push %ebp; mov %esp,%ebp prologue, the arguments are reached as positive offsets from %ebp:
movl 8(%ebp), %eax # 1st arg (xp)
movl 12(%ebp), %edx # 2nd arg (yp)
The layout from %ebp is fixed: 0 = saved %ebp, 4 = return address, 8 = first argument, 12 = second, and so on — a pattern you can rely on when reading 32-bit disassembly.
Go deeper:
x86 calling conventions (Wikipedia) — IA-32 stack argument order and cleanup conventions.