05-Combinational Circuits
05-Combinational Circuits
Decoder
if some input codes
are unused
n
a1 2-to-4 d1
4 Outputs
a1 a0 d0 d1 d2 d3
2 Inputs
a0 d2
Decoder
0 0 1 0 0 0 Truth
d3
0 1 0 1 0 0
Tables
1 0 0 0 1 0
1 1 0 0 0 1
d0
Inputs Outputs
d1
a2 a1 a0 d0 d1 d2 d3 d4 d5 d6 d7
d2
a2
0 0
3-to-8 d3
1 0 0 0 0 0 0 0
8 Outputs
0
a1
3 Inputs
d4
0 0
a0 Decoder
0 1 0 0 0 0 0 0
1
d5
0 1
d6
0 0 1 0 0 0 0 0
0
d7
0 1
0 0 0 1 0 0 0 0
1
1 0
0 0 0 0 1 0 0 0
0
ITCS 222– Computer Organization slide1#5 0 Decoders, Encoders, and Multiplexers
0 0 0 0 0 1 0 0
Decoder Implementation
2-to-4 Decoder 3-to-8 Decoder
Inputs Outputs
𝑎2
a1 a 0 d0 d1 d2 d3 𝑎1
′ ′ ′
0 0 1 0 0 0 𝑎0 𝑑0 =𝑎2 𝑎1 𝑎0
0 1 0 1 0 0 ′ ′
1 0 0 0 1 0 𝑑1=𝑎2 𝑎1 𝑎0
′ ❑ ′
1 1 0 0 0 1
𝑑2 =𝑎2 𝑎1 𝑎0
𝑎1 ′ ❑
𝑑3 =𝑎2 𝑎1 𝑎0
𝑎0 ❑ ′ ′
𝑑 4=𝑎2 𝑎1 𝑎0
′
𝑑1=𝑎1 𝑎 0 ❑ ′
′ 𝑑5 =𝑎2 𝑎1 𝑎0
𝑑2 =𝑎1 𝑎 0 ❑ ❑ ′
𝑑3 =𝑎1 𝑎0 𝑑6 =𝑎2 𝑎1 𝑎0
❑ ❑
𝑑7 =𝑎2 𝑎1 𝑎0
Each decoder output is a minterm
ITCS 222– Computer Organization slide #6 Decoders, Encoders, and Multiplexers
Using Decoders to implement Functions
• A decoder generates all possible minterms over the inputs
• A Boolean function can be expressed as a sum of minterms
• Any function can be implemented using a decoder + OR
gate
Note: the function must NOT be minimized
d0
• Example:
Inputs Full Adder sum = ∑(1, 2, 4, 7), cout = ∑(3, 5, 6, 7)
Outputs
d1
sum
a b c cout sum
d2
a 22
0 0 0 0 0
3-to-8 d3
b
0 0 1 0 1
21
d
0 1 0 0 1
c 20 Decoder 4 cout
d5
0 1 1 1 0
d6
1 0 0 0 1
1 0 1 1 0
d7
1 1 0 1 0
1 1 1 1 1
ITCS 222– Computer Organization slide #7 Decoders, Encoders, and Multiplexers
Using Decoders to implement Functions
• Good if many output functions of the same input variables
• If number of minterms is large Wider OR gate is needed
• Use NOR gate if number of maxterms is less than minterms
• Example: f = ∑(2, 5, 6), g = ∏(3, 6) g' = ∑(3, 6), h = ∑(0, 5)
Inputs Outputs
a b c f g h
d0
d1 f
0 0 0 0 1 1
0 0 1 0 1 0 d2
a 22
0 1 0 1 1 0 3-to-8 d3
b 21 g
0 1 1 0 0 0 d
c 20 Decoder 4
1 0 0 0 1 0 d5
1 0 1 1 1 1 d6 h
1 1 0 1 0 0 d7
1 1 1 0 1 0
d0
Truth Table
a1
2-to-4 d1
a0 d2
Inputs Outputs
Decoder
EN d3
EN a1 a0 d0 d1 d2 d3
0 X X 0 0 0 0
1 0 0 1 0 0 0
1 0 1 0 1 0 0 𝒂𝟏
′ ′
1 1 0 0 0 1 0
𝒂𝟎 𝒅 𝟎=𝑬𝑵 𝒂𝟏 𝒂𝟎
1 1 1 0 0 0 1 ′
𝒅𝟏 =𝑬𝑵 𝒂 𝟏 𝒂𝟎
′
𝒅𝟐 =𝑬𝑵 𝒂 𝟏 𝒂𝟎
If EN input is zero then all
outputs are zeros, regardless
𝒅𝟑 =𝑬𝑵 𝒂 𝟏 𝒂𝟎
of a1 and a0 𝑬𝑵
ITCS 222– Computer Organization slide #9 Decoders, Encoders, and Multiplexers
Building Larger Decoders
• Larger decoders can be built hierarchically using smaller ones
• Example: A 3-to-8 decoder can be built using two 2-to-4 decoders
with Enable input and an inverter (1-to-2 decoder)
a2
d0
Inputs Outputs
a1 a1 Top
d1
a0 a0
a2 a1 a0 d0 d1 d2 d3 d4 d5 d6 d7
d2
0 2-to-4
Decoder
d3
0 1 0 0 0 0 0 0 0
EN
0
0
0 0 1 0 0 0 0 0 0
1-to-2 Decoder
1
d4
1
a1
0 0 0 1 0 0 0 0 0
d5
0
Bottom
a0
1
d6
2-to-4
0 0 0 0 1 0 0 0 0
1
Decoder
d7
0
EN
1 0 0 0 0 1 0 0 0
0
0
1 0 0 0 0 0 1 0 0
1
ITCS1222– Computer Organization slide #10 Decoders, Encoders, and Multiplexers
Building Larger Decoders
a1 a1 2-to-4 d0
d1
Example: A 4-to-16
a0 a0Decoder d2
1 d3
decoder with enable can
EN
d4
be built using five 2-to-4
a1 2-to-4
d5
a0Decoder
decoders with enables
d6
a3 a1 2-to-4 EN 2 d7
a2 a0Decoder
a1 2-to-4 d8
EN EN 0 d9
a0Decoder d10
EN 3 d11
a1 2-to-4 d12
d13
a0Decoder d14
Larger decoders can be built
hierarchically in a similar way
EN 4 d15
ITCS 222– Computer Organization slide #11 Decoders, Encoders, and Multiplexers
Encoders
• An encoder performs the opposite operation of a decoder
• An encoder is a combinational circuit that converts a 2n code
at its input to an n-bit code at its output.
Typically, one input should be 1 and all others must be 0's
n Outputs
An encoder can have less 2n Inputs 2n to n
Encoder
than 2n inputs if some
input lines are unused
ITCS 222– Computer Organization slide #12 Decoders, Encoders, and Multiplexers
Example of an 8-to-3 Binary Encoder
• 8 inputs, 3 outputs, only one input is 1 (active), all others are
0's (inactive)
• Encoder generates the output binary code for the active input
• Output is not specified if more than one input is 1
d7
Inputs Outputs
d6
d7 d6 d5 d4 d3 d2 d1 d0 a2 a1 a0
d5 8-to-3 a2
0 0 0 0 0 0 0 1 0 0 0
d4
3 Outputs
a1
0 0 0 0 0 0 1 0 0 0 1
8 Inputs
d3 Binary
a0
0 0 0 0 0 1 0 0 0 1 0
d2
Encoder
0 0 0 0 1 0 0 0 0 1 1
d1
0 0 0 1 0 0 0 0 1 0 0
d0
0 0 1 0 0 0 0 0 1 0 1
0 1 0 0 0 0 0 0 1 1 0
1 0 0 0 0 0 0 0 1 1 1
ITCS 222– Computer Organization slide #13 Decoders, Encoders, and Multiplexers
8-to-3 Binary Encoder Implementation
d7
d6
d5 8-to-3
Inputs Outputs
a2
d4 a1
Binary
d7 d6 d5 d4 d3 d2 d1 d0 a 2 a 1 a 0
d3 a0
d2
0 0 0 0 0 0 0 1 0 0 0
d1 Encoder
0 0 0 0 0 0 1 0 0 0 1
d0
0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 1 0 0 0 0 1 1
d4
0 0 0 1 0 0 0 0 1 0 0
d5
a2
0 0 1 0 0 0 0 0 1 0 1
d6
0 1 0 0 0 0 0 0 1 1 0
1 0 0 0 0 0 0 0 1 1 1 d7
d2
d3
d6 a1
a2 = d4 + d5 + d6 + d7
d7
a1 = d2 + d3 + d6 + d7
d1
8-to-3 binary encoder
d
a0
implemented using
a0 = d1 + d3 + d5 + d7 three 4-input OR gates d3
d7
5
ITCS 222– Computer Organization slide #14 Decoders, Encoders, and Multiplexers
Binary Encoder Limitations
• Exactly one input must be 1 at a time (all others must be 0's)
If more than one input is 1 then the output will be incorrect
For example, in the 8-3-encoder:
a2 = d4 + d5 + d6 + d7
if d3 = d6 = 1, then
a1 = d2 + d3 + d6 + d7
a2 a1 a0 = 111 (incorrect)
a0 = d1 + d3 + d5 + d7
Priority a0
d1
d3 d2 d1 d0 a1 a0 V
d0 Encoder
lowest priority V
0 0 0 0 X X 0
0 0 0 1 0 0 1
ITCS 222– Computer Organization slide #16 Decoders, Encoders, and Multiplexers
Implementing a 4-to-2 Priority Encoder
d3
Output Expressions:
a1
d2
a0
d1
V
d0
ITCS 222– Computer Organization slide #17 Decoders, Encoders, and Multiplexers
Multiplexers
• In digital systems, selecting data is an essential function
• A functional block (combinational circuit) that performs selection
operation is called multiplexer.
• A Multiplexer (or MUX) is a combinational circuit that has:
Multiple data inputs (typically 2n, where n = 1,2,3,… ) to select from
One output Y d0
2n Inputs
An n-bit select input S used for control d1
d2
Mux
. Y
.
.
d2n–1
n
S
• The n-bit select input defines which data input is passed to the output
ITCS 222– Computer Organization slide #18 Decoders, Encoders, and Multiplexers
Examples of Multiplexers
• 2-to-1 Multiplexer
d0
Inputs Output
if (S == 0) Y = d0 ;
Y
S d0 d1 Y
2-to-1
Mux
d1
else Y = d1; 0 =
0 0 X
d0
Logic expression: 1 =
0 1 X
S
d0
0 =
1 X 0
Inputs d1 Output
• 4-to-1 Multiplexer
d0
1 =
S11 S0 X d0 1d1 d2 dd3 Y
if (S1S0 == 00) Y = d0 ;
d1
1
0 0 0 X X X 0 = d0
4-to-1 Y
d2
else if (S1S0 == 01) Y = d1; 0 0 1 X X X 1 = d0
Mux 0 1 X 0 X X 0 = d1
d3
else if (S1S0 == 10) Y = d2; 0 1 X 1 X X 1 = d1
else Y = d3;
2
1 0 X X 0 X 0 = d2
S1 S0
1 0 X X 1 X 1 = d2
1 1 X X X 0 0 = d3
• Logic expression: 1 1 X X X 1 1 = d3
ITCS 222– Computer Organization slide #19 Decoders, Encoders, and Multiplexers
Implementing Multiplexers
d0
d0 2-to-1
Mux Y
d1
d1 Enabling
S AND Gates
S d0
d0
d1
d1
d2 Y
4-to-1
d2
Mux
d3
d3
2
Enabling
S1 S0
S1 AND Gates
S0
ITCS 222– Computer Organization slide #20 Decoders, Encoders, and Multiplexers
Implementing Multiplexers (cont'd)
A Multiplexer can also be d0
implemented using:
4-to-
1 Mux
d1
1) A decoder and
Y
d2
(buffers)
Gates
2
d0
S1 S0
3-State d1
Gates
d0 Y
d2
d0
Y
2-to-
1 Mux
d1 d3
Y
d1
S 1-to-2
S1 2-to-4
Decod
er S0 Decod
er
S
ITCS 222– Computer Organization slide #21 Decoders, Encoders, and Multiplexers
Building Larger Multiplexers
Larger multiplexers can be built hierarchically using smaller ones
Example #2: Building 8-to-1 MUX using
Example #1: Building 4-to-1 two 4-to-1 MUXes and a 2-to-1 MUX
MUX using three 2-to-1MUXes
d0 Question #2: What will be Y if
d0 d5
4-to-
1 Mux
d1 s2s1s0 = 101 ?
Mux
d1 d2
d0
d3
Mux
S0 Y d1
2
8-to-1 Mux
d2
Mux
S1 S0 Y d2
Mux
S1 d3
d3 Y
d4 d4
S0 S2
4-to-
1 Mux
d5 d5
Question #1: d6 d6
d7 d7
What will be Y if s1s0 = 11 ? 3
2
S2 S1 S0
d3 S1 S0
ITCS 222– Computer Organization slide #22 Decoders, Encoders, and Multiplexers
Multiplexers with Vector Input and Output
Each input and each output of a MUX can be m-bit vectors
Generic 2-to-1 Multiplexer
Inputs and outputs are m-bit vectors
Generic 4-to-1 Multiplexer
Using m copies of a 2-to-1 MUX
Inputs and outputs are m-bit vectors
Using m copies of a 4-to-1 MUX
A [m–1:0]
2-to-1
m
Mux
Y [m–1: 0]
A [m–1:0]
m
B [m–1:0] m
B
4-to-
1 Mux
m [m–1:0]
m Y [m–1: 0]
C [m–1:0] m
m
S D [m–1:0]
m 2
S1 S0
ITCS 222– Computer Organization slide #23 Decoders, Encoders, and Multiplexers
BCD to 7-Segment Decoder
• A seven-segment display is used to display one
decimal digit ( 0 to 9).
Found in electronic devices: such as clocks, calculators, etc.
Made of seven segments: light-emitting diodes (LED)
a
I3
The display is controlled by a BCD to 7-segment decoder.
b
BCD to c
I2
7-Segment d
I1 e
I0 Decoder f
A BCD to 7-Segment Decoder
Accepts as input a BCD decimal digit (0 to 9) g
Generates output to the seven LED segments to display the BCD digit
Each segment can be turned on or off separately
ITCS 222– Computer Organization slide #24 Decoders, Encoders, and Multiplexers
BCD to 7-Segment Decoder
Truth Table
Specification:
BCD input 7-Segment Output
Input: 4-bit BCD (I3, I2, I1, I0) I3 I2 I1 I0 a b c d e f g
0 0 0 0 1 1 1 1 1 1 0
Output: 7-bit (a, b, c, d, e, f, g)
0 0 0 1 0 1 1 0 0 0 0
Display should be OFF for Non-BCD
0 0 1 0 1 1 0 1 1 0 1
input codes.
0 0 1 1 1 1 1 1 0 0 1
Implementation uses: 0 1 0 0 0 1 1 0 0 1 1
A binary decoder 0 1 0 1 1 0 1 1 0 1 1
0 1 1 0 1 0 1 1 1 1 1
Additional gates
0 1 1 1 1 1 1 0 0 0 0
1 0 0 0 1 1 1 1 1 1 1
1 0 0 1 1 1 1 1 0 1 1
1010 to 0 0 0 0 0 0 0
1111
ITCS 222– Computer Organization slide #25 Decoders, Encoders, and Multiplexers
Implementing a BCD to 7-Segment Decoder
a
Truth Table
I3 I2 I1 I0 a b c d e f
b
g
0
0 0 0 0 1 1 1 1 1 1
c
1 0
2
0 0 0 1 0 1 1 0 0 0
d
I3 4-to-10 3 0
I2 4 0 0 1 0 1 1 0 1 1 0
e
I1 Binary 5 1
I0 Decoder 6 0 0 1 1 1 1 1 1 0 0
7 1
f
8 0 1 0 0 0 1 1 0 0 1
1
9
g
0 1 0 1 1 0 1 1 0 1
𝑰 𝟑 (𝑰 𝟐 +𝑰 𝟏 ) 1
outputs:
Combinational
inputs outputs
Circuit
ITCS 222– Computer Organization slide #27 Decoders, Encoders, and Multiplexers
Combinational Circuit Example: Full Adder
• Design a Full adder to add 3 bits: a, b, and c Truth Table
• Two output bits: a a b c su cout
𝒔𝒖𝒎 m
1) Carry bit: cout b Full
0 0 0 0 0
2) Sum bit: sum
c
Adder 𝒄𝒐𝒖𝒕 0 0 1 1 0
0 1 0 1 0
• Sum bit is 1 if the number of 1's in the input
0 1 1 0 1
value is odd (odd function)
1 0 0 1 0
sum = (a b) c
1 0 1 0 1
• Carry bit is 1 if the number of 1's in the
1 1 0 0 1
input is 2 or 3
1 1 1 1 1
cout = a·b + (a b)·c
ITCS 222– Computer Organization slide #28 Decoders, Encoders, and Multiplexers
Combinational
Full AdderCircuit
Module Design
// Code in Verlog Language
F
Logic operations: AND, OR, XOR, etc.
[2:0]
• Example: design an ALU with 8 operations 3
ALU
R [n -
as shown in the table below. VC n
1:0]
The function of F is coded with 3 bits: F2 F1 F0.
n 𝐹1
n XOR n n n n n n
gates
n n n AND n OR n XOR
gates gates gates
cn-1 n
n-bit Adder c0 𝐹0 n ′
𝐹2𝐹 𝐹0
1 𝐹 2 𝐹 ❑1 𝐹 0 n
cn ′ ′ ❑ ′
𝐹2𝐹1𝐹0 𝐹2𝐹1 𝐹0
n
3-state ′
𝐹2
buffers n n n n
n Result Bus
2) Formulation
Convert the specification into truth tables or logic expressions for
outputs
3) Logic Minimization
Minimize the output functions using K-map or Boolean algebra
4) Technology Mapping
Draw a logic diagram using ANDs, ORs, and inverters
Map the logic diagram into the selected technology
Considerations: cost, delays, fan-in, fan-out
5) Verification
Verify the correctness of the design, either manually or using simulation
ITCS 222– Computer Organization slide #32 Decoders, Encoders, and Multiplexers
BCD to 7-Segment Decoder (optional)
• Seven-Segment Display is used to display decimal
digits 0 to 9.
Made of Seven segments: light-emitting diodes (LED)
Found in electronic devices: such as clocks, calculators, etc.
The display is controlled by a BCD to 7-segment decoder.
a
I3 BCD to b
I2 c
7-Segment d
I1 e
I0 Decoder f
g
A BCD to 7-Segment Decoder
Accepts as input a BCD decimal digit (0 to 9)
Generates output to the seven LED segments to display the BCD digit
Each segment can be turned on or off separately
ITCS 222– Computer Organization slide #33 Decoders, Encoders, and Multiplexers
Designing a BCD to 7-Segment Decoder (optional)
1. Specification: Truth Table
Input: 4-bit BCD (A, B, C, D)
BCD input 7-Segment decoder
Output: 7-bit (a, b, c, d, e, f, g) A B C D a b c d e f g
Display should be OFF for 0 0 0 0 1 1 1 1 1 1 0
0 0 0 1 0 1 1 0 0 0 0
Non-BCD input codes
0 0 1 0 1 1 0 1 1 0 1
2. Formulation 0 0 1 1 1 1 1 1 0 0 1
0 1 0 0 0 1 1 0 0 1 1
Done with a truth table
0 1 0 1 1 0 1 1 0 1 1
Output is zero for 1010 to 0 1 1 0 1 0 1 1 1 1 1
1111 0 1 1 1 1 1 1 0 0 0 0
1 0 0 0 1 1 1 1 1 1 1
1 0 0 1 1 1 1 1 0 1 1
1010 to 0 0 0 0 0 0 0
1111
ITCS 222– Computer Organization slide #34 Decoders, Encoders, and Multiplexers
Designing a BCD to 7-Segment Decoder (optional)
3. Logic Minimization Using K-Maps
𝐶𝐷 K-map for 𝐶𝐷 K-map for 𝐶𝐷 K-map for
𝐴𝐵 00 01 11 10 𝐴𝐵 00 01 11 10 𝐴𝐵 00 01 11 10
00 1 1 1 00 1 1 1 1 00 1 1 1
01 1 1 1 01 1 1 01 1 1 1 1
11 11 11
10 1 1 10 1 1 10 1 1
ITCS 222– Computer Organization slide #35 Decoders, Encoders, and Multiplexers
Designing a BCD to 7-Segment Decoder (optional)
10 1 1 10 1 10 1 1 10 1 1
ITCS 222– Computer Organization slide #36 Decoders, Encoders, and Multiplexers
Designing a BCD to 7-Segment Decoder (optional)
4. Technology Mapping A T4
B'
T2
Many Common AND terms: thru C'
D' T5
B' T6
A'
C T0
D' T7
Optimized Logic Expressions
C' T8
A'
T1
B
D' T9
Showing only
Outputs e, f, g e f g
ITCS 222– Computer Organization slide #37 Decoders, Encoders, and Multiplexers
Example of Hierarchical Design (optional)
• Top Level: 16-input odd function: 16 inputs, one output
• Second Level: Five 4-input odd functions
• Third Level: Three 2-input XOR gates
x0
x0 x0 x0 x1
x1 x1 x1 4-Input z
x2 x2 x2 Odd z x2
x3 x3 x3 Function x3
x4 x4 x0
x5 x1 4-Input
x5
x6 x2 Odd z
16-Input x6 x0
x7 x3 Function x1 4-Input
z x7 x0 Odd z z
x8 Odd x8 x2
4-Input
x9 x9 x1 x3 Function
x2 Odd z
x10 Function x10
x3 Function Hierarchical Design
x11 x11
x12 x12 x0 typically includes
x1 4-Input
x13
x13
x2 Odd z blocks of different
x14 x14
x15 x3 Function functions and size
x15
ITCS 222– Computer Organization slide #38 Decoders, Encoders, and Multiplexers
Top-Down versus Bottom-Up Design (optional)
s3 s2 s1 s0 si
ITCS 222– Computer Organization slide #41 Decoders, Encoders, and Multiplexers
Hierarchical Design in Verilog (optional)
// Module Odd_4: 4-input Odd function uses three xor gates
module Odd_4 (input [0:3] x, output z);
wire [0:1] w;
xor g1(w[0], x[0], x[1]);
xor g2(w[1], x[2], x[3]);
xor g3(z, w[0], w[1]);
endmodule
ITCS 222– Computer Organization slide #42 Decoders, Encoders, and Multiplexers
Bit Vectors in Verilog (optional)
• A Bit Vector is multi-bit declaration that uses a single name
• A Bit Vector is specified as a Range [msb:lsb]
• msb is most-significant bit and lsb is least-significant bit
• Examples:
input [0:15] x; // x is a 16-bit input vector
ITCS 222– Computer Organization slide #44 Decoders, Encoders, and Multiplexers
Testing the 16-bit Adder (optional)
• Exhaustive testing: 216 × 216 × 2 = 8,589,934,592 test cases
• Let us choose only: 3 × 3 × 2 = 18 test cases
• Input test cases for a[15:0] = 'h158A, 'h52AF, 'hB903
Chosen randomly with values shown in hexadecimal
'h158A (hexadecimal) = 'b0001_0101_1000_1010 (binary)
Underscores are ignored (used to enhance readability)
• Input test cases for b[15:0] = 'h7095, 'h9A4E, 'hC6BD
Also chosen randomly with values shown in hexadecimal
Radix symbol: 'b (binary), 'o (octal), 'd (decimal), 'h (hex)
• Input test cases for cin = 0, 1
ITCS 222– Computer Organization slide #45 Decoders, Encoders, and Multiplexers
Writing a Test bench for the 16-bit Adder (optional)
module Test_Adder_16; // Test bench for Adder_16
reg [15:0] A, B; reg Cin; // Data and Carry inputs
wire [15:0] Sum; wire Cout; // Sum and Carry outputs
Adder_16 Test (A, B, Cin, Sum, Cout); // Instantiate 16-bit
adder
initial begin
A='h158A; B='h7095; Cin=0; // Initialize A, B, Cin
#200 $finish; // At t=200 end simulation
end
always begin // Change A every 60 ns
#60 A='h52AF; #60 A='hB903; #60 A='h158A;
end
always begin // Change B every 20 ns
#20 B='h9A4E; #20 B='hC6BD; #20 B='h7095;
end
always #10 Cin = ~Cin; // Invert Cin every 10 ns
endmodule
ITCS 222– Computer Organization slide #46 Decoders, Encoders, and Multiplexers
Simulator Waveforms (optional)