Conditional jumps
| The jump family | |
| Signed versus unsigned | |
| The compare-then-jump pattern |
The jump family
Conditional jumps read the flags from the last CMP or arithmetic instruction. JE and JZ are the same jump (zero flag), as are JNE and JNZ:
cmp rax, rbx
je equal ; taken when rax = rbx
jne not_equal ; taken when rax != rbx
Signed versus unsigned
JG, JGE, JL, JLE compare signed values. JA, JAE, JB, JBE compare unsigned. The same bits mean different things in each reading, so pick the family that matches your data:
cmp rax, rbx
jg greater ; signed: rax > rbx
ja above ; unsigned: rax > rbx
The compare-then-jump pattern
The universal pattern is CMP then Jcc: compare first, branch second, and never put anything between them that could overwrite the flags. A jump target is a label, and the assembler picks the shortest encoding that reaches it.
Next: Loops
Article author: Arthur Isaev