After each operation, an ALU produces a few extra bits that describe its result R. These status flags (also called condition codes) let a program ask "was it zero?" or "did it overflow?" without examining the result itself.
For an n-bit result, the four standard flags are:
- N, negative = Rₙ₋₁, the result's MSB (negative flag)
- Z, zero = 1 when every result bit is 0, a NOR of all the bits (zero flag, built by a zero detector)
- C, carry = Cₙ, the adder's carry-out (carry flag)
- V, overflow = Cₙ ⊕ Cₙ₋₁, signed overflow (overflow flag)
Where they come from matters. N and Z describe the value the ALU outputs, so they're taken from the result MUX output. C and V only exist inside the adder, so they come from the carry chain and only mean something after ADD or SUB.
In this course C is the raw carry-out, so after SUB, C = 1 means "no borrow". ARM processors work this way; x86 stores the inverted bit as a borrow.
The flags turn subtraction into comparison. Compute A − B and read them: Z = 1 means equal, C = 0 means unsigned A < B, and = 1 means signed A < B. See comparison by subtraction.