Master the fundamental concepts of x86 assembly (intel syntax) through this focused micro-challenge.
Calling conventions are the contract between separately compiled functions. On x86-64 Linux, the System V AMD64 ABI passes the first six integer/pointer args in rdi, rsi, rdx, rcx, r8, r9 and returns scalars in rax. Python ctypes, Rust extern "C", and JNI all assume these slots.
nasmLoading…
Before call, rsp must be 16-byte aligned. The call itself pushes 8 bytes, which is why prologues often subtract another 8 bytes of stack space.
Seventh and later arguments spill to the stack in order.
For this exercise, you will implement add_numbers and recursive factorial obeying these rules. This task asks you to read arguments from rdi/rsi and return in rax, because GDB backtraces and FFI bugs are unreadable without this map.
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 functions following x86-64 calling conventions.
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