Flags, Comparisons & Branches
cmp and the NZCV flags, conditional branches, compare-and-branch, csel, and writing loops.
Assembly has no if or while. Decisions are made in two steps: an instruction sets the condition flags, then a conditional instruction acts on them — a branch to a label, or a conditional select that picks one of two values without branching.
Decisions and loops
cmp x0, x1 computes x0 - x1 and sets the flags; csel x0, x0, x1, gt picks a value without a branch.
cbnz w2, 1b branches if w2 is not zero, without needing cmp; 1b means 'label 1, backwards'.
b.lt and b.ge are signed comparisons; b.lo and b.hs are their unsigned equivalents.
tst x0, #1 tests the lowest bit (AND without storing the result); add x0, x0, x0, lsl #1 computes 3n in one instruction.
Condition codes
cmp x0, x1 b.lt smaller // x0 and x1 hold unsigned sizes cmp x0, x1 b.lo smaller lt is a signed comparison: an unsigned value with the top bit set looks negative. Use lo/hs/hi/ls for unsigned values.
Which flags does cmp x0, x1 set when x0 == x1?
Z = 1 (result zero) and C = 1 (no borrow); N = 0, V = 0.