Flags and Condition Codes
Condition Encoding
Conditional instructions encode a four-bit condition code. The zero-valued condition is T, which is also used for canonical aliases such as JMP for Jcc.T.
The condition-code bits are the low four meaningful bits of FLAGS, as shown in the Programming Model section.
Condition Code Encoding
| Bits | Name | Aliases | Expression |
|---|---|---|---|
0000 |
T |
- |
true |
0001 |
F |
- |
false |
0010 |
EQ |
Z |
FLAGS.Z == 1 |
0011 |
NE |
NZ |
FLAGS.Z == 0 |
0100 |
ULT |
C |
FLAGS.C == 1 |
0101 |
UGE |
NC |
FLAGS.C == 0 |
0110 |
MI |
N |
FLAGS.N == 1 |
0111 |
PL |
NN |
FLAGS.N == 0 |
1000 |
VS |
V |
FLAGS.V == 1 |
1001 |
VC |
NV |
FLAGS.V == 0 |
1010 |
ULE |
- |
FLAGS.C == 1 || FLAGS.Z == 1 |
1011 |
UGT |
- |
FLAGS.C == 0 && FLAGS.Z == 0 |
1100 |
LT |
- |
FLAGS.N != FLAGS.V |
1101 |
GE |
- |
FLAGS.N == FLAGS.V |
1110 |
LE |
- |
FLAGS.Z == 1 || FLAGS.N != FLAGS.V |
1111 |
GT |
- |
FLAGS.Z == 0 && FLAGS.N == FLAGS.V |
Flag Meanings
Integer condition codes are held in FLAGS. Integer instructions leave FLAGS unchanged unless their instruction description explicitly defines a FLAGS write. Every FLAGS-writing instruction replaces the complete FLAGS.Z, FLAGS.N, FLAGS.C, and FLAGS.V image; partial FLAGS writes do not exist. An instruction that does not write FLAGS preserves the complete image.
For an operand width of n bits, ordinary integer ALU results are evaluated modulo 2^n unless the instruction explicitly defines a wider intermediate.
Explicit FLAGS-writing integer instructions include CMP, TEST, ADC, SBB, INCF, DECF, BTEST, BSET, BCLR, BCHG, SETF, WRFLAGS, CMPXCHG, SEGLEA, and the bounds-check instructions. CMPJcc and TESTJcc compute temporary condition flags for their branch decision and do not update architectural FLAGS. ADD, SUB, logic operations, INC, DEC, shifts, rotates, moves, extensions, min/max, and multiply/divide instructions leave FLAGS unchanged.
Integer Condition-Code Bits
| Bit | Name | Meaning |
|---|---|---|
FLAGS.Z |
zero | Set when the result value is zero. |
FLAGS.N |
negative | Set from the most significant result bit at the operand size. |
FLAGS.C |
carry/borrow | Set on unsigned carry out for addition or unsigned borrow for subtraction. |
FLAGS.V |
overflow | Set on signed overflow or an explicitly reported exceptional condition. |
Conditional Consumers
Conditional branches, calls, traps, and sets consume the condition-code table without recomputing FLAGS. An ordinary conditional consumer observes the FLAGS image produced by the last committed FLAGS-writing instruction. REPcc instead tests a temporary flag image derived from the body instruction's repeat-observed value, as defined in Repeated Scalar Execution. That test leaves architectural FLAGS unchanged.
A false condition suppresses the conditional action unless the instruction description explicitly defines a different commit rule, such as a repeat instruction's terminating iteration rule.
Floating-Point Interactions
Floating-point comparison instructions may update integer condition codes only when their instruction definition says so. FFLAGS holds floating-point exception flags, and FSTATUS holds the corresponding exception-condition enables and rounding state. IEEE-754 FFLAGS causes use independent accrued semantics. The complete-image rule applies to integer FLAGS.
Integer conditional consumers do not read FFLAGS directly; floating-point instructions that want integer control-flow consumers must materialize the selected condition into FLAGS or an Rn value.