LOGBOOK

HELP

Quiz Entry - updated: 2026.07.10

What instruction explicitly sets condition codes without storing a result?

CMP — it computes Src1 − Src2, sets all the condition codes, and discards the difference, so you can branch on the comparison.

Where arithmetic instructions set flags as a byproduct, cmp exists only to set flags — it's how you compare two values before a conditional jump.

cmpq Src2, Src1   # compute Src1 - Src2, set flags, store nothing

After cmpq b, a (computing a − b):

  • CF set on carry out — used for unsigned comparisons
  • ZF set if a == b
  • SF set if a − b < 0 (signed)
  • OF set on signed overflow
cmpq %rsi, %rdi   # compute %rdi - %rsi
jg   .L1          # %rdi > %rsi, signed
ja   .L2          # %rdi > %rsi, unsigned

The operand-order trap (AT&T): cmpq b, a computes a − b — the second operand is the left side of the comparison. This reversal versus Intel syntax is one of the most common reading mistakes in x86 disassembly.

Go deeper:

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