Your place is saved automatically on this browser.
The flags live in the eight-bit F register. Tutorial 1 introduced them in the Odin AF display. We now need to understand the common ones more precisely.
How to read the eight bits of F
The flags register is one byte, so its bits are numbered 7 down to 0 just like any other byte. Each named flag has a fixed position. A bit that is 1 contributes its place value to the hex number printed for F; a bit that is 0 contributes nothing.
The P/V bit is one physical flag with two documented meanings, selected by the kind of instruction. It does not independently store both parity and overflow. For example, after CP it indicates signed arithmetic overflow, not the parity of A.
Build a flags byte by hand
Recall the example from Tutorial 1. If A starts at $FF, then ADD A,$01 wraps the eight-bit result to $00. Zero is set ($40), Half-carry is set ($10), and Carry is set ($01). N is cleared because we added rather than subtracted. The other named result flags are clear.
You can check the arithmetic yourself: binary F = 0101 0001. Split that into nibbles, 0101 and 0001, and you get hexadecimal $51. Later, the Odin inspection screen displays AF as a pair of bytes: the first two hex digits are A and the last two are F.
A note about bits 5 and 3: these are sometimes called undocumented X/Y flags. They can change and make F appear more complicated than the named flags alone. Their precise behaviour varies by instruction. For these beginner exercises, use the documented flags to make decisions rather than trying to interpret every bit of F.
Technical reference: For the complete flag rules, consult Zilog’s Z80 CPU User Manual (UM0080): https://www.zilog.com/docs/z80/um0080.pdf. All Odin outputs in this chapter remain to be checked on the target Next.
Two undocumented flag bits can also appear in the numerical value of F. Do not assume every hex digit in AF is a meaningful result you deliberately arranged. At this stage, look at the named flags that the instruction is documented to change.
Carry is not signed overflow
Take the addition $7F + $01. As unsigned values, that is 127 + 1 = 128, which fits in eight bits: no carry beyond bit 7. As signed values, +127 + 1 should give +128, which is outside the signed eight-bit range. The stored byte becomes $80, interpreted as −128; the overflow flag indicates the signed problem.
Therefore, C and P/V tell us different stories. Later, we must not use a simple unsigned Carry test as if it were a complete signed comparison.
Flags can be overwritten
One operation may set the flags and a later operation may replace them before a jump has checked them. For example, CP $10 updates flags; an INC A inserted before a conditional jump will update several of them again. By contrast, ordinary LD instructions do not update the arithmetic flags. Always ask: which instruction most recently established the flag I am testing?
