A result is more than just a number
An ALU doesn't just output the sum or difference of two operands — real processors also latch a handful of one-bit status flags describing properties of that result, because software constantly needs to ask yes/no questions about it: was it zero, did it overflow, did the addition produce a carry.
Zero and carry
Two flags cover the basics:
- Zero (Z) — 1 when every output bit is 0. Boolflow's ZERO_DET block computes exactly this by combining all the output bits.
- Carry (C) — the adder's own Cout, latched alongside the result. On subtraction, a carry-out from A+(¬B)+1 conventionally means 'no borrow occurred', i.e. A≥B.
Overflow: when carry isn't enough
Carry alone doesn't tell you a signed result is wrong — adding two large positive two's-complement numbers can produce a negative-looking result with no carry-out at all. The standard fix is Overflow (V) = Cout XOR (the carry into the sign bit): the two internal carries agree during normal operation and disagree exactly when a signed result has wrapped around.
From flags to branches
A conditional jump instruction like 'branch if equal' is nothing more than checking the Zero flag left over from a preceding comparator or subtraction. Wire a CMP4 or a subtracting ALU into a ZERO_DET in the circuit editor and you've built the condition-check half of every if-statement a CPU ever executes.