Flags and the status register
| The flags register | |
| The common flags | |
| Which instructions set them |
The flags register
The flags register (EFLAGS or RFLAGS) holds one-bit status flags. CMP and arithmetic update them, and conditional jumps read them. You rarely read the register itself.
cmp rax, rbx ; sets flags, changes nothing else
The common flags
ZF (zero flag) sets when a result is zero. CF (carry flag) sets when an unsigned operation overflows. SF (sign flag) copies the result sign bit. OF (overflow flag) sets on signed overflow.
mov rax, 5
sub rax, 5 ; result 0: ZF = 1
cmp rax, rbx ; like sub, but discards the result
Which instructions set them
CMP, SUB, ADD, INC, DEC, AND, OR, XOR, and TEST update flags. MOV does not: it moves data without touching status. TEST is CMP without subtraction: it ANDs its operands, discards the result, and sets only ZF and SF.
Next: Conditional jumps
Article author: Arthur Isaev