Quiz Entry - updated: 2026.07.14
What are the four x86-64 condition-code flags and when are they set?
CF, ZF, SF, and OF are single-bit flags set implicitly as a side effect of arithmetic — CF and OF for unsigned vs. signed overflow respectively, ZF for zero, SF for negative.
These four flags are the entire basis of conditional execution. Nearly every arithmetic instruction updates them automatically; later, a jump or set instruction reads them.
| Flag | Name | Set when… |
|---|---|---|
| CF | Carry | Unsigned overflow (carry out of the top bit) |
| ZF | Zero | Result is zero |
| SF | Sign | Result is negative (top bit = 1) |
| OF | Overflow | Signed (two's-complement) overflow |
For t = a + b:
- CF set if there's a carry out of the most significant bit
- ZF set if
t == 0 - SF set if
t < 0(as signed) - OF set if
(a>0 && b>0 && t<0) || (a<0 && b<0 && t≥0)
Key exceptions: lea and mov set no flags at all, and the logical operations (and, or, xor) force CF and OF to 0. Remembering "CF = unsigned, OF = signed" is the single most useful takeaway.
Go deeper:
FLAGS register (Wikipedia) — maps CF/ZF/SF/OF to their bits and roles.