Overview
A number of instructions operate with respect to the condition code registers.
The conventional way to implement conditional operationsis through a conditional transfer of control, where the program follows one execution path when a condition holds and another when it does not.
An alternate strategy is through a conditional transfer of data. This approach computes both outcomes of a conditional operation and then selects one based on whether or not the condition holds.
Instructions
CMP and TEST
| Instruction | Operands | Based On | Description | 
|---|---|---|---|
| cmp[bwlq] | Compare | ||
| test[bwlq] | Test | 
SET
The description of the SET commands apply to the case of a comparison instruction. That is, the condition codes are set according to computation t = a - b, where t, a, and b may be interpreted as signed or unsigned depending on the SET instruction invoked.
| Instruction | Synonym | Evaluation | Description | 
|---|---|---|---|
| sete | setz | ZF | Equal / zero | 
| setne | setnz | ~ZF | Not equal / not zero | 
| sets | SF | Negative | |
| setns | ~SF | Nonnegative | |
| setl | setnge | SF ^ OF | Less (signed <) | 
| setle | setng | (SF ^ OF) | ZF | Less or equal (signed <=) | 
| setg | setnle | ~(SF ^ OF) & ~ZF | Greater (signed >) | 
| setge | setnl | ~(SF ^ OF) | Greater or equal (signed >=) | 
| setb | setnae | CF | Below (unsigned <) | 
| setbe | setna | CF | ZF | Below or equal (unsigned <=) | 
| seta | setnbe | ~CF & ~ZF | Above (unsigned >) | 
| setae | setnb | ~CF | Above or equal (unsigned >=) | 
Note how the other condition code evaluations are easy to derive from setl and setb.
JMP
Jump instructions are categorized as either direct or indirect. Direct jump instructions specify a label whereas indirect jump instructions specify a * followed by an memory operand.
| Instruction | Synonym | Jump Condition | Description | 
|---|---|---|---|
| jmpLabel | - | 1 | Direct jump | 
| jmp*Operand | - | 1 | Indirect jump | 
| jeLabel | jz | ZF | Equal / zero | 
| jneLabel | jnz | ~ZF | Not equal / not zero | 
| jsLabel | - | SF | Negative | 
| jnsLabel | - | ~SF | Nonnegative | 
| jlLabel | jnge | SF ^ OF | Less (signed <) | 
| jleLabel | jng | (SF ^ OF) | ZF | Less or equal (signed <=) | 
| jgLabel | jnle | ~(SF ^ OF) & ~ZF | Greater (signed >) | 
| jgeLabel | jnl | ~(SF ^ OF) | Greater or equal (signed >=) | 
| jbLabel | jnae | CF | Below (unsigned <) | 
| jbeLabel | jna | CF | ZF | Below or equal (unsigned <=) | 
| jaLabel | jnbe | ~CF & ~ZF | Above (unsigned >) | 
| jaeLabel | jnb | ~CF | Above or equal (unsigned >=) | 
CMOV
Like MOV instructions, but with the data transfer only happening if the move condition is satisfied.
| Instruction | Synonym | Move Condition | Description | 
|---|---|---|---|
| cmove | cmovz | ZF | Equal / zero | 
| cmovene | cmovnz | ~ZF | Not equal / not zero | 
| cmovs | - | SF | Negative | 
| cmovns | - | ~SF | Nonnegative | 
| cmovl | cmovnge | SF ^ OF | Less (signed <) | 
| cmovle | cmovng | (SF ^ OF) | ZF | Less or equal (signed <=) | 
| cmovg | cmovenle | ~(SF ^ OF) & ~ZF | Greater (signed >) | 
| cmovge | cmovnl | ~(SF ^ OF) | Greater or equal (signed >=) | 
| cmovb | cmovnae | CF | Below (unsigned <) | 
| cmovbe | cmovna | CF | ZF | Below or equal (unsigned <=) | 
| cmova | cmovnbe | ~CF & ~ZF | Above (unsigned >) | 
| cmovae | cmovnb | ~CF | Above or equal (Unsigned >=) | 
Bibliography
- Bryant, Randal E., and David O’Hallaron. Computer Systems: A Programmer’s Perspective. Third edition, Global edition. Always Learning. Pearson, 2016.