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 worksArithmetic on x86 sets condition flags in RFLAGS. cmp eax, ebx subtracts for comparison without storing; test ANDs for zero checks. Conditional jumps (jg, jl, ja, jb, ...) read those bits. Spectre-class bugs live in mispredicted branches, so knowing signed vs unsigned jumps matters.
| Flag | Meaning |
|---|---|
| ZF | Result was zero |
| SF | Result negative (MSB set) |
| CF | Unsigned borrow/overflow |
| OF | Signed overflow |
nasmLoading…
Use jl/jg for signed ints; jb/ja for unsigned sizes.
For this exercise, you will implement find_max and absolute_value with conditional jumps only. This task asks you to pick the correct jump family, because mixing signed and unsigned compares is a subtle security and correctness bug in hand-written assembly.
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. Treat each failure as a contract test: the CPU, kernel, and borrow checker enforce rules whether or not the tutorial mentioned them explicitly.
cmp a, b computes a - b, throws the result away, and sets the flags. Which jump you use after it decides what the comparison means. Write three functions in x86-64 NASM:
nasmLoading…
compare uses the signed jumps (jl, jg), ucompare the unsigned ones (jb, ja). The same bits can compare differently: -1 is less than 1 signed, but as unsigned it is 2^64 - 1, above 1.flags_after_cmp returns the zero flag in bit 0 and the sign flag in bit 1. setz and sets copy a flag into a byte register.One line: cmp A B, ucmp A B or flags A B, with signed 64-bit integers.
cmp and ucmp: LT, EQ or GT.flags: ZF=z SF=s, for example ZF=1 SF=0 for flags 4 4.