LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

What does the %rflags register contain?

%rflags is a register of single-bit status flags that arithmetic and comparison instructions set as a side effect, recording facts about the most recent result.

The four condition flags ZF, SF, CF and OF with their meanings.

* Arithmetic sets ZF, SF, CF and OF at once — CF reads the result as unsigned, OF as signed. *

You rarely set these flags on purpose; instructions like add, sub, and cmp set them automatically, and then conditional jumps read them. The four that matter most for control flow:

Flag Name Set when…
ZF Zero Result is zero
SF Sign Result is negative (top bit = 1)
CF Carry Unsigned overflow / borrow
OF Overflow Signed overflow

The crucial mental model is that CF is the flag for unsigned comparisons and OF for signed ones — the same subtraction sets both, and the jump you choose decides which interpretation you mean:

cmp %rax, %rbx   # compute %rbx - %rax, set flags
je  equal        # ZF=1  → equal
jl  less         # SF≠OF → signed less-than
jb  below        # CF=1  → unsigned less-than

Tip: cmp is just a subtraction that throws away the result and keeps only the flags — that's the whole trick behind conditional branches.

Go deeper:

From Quiz: REVE1 / The Processor Interface | Updated: Jul 14, 2026