Dr. Ahmad Almulhem
Email: ahmadsm AT kfupm
Phone: 860-7554
Office: 22-324
Ahmad Almulhem, KFUPM 2009
• Design of 4-bit magnitude comparator
• Adding Three 4-bit numbers
• Building 4-to-16 Decoders with 2-to-4 Decoders
• Getting the larger of 2 numbers (Maximum)
• Excess-3 Code Converter
Ahmad Almulhem, KFUPM 2009
Definition: A magnitude comparator is a combinational circuit that compares two numbers A & B to determine whether:
A > B, or
A = B, or
A < B
Inputs n-bit input
A n-bit magnitude comparator
GT
First n-bit number A
Second n-bit number B n-bit input
EQ
Outputs
3 output signals (GT, EQ, LT), where:
GT = 1 IFF A > B
EQ = 1 IFF A = B
LT = 1 IFF A < B
B
LE
Note: Exactly One of these 3 outputs equals 1, while the other 2 outputs are
0`s
Ahmad Almulhem, KFUPM 2009
Example 1: Magnitude Comparator (4-bit)
Problem: Design a magnitude comparator that compares 2 4-bit numbers A and B and determines whether:
A > B, or
4-bit input
A
4-bit magnitude comparator
GT
A = B, or
A < B
4-bit input
EQ
B
LE
Ahmad Almulhem, KFUPM 2009
Example 1: Magnitude Comparator (4-bit)
Solution:
Inputs: 8-bits (A ⇒ 4-bits , B ⇒ 4-bits)
A and B are two 4-bit numbers
Let A = A
3
A
2
A
1
A
0
, and
Let B = B
3
B
2
B
1
B
0
Inputs have 2 8 (256) possible combinations (size of truth table and K-map?)
4-bit input
4-bit input
A
4-bit magnitude comparator
GT
B
Not easy to design using conventional techniques
The circuit possesses certain amount of regularity
⇒ can be designed algorithmically .
EQ
LE
Ahmad Almulhem, KFUPM 2009
Example 1: Magnitude Comparator (4-bit)
Designing EQ:
Define X i
X i
X i
= A i xnor
= 1 IFF A i
= 0 IFF A i
= B i
≠ B i
B i
= A i
B i
+ A i
’ B
∀ i =0, 1, 2 and 3
’ i
Therefore the condition for A = B or EQ=1 IFF
A
3
= B
3
A
2
= B
2
A
1
= B
1
A
0
= B
0
→ (X
3
→ (X
2
→ (X
1
→ (X
0
= 1), and
= 1), and
= 1), and
= 1).
Thus, EQ=1 IFF X
EQ = X
3
X
2
X
3
1
X
X
2
0
X
1
X
0
= 1. In other words,
Ahmad Almulhem, KFUPM 2009
Example 1: Magnitude Comparator (4-bit)
Designing GT and LT:
GT = 1 if A > B:
• If A
• If A
3
• If A
3
• If A
3
3
> B
= B
= B
= B
3
3
3
3
A
3
= 1 and B
3 and A and A and A
2
2
2
> B
= B
= B
2
2
2
= 0 and A and A
1
1
> A
1
= B
1 and A
0
> B
0
Therefore,
GT = A
3
B
3
‘ + X
3
A
2
Similarly, LT = A
3
’B
3
B
2
‘ + X
3
+ X
3
A
2
X
2
‘B
2
A
1
B
+ X
1
3
‘ + X
3
X
2
A
1
X
2
’B
1
X
1
A
0
+ X
3
B
0
‘
X
2
X
1
A
0
’ B
0
Ahmad Almulhem, KFUPM 2009
Example 1: Magnitude Comparator (4-bit)
EQ = X
3
X
2
X
1
X
0
GT = A
3
B
3
’
+ X
3
A
2
B
2
’
+ X
3
X
2
A
1
B
1
’
+ X
3
X
2
X
1
A
0
B
0
’
LT = B
3
A
3
’
+ X
3
B
2
A
2
’
+ X
3
X
2
B
1
A
1
’
+ X
3
X
2
X
1
B
0
A
0
’
4-bit magnitude comparator
Ahmad Almulhem, KFUPM 2009
Example 1: Magnitude Comparator (4-bit)
• Do you need all three outputs?
• Two outputs can tell about the third one
• Example: when A is NOT GREATER THAN B, and A is NOT LESS THAN B THEN A is EQUAL TO B
• Therefore, we can save some logic gates:
4-bit input
4-bit input
A
4-bit magnitude comparator
GT
EQ
B
LE
EQ
Ahmad Almulhem, KFUPM 2009
Example 2: Adding three 4-bit numbers
Problem: Add three 4-bit numbers using standard MSI combinational components
Solution:
Let the numbers be X
3
X
2
X
1
X
0
, Y
3
Y
2
Y
1
Y
0
, Z
3
Z
2
Z
1
Z
0
,
X
3
X
2
S
3
S
2
X
1
X
0
+ Y
3
Y
2
Y
1
Y
0
-------------------
C
4
S
1
S
0
S
3
S
2
S
1
S
0
+ Z
3
Z
2
Z
1
Z
0
-------------------
D
4
F
3
F
2
F
1
F
0
Note: C
4 and D
4 is generated in position 4. They must be added to generate the most significant bits of the result
Ahmad Almulhem, KFUPM 2009
Example 2: Adding three 4-bit numbers
Ahmad Almulhem, KFUPM 2009
Example 3: 4-to-16 Decoder
Problem: Design a 4x16 Decoder using 2x4 Decoders
Solution:
• Each group combination holds a unique value for A
3
A
2
One Decoder can be therefore used with inputs: A
3
A
2
Four more decoders are needed for representing each individual color combination
A
3
A
2
= 00
A
3
A
2
= 01
A
3
A
2
= 10
A
3
A
2
= 11
Ahmad Almulhem, KFUPM 2009
0
1
0
0
0
0
0
0
1
1
1
1
1
A
3
0
1
1
1
0
0
1
1
0
0
1
1
0
0
1
0
A
1
0
1
1
1
0
1
1
0
1
0
0
0
1
0
0
1
A
2
0
1
1
1
0
1
0
1
0
1
0
1
0
1
0
1
A
0
0
0
1
Output
D
4
D
5
D
6
D
11
D
12
D
13
D
7
D
8
D
9
D
10
D
14
D
15
D
0
D
1
D
2
D
3
Example 3: 4-to-16 Decoder
A
2
A
3
2x4
Decoder
A
0
A
1
A
A
A
A
0
1
0
1
2x4
Decoder
2x4
Decoder
2x4
Decoder
A
A
0
1
2x4
Decoder
Ahmad Almulhem, KFUPM 2009
D
8
D
9
D
10
D
11
D
12
D
13
D
14
D
15
D
4
D
5
D
6
D
7
D
0
D
1
D
2
D
3
Example 4: The larger of 2 numbers
Problem: Given two 4-bit unsigned numbers, design a circuit such that the output is the larger of the two numbers
Solution: We will use a magnitude comparator and a
Quad 2x1 MUX. How?
Ahmad Almulhem, KFUPM 2009
Example 4: The larger of 2 numbers
B
0
B
1
B
2
B
3
A
0
A
1
A
2
A
3
4-bit
Magnitude
Comparator
A>B
A<B
A=B
GT
LT
EQ
B
0
B
1
B
2
B
3
A
0
A
1
A
2
A
3
QUAD
2X1
MUX
Y
0
Y
1
Y
2
Y
3
S
0
For So=1, A is selected,
For So=0, B is selected
Ahmad Almulhem, KFUPM 2009
Example 5: Excess-3 Code Converter
Problem: Design an excess-3 code converter that takes as input a
BCD number, and generates an excess-3 output.
Solution: Use decoders and encoders
0
0
0
0
0
0
1
W
0
0
1
0
0
1
1
1
1
0
X
0
0
0
1
1
0
0
1
1
0
Y
0
0
0
0
1
0
1
0
1
0
Z
0
1
1
0
0
0
1
1
1
1
A
0
0
1
1
1
1
0
0
0
0
B
0
1
1
0
1
1
0
0
1
1
C
1
0
0
1
0
1
0
1
0
1
D
1
0
0
Ahmad Almulhem, KFUPM 2009
Example 5: Excess-3 Code Converter
Z
Y
X
W
D0
D1
D2
D3
4-to-16 line Decoder
O9
O10
O11
O12
O13
O14
O15
O4
O5
O6
O7
O8
O0
O1
O2
O3
16-to-4 line Encoder
I0
I6
I7
I8
I9
I10
I1
I2
I3
I4
I5
I11
I12
I13
I14
I15
D0
D1
D2
D3
?
?
?
?
What will be the output?
Ahmad Almulhem, KFUPM 2009
Example 5: Excess-3 Code Converter
• A decoder can be used with the inputs being W,X,Y,Z
• It will be a 4x16 decoder, with only a single output bit equal to 1 for any input combination
• An encoder (16x4) will take as input the 16 bit output from the decoder, and will generate the appropriate output in excess-3 format
• For this to function correctly, the output from the decoder must be displaced 3 places while being connected to the encoder input
• It may be noted that outputs
10,11,12,13,14,15 of the decoder are not used – since we are dealing with BCD
Ahmad Almulhem, KFUPM 2009
Ahmad Almulhem, KFUPM 2009