Master the fundamental concepts of x86 assembly (intel syntax) through this focused micro-challenge.
factorial(n) calls itself with n-1 until n <= 1. Each call allocates a fresh frame: saved rbp, return address, locals, saved registers. Deep recursion overflows the stack; tail-call optimization turns the pattern into a loop at -O2, which Compiler Explorer will show you later.
nasmLoading…
n; result returns in eaxcall because it is caller-savedcallIf you touch rbx or r12-r15, save and restore them in the prologue/epilogue.
For this exercise, you will implement recursive factorial in NASM with proper frames. This task asks you to multiply the returned eax by the saved n, because botching the stack turn is how "recursive assembly works once" demos fail on the second call.
Keep the relevant man page, ABI doc, or Rust reference chapter open while you work. When your output disagrees with the reference implementation on the same machine, the mismatch is usually an alignment rule, an off-by-one terminator, or a register slot you misread in GDB. Skim the official documentation for the tool or ABI named in the exercise; the prose changes, but register roles, syscall numbers, and ownership rules stay stable across releases.
Implement recursive factorial function in x86-64 assembly.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github