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 worksAArch64 compares with cmp (subtract, discard result) and branches with b.eq, b.lt, b.ge, etc. SUBS both subtracts and updates flags, which pairs cleanly with b.ne for decrement loops. Mispredicted branches still cost 15+ cycles on modern cores, so tight loop shape matters on every phone frame.
asmLoading…
Signed compares use b.lt / b.gt; unsigned sizes use b.lo / b.hi.
The counter walks down to zero; the accumulator picks up each value. N=0 should skip the body and return zero in x0.
For this exercise, you will implement the sum loop with cmp/b only (no C helpers). This task asks you to return the total in x0 per AAPCS64, because every Android JNI stub and iOS assembly thunk ends with that register holding the scalar result.
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 sum_to_n in AArch64 assembly: return 1 + 2 + ... + N with a loop.
asmLoading…
subs (subtract and set the flags) and loop with a conditional branch such as b.ne, or compare with cmp and branch with b.lt / b.ge.stp/ldp), because the harness keeps its own state there. A function that calls another with bl must save x30 (the return address) first.The harness reads N, calls sum_to_n, and prints the result.
One integer N, 0 <= N <= 1000000.
The sum on one line: 15 for N = 5.
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.