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 worksEach call pushes a return address; each function builds a frame below that. rsp points at the stack top; rbp anchors locals at fixed negative offsets. GDB backtraces, stack overflows, and ROP gadgets all read this layout.
nasmLoading…
[rbp-8], [rbp-16], etc.mov rsp, rbp; pop rbpcall for SSEStep through nested calls and watch rbp chain to older frames:
For this exercise, you will write functions with a standard prologue/epilogue and address locals through rbp. This task asks you to maintain 16-byte alignment across calls, because misaligned stacks surface as mysterious crashes inside libc printf on the next 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.
Write frame_demo in x86-64 NASM with a classic stack frame:
nasmLoading…
push rbp, mov rbp, rsp, then reserve space for two 8-byte locals with sub rsp, 16 (this also keeps rsp 16-byte aligned for the call below).[rbp - 8] and product = a * b at [rbp - 16].print_pair(sum, product), which the harness provides. It prints sum=S product=P and, like any function, may destroy every caller-saved register.[rbp - 8], return it, and leave with an epilogue (leave / ret, or mov rsp, rbp / pop rbp / ret).The locals are the point: anything you only keep in rax, rcx or rdx is gone after the call. The harness then prints return= and your result.
Two integers a and b.
cLoading…
for 3 4.
What call, the function prologue and ret do to memory on x86-64 Linux, one instruction group at a time.
Source
1int bar(int n) {2 return n + 1;3}5int foo(int a) {6 int b = a * 2;7 return bar(b);8}10int main(void) {11 int x = foo(21);◀ RIP12 return x;13}
Registers
lower addresses ↓ (the stack grows this way)
Step 1 of 10
main has its own frame: the address to return to, the caller's saved RBP, and room for x. RSP points at the lowest slot in use.