Skip to content
BetterDL

Zero detector

Also called: zero detect, zero-detect circuit, all-zeros detector

A circuit that outputs 1 only when every bit of a word is 0. For n bits it's a single n-input NOR gate (or an OR followed by NOT). It produces the Z flag.

A zero detector answers one question about an n-bit word: is every bit 0? It's how an ALU produces its zero flag Z.

The logic follows from the definition. A word is nonzero if any bit is 1, which is the OR of all the bits. Zero is the opposite, so for a 4-bit result:

Z = , a single 4-input NOR.

By De Morgan, that's the same as an AND of the inverted bits, . Both say "every bit is 0".

For wide words, real gates don't have 32 or 64 inputs, so the NOR is built as a tree: ORs in stages, then one inverter at the end.

Two things to get right in an ALU:

  • Feed the detector from the ALU output, after the result multiplexer, not from the adder's sum. Otherwise Z is wrong whenever the ALU outputs a logic result.
  • Combined with subtraction, Z becomes an equality test: A − B is zero exactly when A = B. See comparison by subtraction.
R3R2R1R0Z

Worked examples

Example

Z for three results

Apply the 4-input NOR.

  1. 1.

    0000: no input is 1, so Z = 1.

  2. 2.

    0100: one input is 1, so Z = 0.

  3. 3.

    1111: every input is 1, so Z = 0.

Example

Why the source of Z matters

The ALU computes AND with A = 1010 and B = 0101. The output is 0000, so Z must be 1. Meanwhile the adder is computing 1010 + 0101 = 1111. A detector wired to the adder would wrongly give Z = 0.

Common mistakes

  • Using OR (which gives the opposite of Z) or AND (which detects all 1s).

  • Taking Z from the adder when the ALU selected a logic operation.

  • Expecting Z to say anything about the sign of the result.

Practice Zero detector

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Zero detector is taught in Adders and ALUs.