Quiz Entry - updated: 2026.07.14
What are the SetX instructions and how do they work?
SetX instructions write a single byte to 0 or 1 based on the condition codes — turning a comparison's flags into an actual 0/1 value, as for a C boolean.
* A comparison becomes a boolean: setX turns the flags into one 0/1 byte, then movzbl cleans the rest of the register. *
After a cmp, the answer lives in the flags; setX materializes that answer as a byte you can store or return. There's one for each condition, mirroring the conditional jumps.
| Instruction | Condition | Meaning |
|---|---|---|
sete / setne |
ZF / ~ZF | equal / not equal |
sets / setns |
SF / ~SF | negative / non-negative |
setg / setge |
signed | greater / greater-or-equal |
setl / setle |
signed | less / less-or-equal |
seta / setb |
unsigned | above / below |
Because setX writes only a single byte, the usual idiom zero-extends it to a full register:
cmpq %rsi, %rdi # compare x and y
setg %al # %al = (x > y) ? 1 : 0
movzbl %al, %eax # zero-extend to a clean 32/64-bit result
Tip: the suffixes (e, ne, g, l, a, b, …) are the same across setX, jX, and cmovX, so learning one set teaches all three.
Go deeper:
Felix Cloutier — SETcc — the SETcc family materialising flags into a 0/1 byte.