Your place is saved automatically on this browser.
The F register is a collection of status bits
The F register is eight bits wide, but unlike A we do not normally think of it as one ordinary number. Individual bits have particular meanings. They are called flags because they signal that something about the previous operation is true.
A useful analogy is a row of indicator lamps. Each lamp can be off or on. After certain instructions, the CPU updates those lamps to describe the result.
The main flags we care about
Where the flags live inside F
F is one 8-bit register. The flags are individual bit positions inside it. For our beginner-level view, we can draw the register like this:
Bits 5 and 3 are not part of the beginner flag set we need to reason about here, so the diagram marks them with dashes. The important idea is that each named flag is a single on/off bit.
Later, if Odin shows F = $51, we can convert $51 to binary and see which flag bits are set. We should understand the individual flags first, then treat the combined hexadecimal byte as a compact display of them.
Not every instruction changes the flags
This is important. Loading a value into A with LD A,$42 does not recalculate all of the flags. Therefore, when Odin showed AF = 42A0 in our first register experiment, the A half was deliberately set by our code, but the F half was inherited state.
Later, when we used ADD, the arithmetic instruction did update the flags. That made the F value meaningful for the result we had just calculated.
Foundation checkpoint before typing the first program
Before moving on, you do not need perfect recall, but the following statements should make sense. If one does not, revisit the matching section.
- A bit is one binary digit, 0 or 1.
- A nibble is four bits and maps to one hexadecimal digit.
- A byte is eight bits and is naturally written as two hexadecimal digits.
- $FF is 255 decimal and is the largest unsigned value in one byte.
- A 16-bit value uses two bytes and is naturally written as four hexadecimal digits.
- An address identifies a location; the contents are the byte stored there.
- A pointer is a value being used as an address.
- Registers are small storage locations inside the CPU.
- A register contains a value; it is not itself the value.
- The assembler translates readable source into machine-code bytes.
- The Z80 executes machine-code bytes from memory, not the assembly source text.
