LogisimRevisited

Components / Arithmetic

Comparator Component in Logisim

Compares two N-bit signed integers A and B and asserts exactly one of its three 1-bit outputs: A>B, A=B, or A<B.

CMPABA>BA=BA<B
Default settings, facing east. Pins are the dots.
LibraryArithmetic
Type nameComparator
Pins and defaultsa A (-40, -10), b B (-40, 10), gt A>B (0, -10), eq A=B (0, 0), lt A<B (0, 10), width 4 (1..32)

Try it in the app

How the Comparator Works in Logisim

The Comparator evaluates the relative magnitude of two N-bit two's complement signed integers A and B (default width = 4 bits). On its right edge, it provides three mutually exclusive 1-bit outputs from top to bottom: A>B (gt), A=B (eq), and A<B (lt).

Whenever both A and B are fully defined, exactly one of the three outputs is 1 and the other two are 0. If any bit of A or B is floating (Z) or in conflict (E), all three comparison outputs become E.

Tip: Note that the Comparator uses signed two's complement ordering (for 4-bit inputs, 0b1111 is -1, which is less than 0b0001 = +1).

Comparator Pins & Pinout

PinDirectionWidthLocation & Role
a (A)Input (Upper-left)1–32 bits (default 4)Offset (-40, -10). First signed operand A.
b (B)Input (Lower-left)1–32 bits (default 4)Offset (-40, 10). Second signed operand B.
gt (A>B)Output (Upper-right)1 bitOffset (0, -10). Outputs 1 when A > B (signed two's complement).
eq (A=B)Output (Middle-right)1 bitOffset (0, 0). Outputs 1 when A = B.
lt (A<B)Output (Lower-right)1 bitOffset (0, 10). Outputs 1 when A < B (signed two's complement).

Comparator Truth Table & Behavior

Comparator output states for defined inputs A and B
Conditiongt (A>B)eq (A=B)lt (A<B)
A > B100
A = B010
A < B001
A or B has Z / EEEE

Related Circuits & Components