0% found this document useful (0 votes)
12 views5 pages

N - Bit Comparator

Uploaded by

Mahesh Morla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

N - Bit Comparator

Uploaded by

Mahesh Morla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Day 8 of RTL Codes

N - Bit Comparator

• Purpose of an N-Bit Comparator


• An N-bit comparator compares two N-bit binary
numbers A and B.
• It produces three outputs:
1. A > B: Indicates that A is greater than B.
2. A = B: Indicates that A is equal to B.
3. A < B: Indicates that A is less than B.

• Inputs and Outputs


• Inputs: Two N-bit binary numbers A[N−1:0] and
B[N−1:0].
• Outputs:
1. Greater: High when A>B.
2. Equal: High when A=B.
3. Lesser: High when A<B.

Aravind Madapati
[email protected]
9618641406
Day 8 of RTL Codes

3. Basic Logic of Comparison


• Comparison starts with the most significant bit
(MSB) and moves toward the least significant bit
(LSB).
• Each bit is compared individually.

4. Truth Table for Single-Bit Comparator


For a single-bit comparator:
A B A>B A=B A<B

0 0 0 1 0

0 1 0 0 1

1 0 1 0 0

1 1 0 1 0

5. Extending to N-Bit Comparator


• For N bits, the comparison logic is applied bit by
bit.
• The outputs Greater, Equal and Lesser are
determined based on cascading logic.
Aravind Madapati
[email protected]
9618641406
Day 8 of RTL Codes

6. Combinational Logic Design


• A > B: True if the first differing bit from MSB to LSB
has A[i] = 1 and B[i] = 0.
• A = B: True if all corresponding bits of A and B are
equal.
• A < B: True if the first differing bit has A[i]= 0 and
B[i] = 1.

7. Block Diagram of N-Bit Comparator


1. Inputs: Two N-bit numbers, A[N−1:0] and B[N−1:0]
2. Modules:
o Equality Block: Checks if each bit of A and B
are equal.
o Greater-Than Block: Checks if A > B.
o Less-Than Block: Checks if A < B.

Aravind Madapati
[email protected]
9618641406
Day 8 of RTL Codes

Design code, Test Bench and Waveform of N-Bit Comparator

Fig: Design Code for N-Bit Comparator

Aravind Madapati
[email protected]
9618641406
Day 8 of RTL Codes

Fig: Test Bench Code for N-Bit Comparator

Fig: Waveform

Aravind Madapati
[email protected]
9618641406

You might also like