Class 02 · KP 13 / 23
Comparison and Branching
cmp eax, 10 ; compute eax - 10, set flags, discard result
test eax, eax ; AND eax with itself, set flags (is it zero?)
je label ; jump if equal (ZF=1)
jne label ; jump if not equal (ZF=0)
jg label ; jump if greater (signed)
jl label ; jump if less (signed)
ja label ; jump if above (unsigned)
jmp label ; unconditional jump
cmp/test set flags; the jcc that follows reads them.test eax, eax + je is the classic "if (x == 0)" check.- Signed (
jg/jl) vs unsigned (ja/jb) reveals the C variable's signedness.