Comparator Tutorial: Compare Two Numbers in Logisim-evolution

The Comparator (Arithmetic library) answers one question: how does value A relate to value B? It has two multi-bit inputs and three 1-bit outputs — > (A greater than B), = (equal), < (A less than B). Exactly one of them is high at any time. It is the component behind limit detectors, threshold alarms, and the reset logic in counters.

Step 1 — Wire up a first comparison

  1. Place a Comparator from the Arithmetic library. Set Data Bits to 8.
  2. Place two Constants (Wiring library). Set the first one’s Value to 0x2A (42) and wire it into input A; set the second to 0x10 (16) and wire it into input B.
  3. Attach an LED (Input/Output library) to each of the three outputs, or add Probes (Wiring library) so you can read them by name.
  4. Change the constants and watch the outputs: with A=42 and B=16, only the > LED is lit.

Step 2 — Build a threshold alarm

A classic use: sound the alarm when a sensor reading passes a limit.

  1. Wire a Counter (Memory library, 8 bits) into input A — this plays the role of a rising sensor value. Enable ticking with Simulate → Ticks Enabled.
  2. Put a Constant of 0x64 (100) on input B.
  3. Wire the > output to an LED labeled “ALARM”. The LED lights the moment the count passes 100 and stays on while it remains above.

Signed vs unsigned: check the Numeric Type

The Comparator has a Numeric Type attribute. If your values can be negative, make sure it matches how you interpret the bits (two’s complement vs unsigned) — otherwise a negative number can compare as “greater than” a positive one and confuse you for an hour. For plain counters and addresses, the default is fine.

Where comparators show up in real designs

  • Counter reset logic: the digital clock tutorial uses a Comparator to detect “reached 10” and clear the counter.
  • CPU branch decisions: a beq instruction is just “jump if A = B” — see Building a Simple CPU.
  • Range checks: combine two Comparators with an AND gate to test “is X between low and high?”.

Troubleshooting

  • All three outputs dark: an input is disconnected (shown in red). Every input pin must be wired — tie unused bits to a Constant 0.
  • Wrong result with negative numbers: see Numeric Type above.
  • Output flickers during simulation: normal — it follows the inputs combinationally, so it settles once the inputs settle. Use the Chronogram to see it.