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 |
---|---|---|---|
jmp Label | - | 1 | Direct jump |
jmp *Operand | - | 1 | Indirect jump |
je Label | jz | ZF | Equal / zero |
jne Label | jnz | ~ZF | Not equal / not zero |
js Label | - | SF | Negative |
jns Label | - | ~SF | Nonnegative |
jl Label | jnge | SF ^ OF | Less (signed < ) |
jle Label | jng | (SF ^ OF) | ZF | Less or equal (signed <= ) |
jg Label | jnle | ~(SF ^ OF) & ~ZF | Greater (signed > ) |
jge Label | jnl | ~(SF ^ OF) | Greater or equal (signed >= ) |
jb Label | jnae | CF | Below (unsigned < ) |
jbe Label | jna | CF | ZF | Below or equal (unsigned <= ) |
ja Label | jnbe | ~CF & ~ZF | Above (unsigned > ) |
jae Label | 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.