Master the fundamental concepts of arm assembly (aarch64) 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 worksfib(n) needs both fib(n-1) and fib(n-2) unless you memoize. In assembly each bl clobbers x0 and overwrites lr, so you must spill live values to callee-saved registers or the stack. iOS and Android crash reports show these frames as repeated fib symbols when students forget to save lr.
asmLoading…
n <= 1 returns n in x0blFor this exercise, you will implement recursive fib without loops. This task asks you to save lr before every recursive bl, because leaf-vs-non-leaf distinction is the first thing arm64 unwinders check when a stack trace looks truncated.
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 a recursive Fibonacci in AArch64 assembly:
asmLoading…
stp x29, x30, [sp, #-32]!), plus the callee-saved registers you keep n and fib(n - 1) in, and restore them before ret.stp/ldp), because the harness keeps its own state there. A function that calls another with bl must save x30 (the return address) first.One integer n, 0 <= n <= 25.
fib(n) on one line: 55 for 10.
ARM code is not run on this site yet. Submit completes the task once your code assembles for AArch64 and still declares and defines every .global symbol in the starter. The tests below show exactly what a correct program prints, so you can run it yourself: aarch64-linux-gnu-as, aarch64-linux-gnu-ld and qemu-aarch64, or natively on an ARM Linux machine.