The zero flag is how a program makes decisions. It's a 1-bit register that records whether the last result was zero:
- Z = 1 if the value just loaded into the ACC is 0;
- Z = 0 otherwise.
In Tiny8, Z loads at the same edge as the ACC, and only then: on LOAD, ADD and SUB. STORE, JMP, JZ and HALT leave both the ACC and Z unchanged. At reset ACC = 0, so Z = 1.
A conditional branch reads it. JZ a jumps to a only when Z = 1. Together, SUB and JZ give a comparison: subtract two values, and if the result is 0 they were equal.
Z is one of the status flags. Real CPUs have the same flag (ARM's Z, x86's ZF) alongside others for carry, sign and overflow.
Watch out for wrap-around: in 8-bit arithmetic, 128 + 128 = 256 wraps to 0, so Z = 1 even though neither number was 0.