Master the fundamental concepts of x86 assembly (intel syntax) through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksglibc syscall stubs, OpenSSL AES-NI kernels, and ffmpeg SIMD paths are assembly called from C. The linker only cares that both sides agree on symbol names and the System V AMD64 ABI: args in rdi/rsi/..., return in rax, 16-byte stack alignment at the call site.
cLoading…
nasmLoading…
extern; NASM exports globaledi/esi for 32-bit int args in the cdecl/System V mix you see in starter codegcc main.c add.o -o prog (no underscore prefix on Linux x86-64)For this exercise, you will write the assembly adder and call it from C. This task asks you to verify the return in rax, because a one-register mistake here is indistinguishable from "C is broken" until you disassemble the call site.
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.
C code calls assembly all the time: crypto kernels, memcpy, startup code. Write the assembly side of
cLoading…
in x86-64 NASM, following the System V AMD64 ABI that the C compiler assumes:
int arguments arrive in the low 32 bits of rdi and rsi (edi, esi).int result goes in eax. The caller reads only those 32 bits and sign-extends them, exactly as the harness does, so the upper half of rax does not matter.The harness plays the C caller: it reads a and b, calls add_numbers, and prints Result: and the int it got back.
Two integers a and b on one line. Their sum fits in an int.
Result: and the sum, for example Result: 30 for 10 20.