contents.gifindex.gif

4-Bit Comparator

The following design illustrates the implementation of a 4-bit comparator that provides outputs for ``equal to``, ``less than``, ``not equal to``, and ``greater than`` (as well as intermediate outputs). The design is implemented with high-level equations.

Design Specification

The comparator compares the value of two 4-bit inputs (A0-A3 and B0-B3) and determines whether A is equal to, not equal to, less than, or greater than B. The result of the comparison is shown on the output lines EQ, NE, LT, and GT.

webpack00000004.gif

Design Method

The following figure shows the simplified block diagram for the comparator. The inputs are grouped into the sets A and B.

webpack00000005.gif

The equations section of the source file contains the following equations:

EQ = A == B;
NE = !(A == B);
GT = A > B;
LT = !((A > B) # (A == B));

You could also use the following equations, however many more product terms would be required:

EQ = A == B;
NE = A != B;
GT = A > B;
LT = A < B;

The first set of equations takes advantage of product term sharing within the target device, while the second set requires a different set of equations for each equation. For example, the equation:

NE = !(A == B);

uses the same 16 product terms as the equation:

EQ = A == B;

thereby reducing the number of product terms. In a similar manner, the equation:

LT = !((A > B) # (A == B));

uses the same product terms as equations:

EQ = A == B;
GT = A > B;

Whereas (in the second set of equations) the equation:

LT = A < B;

requires the use of additional product terms. Sharing product terms helps to fit designs into smaller devices.

4-Bit Comparator Source File

module comp4a

title `4-bit lookahead comparator`

A3..A0 pin;

A = [A3..A0];

B3..B0 pin;

B = [B3..B0];

NE,EQ,GT,LT pin istype `com`;

No,Yes = 0,1;

equations

EQ = A == B;

NE = !(A == B);

GT = A > B;

LT = !((A > B) # (A == B));

``test_vectors deleted...

end