LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

How do arithmetic instructions affect the flags register?

Most arithmetic and logical instructions set the condition flags as a side effect — but lea and mov set nothing, and inc/dec notably leave the carry flag alone.

Knowing which instructions touch flags is essential when reading code, because a conditional jump depends on whatever last set them.

Instruction Flags modified
add, sub, cmp ZF, SF, CF, OF
and, or, xor, test ZF, SF (CF and OF cleared to 0)
inc, dec ZF, SF, OF (CF unchanged!)
lea, mov none

After cmp a, b (which computes b − a):

Condition Unsigned test Signed test
b == a ZF=1 ZF=1
b < a CF=1 SF≠OF
b > a CF=0 and ZF=0 SF=OF and ZF=0
add %rbx, %rax   # sets all four flags
jo overflow      # OF=1 → signed overflow
jc carry         # CF=1 → unsigned overflow
jz zero          # ZF=1 → result was zero

Gotcha: because inc/dec don't touch CF, multi-word ("bignum") arithmetic that relies on carry must use add $1 / sub $1 instead.

Go deeper:

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