The FLAGS Register and Status Bits
Explore the EFLAGS/RFLAGS register: how arithmetic and comparison instructions set status flags like ZF, CF, SF, and OF that drive every conditional decision.
The FLAGS Register and Status Bits is a free Assembly Language & x86 Low-Level Systems Programming lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Assembly Language & x86 Low-Level Systems Programming learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What is the FLAGS Register?
The FLAGS register (EFLAGS in 32-bit, RFLAGS in 64-bit) is a special register where individual bits record the result of the most recent operation.
Why Flags Matter
The CPU has no boolean type. Instead, instructions set flag bits, and conditional jumps read them. Flags are the glue between arithmetic and control flow.
The Zero Flag (ZF)
ZF is set to 1 when the result of an operation is zero. It is the basis of equality tests.
cmp eax, ebx ; sets ZF if eax == ebxThe Carry Flag (CF)
CF is set when an unsigned operation overflows out of the most significant bit, e.g. an addition that exceeds the register width.
add al, 1 ; CF set if al was 0xFFThe Sign Flag (SF)
SF copies the most significant bit of the result, indicating a negative value in signed interpretation.
The Overflow Flag (OF)
OF is set when a signed operation produces a result too large or small for the destination, i.e. signed overflow.
How CMP Works
CMP a, b performs a - b but discards the result, keeping only the flags. This lets you test relationships without changing operands.
cmp eax, 10TEST for Bit Checks
TEST a, b computes a bitwise AND, discards the result, and sets flags, commonly used to check if a value is zero or test specific bits.
test eax, eax ; ZF set if eax == 0Flags Drive Conditional Jumps
Conditional jumps read flags:
JE/JZ: jump if ZF=1JNE/JNZ: jump if ZF=0JC: jump if CF=1JG: signed greater (uses ZF, SF, OF)
Signed vs Unsigned Conditions
Signed comparisons use SF and OF; unsigned comparisons use CF. Choosing the wrong jump (JA vs JG) is a classic bug.
Directly Affecting Flags
Some instructions set or clear flags explicitly, like STC (set carry) and CLC (clear carry), useful before multi-precision arithmetic.
clc ; clear carry before add chainQuick Check
Test your understanding of CPU flags.
Recap
You learned the FLAGS register:
- ZF zero, CF unsigned overflow, SF sign, OF signed overflow
CMPandTESTset flags without storing results- Conditional jumps branch on flag state
- Match signed/unsigned jumps to the comparison
Frequently asked questions
Is the “The FLAGS Register and Status Bits” lesson free?
Yes — the full text of “The FLAGS Register and Status Bits” is free to read here on the web, and the Assembly Language & x86 Low-Level Systems Programming course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Assembly Language & x86 Low-Level Systems Programming course, upgrade to CoddyKit PRO.
What will I learn in “The FLAGS Register and Status Bits”?
Explore the EFLAGS/RFLAGS register: how arithmetic and comparison instructions set status flags like ZF, CF, SF, and OF that drive every conditional decision. You practise Assembly Language & x86 Low-Level Systems Programming with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Assembly Language & x86 Low-Level Systems Programming?
No prior experience is required. Assembly Language & x86 Low-Level Systems Programming on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “The FLAGS Register and Status Bits” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Assembly Language & x86 Low-Level Systems Programming lesson?
Yes. Every Assembly Language & x86 Low-Level Systems Programming lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- x86 Registers Demystified
- Memory Addressing Modes
- Data Representation and Types
- The FLAGS Register and Status Bits