chapter 4
chapter 4
PROBLEMS
(Answers to problems marked with * appear at the end of the text. Where appropriate, a logic
design and its related HDL modeling problem are cross-referenced.)
4.1 Consider the combinational circuit shown in Fig. P4.1. (HDL—see Problem 4.49.)
A
T3
B
T1
C
F1
T2
T4
D
F2
FIGURE P4.1
(a)* Derive the Boolean expressions for T1 through T4. Evaluate the outputs F1 and F2
as a function of the four inputs.
(b) List the truth table with 16 binary combinations of the four input variables. Then list
the binary values for T1 through T4 and outputs F1 and F2 in the table.
(c) Plot the output Boolean functions obtained in part (b) on maps and show that the
simplified Boolean expressions are equivalent to the ones obtained in part (a).
4.2* Obtain the simplified Boolean expressions for output F and G in terms of the input
variables in the circuit of Fig. P4.2.
A
F
B
C
G
D
FIGURE P4.2
4.5 Design a combinational circuit with three inputs, x, y, and z, and three outputs, A, B, and C.
When the binary input is 0, 1, 2, or 3, the binary output is one greater than the input. When
the binary input is 4, 5, 6, or 7, the binary output is two less than the input.
4.6 A majority circuit is a combinational circuit whose output is equal to 1 if the input variables
have more 1’s than 0’s. The output is 0 otherwise.
(a)* Design a 3-input majority circuit by finding the circuit’s truth table, Boolean equation,
and a logic diagram.
(b) Write and verify a Verilog gate-level model of the circuit.
4.7 Design a combinational circuit that converts a four-bit Gray code (Table 1.6) to a bit four-
binary number.
(a)* Implement the circuit with exclusive-OR gates.
(b) Using a case statement, write and verify a Verilog model of the circuit.
4.8 Design a code converter that converts a decimal digit from
(a)* The 8, 4, –2, –1 code to BCD (see Table 1.5). (HDL—see Problem 4.50.)
(b) The 8, 4, –2, –1 code to Gray code.
4.9 An ABCD-to-seven-segment decoder is a combinational circuit that converts a decimal digit
in BCD to an appropriate code for the selection of segments in an indicator used to display
the decimal digit in a familiar form. The seven outputs of the decoder (a, b, c, d, e, f, g) select
the corresponding segments in the display, as shown in Fig. P4.9(a). The numeric display
chosen to represent the decimal digit is shown in Fig. P4.9(b). Using a truth table and
Karnaugh maps, design the BCD-to-seven-segment decoder using a minimum number of
gates. The six invalid combinations should result in a blank display. (HDL—see Problem 4.51.)
f b
g
b
e c c
d
(a) Segment designation (b) Numerical designation for display
FIGURE P4.9
4.10* Design a four-bit combinational circuit 2’s complementer. (The output generates the 2’s
complement of the input binary number.) Show that the circuit can be constructed with
exclusive-OR gates. Can you predict what the output functions are for a five-bit 2’s com-
plementer?
4.11 Using four half-adders (HDL—see Problem 4.52),
(a) Design a full-subtractor circuit incrementer. (A circuit that adds one to a four-bit
binary number.)
(b)* Design a four-bit combinational decrementer (a circuit that subtracts 1 from a four-
bit binary number).
4.12 Design a half-subtractor circuit with inputs x and y and outputs Diff and Bout. The circuit
subtracts the bits x – y and places the difference in D and the borrow in Bout.
(a) Design a full-subtractor circuit with three inputs x, y, Bin and two outputs Diff and
Bout. The circuit subtracts x – y – Bin, where Bin is the input borrow, Bout is the output
borrow, and Diff is the difference.
184 Chapter 4 Combinational Logic
4.13* The adder–subtractor circuit of Fig. 4.13 has the following values for mode input M and
data inputs A and B.
M A B
(a) 0 0111 0110
(b) 0 1000 1001
(c) 1 1100 1000
(d) 1 0101 1010
(e) 1 0000 0001
In each case, determine the values of the four SUM outputs, the carry C, and overflow V.
(HDL—see Problems 4.37 and 4.40.)
4.14* Assume that the exclusive-OR gate has a propagation delay of 10 ns and that the AND or
OR gates have a propagation delay of 5 ns. What is the total propagation delay time in the
four-bit adder of Fig. 4.12?
4.15 Derive the two-level Boolean expression for the output carry C4 shown in the lookahead
carry generator of Fig. 4.12.
4.16 Define the carry propagate and carry generate as
Pi A i B i
Gi AiBi
respectively. Show that the output carry and output sum of a full adder becomes
Ci + 1 = (Ci Gi + Pi )
Si = (PiGi) { Ci
The logic diagram of the first stage of a four-bit parallel adder as implemented in IC type
74283 is shown in Fig. P4.16. Identify the Pi and Gi terminals and show that the circuit
implements a full-adder circuit.
C1
B0
S0
A0
C0
FIGURE P4.16
First stage of a parallel adder
Problems 185
4.17 Show that the output carry in a full adder circuit can be expressed in the AND-OR-
INVERT form
Ci + 1 = Gi + PiCi = (GiPi + GiCi)
IC type 74182 is a lookahead carry generator circuit that generates the carries with AND-
OR-INVERT gates (see Section 3.8). The circuit assumes that the input terminals have
the complements of the G’s, the P’s, and of C1. Derive the Boolean functions for the
lookahead carries C2, C3, and C4 in this IC. (Hint: Use the equation-substitution method
to derive the carries in terms of Ci)
4.18 Design a combinational circuit that generates the 9’s complement of a
(a)* BCD digit. (HDL—see Problem 4.54(a).)
(b) Gray-code digit. (HDL—see Problem 4.54(b).)
4.19 Construct a BCD adder–subtractor circuit. Use the BCD adder of Fig. 4.14 and the 9’s
complementer of problem 4.18. Use block diagrams for the components. (HDL—see Prob-
lem 4.55.)
4.20 For a binary multiplier that multiplies two unsigned four-bit numbers,
(a) Using AND gates and binary adders (see Fig. 4.16), design the circuit.
(b) Write and verify a Verilog dataflow model of the circuit.
4.21 Design a combinational circuit that compares two 4-bit numbers to check if they are equal.
The circuit output is equal to 1 if the two numbers are equal and 0 otherwise.
4.22* Design an excess-3-to-binary decoder using the unused combinations of the code as
don’t-care conditions. (HDL—see Problem 4.42.)
4.23 Draw the logic diagram of a 2-to-4-line decoder using (a) NOR gates only and (b) NAND
gates only. Include an enable input. (HDL—see Problems 4.36, 4.45.)
4.24 Design a BCD-to-decimal decoder using the unused combinations of the BCD code as
don’t-care conditions.
4.25 Construct a 5-to-32-line decoder with four 3-to-8-line decoders with enable and a 2-to-
4-line decoder. Use block diagrams for the components. (HDL—see Problem 4.63.)
4.26 Construct a 4-to-16-line decoder with five 2-to-4-line decoders with enable. (HDL—see
Problem 4.64.)
4.27 A combinational circuit is specified by the following three Boolean functions:
F1 1A, B, C2 = ⌺11, 4, 62
F2 1A, B, C2 = ⌺13, 52
F3 1A, B, C2 = ⌺12, 4, 6, 72
Implement the circuit with a decoder constructed with NAND gates (similar to Fig. 4.19)
and NAND or AND gates connected to the decoder outputs. Use a block diagram for the
decoder. Minimize the number of inputs in the external gates.
4.28 Using a decoder and external gates, design the combinational circui defined by the
following three Boolean functions:
(a) F1 = x⬘yz⬘ + xz (b) F1 = 1y⬘ + x2z
F2 = xy⬘z⬘ + x⬘y F2 = y⬘z⬘ + x⬘y + yz⬘
F3 = x⬘y⬘z⬘ + xy F3 = 1x + y2z
186 Chapter 4 Combinational Logic
4.29* Design a four-input priority encoder with inputs as in Table 4.8, but with input D0 having
the highest priority and input D3 the lowest priority.
4.30 Specify the truth table of an octal-to-binary priority encoder. Provide an output V to in-
dicate that at least one of the inputs is present. The input with the highest subscript num-
ber has the highest priority. What will be the value of the four outputs if inputs D2 and D6
are 1 at the same time? (HDL—see Problem 4.65.)
4.31 Construct a 16 ⫻ 1 multiplexer with two 8 ⫻ 1 and one 2 ⫻ 1 multiplexers. Use block dia-
grams. (HDL—see Problem 4.67.)
4.32 Implement the following Boolean function with a multiplexer (HDL—see Problem 4.46):
(a) F 1A, B, C, D2 = ⌺ 10, 2, 5, 8, 10, 142
(b) F 1A, B, C, D2 = ⌸ 12, 6, 112
4.42 (a) Write an HDL gate-level description of the BCD-to-excess-3 converter circuit shown
in Fig. 4.4 (see Problem 4.22).
(b) Write a dataflow description of the BCD-to-excess-3 converter using the Boolean
expressions listed in Fig. 4.3.
(c)* Write an HDL behavioral description of a BCD-to-excess-3 converter.
(d) Write a test bench to simulate and test the BCD-to-excess-3 converter circuit in order
to verify the truth table. Check all three circuits.
4.43 Explain the function of the circuit specified by the following HDL description:
module Prob4_43 (A, B, S, E, Q);
input [1:0] A, B;
input S, E;
output [1:0] Q;
assign Q ⫽ E ? (S ? A : B) : 'bz;
endmodule
4.44 Using a case statement, write an HDL behavioral description of a eight-bit arithmetic-
logic unit (ALU). The circuit has a three-bit select bus (Sel), sixteen-bit input datapaths
(A[15:0] and B[15:0]), an eight-bit output datapath (y[15:0]), and performs the arithmetic
and logic operations listed below.
Sel Operation Description
000 y ⫽ 8⬘b0
001 y⫽A&B Bitwise AND
010 y⫽A|B Bitwise OR
011 y⫽A^B Bitwise exclusive OR
100 y ⫽ ~A Bitwise complement
101 y⫽A⫺B Subtract
110 y⫽A⫹B Add (Assume A and B are unsigned)
111 y ⫽ 8⬘hFF
4.45 Write an HDL behavioral description of a four-input priority encoder. Use a four-bit vector
for the D inputs and an always block with if–else statements. Assume that input D[3] has
the highest priority (see Problem 4.36).
4.46 Write a Verilog dataflow description of the logic circuit described by the Boolean function
in Problem 4.32.
4.47 Write a Verilog dataflow description of the logic circuit described by the Boolean function
in Problem 4.35.
4.48 Develop and modify the eight-bit ALU specified in Problem 4.44 so that it has three-state
output controlled by an enable input, En. Write a test bench and simulate the circuit.
4.49 For the circuit shown in Fig. P4.1,
(a) Write and verify a gate-level HDL model of the circuit.
(b) Compare your results with those obtained for Problem 4.1.
4.50 Using a case statement, develop and simulate a behavioral model of
(a)* The 8, 4, –2, –1 to BCD code converter described in Problem 4.8(a).
(b) The 8, 4, –2, –1 to Gray code converter described in Problem 4.8(b).
188 Chapter 4 Combinational Logic
REFERENCES
1. Bhasker, J. 1997. A Verilog HDL Primer. Allentown, PA: Star Galaxy Press.
2. Bhasker, J. 1998. Verilog HDL Synthesis. Allentown, PA: Star Galaxy Press.
3. Ciletti, M. D. 1999. Modeling, Synthesis, and Rapid Prototyping with Verilog HDL. Upper
Saddle River, NJ: Prentice Hall.
4. Dietmeyer, D. L. 1988. Logic Design of Digital Systems, 3rd ed. Boston: Allyn Bacon.
60
CHAPTER 4
4.1
(a) T1 = B'C, T2 = A'B, T3 = A + T1 = A + B'C,
T4 = D ⊕ T2 = D ⊕ (A'B) = A'BD' + D(A + B') = A'BD' + AD + B'D
F1 = T3 + T4 = A + B'C + A'BD' + AD + B'D
With A + AD = A and A + A'BD' = A + BD':
F1 = A + B'C + BD' + B'D
Alternative cover: F1 = A + CD' + BD' + B'D
F2 = T2 + D' = A'B + D'
ABCD T1 T2 T3 T4 F1 F2
CD C
0000 0 0 0 0 0 1 00 01 11 10
0001 0 0 0 1 1 0 M0 M1 M3 M2
0010 1 0 1 0 1 1 00 1 1 1
0011 1 0 1 1 1 0
M4 M5 M7 M6
0100 0 1 0 1 1 1
01 1 1
0101 0 1 0 0 0 1
0110 0 1 0 1 1 1 M12 M13 M15 M14 B
0111 0 1 0 0 0 1 11 1 1 1 1
A M8 M9 M11 M10
1000 0 0 1 0 1 1
10 1 1 1 1
1001 0 0 1 1 1 0
1010 1 0 1 0 1 1
1011 1 0 1 1 1 0 D
1100 0 0 1 0 1 1
1101 0 0 1 1 1 0 F1 = A + B'C+ B'D + BD'
1110 0 0 1 0 1 1
1111 0 0 1 1 1 0
CD C CD C
AB 00 01 11 10 AB 00 01 11 10
M0 M1 M3 M2 M0 M1 M3 M2
00 1 1 00 1 1 1
M4 M5 M7 M6 M4 M5 M7 M6
01 1 1 1 1 01 1 1
M12 M13 M15 M14 B M12 M13 M15 M14 B
11 1 1 A 11 1 1 1 1
A M8 M9 M11 M10 M8 M9 M11 M10
10 1 1 10 1 1 1 1
D D
F2 = A'B + D' F1 = A + CD' + B'D + BD'
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
61
4.2
[(A'D)' A']'= A + D
A'
A
F
B BC + A'
C BC
G
D
(A'D)' = A + D’
D D
F = A'D + ABC + BCD = A'D + ABC G = A'D' + ABC + BCD' = A'D' + ABC
4.4 (a)
xyz F
yz y
000 1 x 00 01 11 10
001 1 m0 m1 m3 m2 x'
010 1 0 1 1 1 y'
011 0
m4 m5 m7 m6 F
100 0
x 1 x'
101 0
y'
110 0
111 0 z
F = x'y' + x'z'
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
62
(b)
xyz F
yz y
000 0 x
00 01 11 10
001 1 m0 m1 m3 m2
010 0 0 1 1
011 0 z F
100 0 m4 m5 m7 m6
101 0 x 1 1 1
110 0
111 0 z
F=z
4.5
xyz ABC A
yz y
000 010 x
00 01 11 10
001 011 m0 m1 m3 m2 x'
010 100 0 1 1 y
011 101
m4 m5 m7 m6 A
100 001
x 1 1 y
101 010
z
110 011
111 100 z
A = x'y + yz
B y
yz
x 00 01 11 10
m0 m1 m3 m2 x
0 1 1 y'
m4 m5 m7 m6
x 1 1 1 y'
B
z
x
z
y
B = x'y' + y'z + xyz'
z'
C
yz y
x
00 01 11 10
m0 m1 m3 m2
0 1 1
x
m4 m5 m7 m6 C
z
x 1 1 1
z
C= x'z + xz'
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
63
4.6
xyz F A
yz y
000 0 x 00 01 11 10
001 0 m0 m1 m3 m2 x
010 0 0 1 z
011 1 y
m4 m5 m7 m6 F
100 0 z
x 1 1 1 1 x
101 1
y
110 1
111 1 z
F = xz + yz + xy
module Prob_4_6 (output F, input x, y, z);
assign F = (x & z) | (y & z) | (x & y);
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
64
4.7 (a)
ABCD wxyz
CD C CD C
0000 0000 AB
00 01 11 10 00 01 11 10
0001 0001 m0 m1 m3 m2 m0 m1 m3 m2
0011 0010 00 00
0010 0011
m4 m5 m7 m6 m4 m5 m7 m6
0110 0100
0111 0101 01 01 1 1 1 1
0101 0110 m12 m13 m15 m14 B m12 m13 m15 m14 B
0100 0111 11 1 1 1 1 11
A m8 m9 m11 m10 A m8 m9 m11 m10
1100 1000
1101 1001 10 1 1 1 1 10 1 1 1 1
1111 1010
1110 1011
D D
1010 1100
w=A x = AB' + A'B = A B
1011 1101
1001 1110
1000 1111
CD C CD C
AB 00 01 11 10 AB 00 01 11 10
m0 m1 m3 m2 m0 m1 m3 m2
00 1 1 00 1 1
m4 m5 m7 m6 m4 m5 m7 m6
01 1 1 01 1 1
m12 m13 m15 m14 B m12 m13 m15 m14 B
11 1 1 11 1 1
A m8 m9 m11 m10 A m8 m9 m11 m10
10 1 1 10 1 1
D D
y = A'B'C A'BC' + ABC + AB'C' z=A B C D
= A'(A B) + A(B C)' =y D
=A B C
= X C
A w
B x
C y
z
D
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
65
(b)
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
66
4.8 (a) The 8-4-2-1 code (Table 1.5) and the BCD code (Table 1.4) are identical for digits 0 – 9.
(b)
8421 Gray
ABCD wxyz
CD C CD C
0000 0000 AB
00 01 11 10 00 01 11 10
0001 0001 m0 m1 m3 m2 m0 m1 m3 m2
0010 0011 00 00
0011 0010
m4 m5 m7 m6 m4 m5 m7 m6
0100 0110
01 01 1 1 1 1
0101 0111
0110 0101 m12 m13 m15 m14 B m12 m13 m15 m14 B
0111 0100 11 11
1000 1100 A A
m8 m9 m11 m10 m8 m9 m11 m10
1001 1101
10 1 1 10 1 1
D D
w = AB'C' x = AB'C' + A'B
CD C CD C
AB AB
00 01 11 10 00 01 11 10
m0 m1 m3 m2 m0 m1 m3 m2
00 1 1 00 1 1
m4 m5 m7 m6 m4 m5 m7 m6
01 1 1 01 1 1
m12 m13 m15 m14 B m12 m13 m15 m14 B
11 11 1
A A
m8 m9 m11 m10 m8 m9 m11 m10
10 10
D D
y = A'BD' + A'B'D z = A'C'D + BC'D + A'CD'
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
67
4.9
CD C CD C
ABCD a b c d e f g AB AB
00 01 11 10 00 01 11 10
0000 1 1 1 1 1 1 0 m0 m1 m3 m2 m0 m1 m3 m2
0001 0 1 1 0 0 0 0 00 1 1 1 00 1 1 1 1
0010 1 1 0 1 1 0 1 m4 m5 m7 m6 m4 m5 m7 m6
0011 1 1 1 1 0 0 1 01 1 1 1 01 1 1
0100 0 1 1 0 0 1 1
m12 m13 m15 m14 B m12 m13 m15 m14 B
0101 1 0 1 1 0 1 1
0110 1 0 1 1 1 1 1 11 11
0111 1 1 1 0 0 0 0 A m8 m9 m11 m10 A m8 m9 m11 m10
1000 1 1 1 1 1 1 1 10 1 1 10 1 1
1001 1 1 1 1 0 1 1
D D
a = A'C + A'BD + B'C'D' + AB'C' b = A'B' + A'C'D' + A'CD + AB'C'
CD C CD C
AB 00 01 11 10 AB 00 01 11 10
m0 m1 m3 m2 m0 m1 m3 m2
00 1 1 1 00 1 1 1
m4 m5 m7 m6 m4 m5 m7 m6
01 1 1 1 1 01 1 1
m12 m13 m15 m14 B m12 m13 m15 m14 B
11 11
A m8 m9 m11 m10 A m8 m9 m11 m10
10 1 1 10 1 1
D D
c = A'B + A'D + B'C'D' + AB'C' d = A'CD' + A'B' C+ B'C'D' + AB'C' + A'BC'D
CD C CD C CD C
AB 00 01 11 10 AB 00 01 11 10 AB 00 01 11 10
m0 m1 m3 m2 m0 m1 m3 m2 m0 m1 m3 m2
00 1 1 00 1 00 1 1
m4 m5 m7 m6 m4 m5 m7 m6 m4 m5 m7 m6
01 1 01 1 1 1 01 1 1 1
m12 m13 m15 m14 B m12 m13 m15 m14 B m12 m13 m15 m14 B
11 11 11
A m8 m9 m11 m10 A m8 m9 m11 m10 A m8 m9 m11 m10
10 1 10 1 1 10 1 1
D D D
e = A'CD' + B'C'D' f = A'BC' + A'C'D' + A'BD + AB'C' g = A'CD' + A'B'C + A'BC' + AB'C'
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
68
4.10
ABCD wxyz CD C CD C
0000 0000 AB 00 01 11 10 00 01 11 10
0001 1111 m0 m1 m3 m2 m0 m1 m3 m2
0010 1110 00 1 1 1 00 1 1 1
0011 1101
m4 m5 m7 m6 m4 m5 m7 m6
0100 1100
0101 1011 01 1 1 1 1 01 1
0110 1001 m12 m13 m15 m14 B m12 m13 m15 m14 B
0111 1000 11 11 1
A m8 m9 m11 m10 A m8 m9 m11 m10
1000 1000
1001 0111 10 1 10 1 1 1
1010 0110
1011 0101
D D
1100 0100
w = A'(B + C + D) + AB'C'D' x = B'(C + D) + CB'D'
1101 0011
= A (B + C + D) = B (C + D)
1110 0010
1111 0001
CD C CD C
AB 00 01 11 10 AB 00 01 11 10
m0 m1 m3 m2 m0 m1 m3 m2
00 1 1 00 1 1
m4 m5 m7 m6 m4 m5 m7 m6
01 1 1 01 1 1
m12 m13 m15 m14 B m12 m13 m15 m14 B
11 1 1 11 1 1
A m8 m9 m11 m10 A m8 m9 m11 m10
10 1 1 10 1 1
D D
z=D
y = CD' + C'D = C D
For a 5-bit 2's complementer with input E and output v:
v=E (A + B + C + D)
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
69
4.11 (a)
A3 A2 A1 A0
1
x y x y x y x y
C S C S C S C S
x y x y x y x y
B D B D B D B D
Note: To decrement the 4-bit number, add -1 to the number. In 2's complement format ( add Fh ) to
the number. An attempt to decrement 0 will assert the borrow bit. For waveforms, see solution to
Problem 4.52.
4.12
(a)
x y B D
0 0 0 0
D = x'y + xy'
0 1 1 1
B = x'y
1 0 0 1
1 1 0 0
(b)
x y Bin B D
0 0 0 0 0
Diff = x y z
0 0 1 1 1
Bout = x'y + x'z + yz
0 1 0 1 1
0 1 1 1 0
1 0 0 0 1
1 0 1 0 0
1 1 0 0 0
1 1 1 1 1
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
70
4.13 Sum C V
(a) 1101 0 1
(b) 0001 1 1
(c) 0100 1 0
(d) 1011 0 1
(e) 1111 0 0
10 + 5 + 5 + 10 = 30 ns
4.16 (a)
(C'G'i + p'i)' = (Ci + Gi)Pi = GiPi + PiCi
= AiBi(Ai + Bi) + PiCi
= A iB i + P i C i = G i + P iC i
= AiBi + (Ai + Bi)Ci = AiBi + AiCi + BiCi = Ci+1
(PiG'i) ⊕ Ci = (Ai + Bi)(AiBi)' ⊕ Ci = (Ai + Bi)(A'i + B'i) ⊕ Ci
= (A'iBi + AiB'i) ⊕ Ci = Ai ⊕ Bi ⊕ Ci = Si
(b)
4.17 (a)
(C'iG'i + P'i)' = (Ci + Gi)Pi = GiPi + PiCi = AiBi(Ai + Bi) + PiCi
= A iB i + P i C i = G i + P iC i
= AiBi + (Ai + Bi)Ci = AiBi + AiCi + BiCi = Ci+1
S0 = (P0G'0)⊕C0
C1 = (C'0G'0 + P'0)' as defined in part (a)
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
71
4.18
Inputs Outputs
ABCD wxyz
0000 1001
d(A, b, c, d) = Σ(10, 11, 12, 13, 14, 15)
0001 1000
0010 0111
0011 0110
0100 0101
0101 0100
0110 0011
0111 0010
1000 0001
1001 0000
CD C CD C
AB AB
00 01 11 10 00 01 11 10
m0 m1 m3 m2 m0 m1 m3 m2
00 1 1 00 1 1
m4 m5 m7 m6 m4 m5 m7 m6
01 01 1 1
m12 m13 m15 m14 B m12 m13 m15 m14 B
11 x x x x 11 x x x x
A m8 m9 m11 m10 A m8 m9 m11 m10
10 x x 10 x x
D D
w = A'B'C' x = BC' + B'C = B C
CD C CD C
00 01 11 10 AB 00 01 11 10
m0 m1 m3 m2 m0 m1 m3 m2
00 1 1 00 1 1
m4 m5 m7 m6 m4 m5 m7 m6
01 1 1 01 1 1 1
m12 m13 m15 m14 B m12 m13 m15 m14 B
11 x x x x 11 x x x x
m8 m9 m11 m10 A m8 m9 m11 m10
10 x x 10 1 x x
D D
y=C z = D'
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
72
4.19
9's Complementer
(See Problem 4.18)
Select
Select = 1 Select = 0
A3 A2 A1 A0
Quadruple 2 x 1 MUX
Cin
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
73
4.20 Combine the following circuit with the 4-bit binary multiplier circuit of Fig. 4.16.
C6 C5 C4 C3 C2 C1 C0
A3
B3 B2 B1 B0
Cout
4-bit Adder Augend
D7 D6 D5 D4 D3 D2 D1 D0
4.21
A0
B0
A1
B1
x
A2
B2
A3
B3
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
74
CD C CD C
AB 00 01 11 10 AB 00 01 11 10
m0 m1 m3 x m0 m1 m3 m2
00 x x 00 X X X
m4 m5 m7 m6 m4 m5 m7 m6
01 01 1
m12 m13 m15 m14 B m12 m13 m15 m14 B
11 1 x x x 11 x x x
A m8 m9 m11 m10 A m8 m9 m11 m10
10 1 10 1 1 1
D D
w = AB + ACD x = B'C' + B'D' + BCD
y = C'D + CD'
z = D'
4.23
D0 = A1'A0' = (A1 + A0)' (NOR) D0' = (A1'A0')' (NAND)
D1 = A1'A0 = (A1 + A0')' (NOR) D1' = (A1'A0)' (NAND)
D2 = A1A0' = (A1' + A0)' (NOR) D2' = (A1A0')' (NAND)
D3 = A1A0 = (A1' + A0)' (NOR) D0' = (A1A0)' (NAND)
A1
A0 D0 = (A1 + A0 + E' )' = A'1A'0E
E A1 A0
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
75
4.24
CD C
AB 00 01 11 10
m0 m1 m3 x
00 D0 D1 D3 D2
Inputs: A, B, C, D
Outputs: D0, D1, ... D9 m4 m5 m7 m6
D0 = A'B'C'D' D5 = BC'D 01 D4 D5 D7 D6
D1 = A'B'C'D D6 = BCD' m12 m13 m15 m14 B
D2 = B'CD' D7 = BCD 11 x x x x
D3 = B'CD D8 = AD'
D4 = BC'D' D9 = AD A m8 m9 m10
m11
10 D8 D9 x x
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
76
4.25
A0 3x8 8
A1 D0 - D7
A2 Decoder
E
8
3x8
Decoder D8 - D15
E
0
A3 20
2x4 1
Decoder 2 8
3x8
A4 21 D16 - D23
3 Decoder
E E
3x8 8
D24 - D31
Decoder
E
4.26
A0 20 2x4 4
D0 - D3
A1 2 1 Decoder
E
20 2x4
4
1 Decoder D4 - D7
2 E
0
A2 20
2x4 1
Decoder 2 20 4
2x4
A3 21 D8 - D11
3 2 1 Decoder
E E
20 2x4 4
D12 - D15
2 1 Decoder
E
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
77
4.27
F1 = Σ(1, 4, 6)
0
1
A 2 3x8 2
2
B 21 Decoder
3
F2 = Σ(3, 5)
C 20 4
5
6
7
F3 = Σ(2, 4, 6, 7)
4.28 (a)
0
F1 = Σ((2, 5, 7)
1
x 22 3 x 8 2
y 21 Decoder 3
4 F1 = Σ((2, 3, 4)
z 20
5
6
7 F1 = Σ(0, 6, 7)
(b)
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
78
4.29
D1D0 D1
D3D2 00 01 11 10
m0 m1 m3 m2
Inputs Outputs 00 1 1 1
D3 D2 D1 D0 x y V m4 m5 m7 m6
01 1 1 1 1
0 0 0 0 x x 0 D2
m12 m13 m15 m14
x x x 1 0 0 1
x x 1 0 0 1 1 11 1 1 1 1
x 1 0 0 1 0 1 D3 m8 m9 m11 m10
1 0 0 0 1 1 1 10 1 1 1 1
D0
V = D0 + D1 + D2 + D3
D1D0 D1D0 D1
D3D2 00 01 11 10 D3D2 00 01 11 10
m0 m1 m3 m2 m0 m1 m3 m2
00 x 00 x 1
m4 m5 m7 m6 m4 m5 m7 m6
01 1 01 1
D2 D2
m12 m13 m15 m14 m12 m13 m15 m14
11 1 11 1
m8 m9 m11 m10 D3 m8 m9 m11 m10
10 1 10 1 1
D0 D0
x = D1'D0'
y = D0'D2' + D1D0'
D0
x
D1
y
D2
D0
D1
D2 V
D3
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
79
4.30
Inputs Outputs
D0 D1 D2 D3 D4 D5 D6 D7 x y z V
0 0 0 0 0 0 0 0 x x x 0
1 0 0 0 0 0 0 0 0 0 0 1
x 1 0 0 0 0 0 0 0 0 1 1
x x 1 0 0 0 0 0 0 1 0 1
x x x 1 0 0 0 0 0 1 1 1
x x x x 1 0 0 0 1 0 0 1
x x x x x 1 0 0 1 0 1 1
x x x x x x 1 0 1 0 0 1
x x x x x x x 1 1 1 1 1
If D2 = 1, D6 = 1, all others = 0
Output xyz = 100 and V = 1
4.31
s0 s0
s1 s1
s2 s2
s3 0 0
1 1
8x1
2 2
MUX
3 3
4 4
5 5
6 6
7 7
s
2x1 y
0
MUX
1
s0
s1
s2
8 0
9 1
8x1
10 2
MUX
11 3
12 4
13 5
14 6
15 7
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
80
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
81
(b)
Value
Inputs
ABCD
000 0 0 0 1F = 1
000 1 0 1 1
001 0 1 2 1 A s0
F=1
001 1 1 3 1 B s1
010 0 2 4 0 C s2
F=D
010 1 2 5 1 0
011 0 3 6 1F = 1 1 F
011 1 3 7 1 8x1
2 Y
100 0 4 8 1 MUX
F = D' 3
100 1 4 9 0 D 4
101 0 5 10 1 5
F=1 1
101 1 5 11 1 6
110 0 6 12 1F = D' 7
110 1 6 13 0
111 0 7 14 1
F=1
111 1 7 15 1
4.33
x 0
S(x, y, z) = Σ(1, 2, 4, 7) 1
C(x, y, z) = Σ(3, 5, 6, 7) 2
S
3
Dual
S I0 I1 I2 I3 I0 I1 I2 I3 4x1 Y
C
MUX
x' 0 1 2 3 x' 0 1 2 3 0 0
C
x 4 5 6 7 x 4 5 6 7 1
x x' x' x 0 x' x' 1 2
1 3
y z
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
82
4.34 (a)
A B C D F CD C
AB 00 01 11 10
I3 = 1 0 1 1 0 1 m0 m1 m3 m2
0 1 1 1 1 00 1
1 0 1 0 1
I5 = 1 m4 m5 m7 m6
1 0 1 1 1
0 0 0 0 0 01 1 1
I0 = D B
0 0 0 1 1 m12 m13 m15 m14
1 0 0 0 0 11 1
I4 = D 1 0 0 1 1 A m8 m9 m11 m10
1 1 0 0 1
I6 = D' 10 1 1 1
1 1 0 1 0
D
Other minterms = 0
since I1 = I2 = I7 = 0 F(A, B, C, D) = Σ(1, 6, 7, 9, 10, 11, 12)
(b)
A B C D F CD C
AB
00 01 11 10
I1 = 0 0 0 1 0 0 m0 m1 m3 m2
0 0 1 1 0 00 1 1
I2 = 0 0 1 0 0 0 m4 m5 m7 m6
0 1 0 1 0 01 1 1
0 1 1 0 1
I3 = 1 B
0 1 1 1 1 m12 m13 m15 m14
1 1 1 0 1 11 1 1 1
I7 = 1
1 1 1 1 1 A m8 m9 m11 m10
I4 = D 1 0 0 0 0 10 1
1 0 0 1 1
0 0 0 0 1
I0 = D' 0 0 0 1 0 D
1 1 0 0 1
I6= D' 1 1 0 1 0 F(A, B, C, D) = Σ(0, 1, 6, 7, 9, 13, 14, 15)
Other minterms = 0
since I1 = I2 = 0
4.35 (a)
Inputs
ABCD F
0000 0
0001 1 AB = 00
0010 0 F=D A s0
0011 1 s1
B
0100 1
AB = 01
0101 0 0 4x1
F = C'D'
0110 0 C 1 MUX
= (C + D)' D F
0111 0 Y
1000 0 2
1001 0 AB = 10 3
1010 0 F = CD
1011 1 1
1100 1
AB = 11
1101 1
F=1
1110 1
1111 1
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
83
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
84
module half_adder (output S, C, input x, y); // See HDL Example 4.2
xor (S, x, y);
and (C, x, y);
endmodule
Name 0 50 100
A[3:0] x a
B[3:0] x 5 3
M
S[3:0] x f 5 7
C
4.38
module quad_2x1_mux ( // V2001
input [3: 0] A, B, // 4-bit data channels
input enable_bar, select, // enable_bar is active-low)
output [3: 0] Y // 4-bit mux output
);
//assign Y = enable_bar ? 0 : (select ? B : A); // Grounds output
assign Y = enable_bar ? 4'bzzzz : (select ? B : A); // Three-state output
endmodule
//
Note
that
this
mux
grounds
the
output
when
the
mux
is
not
active.
module t_quad_2x1_mux ();
reg [3: 0] A, B, C; // 4-bit data channels
reg enable_bar, select; // enable_bar is active-low)
wire [3: 0] Y; // 4-bit mux
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
85
#20 enable_bar = 0;
#30 A = 4'h0;
#40 A = 4'hF;
#50 enable_bar = 1;
#60 select = 1; // channel B
#70 enable_bar = 0;
#80 B = 4'h00;
#90 B = 4'hA;
#100 B = 4'hF;
#110 enable_bar = 1;
#120 select = 0;
#130 select = 1;
#140 enable_bar = 1;
join
endmodule
Name 0 70 140
A[3:0] a 0 f
B[3:0] 5 0 a f
enable_bar
select
Y[3:0] 0 a 0 f 0 5 0 a f 0
Name 0 70 140
A[3:0] a 0 f
B[3:0] 5 0 a f
enable_bar
select
Y[3:0] z a 0 f z 5 0 a f z
always @ (A or B)
if (A==B) Y = 6'b10_0011; // EQ, GE, LE
else if (A < B) Y = 6'b01_0101; // NE, LT, LE
else Y = 6'b01_1010; // NE, GT, GE
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
86
4.40
module Prob_4_40 (
output [3: 0] sum_diff, output carry_borrow,
input [3: 0] A, B, input sel_diff
);
module t_Prob_4_40;
wire [3: 0] sum_diff;
wire carry_borrow;
reg [3:0] A, B;
reg sel_diff;
integer I, J, K;
Prob_4_40 M0 ( sum_diff, carry_borrow, A, B, sel_diff);
initial #4000 $finish;
initial begin
for (I = 0; I < 2; I = I + 1) begin
sel_diff = I;
for (J = 0; J < 16; J = J + 1) begin
A = J;
for (K = 0; K < 16; K = K + 1) begin B = K; #5 ; end
end
end
end
endmodule
4.41
module Prob_4_41 (
output reg [3: 0] sum_diff, output reg carry_borrow,
input [3: 0] A, B, input sel_diff
);
endmodule
module t_Prob_4_41;
wire [3: 0] sum_diff;
wire carry_borrow;
reg [3:0] A, B;
reg sel_diff;
integer I, J, K;
Prob_4_46 M0 ( sum_diff, carry_borrow, A, B, sel_diff);
initial #4000 $finish;
initial begin
for (I = 0; I < 2; I = I + 1) begin
sel_diff = I;
for (J = 0; J < 16; J = J + 1) begin
A = J;
for (K = 0; K < 16; K = K + 1) begin B = K; #5 ; end
end
end
end
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
87
780 810 840 870
Name
sel_diff
A[3:0] 9 a b
B[3:0] c d e f 0 1 2 3 4 5 6 7 8 9 a b c d e f 0 1 2
sum_diff[3:0] 5 6 7 8 a b c d e f 0 1 2 3 4 5 6 7 8 9 b c d
carry_borrow
2064 2094 2124 2154
Name
sel_diff
A[3:0] 9 a b
B[3:0] d e f 0 1 2 3 4 5 6 7 8 9 a b c d e f 0 1 2
sum_diff[3:0] c b a 9 8 7 6 5 4 3 2 1 0 f e d c b a 9
carry_borrow
4.42 (a)
module Xs3_Gates (input A, B, C, D, output w, x, y, z);
wire B_bar, C_or_D_bar;
wire CD, C_or_D;
or (C_or_D, C, D);
not (C_or_D_bar, C_or_D);
not (B_bar, B);
and (CD, C, D);
not (z, D);
or (y, CD, C_or_D_bar);
and (w1, C_or_D_bar, B);
and (w2, B_bar, C_or_D);
and (w3, C_or_D, B);
or (x, w1, w2);
or (w, w3, A);
endmodule
(b)
module Xs3_Dataflow (input A, B, C, D, output w, x, y, z);
assign {w, x, y, z} = {A, B, C, D} + 4'b0011;
endmodule
(c)
module Xs3_Behavior_95 (A, B, C, D, w, x, y, z);
input A, B, C, D;
output w, x, y, z;
reg w, x, y, z;
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
88
Name 0 30 60 90
k 0 1 2 3 4 5 6 7 8 9
A
B
C
D
BCD_value[3:0] 0 1 2 3 4 5 6 7 8 9
w_Gates
x_Gates
y_Gates
z_Gates
Xs3_Gates[3:0] 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100
Xs3_Gates[3:0] 3 4 5 6 7 8 9 a b c
Xs3_Dataflow[3:0] 3 4 5 6 7 8 9 a b c
Xs3_Behavior_95[3:0] 3 4 5 6 7 8 9 a b c
Xs3_Behavior_01[3:0] 3 4 5 6 7 8 9 a b c
4.43 Two-channel mux with 2-bit data paths, enable, and three-state output.
4.44
module ALU (output reg [7: 0] y, input [7: 0] A, B, input [2: 0] Sel);
always @ (A, B, Sel) begin
y = 0;
case (Sel)
3'b000: y = 8'b0;
3'b001: y = A & B;
3'b010: y = A | B;
3'b011: y = A ^ B;
3'b100: y = A + B;
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
89
3'b101: y = A - B;
3'b110: y = ~A;
3'b111: y = 8'hFF;
endcase
end
endmodule
A[7:0] aa 55 aa 55 aa 55 aa 55 ff 00 ff
B[7:0] 55 aa 55 aa 55 00 55 aa
y[7:0] 00 aa 55 aa 00 ff 55 ff 55 ab 00 ff 00 ff
Note that the subtraction operator performs 2's complement subtraction. So 8'h55 – 8'hAA adds the 2's
complement of 8'hAA to 8'h55 and gets 8'hAB. The sign bit is not included in the model, but hand
calculation shows that the 9th bit is 1, indicating that the result of the operation is negative. The magnitude
of the result can be obtained by taking the 2's complement of 8'hAB.
4.45
module priority_encoder_beh (output reg X, Y, V, input D0, D1, D2, D3); // V2001
always @ (D0, D1, D2, D3) begin
X = 0;
Y = 0;
V = 0;
casex ({D0, D1, D2, D3})
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
90
k 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
D0
D1
D2
D3
X
Y
V
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
91
4.46 (a)
F = Σ(0, 2, 5, 7, 11, 14)
See code below.
k 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
D0
D1
D2
D3
X
Y
V
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
92
4.47
module Add_Sub_4_bit_Dataflow (
output [3: 0] S,
output C, V,
input [3: 0] A, B,
input M
);
wire C3;
A[3:0] x a
B[3:0] x 5 3
M
S[3:0] x f 5 7
C
4.48
module ALU_3state (output [7: 0] y_tri, input [7: 0] A, B, input [2: 0] Sel, input En);
reg [7: 0] y;
assign y_tri = En ? y: 8'bz;
always @ (A, B, Sel) begin
y = 0;
case (Sel)
3'b000: y = 8'b0;
3'b001: y = A & B;
3'b010: y = A | B;
3'b011: y = A ^ B;
3'b100: y = A + B;
3'b101: y = A - B;
3'b110: y = ~A;
3'b111: y = 8'hFF;
endcase
end
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
93
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
94
module t_Problem_4_49;
reg A, B, C, D;
wire F1_Gates, F2_Gates;
wire F1_Boolean_1, F2_Boolean_1;
wire F1_Boolean_2, F2_Boolean_2;
module t_Prob_4_50a;
wire [3: 0] Code_BCD;
reg [3: 0]; Code_84_m2_m1;
integer K;
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
95
endmodule
always @ (Code_84_m2_m1)
case (Code_84_m2_m1)
4'b0000: Code_Gray = 4'b0000; // 0
4'b0111: Code_Gray = 4'b0001; // 1
4'b0110: Code_Gray = 4'b0011; // 2
4'b0101: Code_Gray = 4'b0010; // 3
4'b0100: Code_Gray = 4'b0110; // 4
4'b1011: Code_Gray = 4'b0111; // 5
4'b1010: Code_Gray = 4'b0101; // 6
4'b1001: Code_Gray = 4'b0100; // 7
4'b1000: Code_Gray = 4'b1100; // 8
4'b1111: Code_Gray = 4'b1101; // 9
module t_Prob_4_50b;
wire [3: 0] Code_Gray;
reg [3: 0] Code_84_m2_m1;
integer K;
4.51 Assume that that the LEDs are asserted when the output is high.
module Seven_Seg_Display_V2001 (
output reg [6: 0] Display,
input [3: 0] BCD
);
// abc_defg
parameter BLANK = 7'b000_0000;
parameter ZERO = 7'b111_1110; // h7e
parameter ONE = 7'b011_0000; // h30
parameter TWO = 7'b110_1101; // h6d
parameter THREE = 7'b111_1001; // h79
parameter FOUR = 7'b011_0011; // h33
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
96
always @ (BCD)
case (BCD)
0: Display = ZERO;
1: Display = ONE;
2: Display = TWO;
3: Display = THREE;
4: Display = FOUR;
5: Display = FIVE;
6: Display = SIX;
7: Display = SEVEN;
8: Display = EIGHT;
9: Display = NINE;
default: Display = BLANK;
endcase
endmodule
join
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
97
0 60 120
Name
BCD[3:0] x 0 1 2 3 4 5 6 7 8 9
Display[6:0] xx 7e 30 6d 79 33 5b 5f 70 7f 7b
module Seven_Seg_Display_V2001_CA (
output [6: 0] Display,
input [3: 0] BCD
);
// abc_defg
parameter BLANK = 7'b000_0000;
parameter ZERO = 7'b111_1110; // h7e
parameter ONE = 7'b011_0000; // h30
parameter TWO = 7'b110_1101; // h6d
parameter THREE = 7'b111_1001; // h79
parameter FOUR = 7'b011_0011; // h33
parameter FIVE = 7'b101_1011; // h5b
parameter SIX = 7'b101_1111; // h5f
parameter SEVEN = 7'b111_0000; // h70
parameter EIGHT = 7'b111_1111; // h7f
parameter NINE = 7'b111_1011; // h7b
wire A, B, C, D, a, b, c, d, e, f, g;
assign A = BCD[3];
assign B = BCD[2];
assign C = BCD[1];
assign D = BCD[0];
assign Display = {a,b,c,d,e,f,g};
assign a = (~A)&C | (~A)&B&D | (~B)&(~C)&(~D) | A & (~B)&(~C);
assign b = (~A)&(~B) | (~A)&(~C)&(~D) | (~A)&C&D | A&(~B)&(~C);
assign c = (~A)&B | (~A)&D | (~B)&(~C)&(~D) | A&(~B)&(~C);
assign d = (~A)&C&(~D) | (~A)&(~B)&C | (~B)&(~C)&(~D) | A&(~B)&(~C) | (~A)&B&(~C)&D;
assign e = (~A)&C&(~D) | (~B)&(~C)&(~D);
assign f = (~A)&B&(~C) | (~A)&(~C)&(~D) | (~A)&B&(~D) | A&(~B)&(~C);
assign g = (~A)&C&(~D) | (~A)&(~B)&C | (~A)&B&(~C) | A&(~B)&(~C);
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
98
#10 BCD = 0;
#20 BCD = 1;
#30 BCD = 2;
#40 BCD = 3;
#50 BCD = 4;
#60 BCD = 5;
#70 BCD = 6;
#80 BCD = 7;
#90 BCD = 8;
#100 BCD = 9;
join
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
99
module t_Problem_4_52a_Data_Flow;
wire [3: 0] sum;
wire carry;
reg [3: 0] A;
module Problem_4_52b_Data_Flow (output [3: 0] diff, output borrow, input [3: 0] A);
assign {borrow, diff} = A - 1;
endmodule
module t_Problem_4_52b_Data_Flow;
wire [3: 0] diff;
wire borrow;
reg [3: 0] A;
Name 0 30 60 90
A[3:0] 0 1 2 3 4 5 6 7 8 9 a b c d e f
diff[3:0] f 0 1 2 3 4 5 6 7 8 9 a b c d e
borrow
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
100
module Adder_4_bit (output carry, output [3:0] sum, input [3: 0] a, b, input c_in);
assign {carry, sum} = a + b + c_in;
endmodule
module t_Problem_4_53_Data_Flow;
wire [3: 0] Sum;
wire Output_carry;
reg [3: 0] Addend, Augend;
reg Carry_in;
Addend[3:0] 1 2 3
Augend[3:0] 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
Carry_in
Sum[3:0] 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
Output_carry
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
101
initial #11$finish;
initial fork
Word_BCD = 0;
#10 Word_BCD = 1;
#20 Word_BCD = 2;
#30 Word_BCD = 3;
#40 Word_BCD = 4;
#50 Word_BCD = 5;
#60 Word_BCD = 6;
#70 Word_BCD = 7;
#20 Word_BCD = 8;
#90 Word_BCD = 9;
#100 Word_BCD = 4'b1100; // Confirm error detection
join
endmodule
Name 0 60
Word_BCD[3:0] 0 1 2 3 4 5 6 7 9
Word_9s_Comp[3:0] 9 8 7 6 5 4 3 2 0
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
102
initial #11$finish;
initial fork
Word_Gray = 0;
#10 Word_Gray = 1;
#20 Word_Gray = 2;
#30 Word_Gray = 3;
#40 Word_Gray = 4;
#50 Word_Gray = 5;
#60 Word_Gray = 6;
#70 Word_Gray = 7;
#20 Word_Gray = 8;
#90 Word_Gray = 9;
#100 Word_Gray = 4'b1100; // Confirm error detection
join
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
103
9's Complementer
(See Problem 4.18)
Select
Select = 1 Select = 0
A3 A2 A1 A0
Quadruple 2 x 1 MUX
Cin
);
wire [3: 0] Word_9s_Comp, mux_out;
Nines_Complementer M0 (Word_9s_Comp, B);
Quad_2_x_1_mux M2 (mux_out, Word_9s_Comp, B, Mode);
BCD_Adder M1 (Carry_Borrow, BCD_Sum_Diff, mux_out, A, Mode);
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
104
module Quad_2_x_1_mux (output reg [3: 0] mux_out, input [3: 0] b, a, input select);
always @ (a, b, select)
case (select)
0: mux_out = a;
1: mux_out = b;
endcase
endmodule
module BCD_Adder (
output Output_carry,
output [3: 0] Sum,
input [3: 0] Addend, Augend,
input Carry_in);
supply0 gnd;
wire [3: 0] Z_Addend;
wire Carry_out;
wire C_out;
assign Z_Addend = {1'b0, Output_carry, Output_carry, 1'b0};
wire [3: 0] Z_sum;
module Adder_4_bit (output carry, output [3:0] sum, input [3: 0] a, b, input c_in);
assign {carry, sum} = a + b + c_in;
endmodule
module t_Problem_4_55_BCD_Adder_Subtractor();
wire [3: 0] BCD_Sum_Diff;
wire Carry_Borrow;
reg [3: 0] B, A;
reg Mode;
integer J, K, M;
initial begin
for (M = 0; M < 2; M = M + 1) begin
for (J = 0; J < 10; J = J + 1) begin
for (K = 0; K < 10; K = K + 1) begin
A = J; B = K; Mode = M; #5 ;
end
end
end
end
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
105
M 0
A[3:0] 5 6 7
B[3:0] 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
Word_9s_Comp[3:0] 7 6 9 4 3 2 1 0 9 8 7 6 9 4 3 2 1 0 9 8 7 6
mux_out[3:0] 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
BCD_Sum_Diff[3:0] 7 8 9 0 1 2 3 4 6 7 8 9 0 1 2 3 4 5 7 8 9 0
Carry_Borrow
M 1
A[3:0] 5 6 7
B[3:0] 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
Word_9s_Comp[3:0] 9 4 3 2 1 0 9 8 7 6 9 4 3 2 1 0 9 8 7 6 9 4
mux_out[3:0] 9 4 3 2 1 0 9 8 7 6 9 4 3 2 1 0 9 8 7 6 9 4
BCD_Sum_Diff[3:0] 5 0 9 8 7 6 5 4 3 6 1 0 9 8 7 6 5 4 7 2
Carry_Borrow
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
106
4.56
assign
match
=
(A
==
B);
//
Assumes
reg
[3:
0]
A,
B;
4.57
// Priority encoder (See Problem 4.29)
// Caution: do not confuse logic value x with identifier x.
// Verilog 1995
module t_Prob_4_57;
wire x, y, v;
reg D3, D2, D1, D0;
integer K;
Prob_4_57 M0 (x, y, v, D3, D2, D1, D0);
initial #100 $finish;
initial begin
for (K = 0; K < 16; K = K + 1) begin {D3, D2, D1, D0} = K; #5 ; end
end
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
107
4.58 (a)
//module shift_right_by_3_V2001 (output [31: 0] sig_out, input [31: 0] sig_in);
// assign sig_out = sig_in >>> 3;
//endmodule
sig_in[31:0] 00001111111111111111111111111111
sig_out_V1995[31:0] 00000001111111111111111111111111
Name 34 44 54 64
sig_in[31:0] 11110000000000000000000000000000
sig_out_V1995[31:0] 11111110000000000000000000000000
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
108
(b)
integer k;
initial #1000 $finish;
initial begin
sig_in = 32'hf000_0000;
#100 sig_in = 32'h8fff_ffff;
#500 sig_in = 32'h0fff_ffff;
end
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
109
4.59
module BCD_to_Decimal (output reg [3: 0] Decimal_out, input [3: 0] BCD_in);
always @ (BCD_in) begin
Decimal_out = 0;
case (BCD_in)
4'b0000: Decimal_out = 0;
4'b0001: Decimal_out = 1;
4'b0010: Decimal_out = 2;
4'b0011: Decimal_out = 3;
4'b0100: Decimal_out = 4;
4'b0101: Decimal_out = 5;
4'b0110: Decimal_out = 6;
4'b0111: Decimal_out = 7;
4'b1000: Decimal_out = 8;
4'b1001: Decimal_out = 9;
default: Decimal_out = 4'bxxxx;
endcase
end
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
110
4.60
module Even_Parity_Checker_4 (output P, C, input x, y, z);
xor (w1, x, y);
xor (P, w1, z);
xor (C, w1, w2);
xor (w2, z, P);
endmodule
4.61
module Even_Parity_Checker_4 (output P, C, input x, y, z);
assign w1 = x ^ y;
assign P = w1 ^ z;
assign C = w1 ^ w2;
assign w2 = z ^ P;
endmodule
x
y
z
P
C
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
111
4.62
A0 3x8 8
A1 D0 - D7
A2 Decoder
E
8
3x8
Decoder D8 - D15
E
0
A3 20
2x4 1
Decoder 2 8
3x8
A4 21 D16 - D23
3 Decoder
E E
3x8 8
D24 - D31
Decoder
E
module Decoder_3x8 (output D7, D6, D5, D4, D3, D2, D1, D0, input in2, in1, in0, E);
not (in2_bar, in2);
not (in1_bar, in1);
not (in0_bar, in0);
and (D0, in2_bar, in1_bar, in0_bar, E);
and (D1, in2_bar, in1_bar, in0, E);
and (D2, in2_bar, in1, in0_bar, E);
and (D3, in2_bar, in1, in0, E);
and (D4, in2, in1_bar, in0_bar, E);
and (D5, in2, in1_bar, in0, E);
and (D6, in2, in1, in0_bar, E);
and (D7, in2, in1, in0, E);
endmodule
module Decoder_5x32 (
output D31, D30, D29, D28, D27, D26, D25, D24, D23, D22, D21, D20, D19, D18, D17, D16,
D15, D14, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0,
input A4, A3, A2, A1, A0, E;
wire E3, E2, E1, E0;
Decoder_3x8 M0 (D7, D6, D5, D4, D3, D2, D1, D0, A2, aA1, A0, E0);
Decoder_3x8 M1 (D15, D14, D13, D12, D11, D10, D9, D8, A2, A1, A0, E1);
Decoder_3x8 M2 (D23, D22, D21, D20, D19, D18, D17, D16, in2, in1, in0, E2);
Decoder_3x8 M3 (D31, D30, D29, D28, D27, D26, D25, D24, A2, A1, A0, E3);
Decoder_2x4 M4 (E3, E2, E1, E0, A4, A3, E);
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
112
4.63
A0 20 2x4 4
D0 - D3
A1 2 1 Decoder
E
20 2x4
4
1 Decoder D4 - D7
2 E
0
A2 20
2x4 1
Decoder 2 20 4
2x4
A3 21 D8 - D11
3 21 Decoder
E E
20 2x4 4
D12 - D15
21 Decoder
E
module Decoder_2x4 (output D3, D2, D1, D0, input in1, in0, E);
not (in1_bar, in1);
not (in0_bar, in0);
and (D0, in1_bar, in0_bar, E);
and (D1, in1_bar, in0, E);
and (D2, in1, in0_bar, E);
and (D3, in1, in0, E);
endmodule
module Decoder_4x16 (
output D15, D14, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0,
input A3, A2, A1, A0, E);
wire E3, E2, E1, E0;
Decoder_2x4 M0 (output D3, D2, D1, D0, input in1, in0, E0);
Decoder_2x4 M1 (output D7, D6, D5, D4, input in1, in0, E1);
Decoder_2x4 M2 (output D11, D10, D9, D8, input in1, in0, E2);
Decoder_2x4 M3 (output D15, D14, D13, D12, input in1, in0, E3);
Decoder_2x4 M4 (output E3, E2, E1, E0, input A3, A2, E);
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
113
4.64
Inputs Outputs
D0 D1 D2 D3 D4 D5 D6 D7 x y z V
0 0 0 0 0 0 0 0 x x x 0
1 0 0 0 0 0 0 0 0 0 0 1
x 1 0 0 0 0 0 0 0 0 1 1
x x 1 0 0 0 0 0 0 1 0 1
x x x 1 0 0 0 0 0 1 1 1
x x x x 1 0 0 0 1 0 0 1
x x x x x 1 0 0 1 0 1 1
x x x x x x 1 0 1 0 0 1
x x x x x x x 1 1 1 1 1
If D2 = 1, D6 = 1, all others = 0
Output xyz = 100 and V = 1
module Prob_4_64 (output x, y, x, V, input, D0, D1, D2, D3, D4,D5 D6, D7);
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
114
4.65
s0 s0
s1 s1
s2 s2
s3 0 0
1 1
8x1
2 2
MUX
3 3
4 4
5 5
6 6
7 7
s
2x1 y
0
MUX
1
s0
s1
s2
8 0
9 1
8x1
10 2
MUX
11 3
12 4
13 5
14 6
15 7
module Mux_2x1 (
output y_out,
input in1, in0, sel);
not (sel_bar, sel);
and (y0, in0, sel);
and (y1, in1, sel);
or (y_out, in0, in1, sel_bar
);
endmodule
module Mux_4x1 (
output y_out,
input in3, in2, in1, in0, sel1, sel0);
not (sel_1_bar, sel1);
and (s0, sel_1_bar, sel0);
and (s1, sel[1], sel0);
Mux_2x1 M0 (y_M0, in0, in1, s0);
Mux_2x1 M1 (y_M1, in2, in3, s1);
or (y_out, y_M0, y_M1
);
endmodule
module Mux_8x1 (
output y_out,
input in7, in6, in5, in4, in3, in2, in1, in0, sel2, sel1, sel0
);
Mux_4x1 M0 (y_M0, in3, in2, in1, in0, sel1, sel0);
Mux_4x1 M1 (y_M1, in7, in6, in5, in4, sl1, sel0);
Mux_2x1 M2 (y_out, y_M0, y_M1, sel2);
endmodule
module Mux_16x1 (
output y_out,
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.
115
input in15, in14, in13, in12, in11, in10, in9, in8, in7, in6, in5, in4, in3, in2, in1, in0, sel3, sel2, sel1, sel0
);
Mux_8x1 M0 (y_M0, in7, in6, in5, in4, in3, in2, in1, in0, sel2, sel1, sel0);
Mux_8x1 M1 (y_M1, in15, in14, in13, in12, in11, in10, in9, in8, sel2, sel1, sel0);
Mux_2x1 M2 (y_out, y_M0, y_M1, sel3);
endmodule
Digital
Design
With
An
Introduction
to
the
Verilog
HDL
–
Solution
Manual.
M.
Mano.
M.D.
Ciletti,
Copyright
2012,
All
rights
reserved.