This page is a work in progress.

L20: Comparators#

Let’s practice Boolean algebra!

Objective
Practice usage of theorems 5-17 of Boolean algebra.


Before the Lecture#

Required Textbook Reading:

  • 4.5 (Comparison Circuits)
  • 4.6 (Verilog for Combinational Circuits)

Comparison Circuits#

Chapter 3 covered arithmetic circuits for addition, subtraction, and multiplication. Comparator circuits compare the relative sizes of two unsigned binary numbers. A comparator takes two n-bit inputs, A and B, and produces three outputs:

  • AeqB = 1 when A = B
  • AgtB = 1 when A > B
  • AltB = 1 when A < B

Building a full truth table is possible, but it becomes impractical as n grows. A better method is to compare corresponding bits from most significant to least significant bit. For a 4-bit comparator, let A = a3a2a1a0 and B = b3b2b1b0. Define intermediate signals ik = ak ⊕ bk, which are 1 when the bits at position k are equal.

Equality output:

  • AeqB = i3i2i1i0

Greater-than output:

  • AgtB = a3b3 + i3a2b2 + i3i2a1b1 + i3i2i1a0b0

The ik signals ensure that only the first differing bit determines whether A > B. Less-than output can be obtained from the other outputs:

  • AltB = AeqB + AgtB

The same design approach extends to any bit-width n. Comparator circuits can also be designed using alternative methods, such as the one referenced in Chapter 3, Example 3.9.

Verilog for Combinational Circuits#

Discussion & Practice
As a class, let’s work through Section 4.6 in the textbook.