<<< Parity Jumps | Index | Jumps Based on Bit Settings >>> |
The CMP instruction is a common way to test for conditional jumps.
CMP instruction is the same as the SUB instruction, except that CMP does not change the destination operand. Both set flags according to the result of the subtraction.
CMP compares signed or unsigned values, but program must choose appropriate conditional jump to reflect the correct type.
Failure to understand the difference between conditional jump instructions may result in program bugs.
Signed Comparisons | Unsigned Comparisons | ||
---|---|---|---|
Instruction | Jump if True | Instruction | Jump if True |
JE | ZF = 1 | JE | ZF = 1 |
JNE | ZF = 0 | JNE | ZF = 0 |
JG/JNLE | ZF = 0 and SF = OF | JA/JNBE | CF = 0 and ZF = 0 |
JLE/JNG | ZF = 1 or SF OF | JBE/JNA | CF = 1 or ZF = 1 |
JL/JNGE | SF OF | JB/JNAE | CF = 1 |
JGE/JNL | SF = OF | JAE/JNB | CF = 0 |
<<< Parity Jumps | Index | Jumps Based on Bit Settings >>> |