LOGBOOK

HELP

Quiz Entry - updated: 2026.07.30

What are the four x86 condition-code flags, and when is each one set?

CF (carry/unsigned overflow), ZF (zero), SF (sign/negative), OF (signed overflow) — set as a side effect of arithmetic, or deliberately by cmp/test.

These are single-bit flags in a status register. Arithmetic instructions update them automatically; later conditional jumps, sets, and moves read them. They're the bridge between "doing math" and "making a decision."

Flag Name Set when…
CF Carry Unsigned overflow — a carry out of the most-significant bit
ZF Zero The result is exactly 0
SF Sign The result is negative (its MSB is 1)
OF Overflow Signed (two's-complement) overflow occurred

For addq src, dest computing t = a + b:

  • ZF = (t == 0), SF = (t < 0 as signed), CF = unsigned overflow.
  • OF = signed overflow: (a>0 && b>0 && t<0) || (a<0 && b<0 && t>=0) — i.e. two same-signed operands produced a wrong-signed result.

Two flavors of overflow: CF is for unsigned interpretation, OF for signed. The same bits, the same addition — the CPU just sets both so either interpretation has its overflow indicator ready.

Note: lea does not touch the flags (it's just an address calculation), which is part of why compilers love it for arithmetic.

Go deeper:

From Quiz: REVE1 / Translation of C to Assembly | Updated: Jul 30, 2026