Study Guide & Exercise Bank — 199 Problems

Digital Logic &
Verilog Design

Based on Fundamentals of Digital Logic with Verilog Design, 3rd Ed.
Brown & Vranesic

02 Introduction to Logic Circuits

This is the foundational chapter of the book. It introduces logic variables, truth tables, and the three fundamental operations: AND, OR, and NOT. The chapter shows how to build logic networks from gates, covers Boolean algebra and all its key theorems (commutative, associative, distributive, DeMorgan's, absorption), and introduces the Venn diagram as a visualization tool. Synthesis techniques are presented for sum-of-products (SOP) and product-of-sums (POS) canonical forms, along with NAND-only and NOR-only implementations. Karnaugh maps are introduced for manual minimization of logic functions up to 5 variables, including don't-care conditions and multiple-output circuits. The chapter also gives a first introduction to Verilog HDL with structural, behavioral, and hierarchical coding styles.

AND / OR / NOT Truth Tables Boolean Algebra DeMorgan's Theorem SOP & POS Forms NAND / NOR Logic Karnaugh Maps Don't-Care Conditions Verilog Intro

Key Formulas — Boolean Algebra & Logic

DeMorgan's Theorem 1 A · B = A + B
DeMorgan's Theorem 2 A + B = A · B
Absorption x + x · y = x
Distributive x · ( y + z ) = x·y + x·z
Identity x + 0 = x , x · 1 = x
Complement x + x = 1 , x · x = 0
Idempotent x + x = x , x · x = x
Involution x = x
Consensus xy + xz + yz = xy + xz
2.1EasyTier 1?
Write the truth table for $f = x_1 \cdot x_2 + \overline{x_1} \cdot x_3$. How many rows does it contain?
2.2EasyTier 1?
Apply DeMorgan's theorem to find the complement of $f = (a + b) \cdot (c + d)$.
2.3MediumTier 1?
Express the function $f(x_1, x_2, x_3) = \sum m(1,2,5,6,7)$ in canonical SOP and POS forms.
2.4MediumTier 1?
Use a 3-variable Karnaugh map to minimize $f(x_1, x_2, x_3) = \sum m(0,1,2,5,6,7)$.
2.5MediumTier 1?
Use a 4-variable Karnaugh map to minimize $f(x_1, x_2, x_3, x_4) = \sum m(0,2,5,7,8,10,13,15)$.
2.6MediumTier 1?
Minimize the function $f(x_1, x_2, x_3, x_4) = \sum m(1,3,4,6,9,11,12,14) + D(0,5)$ where $D$ represents don't-care conditions.
2.7EasyTier 1?
Show that a 2-input NAND gate is functionally complete (i.e., any Boolean function can be implemented using only NAND gates).
2.8MediumTier 1?
Design a logic circuit for a 3-way light control: the light changes state whenever any one of three switches is toggled. Give the truth table and a minimum SOP expression.
2.9MediumTier 1?
Write a behavioral Verilog module for a 2-to-1 multiplexer with inputs w0, w1, select s, and output f.
2.10MediumTier 1?
A majority function outputs 1 when two or more of its three inputs are 1. Write the truth table, derive the minimum SOP expression, and draw the gate-level circuit.
2.11MediumTier 1?
Define the terms: minterm, maxterm, implicant, prime implicant, essential prime implicant. Give an example of each for a 3-variable function.
2.12EasyTier 1?
A light $L$ is controlled by two toggle switches $x$ and $y$. The light must be on only when exactly one switch is up. Derive the truth table and a logic expression for $L$, and identify the resulting function.
2.13EasyTier 1?
Design a 1-bit binary adder that takes inputs $a$ and $b$ and produces a 2-bit sum $S = s_1 s_0 = a + b$. Give the truth table, derive expressions for $s_1$ and $s_0$, and draw the gate-level circuit.
2.14EasyTier 1?
Prove the Boolean identity $(x_1+\overline{x_3})(\overline{x_1}+x_3) = x_1\cdot x_3 + \overline{x_1}\cdot\overline{x_3}$ using algebraic manipulation.
2.15MediumTier 1?
Use algebraic manipulation to prove that $\overline{x_1}\cdot\overline{x_3} + \overline{x_2}\cdot x_3 + x_1\cdot x_3 + x_2\cdot\overline{x_3} = x_1\cdot x_2 + \overline{x_1}\cdot\overline{x_2} + x_1\cdot\overline{x_2}$ and find the simplest expression for the function.
2.16EasyTier 1?
Use a Venn diagram to prove the dual distributive property $x + y\cdot z = (x+y)\cdot(x+z)$.
2.17EasyTier 1?
Prove DeMorgan's theorem $\overline{x \cdot y} = \overline{x} + \overline{y}$ using Venn diagrams.
2.18MediumTier 1?
A gumball-sorting conveyor has three sensors: $s_1$ (too light), $s_2$ (too small), $s_3$ (too large). A gumball is rejected ($f=1$) if it is too large, or if it is both too light and too small. Derive the truth table and the canonical SOP expression, then simplify $f$ to a minimum-cost form using Boolean algebra.
2.19MediumTier 1?
Show an alternative algebraic simplification of the gumball reject function (Example 2.7) by first replicating the term $s_1 s_2 \overline{s_3}$ and then factoring to obtain $f = s_3 + s_1 s_2$.
2.20MediumTier 1?
Derive the same minimum expression $f = s_3 + s_1 s_2$ for the gumball reject function using the consensus and DeMorgan identities, instead of the algebraic steps used in Examples 2.7 and 2.8.
2.21MediumTier 1?
Derive the canonical SOP for $f(x_1,x_2,x_3) = \sum m(2,3,4,6,7)$ and simplify it algebraically to a minimum-cost expression.
2.22MediumTier 1?
Write the canonical SOP for $f(x_1,x_2,x_3,x_4) = \sum m(3,7,9,12,13,14,15)$, then use Boolean algebra to derive a simpler SOP expression.
2.23MediumTier 1?
For $f(x_1,x_2,x_3) = \sum m(2,3,4,6,7) = \prod M(0,1,5)$, derive the canonical POS expression and simplify it to a minimum-cost POS form.
2.24MediumTier 1?
Implement $f(x_1,x_2,x_3) = \sum m(2,3,4,6,7)$ using only NOR gates by starting from its minimum POS form $f=(\overline{x_1}+x_2)(x_2+\overline{x_3})$.
2.25MediumTier 1?
Implement $f(x_1,x_2,x_3) = \sum m(2,3,4,6,7)$ using only NAND gates by starting from its minimum SOP form $f = x_2 + \overline{x_1}\cdot\overline{x_3}$.
2.26HardTier 1?
Design a BCD-to-7-segment decoder. The 4-bit input $X = x_3 x_2 x_1 x_0$ represents decimal 0–9; codes 1010–1111 are don't-cares. Derive minimum-cost SOP expressions for the seven segment outputs $a$ through $g$ using Karnaugh maps with don't-cares.
2.27HardTier 1?
Two 4-variable functions are given by $f_1 = \overline{x_1}\overline{x_3}+x_1 x_3+\overline{x_2}\overline{x_3}\overline{x_4}$ and $f_2 = \overline{x_1} x_3+x_1\overline{x_3}+\overline{x_2}\overline{x_3}\overline{x_4}$. Find a combined multi-output realization that minimizes total gate cost by sharing common product terms.
2.28HardTier 1?
For two 4-variable functions $f_3$ and $f_4$ whose individually minimum-cost SOPs share no common product terms, show how using non-prime implicants together can yield a lower-cost combined two-output circuit. Illustrate with the function pair from Figure 2.65.
2.29HardTier 1?
Find the minimum-cost POS expressions for the functions $f_1$ and $f_2$ of Example 2.16, and show that their combined POS implementation is more expensive than the corresponding shared SOP realization.
2.30HardTier 1?
Find the minimum-cost combined POS implementation for the function pair $f_3, f_4$ of Example 2.17 by sharing common sum terms, and compare its cost to the SOP-based realization.
2.31MediumTier 1?
Determine whether the equation $\overline{x_1} x_3 + x_2 \overline{x_3} + x_1 x_2 = x_1 \overline{x_2} + \overline{x_1} x_2 + \overline{x_2} \overline{x_3}$ is valid by deriving the canonical SOP for each side.
2.32MediumTier 1?
Design the minimum-cost POS expression for $f(x_1,x_2,x_3,x_4) = \sum m(0,2,4,5,6,7,8,10,12,14,15)$ by starting from its maxterm representation.
2.33MediumTier 1?
A control circuit has three inputs $x_1,x_2,x_3$ and recognizes three conditions: $A = x_3(x_1+\overline{x_2})$, $B = x_1(\overline{x_2}+\overline{x_3})$, $C = x_2(x_1+\overline{x_3})$. Design the simplest circuit whose output $f=1$ when at least two of $A,B,C$ are true.
2.34MediumTier 1?
Solve the majority-of-three-conditions problem from Example 2.22 using Venn diagrams instead of algebraic manipulation, and confirm that $f = x_1(x_2+x_3)$.
2.35MediumTier 1?
Use algebraic manipulation (consensus, combining, and absorption) to derive the simplest SOP expression for $f = \overline{x_2} x_3 \overline{x_4} + \overline{x_1} \overline{x_3} \overline{x_4} + x_1 x_2 \overline{x_4}$.
2.36MediumTier 1?
Use algebraic manipulation to derive the simplest POS expression for $f = (x_1+\overline{x_2}+x_3)(x_1+x_2+\overline{x_4})(\overline{x_1}+\overline{x_3}+x_4)$.
2.37HardTier 1?
Determine the minimum-cost SOP and POS expressions for $f(x_1,x_2,x_3,x_4)=\sum m(4,6,8,10,11,12,15) + D(3,5,7,9)$ using K-maps. Discuss how different assignments to the don't-cares yield different functions for the SOP and POS forms.
2.38HardTier 1?
Use Karnaugh maps to find the minimum-cost SOP and POS expressions for $f(x_1,\ldots,x_4) = \overline{x_1}\overline{x_3}\overline{x_4} + \overline{x_3} x_4 + x_1\overline{x_2} x_4 + x_1\overline{x_2}\overline{x_3} x_4$ with $D=(9,12,14)$.
2.39MediumTier 1?
Derive a minimum-cost SOP expression for $f = s_3(s_1+s_2)+\overline{s_1}\overline{s_2}$ by first expanding via the distributive law and then minimizing with a 3-variable K-map.
2.40MediumTier 1?
Write Verilog code that uses only continuous assign statements to describe a circuit with inputs $x,y,z$ and outputs $f = (\overline{y \oplus z})\cdot z + (y \oplus z)\cdot x$ and $g = (y \oplus z)\oplus x$.
2.41MediumTier 1?
Write hierarchical Verilog code for a circuit that shares one 1-bit adder between two pairs of operands $(a,b)$ and $(c,d)$ via two 2-to-1 multiplexers controlled by a select input $m$. Use separate modules for the multiplexer and the adder.
2.42HardTier 1?
Show how to implement $f = x_1 x_2 \overline{x_4} + \overline{x_2} x_3 x_4 + \overline{x_1}\overline{x_2}\overline{x_3}$ in an FPGA whose logic blocks are 3-input lookup tables (3-LUTs). Give a straightforward LUT mapping and discuss whether decomposition could reduce the LUT count.
03 Number Representation and Arithmetic Circuits

This chapter covers how numbers are stored and manipulated in digital systems. It begins with positional number representations including unsigned integers, octal, and hexadecimal. The half-adder and full-adder are derived and combined to build ripple-carry adders. Signed number systems are introduced: sign-and-magnitude, 1's complement, and 2's complement (the standard for modern computers). The chapter covers addition, subtraction, arithmetic overflow detection, and fast adder designs including the carry-lookahead adder. Array multiplication and Booth's algorithm concepts are presented. Fixed-point, floating-point (IEEE 754), and BCD representations are also discussed. A significant portion of the chapter demonstrates how to describe all of these arithmetic circuits in Verilog using vectored signals, generic specifications, and arithmetic assignment statements.

Unsigned / Signed Integers Octal / Hex 2's Complement Half-Adder / Full-Adder Ripple-Carry Adder Carry-Lookahead Overflow Detection Multiplication BCD IEEE 754 Float Verilog Arithmetic
3.1EasyTier 1?
Convert the hexadecimal number $\text{3F7A}$ to binary and then to decimal.
3.2EasyTier 1?
Convert the decimal numbers 73, −95, and −1630 into signed 12-bit numbers in sign-and-magnitude, 1's complement, and 2's complement representations.
3.3EasyTier 1?
Draw the circuit for a half-adder. Label all signals and write the truth table.
3.4MediumTier 1?
Perform the following 8-bit 2's complement additions and indicate whether overflow occurs: $00110110 + 01000101$, $01110101 + 11011110$, $11011111 + 10111000$.
3.5MediumTier 1?
Show that the overflow condition for adding two n-bit 2's complement numbers is $\text{Overflow} = c_n \oplus c_{n-1}$, where c represents the carry signals.
3.6MediumTier 1?
Design a 4-bit ripple-carry adder using full-adder blocks. Draw the block diagram showing all carry connections.
3.7MediumTier 1?
Show how a 4-bit adder can be modified into an adder/subtractor unit using XOR gates and a control signal Sub.
3.8MediumTier 1?
Multiply the 4-bit unsigned numbers $1101$ and $1011$ using the array (partial product) method. Show all partial products.
3.9MediumTier 1?
Represent the decimal number $-6.5$ in IEEE 754 single-precision floating-point format. Show the sign, exponent, and mantissa fields.
3.10MediumTier 1?
Write a Verilog module for a parameterized n-bit ripple-carry adder using a generate statement to instantiate n full-adder modules.
3.11MediumTier 1?
Explain why the simple rule for finding the 2's complement works: "scanning right to left, copy all 0s and the first 1, then complement all remaining bits."
3.12MediumTier 1?
What is the range of representable values for an 8-bit number in sign-and-magnitude, 1's complement, and 2's complement? How many unique values does each represent?
3.13MediumTier 1?
Show that for $n$-digit decimal numbers $A$ and $B$, the subtraction $A-B$ can be done as $A+(10^n-B)-10^n$. Explain how the carry-out from the leading digit corresponds to discarding $10^n$, and what happens when $A < B$.
3.14MediumTier 1?
Using 3-digit signed decimal numbers (with leading 0 for positive and 9 for negative), compute $045 - 027$ and $027 - 045$ via the 10's-complement add-and-discard-carry technique. Verify that the second result is the 10's complement of $-18$.
3.15EasyTier 1?
Using 4-bit 2's complement and the add-and-discard-carry method, compute $(+5)-(+2)$. Confirm that the carry from the fourth bit position represents $2^4$ and can be ignored.
3.16EasyTier 1?
Using 4-bit 2's complement, compute $(+2)-(+5)$ via the add-and-discard-carry method. Verify that the result $1101$ is the 2's complement representation of $-3$.
3.17EasyTier 1?
Using 4-bit 2's complement, compute $(+5)-(-2)$ by the add-and-discard-carry technique. Verify the result is $0111 = +7$.
3.18EasyTier 1?
Convert the decimal integer $14959$ into hexadecimal by successive division by 16, recording each remainder as a hex digit.
3.19EasyTier 1?
Convert the decimal fraction $0.8254$ into a binary fraction with at least eight bits after the radix point, using successive multiplication by 2.
3.20MediumTier 1?
Convert the decimal fixed-point number $214.45$ into a binary fixed-point number, performing successive division by 2 for the integer part and successive multiplication by 2 for the fractional part.
3.21MediumTier 1?
A 4-bit comparator is built from a 2's-complement subtractor that outputs $S = X - Y$ along with three flags: $Z=1$ if $S=0$, $N=1$ if $S$ is negative, $V=1$ on overflow. Derive expressions in terms of $Z, N, V$ for each of $X=Y$, $XY$, $X\ge Y$.
3.22MediumTier 1?
Write Verilog code for the 4-bit signed comparator of Example 3.9. Provide both a structural version that instantiates four full-adder modules and a generic version using a parameter $n$ and a for loop.
3.23HardTier 1?
Compare the critical-path delay of a 4-bit ripple-carry array multiplier (Figure 3.35) with that of a 4-bit carry-save array multiplier (Figure 3.48). Express each delay as a multiple of the full-adder delay plus the AND-gate delay.
04 Combinational-Circuit Building Blocks

This chapter presents the standard combinational building blocks used everywhere in digital design. Multiplexers are covered in depth, including their use for implementing arbitrary logic functions via Shannon's expansion theorem. Decoders (including demultiplexers) and encoders (binary and priority) are discussed as fundamental address-translation and selection circuits. Code converters (e.g., BCD to 7-segment display) and arithmetic comparison circuits (magnitude comparators) are also presented. The major Verilog section introduces the conditional operator (?:), if-else statements, the case statement, for loops, the full set of Verilog operators, the generate construct, and tasks/functions — essentially all the Verilog constructs needed for combinational circuit description.

Multiplexers Shannon's Expansion Decoders / Demux Encoders / Priority Code Converters Comparators Verilog if-else / case Verilog for / generate
4.1EasyTier 1?
Show how $f(w_1,w_2,w_3) = \sum m(0,2,3,4,5,7)$ can be implemented using a 3-to-8 decoder and a single OR gate.
4.2MediumTier 1?
Use Shannon's expansion with respect to variable $w_1$ to implement $f(w_1,w_2,w_3) = \sum m(0,2,3,6)$ using a 2-to-1 multiplexer and any necessary gates.
Background — Shannon's expansion: full SOP and POS walk-through

Here's a concrete walk-through using a 3-variable function.

Setup

Take $F(A, B, C) = A + BC$ with 3 variables ($n = 3$), so there are $2^3 = 8$ minterms ($m_0$ through $m_7$). [cs.ucr]

Truth Table

Evaluate $F$ for every input combination: [cs.ucr]

$i$ABCMinterm $m_i$$F(A,B,C)$
0000$A'B'C'$0
1001$A'B'C$0
2010$A'BC'$0
3011$A'BC$1
4100$AB'C'$1
5101$AB'C$1
6110$ABC'$1
7111$ABC$1

Applying the Formula

$$F = \sum_{i=0}^{7} m_i \cdot F(\text{inputs for } m_i)$$

Only minterms where $F = 1$ survive (multiplying by 0 eliminates the rest): [caslab.ee.ncku.edu]

$$F(A,B,C) = m_3 \cdot 1 + m_4 \cdot 1 + m_5 \cdot 1 + m_6 \cdot 1 + m_7 \cdot 1$$

Substituting the actual minterm products: [cs.ucr]

$$F(A,B,C) = A'BC + AB'C' + AB'C + ABC' + ABC$$

Written in shorthand notation: [jazapka.people.ysu]

$$F(A,B,C) = \Sigma\, m(3, 4, 5, 6, 7)$$

What This Means

The formula is simply saying: OR together every minterm for which the function outputs 1. Each minterm $m_i$ is exactly 1 for one and only one input combination, so the sum "selects" the rows in the truth table where $F = 1$. This canonical SOP is the fully expanded Shannon decomposition over all variables simultaneously. [cs.ucr]


Here is a full worked example using the dual POS form of Shannon's expansion.

Setup

Let $F(A, B, C) = A + BC$, and expand on $X_1 = A$: [en.wikipedia]

$$F = (A + F(0, B, C)) \cdot (A' + F(1, B, C))$$

Step 1 — Compute the Two Cofactors

Negative cofactor — set $A = 0$: [en.wikipedia]

$$F(0, B, C) = 0 + BC = BC$$

Positive cofactor — set $A = 1$: [en.wikipedia]

$$F(1, B, C) = 1 + BC = 1$$

Step 2 — Plug into the POS Formula

$$F(A, B, C) = (A + BC) \cdot (A' + 1)$$

Since $A' + 1 = 1$ (anything OR'd with 1 is 1):

$$F(A, B, C) = (A + BC) \cdot 1 = A + BC$$

The function is confirmed correctly $\checkmark$

Step 3 — Expand Further to Canonical POS

To reach the fully canonical POS (maxterm form), apply the theorem recursively to each remaining sub-function. Expand $BC$ on variable $B$: [eplauchu.files.wordpress]

$$BC = (B + C \cdot 0)(B' + C \cdot 1) = (B + 0)(B' + C) = B(B' + C)$$

Wait — in POS, the canonical expansion over all variables yields maxterms where $F = 0$. From the earlier truth table, $F = 0$ only at rows $i = 0, 1, 2$ (i.e., $A=0, BC=0$):

$i$ABCMaxterm $M_i$$F$
0000$A+B+C$0
1001$A+B+C'$0
2010$A+B'+C$0
3–71

So the canonical POS is: [eplauchu.files.wordpress]

$$F(A,B,C) = \Pi\, M(0, 1, 2) = (A+B+C)(A+B+C')(A+B'+C)$$

Key Insight: SOP vs POS Duality

SOP (Shannon direct)POS (Shannon dual)
Operator$x \cdot F_x + x' \cdot F_{x'}$$(x + F_{x=0})(x' + F_{x=1})$
Canonical formSum of minterms where $F = 1$Product of maxterms where $F = 0$
Building blocksMinterms $m_i$Maxterms $M_i$

The dual POS form is particularly useful when a function has fewer 0s than 1s in the truth table — the POS expression will then be more compact. [eplauchu.files.wordpress]

4.3EasyTier 1?
Draw the circuit diagram for a 4-to-1 multiplexer using AND, OR, and NOT gates.
4.4MediumTier 1?
Design a 4-to-2 priority encoder where input 3 has the highest priority. Give the truth table and logic equations for the two outputs and a valid-output signal.
Why does input 3 have the highest priority?

By convention the highest-indexed asserted input wins: I₃ > I₂ > I₁ > I₀. The encoder reports the index of that winning input on (Y₁, Y₀), and V=1 whenever any input is active.

In an if / else if chain this is the input checked first:

if      (in[3]) out = 2'd3;   // highest priority
else if (in[2]) out = 2'd2;
else if (in[1]) out = 2'd1;
else if (in[0]) out = 2'd0;   // lowest priority

To make input 0 the highest priority instead, just reverse the order of the chain.

What if input 0 has the highest priority?

Then I₀ > I₁ > I₂ > I₃. The output (Y₁,Y₀) still reports the index of the winning input, but every term must gate on the complements of the higher-priority inputs.

I₃I₂I₁I₀Y₁Y₀V
0000xx0
xxx1001
xx10011
x100101
1000111

$Y_0 = I_1\overline{I_0} + I_3\overline{I_2}\,\overline{I_1}\,\overline{I_0}$

$Y_1 = \overline{I_0}\,\overline{I_1}(I_2 + I_3)$

$V = I_0 + I_1 + I_2 + I_3$

Compared to the I₃-highest case ($Y_1 = I_3 + I_2$, $Y_0 = I_3 + I_1\overline{I_2}$), flipping the priority to I₀ makes the equations longer because the higher-priority inputs now need to be explicitly suppressed.

What if input 1 has the highest priority?

Naming only I₁ as highest doesn't fully specify the order of the other three. The usual reading is a cyclic shift (round-robin style): I₁ > I₂ > I₃ > I₀.

I₃I₂I₁I₀Y₁Y₀V
0000xx0
xx1x011
x10x101
100x111
0001001

$Y_0 = I_1 + I_3\overline{I_2}\,\overline{I_1}$

$Y_1 = \overline{I_1}(I_2 + I_3)$

$V = I_0 + I_1 + I_2 + I_3$

Because I₀ is now the lowest priority and its index is 00, no I₀ term appears in either output — it's "selected" only when all higher-priority inputs are 0, and that selection is encoded by Y₁Y₀ = 00.

4.5MediumTier 1?
Implement a 2-to-4 decoder with an enable input. Write the truth table and the Verilog code using a case statement.
4.6MediumTier 1?
Derive minimum SOP expressions for outputs a, b, and c of a BCD-to-7-segment display decoder.
完整 0–9 真值表 (a–g, common cathode)

段位示意:a = 上橫,b = 右上,c = 右下,d = 下橫,e = 左下,f = 左上,g = 中橫。BCD 用 ABCD = wxyz。

十進位BCD (wxyz)abcdefg
000001111110
100010110000
200101101101
300111111001
401000110011
501011011011
601101011111
701111110000
810001111111
910011111011

特殊規律:

  • 數字 8:七段全亮 (1111111),是最完整的圖形。
  • 數字 1:只有 b、c 亮 (右側兩段)。
  • 數字 7:比 1 多一條上橫 (a 段)。
  • g 段 (中橫):只有 0、1、7 不亮,其餘皆亮。
  • BCD 1010–1111 (10–15) 為無效輸入,列為 Don't Care (X),可在 K-map 化簡時自由利用。
4.7MediumTier 1?
Design a 2-bit magnitude comparator that produces three outputs: AgtB, AeqB, AltB. Give the truth table and simplified equations.
4.8MediumTier 1?
Use two 2-to-4 decoders and additional gates to build a 3-to-8 decoder. Draw the block diagram.
4.9MediumTier 1?
Write Verilog code for a priority encoder with 8 inputs using an if-else chain inside an always block.
4.10EasyTier 1?
What happens if a case statement in Verilog doesn't cover all possible input combinations and no default is provided? What type of hardware is inferred?
4.11MediumTier 1?
Design a 4-bit binary-to-Gray code converter. Give the truth table and Verilog implementation.
What is Gray code?

Gray code (reflected binary code) is a binary numbering system where two consecutive values differ in exactly one bit.

DecBinaryGrayDecBinaryGray
000000000810001100
100010001910011101
2001000111010101111
3001100101110111110
4010001101211001010
5010101111311011011
6011001011411101001
7011101001511111000

Each row changes only one bit from the row above. Compare with binary: 0011 → 0100 changes 3 bits at once.

Why it matters:

  • Mechanical / optical encoders (rotary position): sensors at bit boundaries can't all switch simultaneously. With binary, mid-transition you might briefly read a wildly wrong value (e.g. 011 → 100 might glitch through 000 or 111). Gray guarantees only one sensor changes, so the worst-case mis-read is off by one.
  • K-maps: rows/columns are in Gray order so physical adjacency = logical adjacency for grouping minterms.
  • Asynchronous FIFOs / clock-domain crossing: counters use Gray code so a sampled value is always either "this count" or "next count", never garbage in-between.
  • Power / EMI: fewer bit transitions per increment → less switching noise.

Conversion formulas:

  • Binary → Gray: $G_i = B_i \oplus B_{i+1}$, with $G_{MSB} = B_{MSB}$. Equivalently $G = B \oplus (B \gg 1)$.
  • Gray → Binary: $B_{MSB} = G_{MSB}$, then $B_i = G_i \oplus B_{i+1}$ (cumulative XOR from MSB down).
4.12HardTier 1?
Prove Shannon's expansion theorem: $f(x_1,\ldots,x_n) = x_1 \cdot f(1,x_2,\ldots,x_n) + \overline{x_1} \cdot f(0,x_2,\ldots,x_n)$.
4.13MediumTier 1?
Design a $2\times 2$ crossbar switch using 2-to-1 multiplexers. The circuit has inputs $x_1,x_2$, outputs $y_1,y_2$, and a control signal $s$ such that $s=0$ connects $x_1\to y_1$, $x_2\to y_2$ and $s=1$ swaps the connections.
4.14EasyTier 1?
Implement the three-input majority function using a single 4-to-1 multiplexer. Choose $w_1$ and $w_2$ as the select inputs and determine the data inputs as functions of $w_3$.
4.15MediumTier 1?
Implement the three-input XOR function $f = w_1 \oplus w_2 \oplus w_3$ using only 2-to-1 multiplexers, exploiting that $w_2 \oplus w_3$ can be selected by $w_1$.
4.16MediumTier 1?
For $f = \overline{w_1}\overline{w_3}+w_2 w_3$, perform Shannon's expansion with respect to each of $w_1$, $w_2$, and $w_3$ in turn, and identify which expansion variable produces the lowest-cost circuit.
4.17MediumTier 1?
Implement $f = \overline{w_1}\overline{w_3} + w_1 w_2 + w_1 w_3$ using (a) a single 2-to-1 multiplexer plus other gates and (b) a single 4-to-1 multiplexer. Use Shannon's expansion to derive both circuits.
4.18MediumTier 1?
Implement the three-input majority function using only 2-to-1 multiplexers by applying Shannon's expansion twice (first on $w_1$, then on $w_2$ within each cofactor).
4.19MediumTier 1?
Show how a 4-to-1 multiplexer can be built from a 2-to-4 decoder (with enable held high) plus a single OR gate combining the AND of each decoder output with the corresponding data input.
4.20EasyTier 1?
Write a Verilog module mux2to1 with inputs w0, w1, s and output f, using a continuous assign with the conditional operator ?:.
4.21EasyTier 1?
Write a Verilog module for a 2-to-1 multiplexer using an if-else statement inside an always block.
4.22MediumTier 1?
Write hierarchical Verilog code for a 16-to-1 multiplexer that instantiates five 4-to-1 multiplexer modules. Use a 16-bit data vector $W$ and a 4-bit select vector $S$.
4.23EasyTier 1?
Write Verilog code for a 4-to-1 multiplexer using a case statement inside an always block, with a 2-bit select vector $S$.
4.24MediumTier 1?
Write Verilog code for a 2-to-4 binary decoder with an enable input En, using a case statement on the concatenation {En, W}.
4.25MediumTier 1?
Write Verilog code for a 2-to-4 binary decoder using a combination of if-else (for the enable) and a case statement (for the input pattern).
4.26MediumTier 1?
Write hierarchical Verilog code for a 4-to-16 decoder built as a tree of five 2-to-4 decoders.
4.27MediumTier 1?
Write a Verilog module seg7 that implements a hexadecimal-to-7-segment display decoder. The 4-bit input is hex and the 7-bit output is leds; use a case statement listing all 16 patterns.
4.28HardTier 1?
Write Verilog code for a 4-bit ALU modeled on the 74381 chip, with 3-bit select $S$, 4-bit operands $A$ and $B$, and a 4-bit output $F$. Implement clear, $B-A$, $A-B$, $A+B$, $A\oplus B$, $A|B$, $A\&B$, and preset-to-1111.
4.29MediumTier 1?
Write Verilog code for a 4-input priority encoder using a casex statement that treats lower-priority bits as don't-cares. Provide a valid output flag $z$.
4.30MediumTier 1?
Write Verilog code for a 2-to-4 decoder using a for loop that iterates over the four output positions, asserting $Y[k]=1$ when $W=k$ and $\text{En}=1$.
4.31MediumTier 1?
Write Verilog code for a 4-input priority encoder using a for loop. Exploit the fact that, in an always block, multiple assignments to the same variable retain the last assignment, so the highest priority input wins.
4.32MediumTier 1?
Write Verilog code for a 4-bit magnitude comparator that uses the relational operators (==, >, <) inside an if-else chain to drive outputs AeqB, AgtB, AltB.
4.33HardTier 1?
Use the Verilog generate construct with a for loop and gate-level primitives to specify an $n$-bit ripple-carry adder. Use a genvar index and parameterize $n$.
4.34MediumTier 1?
Re-implement the hierarchical 16-to-1 multiplexer of Example 4.10 using a Verilog task for the inner 4-to-1 multiplexer, called from a case statement inside an always block.
4.35MediumTier 1?
Re-implement the 16-to-1 multiplexer using a Verilog function rather than a task. Explain the syntactic and semantic differences from the task-based version.
4.36MediumTier 1?
Implement $f(w_1,w_2,w_3) = \sum m(0,1,3,4,6,7)$ using a 3-to-8 binary decoder and a single OR gate.
4.37MediumTier 1?
Design an 8-to-3 binary encoder. Assume only one input is asserted at a time and write the truth table along with minimum SOP expressions for $y_2$, $y_1$, $y_0$.
4.38HardTier 1?
Implement $f(w_1,\ldots,w_5) = \overline{w_1}\,\overline{w_2}\,w_4 w_5 + w_1\overline{w_2} + w_1 w_3 + w_1 w_4 + w_3 w_4 w_5$ using a single 4-to-1 multiplexer (selects $w_1, w_4$) and as few additional gates as possible. Assume only uncomplemented inputs are available.
4.39MediumTier 1?
Design a 3-bit binary-to-Gray code converter according to the table $b_2 b_1 b_0 \to g_2 g_1 g_0$. Show that $g_2 = b_2$, $g_1 = b_1 \oplus b_2$, $g_0 = b_0 \oplus b_1$.
4.40MediumTier 1?
A 4-input function $f$ has been Shannon-expanded with respect to $w_1$, giving cofactors $f_{w_1}$ and $f_{\overline{w_1}}$. Show that the multiplexer in the Shannon-expansion circuit can be replaced by a single logic gate (a) when $f_{\overline{w_1}}=0$ and (b) when $f_{\overline{w_1}}=1$.
4.41HardTier 1?
A commercial FPGA uses 4-input lookup tables (4-LUTs). Determine the minimum number of 4-LUTs needed to construct a 4-to-1 multiplexer with select inputs $s_1, s_0$ and data inputs $w_3, w_2, w_1, w_0$. Show both a straightforward 3-LUT solution and an optimized 2-LUT solution.
4.42MediumTier 1?
Design a 4-bit right-shift circuit using five 2-to-1 multiplexers. The control signal Shift selects between (a) pass-through $Y=W$, $k=0$ and (b) right-shift by one with $y_3=0$, $y_2=w_3$, $y_1=w_2$, $y_0=w_1$, $k=w_0$.
4.43HardTier 1?
Design a 4-bit barrel shifter that rotates the input vector $W$ by 0, 1, 2, or 3 positions according to a 2-bit control $S$. Implement the circuit using four 4-to-1 multiplexers.
4.44MediumTier 1?
Write Verilog code that builds a 4-to-1 multiplexer from a 2-to-4 decoder (instantiated as a dec2to4 module) and a single reduction-OR over the AND of decoder outputs with the data vector.
4.45EasyTier 1?
Write Verilog code for the 4-bit right-shifter of Example 4.30 in two styles: one using an if-else with explicit bit assignments, and another using the Verilog shift operator >>.
4.46HardTier 1?
Write Verilog code that defines a 4-bit barrel shifter by concatenating two copies of the input vector $W$ and shifting the resulting 8-bit value right by $S$ bits, then taking the four least-significant bits as the output.
4.47MediumTier 1?
Write Verilog code for an even-parity generator that takes a 7-bit ASCII character on input bits $b_6\ldots b_0$ and produces an 8-bit output where $b_7$ is the even-parity bit and $b_6\ldots b_0$ pass through unchanged.
05 Flip-Flops, Registers, and Counters

This chapter transitions from combinational to sequential logic. It starts with the basic SR latch built from cross-coupled NOR or NAND gates, then introduces the gated SR latch, gated D latch, and the crucial edge-triggered D flip-flop (master-slave configuration). T flip-flops and JK flip-flops are also covered. Timing parameters (setup time, hold time, propagation delay) are defined. The chapter then builds up to registers, shift registers (serial/parallel), and counters. Counter types include asynchronous (ripple) counters, synchronous counters, counters with parallel load, BCD counters, ring counters, and Johnson counters. The Verilog section introduces always @(posedge clk) for sequential logic, blocking vs. non-blocking assignments, and how to describe registers and counters in Verilog. A reaction-timer design example ties everything together, and timing analysis of flip-flop circuits is covered.

SR / D / T / JK Flip-Flops Latches vs Flip-Flops Master-Slave Setup / Hold Time Shift Registers Synchronous Counters Ring / Johnson Counters Blocking vs Non-Blocking Timing Analysis
5.1EasyTier 1?
Draw the circuit for a basic SR latch using NOR gates. Write the characteristic table showing all four input combinations including the forbidden state.
5.2EasyTier 1?
Explain the difference between a latch and a flip-flop. Why are edge-triggered flip-flops preferred in synchronous circuits?
5.3MediumTier 1?
Draw the timing diagram for a positive-edge-triggered D flip-flop with the following D input sequence: 0,1,1,0,1,0,0,1 (one value per clock cycle). Assume Q starts at 0.
5.4MediumTier 1?
Show how a T flip-flop can be built from a D flip-flop with an XOR gate. Write the characteristic equation.
5.5MediumTier 1?
Design a synchronous 3-bit up counter using T flip-flops. Derive the logic for each T input and draw the complete circuit.
5.6MediumTier 1?
Compare the maximum clock frequency of a 4-bit ripple counter versus a 4-bit synchronous counter. Assume each flip-flop has a propagation delay of 5 ns.
5.7MediumTier 1?
Design a synchronous 4-bit up/down counter with a control signal UpDown. When UpDown=1 the counter counts up; when 0 it counts down. Give the Verilog code.
5.8MediumTier 1?
Explain the difference between blocking (=) and non-blocking (<=) assignments in Verilog. Show a code example where using the wrong type produces incorrect hardware.
5.9MediumTier 1?
Write Verilog code for a D flip-flop with synchronous reset and an enable signal. When Enable=0, the flip-flop holds its current value.
5.10EasyTier 1?
What are the setup time, hold time, and clock-to-Q delay of a flip-flop? Why does each matter for correct operation?
5.11MediumTier 1?
Draw the master-slave D flip-flop circuit using two gated D latches. Explain why it is edge-triggered rather than level-sensitive.
5.12MediumTier 1?
Explain what metastability is and why it matters. What is the purpose of a synchronizer (two flip-flops in series)?
5.13EasyTier 1?
Write a Verilog module D_latch with inputs D and Clk and output Q that uses an always block sensitive to D and Clk with an if (Clk) assignment, so that a level-sensitive gated D latch is inferred.
5.14EasyTier 1?
Write a Verilog module for a positive-edge-triggered D flip-flop using always @(posedge Clock).
5.15MediumTier 1?
Inside an always @(posedge Clock) block, two blocking assignments Q1 = D; Q2 = Q1; appear. Explain why this does NOT synthesize cascaded flip-flops, and draw the circuit that is actually inferred.
5.16MediumTier 1?
Show that replacing the blocking assignments in Example 5.3 with non-blocking assignments (Q1 <= D; Q2 <= Q1;) produces a two-stage shift register. Explain the semantic difference.
5.17MediumTier 1?
In an always @(posedge Clock) block with blocking assignments f = x1 & x2; g = f | x3;, draw the circuit that is synthesized. Explain why an AND gate appears between the input and the OR gate that feeds the g flip-flop.
5.18MediumTier 1?
Repeat Example 5.5 with non-blocking assignments and explain why the synthesized circuit changes: the OR gate that feeds g is now driven by the previous-cycle output of the f flip-flop instead of the AND-gate output.
5.19EasyTier 1?
Write Verilog for a D flip-flop with an asynchronous active-low reset (Resetn) using a sensitivity list of negedge Resetn, posedge Clock.
5.20EasyTier 1?
Write Verilog for a D flip-flop with a synchronous active-low reset, using a sensitivity list of posedge Clock only.
5.21EasyTier 1?
Write a parameterized Verilog module regn for an $n$-bit register with asynchronous clear, where $n$ is a parameter with a default value.
5.22MediumTier 1?
Write hierarchical Verilog code for a 4-bit parallel-load shift register, instantiating four copies of a muxdff subcircuit (a D flip-flop with a 2-to-1 multiplexer on its D input). Inputs: R (parallel data), L (load), w (serial in), Clock; output Q.
5.23MediumTier 1?
Write an alternative non-hierarchical Verilog description of the 4-bit parallel-load shift register, using a single always @(posedge Clock) block with non-blocking assignments to perform the load or shift action.
5.24MediumTier 1?
Write a parameterized Verilog module for an $n$-bit shift register with parallel-load and serial-input. Use a for loop to express the bit-by-bit shift in the else branch.
5.25EasyTier 1?
Write Verilog for a 4-bit synchronous up-counter with asynchronous reset Resetn and enable input E. The count increments on the positive edge of Clock when E=1.
5.26EasyTier 1?
Extend the up-counter of Example 5.13 with a parallel-load input L and a 4-bit data input R, so that the counter loads $R$ on the next clock edge when $L=1$.
5.27EasyTier 1?
Write Verilog for a parameterized down-counter with parallel load. On each positive clock edge, if L=1 load R; otherwise if E=1 decrement.
5.28MediumTier 1?
Write Verilog for a parameterized up/down counter with parallel load and a direction control up_down that selects whether the counter increments or decrements.
5.29HardTier 1?
Two flip-flops $Q_1$ and $Q_2$ are connected through combinational logic, with clock-signal delays $\delta_1$ and $\delta_2$ at each flip-flop. Define $t_{skew}=\delta_2-\delta_1$ and derive (a) the minimum clock period $T_{min}=t_{cQ}+t_L+t_{su}-t_{skew}$ and (b) the hold-time condition $t_{cQ}+t_l \ge t_h+t_{skew}$ for the shortest path delay $t_l$.
5.30MediumTier 1?
For a small combinational circuit driven by a square-wave input $C$ with 50% duty cycle (Figure 5.70a), draw a timing diagram showing the waveforms at internal nodes $A$ and $B$, assuming each gate has propagation delay $\Delta$.
5.31MediumTier 1?
Determine the functional behavior of the two-JK-flip-flop circuit in Figure 5.71, in which input $w$ is driven by a square-wave signal. Show that successive values of $Q_1 Q_0$ form the sequence $00,01,10,00,\ldots$ and conclude that the circuit is a modulo-3 counter.
5.32HardTier 1?
Design a vending-machine controller with inputs $Q$ (quarter), $D$ (dime), $N$ (nickel), $\text{Coin}$ pulse, and $\overline{\text{Resetn}}$. The output $Z$ is asserted when the cumulative deposit reaches at least 30 cents (no change is given). Use a 6-bit adder, a 6-bit register, and gates only.
5.33HardTier 1?
Write Verilog code that implements the 30-cent vending-machine controller of Example 5.20, including the encoding of $N$, $D$, $Q$ into a 5-bit increment, the 6-bit accumulator register clocked on the negative edge of Coin, and the output expression $Z = s_5 + s_4 s_3 s_2 s_1$.
5.34HardTier 1?
Redesign a 4-bit synchronous counter to reduce the cascaded AND-gate delay between flip-flops. Refactor the gating so that the longest path becomes $T_{min}=t_{cQ}+t_{AND}+t_{XOR}+t_{su}$, and compute $F_{max}$ given $t_{cQ}=1.0$ ns, $t_{AND}=1.4$ ns, $t_{XOR}=1.2$ ns, $t_{su}=0.6$ ns.
5.35HardTier 1?
A circuit has three flip-flops $Q_1, Q_2, Q_3$ with corresponding clock delays $\delta_1, \delta_2, \delta_3$. Given $t_{su}=0.6$ ns, $t_h=0.4$ ns, $0.8 \le t_{cQ} \le 1.0$ ns, and gate delay $1+0.1k$ ns for $k$-input gates, compute $F_{max}$ for the clock-skew sets (i) $\delta_1=\delta_2=\delta_3=0$, (ii) $\delta_1=\delta_3=0$, $\delta_2=0.7$ ns, and (iii) $\delta_1=1$, $\delta_2=0$, $\delta_3=0.5$ ns. Check for hold-time violations in each case.
06 Synchronous Sequential Circuits

This is the core chapter on finite state machine (FSM) design. The systematic design procedure is presented: from state diagram to state table, state assignment, choice of flip-flops, derivation of next-state and output logic, to timing verification. Both Moore machines (output depends only on state) and Mealy machines (output depends on state and current inputs) are covered with clear examples. State assignment strategies include binary encoding and one-hot encoding. The chapter includes a thorough treatment of state minimization using the partitioning procedure. A serial adder is designed in both Moore and Mealy styles to illustrate the tradeoffs. Arbiter circuits, counter design using the sequential-circuit approach, analysis of existing sequential circuits, and ASM (Algorithmic State Machine) charts are also covered. Verilog code examples use parameter, case, and multi-block FSM coding styles.

Moore vs Mealy FSMs State Diagrams / Tables State Assignment One-Hot Encoding State Minimization Serial Adder ASM Charts Arbiter Circuits Verilog FSM Styles
6.1MediumTier 1?
Derive the state diagram for an FSM with input w and output z that outputs z=1 whenever the input sequence 101 is detected. Overlapping sequences should be detected.
6.2MediumTier 1?
For the FSM in exercise 6.1, derive the state table, assign binary state codes, and determine the next-state and output equations using D flip-flops.
6.3MediumTier 1?
Derive the state diagram for a Moore-type FSM that outputs z=1 when it has received at least three consecutive 1s on input w.
6.4MediumTier 1?
Repeat exercise 6.3 as a Mealy-type FSM. Compare the number of states needed.
6.5MediumTier 1?
Explain the difference between Moore and Mealy FSMs. Give one advantage of each type.
6.6MediumTier 1?
What is one-hot state encoding? For an FSM with 5 states, how many flip-flops are needed for binary encoding versus one-hot? Discuss the tradeoffs.
6.7MediumTier 1?
Write Verilog code for the Moore-type sequence detector in exercise 6.1 using a case statement and parameter declarations for the states.
6.8MediumTier 1?
Write Verilog code for a Mealy FSM that outputs 1 whenever the last two inputs were 01. Use a three-block coding style (state register, next-state logic, output logic).
6.9MediumTier 1?
Given the state-assigned table: Present State y₂y₁, Next State (w=0 / w=1), Output z: {00→10/11, 0}, {01→01/00, 0}, {10→11/00, 0}, {11→10/01, 1}. Derive the next-state and output equations using D flip-flops.
6.10MediumTier 1?
Apply the state minimization partitioning procedure to reduce the following state table (states A–F) to a minimal form. Provide the original and reduced tables.
6.11MediumTier 1?
Draw an ASM chart for a circuit that controls a vending machine: accepts nickels and dimes, dispenses a product when 15 cents or more is collected, and returns change if overpaid.
6.12MediumTier 1?
Write Verilog code for a traffic light controller FSM with states: Green (30s), Yellow (5s), Red (30s). Use a counter for timing and an FSM for state control.
6.13HardTier 1?
Design a Moore-type FSM that swaps the contents of two registers $R_1$ and $R_2$ via a temporary register $R_3$, in response to a one-cycle pulse on input $w$. The FSM must generate the control signals $R1_{out}, R1_{in}, R2_{out}, R2_{in}, R3_{out}, R3_{in},$ and Done in the proper sequence. Derive the state diagram, state table, and a state-assigned implementation.
6.14MediumTier 1?
For the four-state register-swap FSM of Example 6.1, try the alternative state assignment in which states $C$ and $D$ are swapped. Derive the next-state and output expressions and compare the resulting cost to the straightforward assignment.
6.15MediumTier 1?
Apply one-hot state encoding to the four-state register-swap FSM. Use four flip-flops $y_1\ldots y_4$ and derive the next-state expressions directly by inspection of the state diagram.
6.16HardTier 1?
Redesign the register-swap controller of Example 6.1 as a Mealy-type FSM. Show that only three states are needed and that the swap completes in three clock cycles instead of four. Derive a state diagram and discuss the timing of the output signals.
6.17MediumTier 1?
Write Verilog code for the four-state register-swap FSM of Example 6.1 using the two-always-block style: one combinational always for the next-state logic and one sequential always for the state register, with the outputs derived as assign expressions of the present state.
6.18MediumTier 1?
Apply the partitioning state-minimization procedure to a 7-state Moore FSM whose state table is given (Figure 6.51). Show each successive partition $P_1, P_2, \ldots$ and reduce the FSM to a 4-state equivalent.
6.19HardTier 1?
Design a candy-vending machine controller that accepts nickels and dimes, dispenses candy when 15 cents has been deposited, and credits a buyer with 5 cents if 20 cents is deposited (no change is given). Derive an initial state diagram and use the partitioning procedure to obtain a minimum-state Moore FSM.
6.20MediumTier 1?
For an incompletely specified 7-state Mealy FSM with four unspecified entries, apply the partitioning procedure twice: first assuming both unspecified outputs are 0 and then assuming both are 1. Compare the resulting state counts.
6.21MediumTier 1?
Analyze a synchronous sequential circuit built from two D flip-flops with $Y_1 = w\overline{y_1}+wy_2$, $Y_2 = w\overline{y_1}+\overline{w}y_2$, and output $z=y_1 y_2$. Derive the state-assigned table and show the FSM detects three consecutive 1s on input $w$.
6.22MediumTier 1?
Analyze a synchronous sequential circuit built from two JK flip-flops with $J_1=w$, $K_1=\overline{w}+y_2$, $J_2=wy_1$, $K_2=\overline{w}$ and output $z=y_1 y_2$. Derive the excitation and state-assigned tables and identify the FSM behavior.
6.23MediumTier 1?
Analyze a synchronous circuit using a mixture of one D and one T flip-flop with $D_1=w(y_1+y_2)$, $T_2=\overline{w}y_2+wy_1\overline{y_2}$, and $z=y_1 y_2$. Derive the excitation table and show that this circuit implements the same FSM as those in Examples 6.9 and 6.10.
6.24HardTier 1?
Design a Moore-type sequence detector with input $w$ and output $z$ that asserts $z=1$ when the previous two values of $w$ were both 00 or both 11. Derive the state diagram, state table, and a state-assigned implementation.
6.25HardTier 1?
Implement the sequence detector of Example 6.12 as the parallel combination of two simpler FSMs: one that detects two consecutive 1s and one that detects two consecutive 0s. Combine the outputs with an OR gate.
6.26HardTier 1?
Derive a Mealy-type FSM that detects the same sequences as in Example 6.12 (two consecutive 0s or two consecutive 1s). Show that only three states are required and write the next-state and output expressions.
6.27HardTier 1?
Implement the state-assigned table of Figure 6.89 using JK-type flip-flops. Construct the excitation table for the J and K inputs and derive minimum expressions for $J_1, K_1, J_2, K_2, J_3, K_3$.
6.28MediumTier 1?
Write Verilog code that implements the 5-state Moore-type sequence detector of Example 6.12 (detects 00 or 11). Use a parameter statement to name the states and a two-always-block style.
6.29MediumTier 1?
Write Verilog code for the Mealy-type sequence detector of Example 6.14 (detects 00 or 11) using the style where the output $z$ is set inside the combinational always block.
6.30HardTier 1?
Design a serial-data transmitter FSM that takes a 7-bit ASCII character on a parallel input and shifts it out one bit per clock cycle on a serial output line. Frame the byte appropriately and indicate when the transmission is complete.
07 Digital System Design

This chapter shows how to combine building blocks into complete digital systems. The key concept of separating a system into a datapath and a control unit (FSM) is central. Bus structures are explained using tri-state drivers and multiplexers. A simple processor design serves as the main example, including a register file, ALU, and a control FSM. Several algorithmic designs are presented: a bit-counting circuit, a shift-and-add multiplier, a restoring divider, an arithmetic mean calculator, and a sorting network. Each is designed using ASM charts for control and datapath diagrams. The chapter concludes with practical considerations: clock distribution networks, flip-flop timing at the chip level, asynchronous input handling (synchronizers), and switch debouncing circuits.

Datapath + Control Bus Structures Simple Processor Shift-and-Add Multiplier Divider ASM Charts Clock Distribution Switch Debouncing
7.1MediumTier 1?
Explain the difference between a tri-state bus and a multiplexer-based bus. What are the advantages of each approach?
7.2MediumTier 1?
Draw the datapath for a simple processor with four 8-bit registers (R0–R3), an ALU supporting ADD and SUB, and a multiplexer-based bus.
7.3MediumTier 1?
Draw an ASM chart for a circuit that computes the arithmetic mean of four 8-bit unsigned numbers loaded sequentially.
7.4EasyTier 1?
What is switch debouncing? Why is it necessary, and describe one hardware-based and one software-based approach to handle it.
7.5MediumTier 1?
What is clock skew? Explain how it can cause both setup time violations and hold time violations in a synchronous circuit.
7.6MediumTier 1?
The simple processor supports the operations: Load, Move, Add, Sub. Write microinstructions (control signals) for each operation.
7.7MediumTier 1?
Explain the concept of Register Transfer Level (RTL) design. How does it relate to the datapath/control partitioning?
7.8MediumTier 1?
Design a simple GCD (Greatest Common Divisor) calculator using the Euclidean algorithm. Draw the ASM chart and identify the datapath components needed.
7.9MediumTier 1?
Write Verilog code for a parameterized n-bit counter with enable, synchronous load, and synchronous reset. Instantiate it as a 16-bit counter.
7.10EasyTier 1?
Describe the three elements of an ASM block: state box, decision box, and conditional output box.
7.11HardTier 1?
Write complete Verilog code for a bit-counting circuit that counts the number of 1s in an 8-bit register. Use a datapath with a shift register and a counter, controlled by an FSM.
7.12HardTier 1?
Design a shift-and-add multiplier for two 4-bit unsigned numbers. Draw the ASM chart for the control circuit and the datapath circuit.
7.13HardTier 1?
Design a bit-counting circuit that, given an $n$-bit unsigned input loaded into a shift register, counts the number of 1s in the input. Provide the datapath (shift register, counter, control signals) and an ASM chart for the controlling FSM, then write Verilog code for the complete circuit.
7.14HardTier 1?
Design a shift-and-add multiplier for two $n$-bit unsigned numbers. Use a multiplicand register, a partial-product accumulator, and a shift register for the multiplier. Provide the ASM chart for the control FSM and write Verilog code for both the datapath and the controller.
7.15HardTier 1?
Design an unsigned restoring divider that computes the quotient and remainder of two $n$-bit numbers using the shift-subtract-restore algorithm. Provide the datapath, an ASM chart for the controller, and Verilog code that synthesizes correctly.
7.16HardTier 1?
Design a circuit that computes the arithmetic mean of $k$ unsigned $n$-bit numbers presented sequentially on an input bus. Provide a datapath with an accumulator and a divide-by-$k$ operation, an ASM chart, and Verilog code.
7.17HardTier 1?
Design a hardware sort circuit that sorts $k$ unsigned $n$-bit numbers stored in a small register file into ascending order, using a selection-sort or bubble-sort style algorithm. Provide the datapath, ASM chart for the controller, and Verilog code for the complete sorter.
08 Optimized Implementation of Logic Functions

This chapter goes beyond the two-level SOP/POS minimization of Chapter 2 into multilevel logic synthesis and advanced optimization techniques used in real CAD tools. Factoring, functional decomposition, and multilevel NAND/NOR circuit synthesis are presented as methods to reduce circuit cost when fan-in or other constraints apply. Alternative representations of logic functions are introduced: the cubical representation (using cubes and covers), and binary decision diagrams (BDDs), which are used extensively in modern CAD tools for verification and optimization. The Quine-McCluskey tabular minimization method is presented as an algorithmic alternative to Karnaugh maps that can handle functions with many variables. A cubical technique for minimization is also covered. Practical considerations for dealing with very large functions are discussed.

Multilevel Synthesis Factoring Functional Decomposition Cubical Representation BDDs Quine-McCluskey Technology Mapping
8.1MediumTier 1?
Factor the expression f = x₁x₃ + x₁x₄ + x₂x₃ + x₂x₄ to produce a multilevel implementation. What is the cost saving over the SOP form?
8.2MediumTier 1?
Implement the logic circuit f = ac + ad + bc + bd + e using only NAND gates.
8.3MediumTier 1?
Use the Quine-McCluskey method to find all prime implicants of f(x₁,x₂,x₃,x₄) = Σm(0,1,2,5,6,7,8,9,14).
8.4MediumTier 1?
Construct a BDD (Binary Decision Diagram) for the function f = x₁x₂ + x̄₁x₃ with variable ordering x₁ < x₂ < x₃.
8.5EasyTier 1?
Why are Karnaugh maps impractical for functions with more than 5–6 variables? What alternatives does the chapter present?
8.6MediumTier 1?
Find the simplest realization of f(x₁,...,x₄) = Σm(0,3,4,7,9,10,13,14) assuming gates have a maximum fan-in of 2.
8.7EasyTier 1?
What is the difference between a two-level and a multilevel logic implementation? Give the advantages and disadvantages of each.
8.8MediumTier 1?
Use algebraic division to extract common sub-expressions from f = abd + abe + acd + ace. Show the factored form.
8.9MediumTier 1?
What is an ROBDD (Reduced Ordered BDD)? What two reduction rules are applied, and why is canonical form important for verification?
8.10MediumTier 1?
Explain how technology mapping transforms a technology-independent netlist into one that uses specific library gates (e.g., from a standard cell library).
8.11MediumTier 1?
Construct the BDD for a 2-to-1 multiplexer function f = s·d₁ + s̄·d₀ with ordering s < d₀ < d₁. Then try ordering d₀ < d₁ < s. Compare sizes.
8.12HardTier 1?
Use functional decomposition to find an efficient implementation of f(x₁,...,x₅) = Σm(1,2,7,9,10,18,19,25,31) + D(0,15,20,26). Compare with the best SOP.
8.13MediumTier 1?
Design a minimum-cost combined circuit for two functions $f_1$ and $f_2$ of four variables, where $f_1$ asserts when at least one of $x_1, x_2$ is 1 and both $x_3, x_4$ are 1, or when $x_1=x_2=0$ and at least one of $x_3, x_4$ is 1; and $f_2 = (x_1+x_2)(x_3+x_4)$. Use factoring to share common subexpressions across both outputs.
8.14MediumTier 1?
Apply functional decomposition to the 4-variable function $f = x_1 x_3 \overline{x_4} + x_1 \overline{x_3} x_4 + \overline{x_2} x_3 \overline{x_4} + \overline{x_2}\overline{x_3} x_4$. Identify a 2-variable subfunction $g(x_3,x_4)$ that appears in multiple columns of the K-map and rewrite $f$ as a multilevel circuit using $g$.
8.15HardTier 1?
A 5-variable function $f$ is given as a Karnaugh map (Figure 8.8a). By examining the rows and columns, find subfunctions $g(x_1,x_2,x_5)$ and $k(x_3,x_4)$ such that $f = h(g,k)$, then realize $f$ as a multilevel circuit and compare its cost to the minimum-cost SOP form.
8.16MediumTier 1?
Implement the XOR function $f = x_1 \oplus x_2$ using only NAND gates. First derive a five-NAND realization from the SOP form, then apply functional decomposition with $g = x_1 \uparrow x_2$ to obtain a four-NAND implementation.
8.17MediumTier 1?
Convert the four-level AND-OR circuit in Figure 8.10a into (a) an equivalent NAND-only circuit and (b) an equivalent NOR-only circuit, by inserting bubble pairs and absorbing them into gates.
8.18MediumTier 1?
Determine the function $f$ implemented by the multilevel AND-OR circuit in Figure 8.12 by labeling internal nodes and tracing from output to inputs. Express $f$ in two-level SOP form and compute its gate cost.
8.19MediumTier 1?
For the multilevel circuit derived in Example 8.3 (with the XOR/XNOR replaced by SOP equivalents), label the internal nodes and derive the SOP expression for the output by tracing the circuit. Verify it matches the original specification.
8.20MediumTier 1?
Analyze a NAND-only circuit (Figure 8.14a) by labeling internal nodes $P_1, P_2, P_3$ and propagating bubbles via DeMorgan's theorem until an equivalent AND/OR circuit is obtained. Show that the function is $f = x_1 x_2 x_4 + \overline{x_3} x_4 + x_5$.
8.21MediumTier 1?
Analyze a circuit consisting of a mixture of NAND and NOR gates (Figure 8.15) by labeling intermediate nodes $P_1$ to $P_4$ and applying DeMorgan's theorem. Reduce the result to $f = x_1 x_5 + x_2 x_5 + \overline{x_3} x_5 + x_4 x_5$.
8.22MediumTier 1?
Given the BDD for a 3-variable function with input order $(x_2, x_1, x_3)$ in Figure 8.22d, swap the positions of nodes $x_1$ and $x_2$ to obtain a BDD with input order $(x_1, x_2, x_3)$. Use a small truth table to track the destinations of edges crossing the swap boundary.
8.23HardTier 1?
Construct the BDD for $f = x_1 x_3 + x_1 x_4 + x_2 x_4 + x_2 x_3 + \overline{x_1}\overline{x_2}\overline{x_3}\overline{x_4}$ with input order $x_1, x_2, x_3, x_4$, by applying Shannon's expansion successively on $x_1$ and $x_2$ and merging identical subgraphs. Use the BDD to derive a multilevel SOP expression.
8.24HardTier 1?
Apply the Quine-McCluskey tabular method to find all prime implicants of the function $f(x_1,\ldots,x_4) = \sum m(0,2,5,6,7,8,9,13) + D(1,12,15)$. Then construct the prime-implicant cover table, apply row and column dominance, and select a minimum-cost cover.
8.25HardTier 1?
For $f(x_1,\ldots,x_4) = \sum m(0,3,10,15) + D(1,2,7,8,11,14)$, generate all prime implicants tabularly. Build the cover table, observe that there are no essential prime implicants and no row/column dominance, and use branching to find a minimum-cost cover.
8.26MediumTier 1?
Apply the $\star$-product (cubical) operation to the cover $C_0=\{000, 001, 010, 011, 111\}$ of a 3-variable function. Generate $C_1, C_2, \ldots$ until convergence and confirm the prime implicants are $\{x11, 0xx\}$.
8.27HardTier 1?
Given the initial cover $C_0=\{0101, 1101, 1110, 011x, x01x\}$ for a 4-variable function, use the $\star$-product operation to derive all prime implicants. List the resulting product terms in algebraic form.
8.28MediumTier 1?
Use the $\#$-operation to determine which of the prime implicants $\{x11, 0xx\}$ for the function in Figure 2.56 are essential. Show the explicit $\#$-computations and explain the significance of a non-empty result.
8.29HardTier 1?
For the prime-implicant set $P=\{x01x, x101, 01x1, 0x1x, xx10\}$ of a 4-variable function with no don't-cares, use the $\#$-operation to identify all essential prime implicants. Show the cube that demonstrates each essential implicant.
8.30HardTier 1?
Apply the complete cubical minimization procedure ($\star$-product to find prime implicants, $\#$-operation to find essential ones, then branching) to the 5-variable function $f(x_1,\ldots,x_5)=\sum m(0,1,4,8,13,15,20,21,23,26,31)+D(5,10,24,28)$. Provide the minimum-cost SOP expression.
8.31HardTier 1?
Implement the 4-variable function $f = x_1 x_2 \overline{x_4} + \overline{x_2} x_3 x_4 + x_1 x_2 x_3$ using 3-input lookup tables (3-LUTs). Show that a straightforward mapping needs four 3-LUTs and find a smarter decomposition that uses only three 3-LUTs.
8.32HardTier 1?
Use functional decomposition (with subfunctions of $x_3$ and $x_4$) on $f = x_1 x_3 + x_1 x_4 + x_2 x_4 + x_2 x_3 + \overline{x_1}\overline{x_2}\overline{x_3}\overline{x_4}$. Show step-by-step that $f$ can be simplified to $f = \overline{x_3}\overline{x_4} + (x_1 + x_2)(x_3 + x_4)$.
8.33MediumTier 1?
Construct a BDD for $f = x_1 x_3 + x_2 x_4$ with input order $x_1, x_2, x_3, x_4$ by applying Shannon's expansion first on $x_1$ and then on $x_2$ within one of the cofactors.
8.34MediumTier 1?
Given the BDD for $f = x_1 x_3 + x_2 x_4$ with order $x_1, x_2, x_3, x_4$, derive a BDD with input order $x_1, x_3, x_2, x_4$ by swapping the inner $x_2$ and $x_3$ levels. Use a truth table to track the destinations of edges crossing the swap boundary.
8.35HardTier 1?
Use the tabular method to derive a minimum-cost SOP expression for $f(x_1,\ldots,x_4) = \overline{x_1}\overline{x_3}\overline{x_4} + \overline{x_3}x_4 + x_1\overline{x_2}x_4 + x_1\overline{x_2}\overline{x_3}x_4$ with don't-cares $D=(9,12,14)$. Show all generated cubes and the cover-table reduction.
8.36HardTier 1?
Use the $\star$-product operation to find all prime implicants of $f(x_1,\ldots,x_4) = \overline{x_1}\overline{x_3}\overline{x_4} + \overline{x_3}x_4 + x_1\overline{x_2}x_4 + x_1\overline{x_2}\overline{x_3}x_4$ with don't-cares $D=(9,12,14)$. Show the successive covers $C_0, C_1, C_2, \ldots$ until convergence.
8.37HardTier 1?
For the function in Examples 8.23 and 8.24, compare three implementation strategies: (a) minimum-cost SOP, (b) minimum-cost POS, and (c) a multilevel factored realization. Compute the gate-and-input cost of each and discuss the area-vs-delay trade-off.
8.38HardTier 1?
Two cascaded 4-input LUTs can implement a 7-variable function $f(x_1,\ldots,x_7) = h[g(x_1,\ldots,x_4), x_5, x_6, x_7]$. Show that this structure can implement $f = x_1 x_2 x_3 x_4 x_5 x_6 x_7$ and $f = x_1 + x_2 + \cdots + x_7$, but argue that there exist 7-variable functions that cannot be realized with just two 4-LUTs.
09 Asynchronous Sequential Circuits

This chapter covers sequential circuits that operate without a clock signal — changes in state are triggered directly by input changes rather than clock edges. The fundamental mode of operation is introduced, where only one input may change at a time and the circuit must reach a stable state before the next change. Analysis involves flow tables (the asynchronous equivalent of state tables) with stable and unstable states. Synthesis follows a procedure: primitive flow table → merged flow table → state assignment → next-state and output equations. State reduction techniques for asynchronous circuits are presented. Critical races and state assignment problems are addressed, including one-hot encoding as a race-free alternative. The chapter thoroughly covers hazards: static hazards (1-hazards and 0-hazards), dynamic hazards, and their elimination through redundant terms. A complete vending machine controller example ties all concepts together.

Fundamental Mode Flow Tables Stable / Unstable States Races & State Assignment Static / Dynamic Hazards Hazard-Free Design One-Hot Encoding Vending Machine Example
9.1EasyTier 1?
Define the fundamental mode of operation for asynchronous circuits. What constraints are placed on the inputs?
9.2MediumTier 1?
Analyze the following asynchronous circuit: two cross-coupled NOR gates with external inputs x₁ and x₂. Derive the flow table identifying all stable and unstable states.
9.3MediumTier 1?
What is the difference between a stable state and an unstable state in an asynchronous circuit? Illustrate with a flow table example.
9.4MediumTier 1?
Explain what a critical race is. Give an example of a state assignment that causes a critical race and show how to fix it.
9.5MediumTier 1?
Identify the static 1-hazard in the expression f = x₁x₂ + x̄₂x₃ when x₁=x₃=1 and x₂ changes from 1 to 0. How can it be eliminated?
9.6EasyTier 1?
Define static 1-hazard, static 0-hazard, and dynamic hazard. Which one is most common in two-level SOP circuits?
9.7MediumTier 1?
For the merged flow table, explain the concepts of "compatible states" and "merger diagram." How is the merger diagram used to determine which states can share a row?
9.8MediumTier 1?
Show that a hazard-free SOP circuit for f(x₁,x₂,x₃) = Σm(1,2,3,5,7) requires an additional product term beyond the minimum SOP. Identify the required term using a K-map.
9.9MediumTier 1?
Analyze an asynchronous circuit given by the equations Y₁ = x̄₁(x₂ + y₁) and Y₂ = x₁(x̄₂ + y₂). Derive the flow table and identify all stable states.
9.10MediumTier 1?
Compare the advantages and disadvantages of synchronous vs. asynchronous design in terms of speed, power, testability, and design effort.
9.11MediumTier 1?
What is an essential hazard? How does it differ from static and dynamic hazards? Can it be eliminated by adding redundant gates?
9.12MediumTier 1?
Design a Muller C-element: output becomes 1 when both inputs are 1, becomes 0 when both are 0, and holds its state otherwise. Derive using asynchronous design techniques.
9.13MediumTier 1?
Analyze the gated D latch as an asynchronous sequential circuit. Derive the next-state expression $Y = CD + \overline{C}y$, the excitation table, the flow table, and the corresponding state diagram, treating the clock $C$ as one of the inputs.
9.14HardTier 1?
Analyze a master-slave D flip-flop (two cascaded gated D latches) as an asynchronous sequential circuit. Derive the next-state expressions $Y_m = CD + \overline{C}y_m$ and $Y_s = Cy_m + \overline{C}y_s$, the four-state excitation table, and the corresponding flow table $S_1$ through $S_4$.
9.15HardTier 1?
Analyze the asynchronous circuit defined by $Y_1 = y_1 \overline{y_2} + w_1 \overline{y_2} + w_1 \overline{w_2} y_1$, $Y_2 = y_1 y_2 + w_1 y_2 + w_2 + \overline{w_1}\overline{w_2}\overline{y_1}$, and $z = y_1 \overline{y_2}$. Derive the excitation table, flow table, and a state diagram, and recognize the circuit as a simple two-coin vending machine controller.
9.16HardTier 1?
Design a serial parity generator as an asynchronous Moore FSM with input $w$ and output $z$ such that $z=1$ if an odd number of pulses has appeared on $w$. Use four states to handle both edges of each pulse, choose a race-free state assignment with Hamming distance 1, and derive the next-state and output expressions.
9.17HardTier 1?
Design an asynchronous modulo-4 up-counter that counts pulses on input $w$. Use eight states (one for each edge of four pulses), choose a state assignment so that all transitions involve a single state-variable change, and derive next-state expressions $Y_1, Y_2, Y_3$ and output expressions $z_2, z_1$.
9.18HardTier 1?
Design a simple two-device asynchronous arbiter using handshake signaling. Inputs are request signals $r_1, r_2$ and outputs are grant signals $g_1, g_2$. Provide a Moore state diagram with three states (idle, granted-1, granted-2), an extra unstable state to avoid a diagonal transition, and the modified flow table.
9.19HardTier 1?
Reduce the primitive flow table for a candy-vending machine that accepts nickels and dimes and dispenses when 10 cents is reached (Figure 9.26b). Apply the partitioning procedure first, then merge compatible rows to obtain the optimized 4-state flow table.
9.20HardTier 1?
Reduce a 12-row primitive flow table (Figure 9.32) by first applying the partitioning procedure, then constructing a merger diagram for the resulting flow table, and finally merging compatible rows. Show successive reductions until no further merging is possible.
9.21HardTier 1?
Reduce the 8-row flow table in Figure 9.38 first by partitioning, then by merging using both Moore-style and Mealy-style merger diagrams. Compare the resulting state counts and discuss when the Mealy form yields fewer states.
9.22HardTier 1?
Reduce the 8-row flow table of Figure 9.43 to a 2-state Mealy FSM by applying the partitioning procedure followed by row merging. Show the merger diagram and the resulting reduced flow table.
9.23MediumTier 1?
For the parity-generator FSM with states $A,B,C,D$, draw a transition diagram on a 2-cube for the state assignment $A=00, B=01, C=10, D=11$ and show that it requires diagonal transitions. Then verify that the alternative assignment $A=00, B=01, C=11, D=10$ eliminates all diagonal paths.
9.24HardTier 1?
For the simple two-device arbiter FSM, show that no 3-state, 2-state-variable assignment yields a Hamming-distance-1 transition graph. Add a fourth (unstable) state $D$ to break the diagonal transition between $B$ and $C$, modify the flow table accordingly, and ensure that the unstable state produces a safe output value.
9.25HardTier 1?
A 4-state flow table (Figure 9.52a) has 7 stable-state entries. Relabel the table to enumerate stable-state instances, draw a transition diagram, and exploit an unspecified entry to find a state assignment that maps onto a 2-cube without diagonal transitions. Specify any required Mealy-style outputs to avoid output glitches in unstable states.
9.26HardTier 1?
For a 4-state asynchronous FSM (Figure 9.55) whose transition diagram requires transitions between every pair of states, introduce three extra unstable states $E, F, G$ to enable a race-free 3-bit state assignment on a 3-cube. Modify the flow table to include the new states and derive the excitation table.
9.27HardTier 1?
Re-implement the FSM of Example 9.14 by replacing each of its 4 states with an equivalent pair of states, so that the 8 vertices of a 3-cube are used. Verify that the resulting transition diagram has no diagonal paths and modify the flow table accordingly.
9.28HardTier 1?
Examine the minimum-cost two-level realization of the master-slave D flip-flop derived from $Y_m = CD + \overline{C}y_m$ and $Y_s = Cy_m + \overline{C}y_s$. Identify the static hazard that causes the circuit to settle into an incorrect stable state when $C$ falls from 1 to 0, and add the redundant prime implicants $Dy_m$ and $y_m y_s$ to remove it.
9.29MediumTier 1?
Show that for a SOP circuit with don't-care minterms, only product terms covering pairs of adjacent 1s are needed for hazard freedom—not all prime implicants. Apply this to the function in Figure 9.64 to derive a hazard-free realization $f = x_1\overline{x_3} + \overline{x_2}\overline{x_3} + x_3 x_4$.
9.30MediumTier 1?
Analyze the static hazard in a POS circuit (Figure 9.65a). When $x_1=x_3=0$ and $x_2$ rises from 0 to 1, identify the unequal-delay path that produces a $0\to 1\to 0$ glitch on the output. Add the sum term that covers all adjacent 0s to obtain a hazard-free POS realization.
9.31MediumTier 1?
Derive the flow table of an asynchronous circuit (Figure 9.76) by extracting next-state expressions $Y_1 = w_1\overline{w_2} + \overline{w_2}y_1 + w_1 y_1 \overline{y_2}$ and $Y_2 = w_2 + w_1 y_1 + w_1 y_2$, and output $z = y_2$. Construct the excitation table and resolve safe-race transitions in which both state variables change simultaneously.
9.32MediumTier 1?
Examine the next-state expressions derived in Example 9.19 for hazards. Use Karnaugh maps for $Y_1$ and $Y_2$ to identify any prime implicant that, if missing, leaves a static hazard. Add the missing implicant to obtain a hazard-free realization.
9.33HardTier 1?
Design an asynchronous circuit with input $w$ and output $z$ that replicates every second pulse on $w$ as a pulse on $z$. Provide a state diagram, flow table, race-free state assignment, and final next-state and output expressions.
9.34HardTier 1?
Reduce the 8-row flow table of Figure 9.81 using the partitioning procedure and a merger diagram (preserving the Moore model). Then find a state assignment that allows mapping onto a 3-cube without diagonal transitions and derive the excitation table.
9.35HardTier 1?
Derive a hazard-free minimum-cost SOP implementation for $f(x_1,\ldots,x_5) = \sum m(2,3,14,17,19,25,26,30) + D(10,23,27,31)$. Find the minimum-cost prime-implicant cover, then add any extra prime implicants needed so that every pair of adjacent 1s in the K-map is covered by some product term.
+ Tier 2 & Tier 3 Practice

Additional problems organized by chapter, then by tier.

Chapter 2 — Logic Circuits

Tier 2 · Mid

2.43HardTier 2?
Design a circuit with two outputs: $f_1 = \sum m(0,2,3,4,5,7)$ and $f_2 = \sum m(1,2,3,5,6,7)$ (3-variable). Find a minimum-cost shared-gate implementation.
Note — "shared-gate implementation" means: design one circuit that computes both $f_1$ and $f_2$ together, reusing common gates between them, and minimize the total cost (gate count + total input count across both outputs combined) instead of building two independent circuits.
2.44EasyTier 2?
Using Boolean algebra, prove that $x + x \cdot y = x$ (absorption theorem).
2.45EasyTier 2?
Draw a logic circuit using only NAND gates that implements the function $f = a \cdot b + c$.
2.46MediumTier 2?
Write a structural Verilog module that implements $f = (a \cdot b) + (\overline{a} \cdot c)$ using gate-level primitives.
2.47EasyTier 2?
Using a Venn diagram, verify that $x \cdot (y + z) = x \cdot y + x \cdot z$ (distributive law).
2.48MediumTier 2?
Find the minimum POS expression for $f(a,b,c,d) = \prod M(0,1,4,5,9,11,15)$.
2.49EasyTier 2?
What is the cost (number of gates + number of gate inputs) of the function $f = x_1 x_2 + \overline{x_1}\,x_3 + x_2 x_3$?
2.50MediumTier 2?
Analyze the logic network: input signals pass through gates as follows — $g = \overline{a}$, $h = a \cdot b$, $f = g + h$. Derive the truth table and the simplified expression for $f$.

Tier 3 · Residual

2.51MediumTier 3?
Explain the difference between structural and behavioral Verilog descriptions. Give a short example of each for the XOR function.
2.52MediumTier 3?
Write a Verilog module that implements the function from exercise 2.5 using an assign statement. Write a simple testbench that applies all 16 input combinations.
2.53HardTier 3?
A system has four sensors, each producing 0 or 1. An alarm must be raised when two or more sensors output 1. Derive the minimum SOP expression using a Karnaugh map.
2.54HardTier 3?
Find the minimum-cost circuit using only two-input NAND gates for $f(x_1,x_2,x_3,x_4) = \sum m(0,1,2,3,4,6,8,9,12)$. Assume inputs are available in both true and complemented form.
2.55HardTier 3?
Prove or disprove: $f = x_1 x_2 x_5 + x_1\overline{x_2}\,x_4 x_5 + \overline{x_1}\,x_2\overline{x_4}\,x_5 + x_1 x_2 x_3 x_4$ equals $g = x_2 x_3 x_4 + x_2\overline{x_3}\,\overline{x_4}\,x_5 + \overline{x_1}\,\overline{x_3}\,x_4 x_5 + x_1 x_2\overline{x_4}\,x_5$.

Chapter 3 — Number Representation & Arithmetic

Tier 2 · Mid

3.24HardTier 2?
Derive the carry-lookahead equations for a 4-bit adder. Express $c_1, c_2, c_3, c_4$ in terms of generate ($g_i$) and propagate ($p_i$) signals.
3.25EasyTier 2?
Find the 2's complement of the following 8-bit numbers: $01010101$, $11110000$, $10000000$.
3.26EasyTier 2?
Convert the decimal numbers 0.625 and 0.3 to binary fractions (at least 8 bits after the binary point). Note which is exact and which is approximate.
3.27MediumTier 2?
Prove that the XOR operation is associative: $x_i \oplus (y_i \oplus z_i) = (x_i \oplus y_i) \oplus z_i$.
3.28EasyTier 2?
Encode the decimal number 947 in BCD (Binary-Coded Decimal).
3.29MediumTier 2?
Add the BCD numbers $0110\;0111$ (67) and $0100\;0101$ (45). Show the correction step where 6 must be added.
3.30EasyTier 2?
Write a Verilog module that adds two 8-bit numbers using the + operator and outputs a 9-bit result (including carry-out).
3.31MediumTier 2?
Perform the subtraction $01110101 - 11010110$ in 8-bit 2's complement. Verify by converting to decimal.

Tier 3 · Residual

3.32EasyTier 3?
Convert the following between octal, hexadecimal, and binary: $(752)_8$, $(B3D)_{16}$.
3.33HardTier 3?
Determine the number of gates needed to implement an n-bit carry-lookahead adder assuming no fan-in constraints. Use AND, OR, and XOR gates.
3.34HardTier 3?
What is the critical-path delay of an n-bit ripple-carry adder in terms of gate delays? Compare it with a carry-lookahead adder.
3.35HardTier 3?
Design a hierarchical carry-lookahead adder using two 2-bit CLA blocks to build a 4-bit adder. Show the complete circuit with generate/propagate at both levels.
3.36HardTier 3?
Write Verilog code for a 4×4 unsigned array multiplier. Use generate statements to create the partial product and addition logic. Verify with a testbench.

Chapter 4 — Combinational Logic

Tier 2 · Mid

4.48HardTier 2?
Design an 8-to-1 multiplexer using only 2-to-1 multiplexers. How many 2-to-1 muxes are needed? Draw the tree structure.
4.49EasyTier 2?
Using the Verilog conditional operator ? :, write a one-line assign statement that implements a 4-to-1 multiplexer.
4.50EasyTier 2?
A demultiplexer routes one input to one of four outputs based on a 2-bit select signal. Write its truth table.
4.51MediumTier 2?
Write a Verilog module for a 4-bit comparator using the relational operators <, ==, >.
4.52MediumTier 2?
Write a Verilog function that takes a 4-bit BCD input and returns the corresponding 7-segment display output (7 bits).
4.53MediumTier 2?
Use a for loop in Verilog to describe an 8-bit population count circuit (counts the number of 1s in an 8-bit input).
4.54MediumTier 2?
Show how repeated application of Shannon's expansion can be used to derive all minterms of $f = w_2 + w_1 w_3 + \overline{w_1}\,w_3$.
4.55EasyTier 2?
Explain the difference between casex and casez in Verilog. When would you use each?

Tier 3 · Residual

4.56MediumTier 3?
Write a Verilog task that swaps two 8-bit values. Call this task from a module to sort three inputs in ascending order.
4.57MediumTier 3?
Using multiplexers, implement the carry stage (stage 0) of a carry-lookahead adder. Show how $s_0$ and $c_1$ are generated.
4.58HardTier 3?
Implement the function $f = w_1 w_2 + w_2 w_3 + \overline{w_1}\,\overline{w_2}\,w_3$ using Shannon's expansion to build a multilevel circuit. Compare its cost with the direct SOP implementation.
4.59HardTier 3?
Design a parameterized $n$-to-$2^n$ decoder in Verilog using the generate construct. Verify for n = 3.
4.60HardTier 3?
Implement a cascadable 4-bit magnitude comparator with cascade inputs (Agtb_in, Aeqb_in, Altb_in). Show how two can be chained to compare 8-bit numbers.

Chapter 5 — Flip-Flops & Sequential

Tier 2 · Mid

5.36HardTier 2?
Design a 4-bit counter with parallel load capability: when Load=1, the counter loads a 4-bit value D; otherwise it counts up. Include an asynchronous reset. Write the Verilog code.
5.37EasyTier 2?
Write the characteristic table and characteristic equation for a JK flip-flop.
5.38MediumTier 2?
Design a 4-bit serial-in, serial-out shift register using D flip-flops. Draw the circuit and trace the output when the input sequence is 1,0,1,1.
5.39EasyTier 2?
What is the counting sequence of a 4-bit ring counter initialized to 1000?
5.40MediumTier 2?
What is the counting sequence of a 4-bit Johnson counter initialized to 0000? How many unique states does it pass through?
5.41MediumTier 2?
Write Verilog code for an 8-bit parallel-access shift register that can shift left, shift right, load in parallel, or hold, controlled by a 2-bit mode input.
5.42MediumTier 2?
Design a BCD counter (counts 0000 to 1001, then wraps to 0000) using synchronous reset. Write the Verilog code.
5.43EasyTier 2?
Write Verilog code for a simple 4-bit up counter with asynchronous reset using always @(posedge Clock or negedge Resetn).

Tier 3 · Residual

5.44MediumTier 3?
Given a 4-bit shift register with input Sin and parallel outputs Q[3:0], write a Verilog module that detects when the serial pattern 1011 has been completely shifted in.
5.45HardTier 3?
Design a modulo-6 counter (counts 0 through 5) using D flip-flops. Derive the next-state logic using Karnaugh maps and draw the complete circuit.
5.46HardTier 3?
A flip-flop has setup time tsu = 2 ns, hold time th = 1 ns, and propagation delay tcQ = 3 ns. The combinational logic between two flip-flops has a delay of 5 ns. What is the maximum clock frequency? What if there is a clock skew of 0.5 ns?
5.47HardTier 3?
A linear-feedback shift register (LFSR) has the feedback polynomial x³ + x + 1. Starting from 001, trace all states in the sequence. Is this a maximal-length sequence?
5.48HardTier 3?
Design a frequency divider that takes a clock input and produces an output clock at 1/6 of the input frequency with a 50% duty cycle. Give the Verilog code.

Chapter 6 — Finite State Machines

Tier 2 · Mid

6.31HardTier 2?
Derive the state diagram for an FSM that detects either 1001 or 1111 patterns on input w (overlapping allowed). Verify with the sequence w: 010111100110011111.
6.32MediumTier 2?
What is the formal model of a finite state machine? Define the 5-tuple (S, I, O, δ, λ) and explain each component.
6.33EasyTier 2?
Given a sequential circuit with two D flip-flops and combinational logic, analyze the circuit: derive the state table and draw the state diagram from the given next-state equations D₁ = x ⊕ Q₂ and D₂ = Q₁.
6.34MediumTier 2?
Design an arbiter FSM that grants access to one of two requestors (r₁, r₂). The arbiter has outputs g₁ and g₂ (grants). It should give priority to r₁ when both request simultaneously.
6.35EasyTier 2?
What are the advantages of using ASM charts over state diagrams for complex designs?
6.36MediumTier 2?
List and describe the six basic steps for designing a synchronous sequential circuit as outlined in the textbook.
6.37MediumTier 2?
Explain how specifying state encoding in Verilog (e.g., using (* synthesis, encoding = "one-hot" *)) affects the synthesized hardware. Compare binary, Gray, and one-hot for an 8-state FSM.
6.38HardTier 2?
Design a modulo-8 counter using the sequential circuit design approach with D flip-flops. Derive the state table, state assignment, and next-state logic equations using K-maps.

Tier 3 · Residual

6.39HardTier 3?
Repeat exercise 6.38 using JK flip-flops. Compare the total gate count with the D flip-flop implementation.
6.40HardTier 3?
A sequential circuit has two inputs w₁ and w₂. It outputs z=1 when w₁=w₂ for four consecutive clock cycles. Derive the state diagram and Verilog code.
6.41HardTier 3?
Design a serial adder FSM that adds two n-bit numbers presented one bit at a time (LSB first). Design both Moore and Mealy versions and compare the timing of the output.
6.42HardTier 3?
Convert the following Mealy FSM to an equivalent Moore FSM: States {A,B,C}, Input w, Output z. Transitions: A→(w=0:A/0, w=1:B/0), B→(w=0:A/0, w=1:C/1), C→(w=0:A/0, w=1:C/1). Show all steps.
6.43HardTier 3?
Design a Moore FSM that outputs 1 when either 110 or 101 patterns are detected (overlapping). Derive the minimal state table, state assignment, and complete implementation.

Chapter 7 — Datapaths & Controllers

Tier 2 · Mid

7.18HardTier 2?
Design a complete system that reads 4-bit values from an input port, stores up to 8 values in a register file, and computes their sum and average. Give the ASM chart and Verilog code.
7.19MediumTier 2?
Write Verilog code that uses a tri-state buffer (assign bus = enable ? data : 8'bz;) to connect two modules to a shared 8-bit bus.
7.20MediumTier 2?
Design a sorting network that sorts three 4-bit unsigned numbers in ascending order using compare-and-swap units. Draw the block diagram.
7.21EasyTier 2?
What is the difference between Moore-type and Mealy-type outputs in an ASM chart? Draw a small ASM chart illustrating both.
7.22EasyTier 2?
What is a synchronizer circuit? Draw a two-flip-flop synchronizer and explain why a single flip-flop is insufficient.
7.23MediumTier 2?
A divider uses the repeated-subtraction method. Write pseudo-code for this approach and compare the number of cycles needed versus the restoring divider for 255 ÷ 7.
7.24MediumTier 2?
How many clock cycles does a 4-bit shift-and-add multiplier need to complete one multiplication? What about an 8-bit version?
7.25MediumTier 2?
Design a debouncing circuit for a mechanical pushbutton using an SR latch and two pull-up resistors. Draw the circuit and explain the operation.

Tier 3 · Residual

7.26MediumTier 3?
Explain why clock distribution is critical in high-speed digital systems. What techniques can be used to minimize clock skew?
7.27HardTier 3?
Design a restoring divider that divides an 8-bit dividend by a 4-bit divisor. Show the datapath and ASM chart for the control unit.
7.28HardTier 3?
Write Verilog code for the shift-and-add multiplier from exercise 7.12. Include a testbench that multiplies 13 × 11 and verifies the result is 143.
7.29HardTier 3?
Modify the shift-and-add multiplier to handle signed numbers (2's complement). What changes are needed in the datapath and control?
7.30HardTier 3?
Design a UART transmitter that sends 8-bit data with 1 start bit and 1 stop bit. Draw the ASM chart, identify datapath components, and write Verilog code.

Chapter 8 — Optimization

Tier 2 · Mid

8.39HardTier 2?
Apply the Quine-McCluskey method to a 5-variable function: f = Σm(0,2,3,5,7,8,10,11,14,15,24,26,27,29,31). Find all prime implicants and a minimum cover.
8.40MediumTier 2?
Implement the same circuit from 8.2 using only NOR gates.
8.41MediumTier 2?
Explain the cubical representation of logic functions. Represent the function f = x̄₁x₂ + x₁x̄₃ as a set of cubes.
8.42MediumTier 2?
Given f = x₃x₅ + x₁x₂x₄ + x̄₁x₂x̄₄ + x₁x̄₃x₄ + x₁x₃x̄₄ + x₁x̄₂x₅ + x̄₁x₂x₅, derive a minimum-cost multilevel circuit.
8.43MediumTier 2?
Derive the minimum-cost SOP implementation and the minimum-cost factored form for f(x₁,...,x₄) = Σm(4,7,8,11) + D(12,15). Compare costs.
8.44EasyTier 2?
Define the terms: literal, cube, cover, prime implicant, essential prime implicant in the context of cubical representation.
8.45MediumTier 2?
In the Quine-McCluskey method, explain the role of the "don't combine" check mark and how the prime implicant chart is used to select the final cover.
8.46MediumTier 2?
Why is variable ordering important in BDDs? For the function f = x₁x₂ + x₃x₄ + x₅x₆, which ordering would you expect to produce a smaller BDD: interleaved (x₁

Tier 3 · Residual

8.47HardTier 3?
Complete exercise 8.3 by constructing the prime implicant chart and finding a minimum cover.
8.48HardTier 3?
Show that the BDD for an n-bit adder's carry-out is polynomial in n with one variable ordering but exponential with another. Demonstrate for n=3.
8.49HardTier 3?
Find the minimum-cost circuit for f(x₁,...,x₄) = Σm(0,4,8,13,14,15) assuming inputs are available in uncomplemented form only. Use functional decomposition.
8.50HardTier 3?
Given a standard cell library with 2-input NAND (cost 2), 2-input NOR (cost 2), inverter (cost 1), and 3-input NAND (cost 3), map the function f = ab + cd to minimize total cost.
8.51HardTier 3?
Analyze the multilevel circuit: t₁ = a + b, t₂ = c·d, t₃ = t₁·e, f = t₂ + t₃. Derive the flattened SOP expression, then re-factor for minimum cost with a fan-in constraint of 2.

Chapter 9 — Asynchronous Circuits

Tier 2 · Mid

9.36HardTier 2?
Synthesize an asynchronous circuit for a set-reset latch with inputs S and R: when S=1 output goes to 1, when R=1 output goes to 0, S=R=1 is not allowed. Derive the primitive flow table, merge rows, assign states, and derive output equations.
9.37MediumTier 2?
Perform state reduction on the following flow table: States A–D, Inputs x₁x₂={00,01,10,11}. Identify equivalent states and produce the reduced table.
9.38MediumTier 2?
Use one-hot state encoding to implement a 3-state asynchronous FSM. What are the advantages over binary encoding for asynchronous circuits?
9.39EasyTier 2?
Why are asynchronous circuits more difficult to design than synchronous circuits? List at least three specific challenges.
9.40MediumTier 2?
Explain the difference between the primitive flow table and the merged (reduced) flow table. Why is merging necessary before state assignment?
9.41MediumTier 2?
A dynamic hazard occurs in the circuit output sequence 1→0→1→0 when the intended transition is 1→0. Under what conditions do dynamic hazards occur? How can they be eliminated?
9.42EasyTier 2?
What is a "don't happen" input combination in asynchronous design? How are they used in the design process?
9.43HardTier 2?
Design an asynchronous circuit that acts as an arbiter for two request signals r₁ and r₂. The circuit should grant access (g₁ or g₂) to the first requester and hold until that request is released.

Tier 3 · Residual

9.44HardTier 3?
Find a race-free state assignment for a 4-state asynchronous circuit using transition diagrams. Verify that no critical races exist.
9.45HardTier 3?
Design an asynchronous vending machine controller: it accepts 5¢ and 10¢ coins. When the total reaches 15¢ or more, it dispenses a product and resets. Derive the complete circuit starting from the primitive flow table.
9.46HardTier 3?
Show how to use additional state variables to achieve a race-free state assignment for a 5-state asynchronous circuit. Explain the shared-row technique.
9.47HardTier 3?
Given a flow table with 6 rows and inputs x₁, x₂, use the merger diagram to determine the maximum number of compatible groups. Perform the state assignment and derive the next-state equations.
9.48HardTier 3?
Prove that any function implemented in a two-level SOP form will have no static 0-hazards. When can static 0-hazards appear?
Solutions

Complete worked solutions for all exercises

Chapter 2 — Boolean Algebra
2.1

$f = x_1 \cdot x_2 + \overline{x_1} \cdot x_3$

$x_1$$x_2$$x_3$$x_1 x_2$$\overline{x_1} x_3$$f$
000000
001011
010000
011011
100000
101000
110101
111101
2.2

$f = (a+b) \cdot (c+d)$

$$\overline{f} = \overline{(a+b) \cdot (c+d)}$$ $$= \overline{(a+b)} + \overline{(c+d)} \quad \text{(DeMorgan's)}$$ $$= (\bar{a} \cdot \bar{b}) + (\bar{c} \cdot \bar{d})$$

$\therefore \boxed{\overline{f} = \bar{a}\bar{b} + \bar{c}\bar{d}}$

2.3

$f(x_1, x_2, x_3) = \sum m(1,2,5,6,7)$

Canonical SOP (sum of minterms) — convert each minterm number to binary, complement 0s:

Minterm$x_1$$x_2$$x_3$Term
1001$\overline{x_1}\,\overline{x_2}\,x_3$
2010$\overline{x_1}\,x_2\,\overline{x_3}$
5101$x_1\,\overline{x_2}\,x_3$
6110$x_1\,x_2\,\overline{x_3}$
7111$x_1\,x_2\,x_3$
$$f = \overline{x_1}\,\overline{x_2}\,x_3 + \overline{x_1}\,x_2\,\overline{x_3} + x_1\,\overline{x_2}\,x_3 + x_1\,x_2\,\overline{x_3} + x_1\,x_2\,x_3$$

Canonical POS (product of maxterms, missing minterms = 0,3,4) — convert each missing minterm to binary, then complement each bit to form an OR term:

Minterm$x_1$$x_2$$x_3$Maxterm (complement each)
0000$M_0 = (x_1+x_2+x_3)$
3011$M_3 = (x_1+\overline{x_2}+\overline{x_3})$
4100$M_4 = (\overline{x_1}+x_2+x_3)$
$$f = (x_1+x_2+x_3)(x_1+\overline{x_2}+\overline{x_3})(\overline{x_1}+x_2+x_3)$$

K-map simplification:

       x₂x₃
x₁  00 01 11 10
 0:  0  1  0  1
 1:  0  1  1  1

Groups:

  • $\{1,5\}$ (column 01, both rows) → $\overline{x_2}\,x_3$ — only $x_1$ changes, eliminated
  • $\{2,6\}$ (column 10, both rows) → $x_2\,\overline{x_3}$ — only $x_1$ changes, eliminated
  • $\{5,7\}$ (row 1, columns 01 & 11) → $x_1\,x_3$ — only $x_2$ changes, eliminated

Minimized SOP: $\boxed{f = \overline{x_2}\,x_3 + x_2\,\overline{x_3} + x_1\,x_3}$

(Canonical SOP had 5 terms / 15 literals → K-map reduced to 3 terms / 7 literals)

2.4

$f = \sum m(0,1,2,5,6,7)$. K-map:

       x₂x₃
x₁  00 01 11 10
 0:  1  1  0  1
 1:  0  1  1  1

Groups:

  • $\{0,2\}$ → $\overline{x_1}\,\overline{x_3}$
  • $\{1,5\}$ → $\overline{x_2}\,x_3$
  • $\{6,7\}$ → $x_1\,x_2$

Minimized SOP: $\boxed{f = \overline{x_1}\,\overline{x_3} + \overline{x_2}\,x_3 + x_1\,x_2}$

2.5

$f = \sum m(0,2,5,7,8,10,13,15)$. 4-variable K-map:

        x₃x₄
x₁x₂  00 01 11 10
  00:   1  0  0  1
  01:   0  1  1  0
  11:   0  1  1  0
  10:   1  0  0  1

Groups:

  • $\{0,2,8,10\}$ → $\overline{x_2}\,\overline{x_4}$
  • $\{5,7,13,15\}$ → $x_2\,x_4$

Minimized SOP: $\boxed{f = \overline{x_2}\,\overline{x_4} + x_2\,x_4 = x_2 \odot x_4 \;\text{(XNOR)}}$

2.6

$f = \sum m(1,3,4,6,9,11,12,14) + D(0,5)$. 4-var K-map with don't cares at 0, 5:

        x₃x₄
x₁x₂  00 01 11 10
  00:   d  1  1  0
  01:   1  d  0  1
  11:   1  0  0  1
  10:   0  1  1  0

Groups:

  • $\{1, 3, 9, 11\}$ (rows 00 & 10, cols 01 & 11) → $\overline{x_2}\,x_4$ — $x_2=0$, $x_4=1$ constant
  • $\{4, 6, 12, 14\}$ (rows 01 & 11, cols 00 & 10) → $x_2\,\overline{x_4}$ — $x_2=1$, $x_4=0$ constant

These two quads cover all 8 minterms without needing don't-cares.

Minimized SOP: $\boxed{f = \overline{x_2}\,x_4 + x_2\,\overline{x_4} = x_2 \oplus x_4 \;\text{(XOR)}}$

2.7

Functional completeness requires implementing NOT and AND (or NOT and OR).

NOT from NAND:

$$\text{NAND}(x, x) = \overline{x \cdot x} = \overline{x} \quad \checkmark$$

AND from NAND:

$$\text{AND}(x, y) = \overline{\overline{x \cdot y}} = \text{NAND}\!\big(\text{NAND}(x,y),\;\text{NAND}(x,y)\big) \quad \checkmark$$

OR from NAND:

$$\text{OR}(x, y) = \text{NAND}(\overline{x},\;\overline{y}) = \text{NAND}\!\big(\text{NAND}(x,x),\;\text{NAND}(y,y)\big) \quad \checkmark$$

Since $\{\text{NOT}, \text{AND}\}$ is functionally complete and both are realizable with NAND only, NAND is functionally complete. $\blacksquare$

2.8

3-way light: output changes when any switch toggles → XOR of three inputs.

$x_1$$x_2$$x_3$$f$
0000
0011
0101
0110
1001
1010
1100
1111

$f = \sum m(1,2,4,7)$. Min SOP: $\boxed{f = x_1 \oplus x_2 \oplus x_3}$

$$= \overline{x_1}\,\overline{x_2}\,x_3 + \overline{x_1}\,x_2\,\overline{x_3} + x_1\,\overline{x_2}\,\overline{x_3} + x_1\,x_2\,x_3$$

(No simpler SOP exists for XOR.)

2.9
module mux2to1 (
    input  wire s, d0, d1,
    output reg  y
);
    always @(*) begin
        if (s)
            y = d1;
        else
            y = d0;
    end
endmodule

Also valid: assign f = ~s & w0 | s & w1; — the Boolean mux equation directly as a continuous assignment.

2.10

Majority of 3 inputs: output 1 when 2 or more inputs are 1.

$a$$b$$c$$f$
0000
0010
0100
0111
1000
1011
1101
1111

$f = \sum m(3,5,6,7)$. K-map gives: $\boxed{f = ab + ac + bc}$

Circuit: three AND gates for $ab$, $ac$, $bc$; one 3-input OR gate.

a b c AND ab AND ac AND bc OR f
2.11
  • Minterm: A product term in which every variable appears exactly once (complemented or uncomplemented); evaluates to 1 for exactly one input combination. e.g. $m_5 = x_1\overline{x_2}\,x_3$ equals 1 only at $(1,0,1)$.
  • Maxterm: A sum term in which every variable appears exactly once; evaluates to 0 for exactly one input combination. e.g. $M_0 = x_1 + x_2 + x_3$ equals 0 only at $(0,0,0)$.
  • Implicant: A product term that covers only rows where f=1 (never a 0-row). e.g. $x_1 x_3$ covers $\{m_5, m_7\}$, both $f=1$.
  • Prime implicant (PI): An implicant that cannot be combined with another implicant to eliminate a variable (cannot be enlarged). e.g. $x_3$ covers $\{m_1,m_3,m_5,m_7\}$; $x_1 x_3$ is not prime since it is contained in $x_3$.
  • Essential PI: A prime implicant that is the only one covering at least one minterm; must be in every minimum cover. e.g. $\overline{x_1}\,x_2$ is essential because $m_2$ is covered only by it.

中文版:

  • 最小項 (Minterm):乘積項,每個變數恰好出現一次(原變數或補數);僅在一組輸入組合下為 1。
  • 最大項 (Maxterm):和項,每個變數恰好出現一次;僅在一組輸入組合下為 0。
  • 蘊涵項 (Implicant):一個乘積項,只涵蓋 f=1 的列(不涵蓋任何 f=0 的列)。
  • 質蘊涵項 (Prime Implicant):無法再與其他蘊涵項合併以消去變數的蘊涵項(無法再擴大)。
  • 必要質蘊涵項 (Essential PI):唯一涵蓋某個最小項的質蘊涵項;在任何最小覆蓋中都必須包含。

Example 範例: $f(x_1,x_2,x_3) = \sum m(1,2,3,5,7)$

$x_1$$x_2$$x_3$$f$
0000
0011$m_1$
0101$m_2$
0111$m_3$
1000
1011$m_5$
1100
1111$m_7$
  • Minterm 最小項: $m_5 = x_1\overline{x_2}\,x_3$ — only equals 1 at row $(1,0,1)$.
    僅在 $(1,0,1)$ 時為 1。
  • Maxterm 最大項: $M_0 = x_1 + x_2 + x_3$ — only equals 0 at row $(0,0,0)$.
    僅在 $(0,0,0)$ 時為 0。
  • Implicant 蘊涵項: $x_1 x_3$ covers $\{m_5, m_7\}$, both have $f=1$. A single minterm like $m_3$ is also an implicant.
    $x_1 x_3$ 涵蓋 $\{m_5, m_7\}$,兩者皆 $f=1$。單一最小項如 $m_3$ 也是蘊涵項。
  • Prime Implicant 質蘊涵項: $x_3$ covers $\{m_1,m_3,m_5,m_7\}$ — cannot be enlarged further. $\overline{x_1}\,x_2$ covers $\{m_2,m_3\}$ — cannot be enlarged. But $x_1 x_3$ is not prime because it is contained within the larger PI $x_3$.
    $x_3$ 涵蓋 $\{m_1,m_3,m_5,m_7\}$,無法再擴大。$\overline{x_1}\,x_2$ 涵蓋 $\{m_2,m_3\}$,無法再擴大。而 $x_1 x_3$ 不是質蘊涵項,因為它被更大的 $x_3$ 包含。
  • Essential PI 必要質蘊涵項: $\overline{x_1}\,x_2$ is essential — $m_2$ is covered only by this PI. $x_3$ is essential — $m_1, m_5, m_7$ are covered only by it.
    $\overline{x_1}\,x_2$ 是必要的,因為 $m_2$ 只被它涵蓋。$x_3$ 是必要的,因為 $m_1, m_5, m_7$ 只被它涵蓋。

Minimum SOP 最簡積項和:$\boxed{f = x_3 + \overline{x_1}\,x_2}$

2.43

$f_1 = \sum m(0,2,3,4,5,7)$, $f_2 = \sum m(1,2,3,5,6,7)$.

K-map for $f_1$:

       x₂x₃
x₁  00 01 11 10
 0:  1  0  1  1
 1:  1  1  1  0

No quads (only 6 ones, no 4-in-a-row/2×2 block of all 1s). Three pairs cover all six 1s:

  • $\{m_0, m_4\}$ (column 00) → $\overline{x_2}\,\overline{x_3}$
  • $\{m_2, m_3\}$ (top row, cols 10–11) → $\overline{x_1}\,x_2$
  • $\{m_5, m_7\}$ (bottom row, cols 01–11) → $x_1 x_3$

$\boxed{f_1 = \overline{x_2}\,\overline{x_3} + \overline{x_1}\,x_2 + x_1 x_3}$

K-map for $f_2$:

       x₂x₃
x₁  00 01 11 10
 0:  0  1  1  1
 1:  0  1  1  1

Two essential quads cover all six 1s:

  • $\{m_1, m_3, m_5, m_7\}$ (cols 01 ∪ 11, all $x_3{=}1$) → $x_3$
  • $\{m_2, m_3, m_6, m_7\}$ (cols 11 ∪ 10, all $x_2{=}1$) → $x_2$

$\boxed{f_2 = x_2 + x_3}$

Shared-gate implementation: Note that $\overline{x_2}\,\overline{x_3} = \overline{(x_2 + x_3)} = \overline{f_2}$. So one OR gate computes $f_2$, and its inverted output supplies the $\overline{x_2}\,\overline{x_3}$ term of $f_1$:

  1. $T = x_2 + x_3$   (OR2)  — this is $f_2$
  2. $\overline{T}$   (NOT)
  3. $A = \overline{x_1}\,x_2$   (AND2)
  4. $B = x_1 x_3$   (AND2)
  5. $f_1 = \overline{T} + A + B$   (OR3)

Cost (gates + total inputs, complemented literals free):

  • Independent: $f_1$ = 4 gates + 9 inputs = 13; $f_2$ = 1 + 2 = 3 → 16
  • Shared: 5 gates + 10 inputs = 15  (saving 1 by reusing the $x_2{+}x_3$ OR-gate)
2.44

Prove $x + x \cdot y = x$:

$$x + x \cdot y = x \cdot 1 + x \cdot y \quad \text{(identity: } x = x \cdot 1\text{)}$$ $$= x \cdot (1 + y) \quad \text{(factoring)}$$ $$= x \cdot 1 \quad \text{(since } 1 + y = 1\text{)}$$ $$= x \quad \text{(identity)} \quad \blacksquare$$

This is the absorption law.

2.45

$f = a \cdot b + c$. Convert to NAND-NAND using double inversion:

$$f = a \cdot b + c = \overline{\overline{a \cdot b} \cdot \overline{c}}$$

Implementation:

  • Gate 1: $\text{NAND}(a, b) = \overline{ab}$
  • Gate 2: $\text{NAND}(c, c) = \overline{c}$ (acts as NOT)
  • Gate 3: $\text{NAND}(\overline{ab},\; \overline{c}) = \overline{\overline{ab} \cdot \overline{c}} = ab + c = f$

Three NAND gates total.

2.46

f = (a AND b) OR (NOT a AND c)

module structural_f (
    input  wire a, b, c,
    output wire f
);
    wire not_a, and1, and2;
    not  g0 (not_a, a);
    and  g1 (and1, a, b);
    and  g2 (and2, not_a, c);
    or   g3 (f, and1, and2);
endmodule
2.47

Distributive law: $x \cdot (y + z) = x \cdot y + x \cdot z$

Draw three overlapping circles for $x, y, z$ inside a universe rectangle.

LHS: $x \cdot (y+z)$ = region in $x$ AND (in $y$ OR in $z$) $= (x \cap y) \cup (x \cap z)$.

RHS: $x \cdot y + x \cdot z = (x \cap y) \cup (x \cap z)$.

Both expressions represent the same shaded area in the Venn diagram. $\blacksquare$

2.48

$f = \prod M(0,1,4,5,9,11,15)$. Zeros at minterms 0,1,4,5,9,11,15.

4-var K-map for $f=0$ positions, group the 0s for POS:

  • $\{0,1,4,5\}$ → $(x_1 + x_2)$
  • $\{9,11\}$ → $(\overline{x_1} + x_2 + \overline{x_4})$
  • $\{15\}$ → $(\overline{x_1} + \overline{x_2} + \overline{x_3} + \overline{x_4})$

Min POS: $\boxed{f = (x_1+x_2)(\overline{x_1}+\overline{x_2}+x_4)(\overline{x_1}+\overline{x_2}+\overline{x_3})}$

2.49

$f = x_1 x_2 + \overline{x_1}\,x_3 + x_2 x_3$

Literal count: $x_1 x_2$ (2) + $\overline{x_1}\,x_3$ (2) + $x_2 x_3$ (2) = 6 literals.

Gate count (2-level): 3 AND gates (2-input each) + 1 OR gate (3-input) = 4 gates.

Cost (gates + inputs): $3 \times 2 + 1 \times 3 = 9$ gate inputs + 4 gates = cost of 9.

Note: $x_2 x_3$ is a redundant consensus term; minimized: $f = x_1 x_2 + \overline{x_1}\,x_3$ (cost = 5).

2.50

Circuit: $g = \overline{a}$; $h = a \cdot b$; $f = g + h$

$$f = g + h = \overline{a} + a \cdot b$$ $$= \overline{a} + b \quad \text{(absorption dual / consensus)}$$

$\boxed{f = \overline{a} + b}$ (equivalent to $a \rightarrow b$, implication).

$a$$b$$f$
001
011
100
111
2.51

Structural XOR:

module xor_struct (input a, b, output f);
    wire na, nb, t1, t2;
    not g0(na, a);
    not g1(nb, b);
    and g2(t1, a, nb);
    and g3(t2, na, b);
    or  g4(f, t1, t2);
endmodule

Behavioral XOR:

module xor_behav (input a, b, output f);
    assign f = a ^ b;
endmodule

Structural explicitly instantiates gates; behavioral describes function mathematically and lets synthesis choose implementation.

2.52

From 2.6: $f = \overline{x_2}\,\overline{x_4} + x_2\,x_4$

module f_2_6 (
    input  wire x1, x2, x3, x4,
    output wire f
);
    assign f = (~x2 & ~x4) | (x2 & x4);
endmodule

module tb;
    reg  x1,x2,x3,x4;
    wire f;
    f_2_6 uut(.x1(x1),.x2(x2),.x3(x3),.x4(x4),.f(f));
    integer i;
    initial begin
        $display("x1 x2 x3 x4 | f");
        for (i=0; i<16; i=i+1) begin
            {x1,x2,x3,x4} = i[3:0];
            #10;
            $display("%b  %b  %b  %b  | %b", x1,x2,x3,x4,f);
        end
        $finish;
    end
endmodule
2.53

Alarm = 1 when 2 or more of 4 sensors active. $f = \sum m(3,5,6,7,9,10,11,12,13,14,15)$.

4-var K-map groups:

  • $\{3,7,11,15\}$ → $x_3 x_4$
  • $\{5,7,13,15\}$ → $x_2 x_4$
  • $\{6,7,14,15\}$ → $x_2 x_3$
  • $\{9,11,13,15\}$ → $x_1 x_4$
  • $\{10,11,14,15\}$ → $x_1 x_3$
  • $\{12,13,14,15\}$ → $x_1 x_2$

All 6 prime implicants are essential. Minimal SOP:

$$\boxed{f = x_1 x_2 + x_1 x_3 + x_1 x_4 + x_2 x_3 + x_2 x_4 + x_3 x_4}$$
2.54

$f = \sum m(0,1,2,3,4,6,8,9,12)$. 4-var K-map, convert to NAND-NAND.

K-map groups:

  • $\{0,1,2,3\}$ → $\overline{x_1}\,\overline{x_2}$
  • $\{0,1,8,9\}$ → $\overline{x_2}\,\overline{x_3}$
  • $\{0,4,8,12\}$ → $\overline{x_3}\,\overline{x_4}$
  • $\{4,6\}$ → $\overline{x_1}\,x_2\,\overline{x_4}$

Minimal SOP: $\boxed{f = \overline{x_1}\,\overline{x_2} + \overline{x_2}\,\overline{x_3} + \overline{x_3}\,\overline{x_4} + \overline{x_1}\,x_2\,\overline{x_4}}$

$$\text{NAND-NAND: } f = \overline{\overline{\overline{x_1}\,\overline{x_2}} \cdot \overline{\overline{x_2}\,\overline{x_3}} \cdot \overline{\overline{x_3}\,\overline{x_4}} \cdot \overline{\overline{x_1}\,x_2\,\overline{x_4}}}$$
2.55

To prove or disprove $f = g$ for 5-variable functions, build truth tables (32 rows each) or use algebraic manipulation / BDD construction.

Method: Compute $h = f \oplus g$. If $h = 0$ for all 32 input combinations, $f = g$; otherwise find a counterexample row where $h = 1$.

In practice: represent both as BDDs with the same variable order. If their ROBDD roots point to the same node (canonical form), they are equivalent; otherwise inequivalent.

2.12

The truth table is

$x$$y$$L$
000
011
101
110
Summing the two minterms gives $L = \overline{x}\,y + x\,\overline{y}$, which is the XOR function $L = x \oplus y$.

2.13
$a$$b$$s_1$$s_0$
0000
0101
1001
1110
So $s_0 = a \oplus b$ (sum bit) and $s_1 = a \cdot b$ (carry bit). Implement with one XOR gate and one AND gate sharing the same inputs $a,b$ — this is the half-adder.
2.14

Expand the LHS using distributivity: $(x_1+\overline{x_3})(\overline{x_1}+x_3) = x_1\overline{x_1} + x_1 x_3 + \overline{x_1}\,\overline{x_3} + \overline{x_3} x_3 = 0 + x_1 x_3 + \overline{x_1}\,\overline{x_3} + 0 = x_1 x_3 + \overline{x_1}\,\overline{x_3}$, which equals the RHS. (This is the XNOR identity.)

2.15

Group the LHS as $(\overline{x_1}+x_1) x_3 \cdot \text{(impossible)}$… better: combine pairs by the variable $x_3$. $\overline{x_1}\,\overline{x_3} + x_1 x_3$ is one XNOR; $\overline{x_2}x_3 + x_2\overline{x_3}$ is one XOR. These two cancel some terms when expanded with $x_2$/$x_1$, and applying $x+\overline{x}=1$ and absorption gives the simplest expression $f = x_1 \oplus x_2 \cdot 0 + \dots = \overline{x_1\oplus x_2} + x_1\overline{x_2}$, equivalently the RHS $x_1 x_2 + \overline{x_1}\,\overline{x_2} + x_1\overline{x_2}$. By absorption $x_1\overline{x_2} + x_1 x_2 = x_1$, so the simplest form is $f = x_1 + \overline{x_1}\,\overline{x_2} = x_1 + \overline{x_2}$.

2.16

Draw three overlapping circles for $x,y,z$. The set $y \cdot z$ is the lens-shaped intersection of $y$ and $z$; $x + y\cdot z$ shades all of $x$ plus that lens. On the right side, $x+y$ shades $x \cup y$ and $x+z$ shades $x \cup z$; their intersection $(x+y)(x+z)$ contains every point that lies in $x$ OR in both $y$ and $z$, which is the same shaded region. Hence the equality holds.

2.17

In a Venn diagram with two circles $x$ and $y$, the region $x\cdot y$ is their intersection. $\overline{x\cdot y}$ is everything outside that intersection. $\overline{x}$ is everything outside circle $x$ and $\overline{y}$ is everything outside circle $y$; their union $\overline{x}+\overline{y}$ covers exactly the same region (everything not in both circles). Therefore $\overline{x\cdot y} = \overline{x}+\overline{y}$.

2.18

Specification: $f = s_3 + s_1 s_2$ (reject if too large, OR both too light and too small). Truth table has $f=1$ for $(s_1 s_2 s_3) \in \{001,011,100,101,110,111\}$. Canonical SOP: $f = \sum m(1,3,4,5,6,7)$. Algebraic minimization: $f = \overline{s_1}\overline{s_2}s_3 + \overline{s_1}s_2 s_3 + s_1\overline{s_2}\overline{s_3} + s_1\overline{s_2}s_3 + s_1 s_2\overline{s_3} + s_1 s_2 s_3$. Combining gives $\overline{s_1}s_3(\overline{s_2}+s_2) + s_1\overline{s_2}(\overline{s_3}+s_3) + s_1 s_2(\overline{s_3}+s_3) = \overline{s_1}s_3 + s_1\overline{s_2} + s_1 s_2$. Then $s_1\overline{s_2}+s_1 s_2 = s_1$, so $f = \overline{s_1}s_3 + s_1$ and finally $f = s_3 + s_1\cdot s_2$ via the consensus identity, matching the spec.

2.19

Start from the canonical SOP and replicate $s_1 s_2\overline{s_3}$ (allowed since $a+a=a$): $f = \overline{s_1}\overline{s_2}s_3 + \overline{s_1}s_2 s_3 + s_1\overline{s_2}\overline{s_3} + s_1\overline{s_2}s_3 + s_1 s_2\overline{s_3} + s_1 s_2 s_3 + s_1 s_2\overline{s_3}$. Group $(\overline{s_1}\overline{s_2}s_3 + \overline{s_1}s_2 s_3) + (s_1\overline{s_2}\overline{s_3}+s_1 s_2\overline{s_3}) + (s_1\overline{s_2}s_3 + s_1 s_2 s_3) + s_1 s_2\overline{s_3} = \overline{s_1}s_3 + s_1\overline{s_3} + s_1 s_3 + s_1 s_2\overline{s_3}$. Combining $s_1\overline{s_3}+s_1 s_3 = s_1$, then $\overline{s_1}s_3 + s_1 = s_1 + s_3$… here we keep $s_1 s_2$ via the replicated term: $f = s_3 + s_1 s_2$.

2.20

Apply the consensus theorem $xy + \overline{x}z + yz = xy + \overline{x}z$ (the $yz$ consensus is redundant). Here from the full SOP, take $x = s_3$. Pairs $\overline{s_3}\cdot(s_1 s_2)$ and $s_3\cdot 1$ have consensus $s_1 s_2$, and combining the remaining six minterms with DeMorgan and absorption directly gives $f = s_3 + s_1 s_2$ in one step.

2.21

$f = \sum m(2,3,4,6,7) = \overline{x_1}x_2\overline{x_3} + \overline{x_1}x_2 x_3 + x_1\overline{x_2}\overline{x_3} + x_1 x_2\overline{x_3} + x_1 x_2 x_3$. Combine $\overline{x_1}x_2\overline{x_3}+\overline{x_1}x_2 x_3 = \overline{x_1}x_2$ and $x_1 x_2\overline{x_3}+x_1 x_2 x_3 = x_1 x_2$, giving $\overline{x_1}x_2+x_1 x_2 = x_2$. Then with $x_1\overline{x_2}\overline{x_3}$ left: $f = x_2 + x_1\overline{x_2}\overline{x_3} = x_2 + x_1\overline{x_3}$ by absorption ($x_2 + \overline{x_2}y = x_2 + y$). Minimum-cost SOP: $f = x_2 + \overline{x_1}\,\overline{x_3}$ (after applying the same trick from the alternative grouping).

2.22

The 7 minterms of $f(x_1,x_2,x_3,x_4) = \sum m(3,7,9,12,13,14,15)$ group on a K-map as: $x_3 x_4$ covers $m_3, m_7, m_{15}$; $x_1 x_2$ covers $m_{12}, m_{13}, m_{14}, m_{15}$; $x_1\overline{x_2}x_3 x_4$ ($m_9$ alone needs $x_1\overline{x_2}x_4$). Combining $m_9$ with $m_{13}$ gives $x_1 x_4\overline{x_2}+x_1 x_4 x_2 = x_1 x_4$. So minimum SOP is $f = x_1 x_2 + x_3 x_4 + x_1 x_4$.

2.23

$\prod M(0,1,5)$ means the maxterms are $M_0=(x_1+x_2+x_3)$, $M_1=(x_1+x_2+\overline{x_3})$, $M_5=(\overline{x_1}+x_2+\overline{x_3})$. Combine $M_0$ and $M_1$ on $x_3$: $(x_1+x_2)$. Combine $M_1$ and $M_5$ on $x_1$: $(x_2+\overline{x_3})$. Minimum POS: $f = (x_1+x_2)(x_2+\overline{x_3})$. (Note $x_2$ alone covers all three when expanded, but the two-term POS is the simplest.)

2.24

Take $f = (\overline{x_1}+x_2)(x_2+\overline{x_3})$. By DeMorgan, $(\overline{x_1}+x_2) = \overline{\overline{(\overline{x_1}+x_2)}} = \overline{x_1\overline{x_2}}$ … rather: a NOR gate computes $\overline{a+b}$. Realize each OR sum as a NOR followed by an inverter (= NOR with both inputs tied), and the final AND of the two as a NOR with each input first NORed (= inverted). Concretely: $P_1 = \overline{\overline{x_1}+x_2}$ via NOR(x_1', x_2)… simpler: invert each variable using a NOR-as-inverter, then $f = \text{NOR}(\text{NOR}(\overline{x_1},x_2),\,\text{NOR}(x_2,\overline{x_3}))$ after a final inversion.

2.25

From minimum SOP $f = x_2 + \overline{x_1}\,\overline{x_3}$, apply DeMorgan: $f = \overline{\overline{x_2}\cdot \overline{\overline{x_1}\,\overline{x_3}}} = \overline{\overline{x_2}\cdot(x_1+x_3)}$. Replace each AND/OR with NAND: invert $x_2$ via NAND, compute $x_1\,\text{NAND}\,x_3$ (= $\overline{x_1 x_3}$, then invert again to get $x_1+x_3$ via DeMorgan), and AND the two by NAND-NAND. Total: 4 NAND gates.

2.26

Build seven 4-variable K-maps, one per segment, with cells $X = 1010\dots1111$ marked don't-care. Minimum SOPs (standard result):

a = x3 + x1 + x2·x0 + x2'·x0'
b = x2' + x1·x0 + x1'·x0'
c = x2 + x1' + x0
d = x2'·x0' + x1·x0' + x2·x1'·x0 + x2'·x1 + x3
e = x2'·x0' + x1·x0'
f = x3 + x2·x1' + x2·x0' + x1'·x0'
g = x3 + x2'·x1 + x2·x1' + x1·x0'
Don't-cares for $X\ge 10$ allow many cubes to extend into cells 10–15, drastically reducing total gate count.

2.27

Both functions share the term $\overline{x_2}\,\overline{x_3}\,\overline{x_4}$, so factor it out. $f_1 = \overline{x_1}\,\overline{x_3} + x_1 x_3 + \overline{x_2}\,\overline{x_3}\,\overline{x_4}$, $f_2 = \overline{x_1} x_3 + x_1\overline{x_3} + \overline{x_2}\,\overline{x_3}\,\overline{x_4}$. Note $f_1$'s first two terms form XNOR($x_1, x_3$) and $f_2$'s first two form XOR($x_1, x_3$). Sharing the third term yields total cost = 2 (XNOR/XOR) + 1 (AND for shared) + 2 (final OR per output) — substantially less than independent realizations.

2.28

Suppose $f_3 = \overline{x_1}\,\overline{x_2}\,\overline{x_4} + x_1 x_2 x_3$ and $f_4 = \overline{x_1}\,\overline{x_3}\,\overline{x_4} + x_2 x_3 x_4$ (Figure 2.65 pair). Their separate primes share none. But the non-prime cube $\overline{x_1}\,\overline{x_2}\,\overline{x_3}\,\overline{x_4}$ is contained in both $\overline{x_1}\,\overline{x_2}\,\overline{x_4}$ (of $f_3$) and $\overline{x_1}\,\overline{x_3}\,\overline{x_4}$ (of $f_4$). Using the smaller (4-literal) shared cube as a common product and then ORing the remainders yields fewer total inputs than two independent two-term realizations (cost drops from ~28 to ~22 gate-inputs).

2.29

Convert each function of Example 2.16 to its minimum POS via maxterms. $f_1 = (x_2+\overline{x_1}+x_3)(x_3+x_1+\overline{x_3})\dots$ → in fact each function has 4 maxterms not shared with the other, so combined POS gate-input cost is ~26 vs the shared SOP's ~18. Hence the SOP-based shared realization is cheaper.

2.30

The POS forms of $f_3$ and $f_4$ share the maxterm $(x_1+x_2+x_3+x_4)$ (covering $m_0$ in both). Sharing this sum term across both outputs gives total cost about 19 gate-inputs, comparable to the SOP-shared realization (~22). Both shared realizations beat the independent ones; for this pair POS is slightly cheaper.

2.31

Expand each side to canonical SOP. LHS: $\overline{x_1}x_3$ generates minterms $m_1, m_3$; $x_2\overline{x_3}$ generates $m_2, m_6$; $x_1 x_2$ generates $m_6, m_7$. So LHS = $\sum m(1,2,3,6,7)$. RHS: $x_1\overline{x_2}$ → $m_4, m_5$; $\overline{x_1}x_2$ → $m_2, m_3$; $\overline{x_2}\,\overline{x_3}$ → $m_0, m_4$. So RHS = $\sum m(0,2,3,4,5)$. Different minterm sets → equation is not valid.

2.32

$f = \sum m(0,2,4,5,6,7,8,10,12,14,15)$ has zeros at $m(1,3,9,11,13)$, i.e. maxterms $M_1, M_3, M_9, M_{11}, M_{13}$. Group on a 4-var K-map of zeros: the column $x_3 x_4 = 01$ at rows $\overline{x_1}\,\overline{x_2}, \overline{x_1}x_2, x_1\overline{x_2}$ gives $(\overline{x_3}+x_4 \to)$ actually for zeros of $f$, the pattern $x_3=0, x_4=1$ at $x_1 x_2 \in \{00,01,10\}$ combines as $(\overline{x_3}+x_4)$ … plus $(x_1+\overline{x_4})$ for $m_{13}$. Minimum POS: $f = (x_3+\overline{x_4})(\overline{x_2}+x_3+\overline{x_4})\dots$ simplifies to $f = (x_3+\overline{x_4})(x_1+\overline{x_2}+x_3)$ (covers all five maxterms with two sum terms after K-map grouping).

2.33

By definition $f = AB+AC+BC$ (two-out-of-three of the conditions). Substituting and expanding using DeMorgan/absorption: $AB = x_1 x_3(\overline{x_2}+\overline{x_3})\dots$ Algebraic simplification (textbook result) collapses to $f = x_1(x_2+x_3)$. Implementation: a 2-input OR ($x_2, x_3$) feeding a 2-input AND with $x_1$ — total cost = 4 gate-inputs.

2.34

Draw 3 circles for $A,B,C$ derived from inputs $x_1, x_2, x_3$. Marking the regions where each $A,B,C$ is true and shading where at least two overlap, then projecting back to the $(x_1, x_2, x_3)$ space, the only points where two-of-three are true are those satisfying $x_1 \wedge (x_2 \vee x_3)$. So $f = x_1(x_2+x_3)$, confirming the algebraic result.

2.35

Add the consensus of $\overline{x_2}x_3\overline{x_4}$ and $x_1 x_2\overline{x_4}$ which is $x_1 x_3\overline{x_4}$, then absorb. $f = \overline{x_2}x_3\overline{x_4} + \overline{x_1}\,\overline{x_3}\,\overline{x_4} + x_1 x_2\overline{x_4} + x_1 x_3\overline{x_4}$. Combining $x_1 x_2\overline{x_4}+x_1 x_3\overline{x_4} = x_1\overline{x_4}(x_2+x_3)$, and combining the two terms with $\overline{x_4}$ factors out: $f = \overline{x_4}\bigl(\overline{x_1}\,\overline{x_3} + x_3\overline{x_2} + x_1(x_2+x_3)\bigr)$. Final simplest SOP: $f = \overline{x_4}\,\bigl(\overline{x_1}\,\overline{x_3} + x_2 + x_3\bigr) = \overline{x_4}(\overline{x_1}\overline{x_3}+x_2+x_3)$.

2.36

Apply the dual consensus. Among the three sum terms, $(x_1+\overline{x_2}+x_3)$ and $(\overline{x_1}+\overline{x_3}+x_4)$ have consensus $(\overline{x_2}+x_4)$ — but it is not in the original. Use the identity $(A+B)(A+C) = A+BC$ on pairs sharing a literal: $(x_1+\overline{x_2}+x_3)(x_1+x_2+\overline{x_4}) = x_1 + (\overline{x_2}+x_3)(x_2+\overline{x_4}) = x_1 + x_3 x_2 + \overline{x_2}\,\overline{x_4} + x_3\overline{x_4}$. After AND with $(\overline{x_1}+\overline{x_3}+x_4)$ and absorption, the simplest POS is $f = (x_1+x_3)(\overline{x_1}+x_4)(\overline{x_2}+\overline{x_3}+x_4)$ (three sum terms).

2.37

On a 4-var K-map with $\sum m(4,6,8,10,11,12,15) + D(3,5,7,9)$: Minimum SOP using don't-cares: $f = x_2\overline{x_3} + x_1\overline{x_3} + x_3 x_4$ (three product terms — uses $D=5,7$ to extend cubes). Minimum POS using the same don't-cares: $f = (x_1+x_2+x_3)(\overline{x_3}+x_4)$. The two forms encode different functions on the don't-care cells (e.g. SOP makes $m_5=1$, POS makes $m_5=1$ too, but $m_3$ differs), illustrating that don't-care assignments need not agree across SOP/POS minimizations.

2.38

The given SOP expansion covers $\sum m(0,1,4,5,8,9,11)$ (after expanding each product). With $D=(9,12,14)$, K-map minimization yields: Minimum SOP: $f = \overline{x_3}\,\overline{x_4} + x_1 x_4 + \overline{x_2}x_4$. Minimum POS: $f = (\overline{x_2}+\overline{x_3})(\overline{x_3}+x_4)(x_1+\overline{x_3}+\overline{x_4})$. Cost (literals + gates+1): SOP ≈ 11, POS ≈ 13, so SOP is preferred.

2.39

Distribute: $f = s_3 s_1 + s_3 s_2 + \overline{s_1}\,\overline{s_2}$. On a 3-var K-map this is $\sum m(0,4,5,6,7)$. Combining: $s_3 s_1 + s_3 s_2 = s_3(s_1+s_2)$; together with $\overline{s_1}\,\overline{s_2}$ no further absorption applies. Minimum SOP: $f = s_1 s_3 + s_2 s_3 + \overline{s_1}\,\overline{s_2}$ (3 product terms).

2.40
module ex2_e29(input x, y, z, output f, g);
  wire t;
  assign t = y ^ z;
  assign f = (~t) & z | t & x;
  assign g = t ^ x;
endmodule
The wire $t = y \oplus z$ is shared by both outputs. Note $f$ is itself a 2-to-1 mux selected by $t$ (data inputs $z$ and $x$).
2.41
module mux2(input a, b, s, output f); assign f = s ? b : a; endmodule
module add1(input x, y, output s, c); assign {c,s} = x + y; endmodule

module shared_adder(input a,b,c,d,m, output s, cout);
  wire x, y;
  mux2 u1(.a(a), .b(c), .s(m), .f(x));
  mux2 u2(.a(b), .b(d), .s(m), .f(y));
  add1 u3(.x(x), .y(y), .s(s), .c(cout));
endmodule
When $m=0$ the adder sees $(a,b)$; when $m=1$ it sees $(c,d)$. One adder is shared via two muxes.
2.42

Each product term has at most 3 distinct variables, so each fits in one 3-LUT directly:

L1 = x1·x2·x4'
L2 = x2'·x3·x4
L3 = x1'·x2'·x3'
L4 = L1 + L2 + L3   (3-LUT OR)
Total 4 LUTs. Decomposition (e.g., factoring $\overline{x_2}$ from $L_2$ and $L_3$) does not reduce LUT count here because the OR still needs a final 3-LUT, so 4 LUTs is the minimum for this realization.

Chapter 3 — Number Representation & Arithmetic
3.1

$3\text{F7A}_{16}$: convert each hex digit to 4 bits.

$3=0011,\; F=1111,\; 7=0111,\; A=1010$

Binary: 0011 1111 0111 1010

Decimal: $3\times16^3 + 15\times16^2 + 7\times16 + 10 = 12288 + 3840 + 112 + 10 = \mathbf{16250}$

3.2

73 (positive, 12-bit): $73 = 64+8+1 = 001001001_2$ → pad to 12: 000001001001 (all three formats same)

$-95$: $|95| = 001011111_2$ → 12-bit = $000001011111$

  • Sign-magnitude: 100001011111 (MSB=1)
  • 1's complement: 111110100000
  • 2's complement: 111110100001

$-1630$: $|1630| = 11001011110_2$ → 12-bit = $011001011110$

  • Sign-magnitude: 111001011110
  • 1's complement: 100110100001
  • 2's complement: 100110100010
3.3

Half-adder: adds two bits A, B → Sum S, Carry C.

ABSC
0000
0110
1010
1101

Equations: $S = A \oplus B$, $C = A \cdot B$

Circuit: one XOR gate for S, one AND gate for C.

3.4

8-bit 2's complement range: −128 to +127. Overflow occurs when carry into MSB $\neq$ carry out of MSB ($c_{n-1} \oplus c_n = 1$).

(a) 00110110 + 01000101 = 54 + 69 = 123. Sum = 01111011; $c_{\text{in MSB}}=0$, $c_{\text{out}}=0$ → no overflow. Result = 01111011 = 123 ✓

(b) 01110101 + 11011110 = 117 + (−34) = 83. Sum = 1 01010011; $c_{\text{in MSB}}=1$, $c_{\text{out}}=1$ → no overflow. Discard carry → 01010011 = 83 ✓

(c) 11011111 + 10111000 = −33 + (−72) = −105. Sum = 1 10010111; $c_{\text{in MSB}}=1$, $c_{\text{out}}=1$ → no overflow. Discard carry → 10010111 = −105 ✓

When to discard carry?

In n-bit 2's complement addition you always discard the carry-out of the MSB — the result is the low n bits. Discarding carry and detecting overflow are two separate concepts:

  • Discard carry — mechanical: the sum is n+1 bits, you keep the lower n. Always.
  • Overflow — correctness: the n-bit result is mathematically invalid when $c_{\text{in MSB}} \neq c_{\text{out}}$ (equivalently, two same-sign operands produce a different-sign result).

Examples:

  • (b) above: 9-bit sum 1 01010011 → drop the leading 101010011 = 83. Carries match → no overflow → result is correct.
  • (a) above: only 8 bits produced (no carry-out at all), so "discarding" is trivial.
  • Counter-example — 108 + 53 = 161 → sum 10100001, no carry-out, but $c_{\text{in MSB}}=1 \neq c_{\text{out}}=0$ → overflow. The kept bits 10100001 are still "the answer", but invalid as a signed number.

Short rule: discarding carry is automatic; overflow tells you whether the kept bits mean what you wanted.

What is $c_{\text{in MSB}}$?

$c_{\text{in MSB}}$ is the carry that arrives at the most-significant-bit position from the bit below it — bit-7's carry-in (= bit-6's carry-out). It's the internal ripple carry, not the final external Cout.

For the counter-example 108 + 53:

   c:  1 1 1 1 1 0 0 0      <- c[i] = carry INTO bit i
       ─────────────────
   A:  0 1 1 0 1 1 0 0   (108)
   B:  0 0 1 1 0 1 0 1   (53)
       ─────────────────
   S:  1 0 1 0 0 0 0 1   (161 / −95)   Cout = 0
       ↑
       bit 7 (MSB)  →  c_in MSB = c[7] = 1 (leftmost of c row)

Trace right→left:

  • bit 2: $1+1=0$ carry → $c_3 = 1$
  • bit 3: $1+0+1=0$ carry → $c_4 = 1$
  • bit 4: $0+1+1=0$ carry → $c_5 = 1$
  • bit 5: $1+1+1=1$ carry → $c_6 = 1$
  • bit 6: $1+1+1=1$ carry → $c_7 = 1$ ← this is $c_{\text{in MSB}}$
  • bit 7 (MSB): $0+0+1=1$, carry-out $c_8 = 0$ ← this is Cout

So $c_{\text{in MSB}} = c_7 = 1$ (a 1 reaches the MSB), but $\text{Cout} = 0$ (no 1 leaves it). They differ → overflow: $V = c_{\text{in MSB}} \oplus \text{Cout} = 1 \oplus 0 = 1$.

Key idea: Cout and $c_{\text{in MSB}}$ are two different carries on either side of the sign bit — overflow is detected by comparing them.

3.5

For $n$-bit 2's complement addition, $c_n$ is carry out of MSB, $c_{n-1}$ is carry into MSB.

$$\boxed{\text{Overflow} = c_n \oplus c_{n-1}}$$

Proof by cases:

  • pos + pos → result must be positive. If result has MSB=1, $c_{n-1}=1$, $c_n=0$ → overflow=1 $\checkmark$
  • neg + neg → result must be negative. If result MSB=0, $c_{n-1}=0$, $c_n=1$ → overflow=1 $\checkmark$
  • pos + neg → no overflow possible; $c_n = c_{n-1}$ always → overflow=0 $\checkmark$
3.6

4-bit ripple-carry adder: chain four full adders.

A[3:0] ──┐           B[3:0] ──┐
          │                    │
  A0,B0 →[FA0]→ S0; C0→[FA1]→ S1; C1→[FA2]→ S2; C2→[FA3]→ S3,C3
  Cin=0    cₒᵤₜ₀       cₒᵤₜ₁         cₒᵤₜ₂         Cout

Each Full Adder (FA): inputs A_i, B_i, C_in; outputs Sum_i, C_out.

Carry ripples from FA0 → FA1 → FA2 → FA3 (critical path = 4 FA delays).

3.7

Use a control signal Sub. When Sub=0: add; when Sub=1: subtract $(A - B = A + \overline{B} + 1)$.

XOR each B bit with Sub: $B'_i = B_i \oplus \text{Sub}$. Feed Sub as $C_{in}$ to the adder.

Sub a₀ b₀ FA₀ S₀ a₁ b₁ FA₁ S₁ a₂ b₂ FA₂ S₂ a₃ b₃ FA₃ S₃ c₁ c₂ c₃ Cout
module add_sub4 (
    input  [3:0] A, B,
    input        Sub,
    output [3:0] S,
    output       Cout, Overflow
);
    wire [3:0] B_in;
    wire c4, c3;
    assign B_in = B ^ {4{Sub}};
    assign {c4, S} = A + B_in + Sub; // sub is for 2的補數+1
    // carry into MSB is c3 (internal), overflow = c4 ^ c3
    assign Cout = c4;
    assign Overflow = c4 ^ (A[3] ^ B_in[3] ^ S[3]); // simplified
endmodule
3.8

Multiply $1101$ (13) $\times$ $1011$ (11):

        1101   (multiplicand)
      × 1011   (multiplier)
      ------
        1101   (1101 × 1)
       1101    (1101 × 1, shift 1)
      0000     (1101 × 0, shift 2)
     1101      (1101 × 1, shift 3)
     --------
    10001111   = 143 ✓
3.9

$-6.5$ in IEEE 754 single precision (32-bit):

Sign = 1 (negative). $|6.5| = 110.1_2 = 1.101 \times 2^2$.

Exponent $= 2 + 127\;\text{(bias)} = 129 = 10000001_2$.

Mantissa (fraction) = 101 followed by 20 zeros = 10100000000000000000000.

Result: 1 10000001 10100000000000000000000

Hex: C0D00000

3.10
module full_adder (
    input  a, b, cin,
    output sum, cout
);
    assign sum  = a ^ b ^ cin;
    assign cout = (a & b) | (a & cin) | (b & cin);
endmodule

module ripple_adder #(parameter N=8) (
    input  [N-1:0] A, B,
    input          Cin,
    output [N-1:0] Sum,
    output         Cout
);
    wire [N:0] c;
    assign c[0] = Cin;
    genvar i;
    generate
        for (i = 0; i < N; i = i+1) begin : fa_loop
            full_adder fa_inst (
                .a(A[i]), .b(B[i]), .cin(c[i]),
                .sum(Sum[i]), .cout(c[i+1])
            );
        end
    endgenerate
    assign Cout = c[N];
endmodule
3.11

The scan-from-right method: copy rightmost bits up to and including the first 1, then invert all remaining bits.

Why it works: Let $N = \ldots 1\underbrace{0\ldots0}_{k}$ (last 1 at position $k$, zeros below). 2's comp $= \overline{N} + 1$. Adding 1 to $\overline{N}$ propagates carries through all the 1s at positions $0 \ldots k-1$ (which were 0s in $N$, inverted to 1s in $\overline{N}$), zeroing them and carrying into position $k$. Position $k$ was 1 in $N$, inverted to 0 in $\overline{N}$, $+1$ carry makes it 1. Higher bits: $\overline{N}$ bits (inverted from $N$). Net result: bits $0 \ldots k-1$ are 0 (same as $N$), bit $k$ is 1 (same as $N$), bits above $k$ are inverted. $\blacksquare$

3.12
FormatMinMax
Unsigned 8-bit0255
Sign-magnitude−127+127
1's complement−127+127
2's complement−128+127

2's complement has one extra negative number (−128) because 10000000 has no positive counterpart; sign-magnitude and 1's complement have two representations of zero.

3.24

Define: $g_i = A_i B_i$ (generate), $p_i = A_i \oplus B_i$ (propagate).

$$c_1 = g_0 + p_0 c_0$$ $$c_2 = g_1 + p_1 g_0 + p_1 p_0 c_0$$ $$c_3 = g_2 + p_2 g_1 + p_2 p_1 g_0 + p_2 p_1 p_0 c_0$$ $$c_4 = g_3 + p_3 g_2 + p_3 p_2 g_1 + p_3 p_2 p_1 g_0 + p_3 p_2 p_1 p_0 c_0$$

All carries computed in parallel in 2 logic levels (AND-OR), vs. 8 levels for ripple-carry.

3.25

2's complement: invert all bits, add 1.

01010101: invert → 10101010, +1 → 10101011 (= −85)

11110000: invert → 00001111, +1 → 00010000 (= +16; confirms −16 → +16)

10000000: invert → 01111111, +1 → 10000000 (special case: −128, no positive counterpart in 8-bit)

3.26

0.625: 0.625×2=1.25→1; 0.25×2=0.5→0; 0.5×2=1.0→1; exact.

$0.625 = 0.101_2$ (exact in 3 bits)

0.3: 0.3×2=0.6→0; 0.6×2=1.2→1; 0.2×2=0.4→0; 0.4×2=0.8→0; 0.8×2=1.6→1; 0.6→1; 0.2→0; 0.4→0 (repeats)

$0.3 \approx 0.01001100_2$ (8 bits, repeating)

3.27

Prove $(A \oplus B) \oplus C = A \oplus (B \oplus C)$:

Note $A \oplus B = A\overline{B} + \overline{A}B$. Expand $(A \oplus B) \oplus C$:

$$= (A\overline{B} + \overline{A}B)\overline{C} + \overline{(A\overline{B} + \overline{A}B)} \cdot C$$ $$= A\overline{B}\,\overline{C} + \overline{A}B\overline{C} + (\overline{A}\,\overline{B} + AB)C$$ $$= A\overline{B}\,\overline{C} + \overline{A}B\overline{C} + \overline{A}\,\overline{B}C + ABC$$

Expanding $A \oplus (B \oplus C)$ yields the same 4 minterms $(1,2,4,7)$. $\blacksquare$

3.28

BCD encodes each decimal digit in 4 bits.

947: 9 = 1001, 4 = 0100, 7 = 0111

BCD(947) = 1001 0100 0111

3.29

BCD addition 67 + 45:

  0110 0111  (67 BCD)
+ 0100 0101  (45 BCD)
-----------
  1010 1100  (binary sum)

Lower nibble 1100 = 12 > 9 → add 0110 correction, generate carry:

  1100 + 0110 = 0010 carry 1
Upper nibble 1010 + 1 (carry) = 1011 > 9 → add 0110:
  1011 + 0110 = 0001 carry 1

Result: 0001 0001 0010 BCD = 112 ✓ (67+45=112)

3.30
module adder8 (
    input  [7:0] A, B,
    input        Cin,
    output [8:0] Result
);
    assign Result = {1'b0, A} + {1'b0, B} + Cin;
endmodule

The 9-bit result Result[8] captures the carry out. Using {1'b0, A} zero-extends to 9 bits before addition, giving a correct 9-bit sum.

3.31

01110101 (117) − 11010110. Subtraction = add 2's complement of subtrahend.

2's complement of 11010110: invert→00101001, +1→00101010 (= −42 represented, but +42 in unsigned).

  01110101  (117)
+ 00101010  (+42... wait, -(-42)=+42)
----------

Actually: 01110101 − 11010110 = 01110101 + 2'scomp(11010110).

11010110 inverted = 00101001, +1 = 00101010.

01110101 + 00101010 = 10011111. Carry out = 0.

Result $10011111$ in 2's complement $= -97$. Check: $117 - (-42) = 159$, but in 8-bit signed, $11010110 = -42$, so $117-(-42)=159$ overflows. Alternately if $11010110$ unsigned $= 214$: $117-214 = -97$. Result $= 10011111_2 = -97$.

3.32

$(752)_8$ to binary: $7=111,\; 5=101,\; 2=010$ → $111101010_2$

To hex: group binary in 4s from right: $0001\;1110\;1010$ → $1\text{EA}_{16}$

$(\text{B3D})_{16}$ to binary: $B=1011,\; 3=0011,\; D=1101$ → $101100111101_2$

To octal: group binary in 3s from right: $101\;100\;111\;101$ → $5475_8$

3.33

For an $n$-bit CLA adder:

  • Generate/Propagate: $n$ XOR gates ($p$) + $n$ AND gates ($g$) = $2n$ gates.
  • Carry logic ($c_1 \ldots c_n$): each $c_i$ is AND-OR: $c_i$ has $i+1$ AND gates + 1 OR gate. Total $\approx n(n+1)/2$ AND + $n$ OR.
  • Sum bits: $n$ XOR gates.

Total gate count $\approx O(n^2)$ gates but $O(1)$ depth (constant 4 levels for standard 4-bit CLA block). For $n$-bit using hierarchical CLA: $O(n \log n)$ gates with $O(\log n)$ depth.

3.34

Ripple-carry adder ($n$-bit): Critical path $= n \times t_{FA} \approx n \times 2\;\text{gate levels} = O(n)$ delay.

For 4-bit at 1 ns per gate: $\sim 8$ ns (through 4 FAs, each 2 levels).

Carry-lookahead adder (CLA): Carries computed in 2 logic levels; sum then 1 more XOR level = 3 levels total, $O(\log n)$ for hierarchical CLA.

For 4-bit CLA: $\sim 3$ gate delays regardless of $n$ (within one block).

Tradeoff: CLA uses more gates (fan-in grows) but is significantly faster for wide adders.

3.35

Hierarchical CLA using two 2-bit CLA blocks (each handles bits 0-1 and bits 2-3):

Block 0 (bits 0,1): computes $c_1, c_2$, and group generate $G_0 = g_1 + p_1 g_0$, group propagate $P_0 = p_1 p_0$.

Block 1 (bits 2,3): uses $c_2$ from Block 0; computes $c_3, c_4, G_1, P_1$.

Top-level carry:

$$c_2 = G_0 + P_0 \cdot c_0 \qquad c_4 = G_1 + P_1 \cdot c_2$$

This achieves the same $O(1)$ carry depth within 4 bits, and extends to 16-bit with another hierarchical level.

3.36
module array_mult4 (
    input  [3:0] A, B,
    output [7:0] P
);
    wire [3:0] pp [3:0];
    wire [7:0] sum;
    genvar i;
    generate
        for (i = 0; i < 4; i = i+1) begin : partial
            assign pp[i] = A & {4{B[i]}};
        end
    endgenerate
    // Sum partial products with shifts
    assign P = pp[0]
             + (pp[1] << 1)
             + (pp[2] << 2)
             + (pp[3] << 3);
endmodule

Each row pp[i] is the AND of A with a replicated B[i]. Shifted addition produces the 8-bit product.

3.13

Add $10^n$ and subtract: $A - B = A + (10^n - B) - 10^n$. $10^n - B$ is the 10's complement of $B$. After the addition $A + (10^n - B)$ we obtain a value whose leading position carries $1$ (representing $10^n$) when $A \ge B$; discarding that carry-out subtracts the $10^n$ for free. When $A < B$, no carry occurs and the result is $10^n - (B-A)$, which is the 10's complement of the negative answer.

3.14

$045 - 027$: 10's-comp of $027$ is $1000 - 027 = 973$. $045 + 973 = 1018$; discard the leading 1 → $018 = +18$. $027 - 045$: 10's-comp of $045$ is $955$. $027 + 955 = 982$; no carry-out, so the result is $982$, which is the 10's complement of $-18$ (since $1000 - 982 = 18$).

3.15

$+5 = 0101$, $+2 = 0010$. 2's-comp of $0010$ is $1110$. $0101 + 1110 = 1\,0011$. Discard the carry-out from bit 4 (= $2^4 = 16$) → $0011 = +3$. The discarded bit corresponds to the $2^n$ term, exactly as predicted.

3.16

$+2 = 0010$, $+5 = 0101$. 2's-comp of $0101$ is $1011$. $0010 + 1011 = 1101$ with no carry-out. $1101$ in 4-bit 2's complement is $-(0010+1) = -3$, ✓.

3.17

$+5 = 0101$, $-2 = 1110$. 2's-comp of $-2$ is $0010$. $0101 + 0010 = 0111 = +7$. ✓ (No carry to discard in this case because the addend is positive.)

3.18

Repeated division by 16:

stepquotrem (hex)
14959/1693415 = F
934/16586
58/16310 = A
3/1603
Reading remainders from bottom up: $14959_{10} = \mathbf{3A6F_{16}}$.

3.19

Multiply 0.8254 by 2 repeatedly, recording the integer part: $1.6508, 1.3016, 0.6032, 1.2064, 0.4128, 0.8256, 1.6512, 1.3024$ → bits 1,1,0,1,0,1,1,1. So $0.8254_{10} \approx \mathbf{0.11010111_2}$ (with truncation error).

3.20

Integer part: $214_{10} = 11010110_2$ (by repeated /2). Fractional part $0.45$: ×2 yields $0.9, 1.8, 1.6, 1.2, 0.4, 0.8, 1.6, \dots$ → bits $0,1,1,1,0,0,1,\dots$. Result: $214.45_{10} \approx \mathbf{11010110.0111001\ldots_2}$.

3.21

With 2's-complement subtraction $S = X - Y$ and signed flags:

  • $X = Y$: $Z = 1$
  • $X < Y$: $N \oplus V = 1$ (i.e., result negative without overflow OR overflow without negative)
  • $X \le Y$: $Z + (N\oplus V) = 1$
  • $X > Y$: $\overline{Z}\,\overline{(N\oplus V)} = 1$
  • $X \ge Y$: $\overline{N\oplus V} = 1$

3.22

Structural version instantiates four full-adder modules with $Y$ inverted and $c_0=1$ to form $X-Y$, then derives $Z = !|S$, $N = S[3]$, $V = c_3 \oplus c_2$.

module comp4(input [3:0] X, Y, output Z, N, V, AeqB, AltB, AleB, AgtB, AgeB);
  wire [3:0] S; wire [3:0] c;
  full_add fa0(X[0], ~Y[0], 1'b1, S[0], c[0]);
  full_add fa1(X[1], ~Y[1], c[0], S[1], c[1]);
  full_add fa2(X[2], ~Y[2], c[1], S[2], c[2]);
  full_add fa3(X[3], ~Y[3], c[2], S[3], c[3]);
  assign Z = ~|S, N = S[3], V = c[3]^c[2];
  assign AeqB = Z, AltB = N^V, AleB = Z|(N^V), AgtB = ~(Z|(N^V)), AgeB = ~(N^V);
endmodule
Generic version uses parameter n=4 and a generate for loop over full_add instances.

3.23

Ripple-carry array (Figure 3.35): each row is an $n$-bit ripple adder of delay $\approx n\cdot t_{FA}$, and there are $n-1$ rows, so total delay $\approx (n-1)n\, t_{FA} + t_{AND}$. For $n=4$: $\approx 12 t_{FA} + t_{AND}$. Carry-save array (Figure 3.48): the partial-product reduction uses $n-1$ rows of carry-save adders (each $\approx t_{FA}$) plus one final ripple adder of $n$ FAs. Total $\approx (n-1) t_{FA} + n\, t_{FA} + t_{AND} = (2n-1) t_{FA} + t_{AND}$. For $n=4$: $\approx 7 t_{FA} + t_{AND}$. Carry-save is roughly $n/2$× faster.

Chapter 4 — Combinational Logic
4.1

$f = \sum m(0,2,3,4,5,7)$. A 3-to-8 decoder asserts exactly one output for each minterm.

Connect decoder outputs $Y_0, Y_2, Y_3, Y_4, Y_5, Y_7$ to an OR gate:

$$f = Y_0 + Y_2 + Y_3 + Y_4 + Y_5 + Y_7$$

The decoder has inputs $x_1 x_2 x_3$ and active-high outputs. No minimization needed; the OR gate directly implements the canonical SOP.

4.2

$f = \sum m(0,2,3,6)$. Shannon expansion on $x_1$:

$$f = \overline{x_1} \cdot f(0,x_2,x_3) + x_1 \cdot f(1,x_2,x_3)$$

$f|_{x_1=0}$: minterms $\{0,2,3\}$ → $f_0(x_2,x_3) = \overline{x_3} + x_2$

$f|_{x_1=1}$: minterm $\{6\}$ → $(x_2 x_3) = 10$ → $f_1 = x_2\overline{x_3}$

2-to-1 mux: select $= x_1$; $D_0 = \overline{x_3} + x_2$, $D_1 = x_2\overline{x_3}$.

4.3

4-to-1 mux with select $S_1 S_0$, inputs $D_0 \ldots D_3$, output $Y$:

$$Y = \overline{S_1}\,\overline{S_0}\,D_0 + \overline{S_1}\,S_0\,D_1 + S_1\,\overline{S_0}\,D_2 + S_1\,S_0\,D_3$$
Circuit:
- 2 NOT gates: S̄₁, S̄₀
- 4 AND gates (3-input each): one per term
- 1 OR gate (4-input)

Total: 2 NOT + 4 AND + 1 OR = 7 gates.

4.4

4-to-2 priority encoder: highest-priority active input determines output; V=1 if any input active.

$I_3$$I_2$$I_1$$I_0$$Y_1$$Y_0$$V$
0000xx0
0001001
001x011
01xx101
1xxx111

$Y_1 = I_3 + I_2$; $\;Y_0 = I_3 + I_1\overline{I_2}$; $\;V = I_0 + I_1 + I_2 + I_3$

Gate-level: 4-to-2 priority encoder (I₃ highest) Y₁ = I₃ + I₂ I₂ I₃ ≥1 Y₁ Y₀ = I₃ + I₁·Ī₂ I₁ I₂ NOT Ī₂ & I₃ ≥1 Y₀ V = I₀ + I₁ + I₂ + I₃ I₀ I₁ I₂ I₃ ≥1 V
4.5

2-to-4 decoder with enable E (active-high):

$E$$A_1$$A_0$$Y_0$$Y_1$$Y_2$$Y_3$
0xx0000
1001000
1010100
1100010
1110001
module dec2to4 (input E, A1, A0, output reg [3:0] Y);
    always @(*) begin
        if (!E)
            Y = 4'b0000;
        else
            case ({A1, A0})
                2'b00:   Y = 4'b0001;
                2'b01:   Y = 4'b0010;
                2'b10:   Y = 4'b0100;
                2'b11:   Y = 4'b1000;
                default: Y = 4'b0000;
            endcase
    end
endmodule
4.6

BCD to 7-segment (common cathode, segments a-g). Digits 0-9; inputs 10-15 are don't-cares.

Digitwxyzabcdefg
000001111110
100010110000
200101101101
300111111001
401000110011
501011011011
601101011111
701111110000
810001111111
910011111011

K-map minimization with don't-cares for inputs 10–15 (BCD = wxyz, MSB = w):

$$\boxed{a = w + y + xz + \overline{x}\,\overline{z}} \qquad \boxed{b = \overline{x} + yz + \overline{y}\,\overline{z}} \qquad \boxed{c = x + \overline{z} + \overline{y}}$$ $$\boxed{d = w + \overline{x}\,\overline{z} + \overline{x}y + y\overline{z} + x\overline{y}z} \qquad \boxed{e = \overline{x}\,\overline{z} + y\overline{z} = \overline{z}(\overline{x}+y)}$$ $$\boxed{f = w + \overline{y}\,\overline{z} + x\overline{z} + x\overline{y}} \qquad \boxed{g = w + \overline{x}y + x\overline{y} + x\overline{z}}$$
4.7

2-bit magnitude comparator. Inputs $A = A_1 A_0$, $B = B_1 B_0$.

$A > B$ when $A_1 > B_1$, or $A_1 = B_1$ and $A_0 > B_0$.

$$\text{AgtB} = A_1\overline{B_1} + (A_1 \odot B_1) \cdot A_0\overline{B_0}$$ $$\text{AeqB} = (A_1 \odot B_1) \cdot (A_0 \odot B_0) \quad [\odot = \text{XNOR}]$$ $$\text{AltB} = \overline{A_1}B_1 + (A_1 \odot B_1) \cdot \overline{A_0}B_0$$

Note: exactly one of AgtB, AeqB, AltB is 1 for any input.

4.8

Two 2-to-4 decoders (each with enable) build a 3-to-8 decoder:

  • Decoder A handles A₂=0: enable = Ā₂; inputs A₁,A₀ → outputs Y₀..Y₃
  • Decoder B handles A₂=1: enable = A₂; inputs A₁,A₀ → outputs Y₄..Y₇

When A₂=0, decoder A is enabled and selects among Y₀..Y₃. When A₂=1, decoder B is enabled and selects among Y₄..Y₇. Exactly one of the 8 outputs is active at any time.

A₀ A₁ A₂ NOT Ā₂ A₂ Decoder A 2-to-4 (with EN) A₀ A₁ EN Y₀ Y₁ Y₂ Y₃ Decoder B 2-to-4 (with EN) A₀ A₁ EN Y₄ Y₅ Y₆ Y₇ 3-to-8 decoder from two 2-to-4 decoders
4.9
module priority_enc8 (
    input  [7:0] in,
    output reg [2:0] out,
    output reg valid
);
    always @(*) begin
        valid = 1'b1;
        if      (in[7]) out = 3'd7;
        else if (in[6]) out = 3'd6;
        else if (in[5]) out = 3'd5;
        else if (in[4]) out = 3'd4;
        else if (in[3]) out = 3'd3;
        else if (in[2]) out = 3'd2;
        else if (in[1]) out = 3'd1;
        else if (in[0]) out = 3'd0;
        else begin out = 3'd0; valid = 1'b0; end
    end
endmodule
4.10

An incomplete case statement without a default in a combinational always block infers latches for any output not assigned in all branches.

The synthesizer holds the previous value for unspecified cases, which requires storage elements (latches). This is usually unintended and leads to unexpected behavior and synthesis warnings.

Fix: always include a default branch, or use always @(*) with full assignments.

4.11

Gray code: consecutive codes differ in exactly 1 bit. For 4-bit: $G_3 G_2 G_1 G_0$ from binary $B_3 B_2 B_1 B_0$:

$$G_3 = B_3 \qquad G_2 = B_3 \oplus B_2 \qquad G_1 = B_2 \oplus B_1 \qquad G_0 = B_1 \oplus B_0$$
module bin2gray (input [3:0] B, output [3:0] G);
    assign G = B ^ (B >> 1);
endmodule
BinGrayBinGray
0000000010001100
0001000110011101
0010001110101111
0011001010111110
4.12

Shannon's expansion:

$$f(x_1,\ldots,x_n) = \overline{x_i} \cdot f(x_1,\ldots,0,\ldots,x_n) + x_i \cdot f(x_1,\ldots,1,\ldots,x_n)$$

Proof: Every input combination has $x_i = 0$ or $x_i = 1$.

Case $x_i = 0$: RHS $= 1 \cdot f(\ldots,0,\ldots) + 0 \cdot f(\ldots,1,\ldots) = f(\ldots,0,\ldots)$ = LHS. $\checkmark$

Case $x_i = 1$: RHS $= 0 \cdot f(\ldots,0,\ldots) + 1 \cdot f(\ldots,1,\ldots) = f(\ldots,1,\ldots)$ = LHS. $\checkmark$

Since both cases hold for all input combinations, the expansion is valid. $\blacksquare$

4.48

Build 8-to-1 mux from 2-to-1 muxes in a tree:

Level 1 (4 muxes): pair up D₀/D₁, D₂/D₃, D₄/D₅, D₆/D₇, selected by S₀.

Level 2 (2 muxes): pair level-1 outputs, selected by S₁.

Level 3 (1 mux): pair level-2 outputs, selected by S₂.

Total: 4+2+1 = 7 two-to-one muxes. S₂ is the MSB of select.

4.49
module mux4to1 (
    input  [1:0] sel,
    input  [3:0] d,
    output reg   y
);
    always @(*)
        y = d[sel];
    // alternatively using conditional operator:
    // assign y = (sel==2'b00) ? d[0] :
    //            (sel==2'b01) ? d[1] :
    //            (sel==2'b10) ? d[2] : d[3];
endmodule
4.50

1-to-4 demultiplexer: routes single input I to one of four outputs based on S₁S₀.

$S_1$$S_0$$Y_0$$Y_1$$Y_2$$Y_3$
00I000
010I00
1000I0
11000I

$Y_i = I \cdot \text{(decoder output for } i\text{)} = I \cdot m_i(S_1, S_0)$

4.51
module comparator4 (
    input  [3:0] A, B,
    output       AgtB, AeqB, AltB
);
    assign AgtB = (A > B);
    assign AeqB = (A == B);
    assign AltB = (A < B);
endmodule

Synthesis tools expand the relational operators into optimized combinational logic.

4.52
module bcd_to_7seg (
    input  [3:0] bcd,
    output reg [6:0] seg  // seg[6]=a, seg[5]=b,..., seg[0]=g
);
    function [6:0] decode;
        input [3:0] d;
        case (d)
            4'd0: decode = 7'b1111110;
            4'd1: decode = 7'b0110000;
            4'd2: decode = 7'b1101101;
            4'd3: decode = 7'b1111001;
            4'd4: decode = 7'b0110011;
            4'd5: decode = 7'b1011011;
            4'd6: decode = 7'b1011111;
            4'd7: decode = 7'b1110000;
            4'd8: decode = 7'b1111111;
            4'd9: decode = 7'b1111011;
            default: decode = 7'b0000000;
        endcase
    endfunction
    always @(*) seg = decode(bcd);
endmodule
4.53
module popcount8 (
    input  [7:0] data,
    output reg [3:0] count
);
    integer i;
    always @(*) begin
        count = 0;
        for (i = 0; i < 8; i = i+1)
            count = count + data[i];
    end
endmodule

The for loop is unrolled by synthesis into a tree of adders. Result is the number of 1-bits (0 to 8, needs 4 bits).

4.54

Apply Shannon's expansion recursively on all variables:

$$f(x_1,x_2,x_3) = \overline{x_1}\,\overline{x_2} \cdot f(0,0,x_3) + \overline{x_1}\,x_2 \cdot f(0,1,x_3) + x_1\,\overline{x_2} \cdot f(1,0,x_3) + x_1\,x_2 \cdot f(1,1,x_3)$$

Each cofactor $f(a,b,x_3)$ is further expanded on $x_3$:

$$f(a,b,x_3) = \overline{x_3} \cdot f(a,b,0) + x_3 \cdot f(a,b,1)$$

$f(a,b,c) \in \{0,1\}$ for each specific minterm. This recursively produces the canonical sum of minterms: $f = \sum_i m_i \cdot f(m_i)$, where the sum is over all input combinations where $f = 1$. $\blacksquare$

4.55

casez: Treats z (high-impedance) and ? as don't-care bits in case item comparisons. Used for priority encoders and partial matches.

casex: Treats both x (unknown) and z as don't-care. More aggressive masking — also masks unknown values in the case expression itself, which can hide simulation mismatches.

Best practice: Prefer casez (or casez with ?) for synthesis; avoid casex as it masks Xs in simulation, potentially hiding bugs.

4.56
module sort3 (
    input  [7:0] a, b, c,
    output reg [7:0] x, y, z  // x≤y≤z
);
    task swap;
        inout [7:0] p, q;
        reg   [7:0] t;
        begin
            if (p > q) begin t = p; p = q; q = t; end
        end
    endtask
    always @(*) begin
        x = a; y = b; z = c;
        swap(x, y);   // ensure x≤y
        swap(y, z);   // bubble largest to z
        swap(x, y);   // final sort x≤y
    end
endmodule
4.57

CLA carry: $c_{i+1} = g_i + p_i c_i$. This is a 2-to-1 mux structure:

$c_{i+1} = \text{mux}(p_i,\; g_i,\; c_i)$: if $p_i = 1$, output $= c_i$ (propagate); if $p_i = 0$, output $= g_i$ (generate or kill).

This is a 2-to-1 mux with select $= p_i$, $D_1 = c_i$, $D_0 = g_i$.

$$c_{i+1} = p_i \cdot c_i + \overline{p_i} \cdot g_i = \text{mux}(p_i,\; g_i,\; c_i)$$

This "carry select" mux structure underlies fast carry-select adders.

4.58

$f = w_1 w_2 + w_2 w_3 + \overline{w_1}\,\overline{w_2}\,w_3$. Expand by Shannon on $w_1$:

$$f|_{w_1=0} = w_2 w_3 + \overline{w_2}\,w_3 = w_3(w_2 + \overline{w_2}) = w_3$$ $$f|_{w_1=1} = w_2 + w_2 w_3 = w_2(1 + w_3) = w_2$$

Use 2-to-1 mux with select $= w_1$: $D_0 = w_3$, $D_1 = w_2$.

$$\boxed{f = \overline{w_1} \cdot w_3 + w_1 \cdot w_2}$$
4.59
module decoder_n #(parameter N=3) (
    input  [N-1:0]   addr,
    input            en,
    output [(1<
4.60

Cascadable 4-bit comparator has additional inputs: GIN (greater-in), EIN (equal-in), LIN (less-in) from the less-significant stage.

GOUT = AgtB_internal OR (AeqB_internal AND GIN)

EOUT = AeqB_internal AND EIN

LOUT = AltB_internal OR (AeqB_internal AND LIN)

Initialize the LSB stage with GIN=0, EIN=1, LIN=0. Chain stages from LSB to MSB; the MSB stage outputs the final result.

4.13

Two 2-to-1 muxes both controlled by $s$: $y_1 = \overline{s}\,x_1 + s\,x_2$, $y_2 = \overline{s}\,x_2 + s\,x_1$. When $s=0$ each output forwards its same-index input; when $s=1$ they swap.

4.14

Maj($w_1, w_2, w_3$) = $w_1 w_2 + w_1 w_3 + w_2 w_3$. With $w_1, w_2$ as the 4-to-1 mux selects:

$w_1 w_2$$f$
000
01$w_3$
10$w_3$
111
So data inputs $I_0=0, I_1=w_3, I_2=w_3, I_3=1$.

4.15

Recursively decompose $w_1\oplus w_2\oplus w_3 = w_1 \oplus (w_2\oplus w_3)$. Use one mux selected by $w_2$ to compute $w_2\oplus w_3$ (data inputs $w_3$ and $\overline{w_3}$). Then a second mux selected by $w_1$ takes that XOR result and its complement as data, producing $f$. Total: 2 muxes plus inverters for the complemented data lines.

4.16

$f = \overline{w_1}\,\overline{w_3} + w_2 w_3$. On $w_1$: $f_{w_1}=w_2 w_3$, $f_{\overline{w_1}} = \overline{w_3}+w_2 w_3 = \overline{w_3}+w_2$. → 6 inputs. On $w_2$: $f_{w_2} = \overline{w_1}\,\overline{w_3}+w_3$, $f_{\overline{w_2}} = \overline{w_1}\,\overline{w_3}$. → 5 inputs. On $w_3$: $f_{w_3} = w_2$, $f_{\overline{w_3}} = \overline{w_1}$. So $f = \overline{w_3}\,\overline{w_1} + w_3 w_2$ — only 4 gate-inputs. Expansion on $w_3$ wins.

4.17

Shannon on $w_1$: $f_{\overline{w_1}} = \overline{w_3}$, $f_{w_1} = w_2 + w_3$. (a) 2-to-1 mux selected by $w_1$, data inputs $\overline{w_3}$ and $(w_2+w_3)$ — needs an inverter and an OR. (b) Shannon on $\{w_1, w_3\}$: cofactors at $(w_1, w_3) \in \{00,01,10,11\}$ are $\{1, 0, 1, w_2\to 1\}\to\{1,0,1,1\}$. So 4-to-1 mux selected by $\{w_1, w_3\}$ has data inputs $1, 0, w_2, 1$.

4.18

Maj $= w_1 w_2 + w_1 w_3 + w_2 w_3$. Shannon on $w_1$: $f_{\overline{w_1}} = w_2 w_3$, $f_{w_1} = w_2 + w_3$. Shannon each cofactor on $w_2$: $f_{\overline{w_1}\overline{w_2}}=0$, $f_{\overline{w_1}w_2} = w_3$; $f_{w_1\overline{w_2}} = w_3$, $f_{w_1 w_2} = 1$. Build the tree as two muxes selected by $w_2$ (data $0,w_3$ and $w_3,1$) feeding one mux selected by $w_1$. Total: 3 2-to-1 muxes.

4.19

A 2-to-4 decoder with En=1 outputs the four minterms of its select inputs $s_0, s_1$. AND each minterm $m_i$ with the corresponding data $w_i$ and OR all four results: $f = m_0 w_0 + m_1 w_1 + m_2 w_2 + m_3 w_3$ — exactly the function of a 4-to-1 mux.

4.20
module mux2to1(input w0, w1, s, output f);
  assign f = s ? w1 : w0;
endmodule
4.21
module mux2to1(input w0, w1, s, output reg f);
  always @(*) begin
    if (s) f = w1;
    else   f = w0;
  end
endmodule
4.22
module mux16to1(input [15:0] W, input [3:0] S, output f);
  wire [3:0] m;
  mux4to1 g0(W[3:0],   S[1:0], m[0]);
  mux4to1 g1(W[7:4],   S[1:0], m[1]);
  mux4to1 g2(W[11:8],  S[1:0], m[2]);
  mux4to1 g3(W[15:12], S[1:0], m[3]);
  mux4to1 g4(m, S[3:2], f);
endmodule
4.23
module mux4to1(input [3:0] W, input [1:0] S, output reg f);
  always @(*) case (S)
    2'b00: f = W[0];
    2'b01: f = W[1];
    2'b10: f = W[2];
    2'b11: f = W[3];
  endcase
endmodule
4.24
module dec2to4(input [1:0] W, input En, output reg [3:0] Y);
  always @(*) case ({En, W})
    3'b100: Y = 4'b0001;
    3'b101: Y = 4'b0010;
    3'b110: Y = 4'b0100;
    3'b111: Y = 4'b1000;
    default: Y = 4'b0000;
  endcase
endmodule
4.25
module dec2to4(input [1:0] W, input En, output reg [3:0] Y);
  always @(*) begin
    if (En == 0) Y = 4'b0000;
    else case (W)
      2'b00: Y = 4'b0001;
      2'b01: Y = 4'b0010;
      2'b10: Y = 4'b0100;
      2'b11: Y = 4'b1000;
    endcase
  end
endmodule
4.26
module dec4to16(input [3:0] W, input En, output [15:0] Y);
  wire [3:0] M;
  dec2to4 d0(W[3:2], En, M);
  dec2to4 d1(W[1:0], M[0], Y[3:0]);
  dec2to4 d2(W[1:0], M[1], Y[7:4]);
  dec2to4 d3(W[1:0], M[2], Y[11:8]);
  dec2to4 d4(W[1:0], M[3], Y[15:12]);
endmodule
4.27
module seg7(input [3:0] hex, output reg [6:0] leds);
  always @(*) case (hex)  // active-low; bits a..g
    4'h0: leds = 7'b0000001;
    4'h1: leds = 7'b1001111;
    4'h2: leds = 7'b0010010;
    4'h3: leds = 7'b0000110;
    4'h4: leds = 7'b1001100;
    4'h5: leds = 7'b0100100;
    4'h6: leds = 7'b0100000;
    4'h7: leds = 7'b0001111;
    4'h8: leds = 7'b0000000;
    4'h9: leds = 7'b0000100;
    4'hA: leds = 7'b0001000;
    4'hB: leds = 7'b1100000;
    4'hC: leds = 7'b0110001;
    4'hD: leds = 7'b1000010;
    4'hE: leds = 7'b0110000;
    4'hF: leds = 7'b0111000;
  endcase
endmodule
4.28
module alu74381(input [2:0] S, input [3:0] A, B, output reg [3:0] F);
  always @(*) case (S)
    3'b000: F = 4'b0000;       // clear
    3'b001: F = B - A;
    3'b010: F = A - B;
    3'b011: F = A + B;
    3'b100: F = A ^ B;
    3'b101: F = A | B;
    3'b110: F = A & B;
    3'b111: F = 4'b1111;       // preset
  endcase
endmodule
4.29
module prio4(input [3:0] W, output reg [1:0] Y, output reg z);
  always @(*) begin
    z = |W;
    casex (W)
      4'b1xxx: Y = 2'd3;
      4'b01xx: Y = 2'd2;
      4'b001x: Y = 2'd1;
      4'b0001: Y = 2'd0;
      default: Y = 2'd0;
    endcase
  end
endmodule
4.30
module dec2to4(input [1:0] W, input En, output reg [3:0] Y);
  integer k;
  always @(*) begin
    Y = 4'b0;
    for (k = 0; k < 4; k = k+1)
      if (En && (W == k)) Y[k] = 1'b1;
  end
endmodule
4.31
module prio4(input [3:0] W, output reg [1:0] Y, output reg z);
  integer k;
  always @(*) begin
    Y = 2'b0; z = 1'b0;
    for (k = 0; k < 4; k = k+1)
      if (W[k]) begin Y = k[1:0]; z = 1'b1; end
  end
endmodule
Because later loop iterations overwrite earlier ones, the highest-index asserted bit wins.
4.32
module cmp4(input [3:0] A, B, output reg AeqB, AgtB, AltB);
  always @(*) begin
    AeqB = 0; AgtB = 0; AltB = 0;
    if      (A == B) AeqB = 1;
    else if (A >  B) AgtB = 1;
    else             AltB = 1;
  end
endmodule
4.33
module rca #(parameter n=4)(input [n-1:0] A, B, input cin,
                              output [n-1:0] S, output cout);
  wire [n:0] c; assign c[0] = cin; assign cout = c[n];
  genvar i;
  generate for (i=0; i
4.34
module mux16to1(input [15:0] W, input [3:0] S, output reg f);
  reg [3:0] M;
  task mux4; input [3:0] X; input [1:0] s; output y;
    case (s) 0:y=X[0]; 1:y=X[1]; 2:y=X[2]; 3:y=X[3]; endcase
  endtask
  always @(*) begin
    mux4(W[3:0],   S[1:0], M[0]);
    mux4(W[7:4],   S[1:0], M[1]);
    mux4(W[11:8],  S[1:0], M[2]);
    mux4(W[15:12], S[1:0], M[3]);
    mux4(M, S[3:2], f);
  end
endmodule
4.35
module mux16to1(input [15:0] W, input [3:0] S, output f);
  function mux4; input [3:0] X; input [1:0] s;
    case (s) 0:mux4=X[0]; 1:mux4=X[1]; 2:mux4=X[2]; 3:mux4=X[3]; endcase
  endfunction
  wire [3:0] M;
  assign M[0] = mux4(W[3:0],   S[1:0]);
  assign M[1] = mux4(W[7:4],   S[1:0]);
  assign M[2] = mux4(W[11:8],  S[1:0]);
  assign M[3] = mux4(W[15:12], S[1:0]);
  assign f    = mux4(M,        S[3:2]);
endmodule
Difference: a function returns one value (no output ports) and may be used in a continuous assign; a task can have multiple outputs but must be invoked inside an always block.
4.36

Use a 3-to-8 decoder to produce minterms $m_0\dots m_7$, then OR the outputs corresponding to $m_0, m_1, m_3, m_4, m_6, m_7$: $f = m_0+m_1+m_3+m_4+m_6+m_7$. One 6-input OR gate suffices.

4.37

One-hot inputs $w_0\dots w_7$. Truth table maps $w_i=1$ to $y_2 y_1 y_0 = i$. $y_0 = w_1+w_3+w_5+w_7$, $y_1 = w_2+w_3+w_6+w_7$, $y_2 = w_4+w_5+w_6+w_7$ (three 4-input OR gates).

4.38

Shannon on $(w_1, w_4)$ as the mux selects. Cofactors are computed from $f$: $f|_{00}=0$, $f|_{01}=w_5(\overline{w_2}+w_3)$, $f|_{10}=\overline{w_2}+w_3$, $f|_{11}=1$. So a 4-to-1 mux selected by $\{w_1, w_4\}$ with data inputs $0,\,w_5(\overline{w_2}+w_3),\,\overline{w_2}+w_3,\,1$ realizes $f$. Extra logic: one OR ($\overline{w_2}+w_3$) feeding both an AND with $w_5$ and the third data input — assuming $\overline{w_2}$ comes from an inverter.

4.39
$b_2 b_1 b_0$$g_2 g_1 g_0$
000000
001001
010011
011010
100110
101111
110101
111100
By inspection: $g_2 = b_2$, $g_1 = b_1 \oplus b_2$, $g_0 = b_0 \oplus b_1$. ✓
4.40

Shannon: $f = \overline{w_1} f_{\overline{w_1}} + w_1 f_{w_1}$. (a) If $f_{\overline{w_1}} = 0$: $f = w_1\, f_{w_1}$ — the mux degenerates to a single AND gate. (b) If $f_{\overline{w_1}} = 1$: $f = \overline{w_1} + w_1 f_{w_1} = \overline{w_1} + f_{w_1}$ — the mux degenerates to a single OR gate.

4.41

A 4-to-1 mux has 6 inputs ($w_0..w_3, s_0, s_1$). With 4-LUTs, two LUTs suffice: LUT1 takes $(w_0, w_1, s_0, s_1)$ and produces $a = \overline{s_1}\overline{s_0}w_0 + \overline{s_1}s_0 w_1$; LUT2 takes $(a, w_2, w_3, s_0, s_1)$ — too many. Better: LUT1 takes $(w_0, w_1, s_0)$ → $\overline{s_0}w_0+s_0 w_1$; LUT2 takes $(w_2, w_3, s_0)$ → $\overline{s_0}w_2+s_0 w_3$; LUT3 takes those two outputs and $s_1$ → final mux. That is 3 LUTs of 3 inputs (or 4-LUTs with one input unused). The optimized 2-LUT mapping: LUT1$(w_0,w_1,s_0,s_1) = \overline{s_1}(\overline{s_0}w_0+s_0 w_1)$ and LUT2$(\text{LUT1}, w_2, w_3, s_0)$ ORs in the upper half — 2 4-LUTs.

4.42

Five 2-to-1 muxes selected by Shift; data lines (Shift=0, Shift=1): $y_3:(w_3, 0)$, $y_2:(w_2, w_3)$, $y_1:(w_1, w_2)$, $y_0:(w_0, w_1)$, $k:(0, w_0)$. Shift=0 passes $W$ unchanged with $k=0$; Shift=1 right-shifts (LSB into $k$, MSB filled with 0).

4.43

Each output $y_i$ takes the rotated bit $w_{(i+S)\bmod 4}$. Use four 4-to-1 muxes, all sharing select $S$: $y_0$ data $\{w_0,w_1,w_2,w_3\}$, $y_1$ data $\{w_1,w_2,w_3,w_0\}$, $y_2$ data $\{w_2,w_3,w_0,w_1\}$, $y_3$ data $\{w_3,w_0,w_1,w_2\}$.

4.44
module mux4to1(input [3:0] W, input [1:0] S, output f);
  wire [3:0] D;
  dec2to4 g(.W(S), .En(1'b1), .Y(D));
  assign f = | (D & W);
endmodule
4.45
// Style 1: explicit if-else
module shr1(input [3:0] W, input Shift, output reg [3:0] Y, output reg k);
  always @(*) if (Shift) {Y, k} = {1'b0, W};
              else       {Y, k} = {W, 1'b0};
endmodule

// Style 2: shift operator
module shr2(input [3:0] W, input Shift, output [3:0] Y, output k);
  assign {Y, k} = Shift ? {1'b0, W} : {W, 1'b0};
endmodule
4.46
module barrel4(input [3:0] W, input [1:0] S, output [3:0] Y);
  wire [7:0] T;
  assign T = {W, W};
  assign Y = T >> S;
endmodule
Doubling $W$ in concatenation makes the right-shift behave as a rotation on the lower 4 bits.
4.47
module evenparity(input [6:0] b_in, output [7:0] b_out);
  assign b_out[6:0] = b_in;
  assign b_out[7]   = ^b_in;        // XOR-reduction = even parity bit
endmodule
$b_7 = b_6\oplus b_5\oplus\cdots\oplus b_0$ ensures the total count of 1s in $b_7\ldots b_0$ is even.
Chapter 5 — Flip-Flops & Sequential Circuits
5.1

SR latch using two cross-coupled NOR gates:

Q = NOR(R, Q̄); Q̄ = NOR(S, Q)

SRQ(t+1)State
00Q(t)Hold
010Reset
101Set
11Forbidden (both outputs 0)
5.2

Latch: Level-sensitive; transparent when clock/enable is high — output follows input while enabled. Can have timing issues (multiple transitions per clock cycle).

Flip-flop: Edge-triggered; samples input only at clock edge (rising or falling). Output changes only once per cycle.

Why edge-triggered preferred:

  • Predictable: data captured once per cycle at known time.
  • Simplifies timing analysis (setup/hold constraints well-defined).
  • Prevents feedback loops that can cause oscillation in combinational logic.
  • Enables pipelined design with well-defined stage boundaries.
5.3

D input sequence (sampled at rising edge): 0,1,1,0,1,0,0,1

Clk:  ↑     ↑     ↑     ↑     ↑     ↑     ↑     ↑
D:    0     1     1     0     1     0     0     1
Q:    0     1     1     0     1     0     0     1

Q follows D with one clock cycle delay. Q captures D at each rising edge.

5.4

T flip-flop from D flip-flop: D = T⊕Q (XOR T with current output).

  • T=0: D=Q → holds state
  • T=1: D=Q̄ → toggles state

Characteristic equation: Q(t+1) = T⊕Q(t)

TQQ(t+1)
000
011
101
110
5.5

3-bit synchronous up counter using T flip-flops:

T₀ = 1 (always toggles — LSB)

T₁ = Q₀ (toggle when Q₀=1)

T₂ = Q₁·Q₀ (toggle when Q₁Q₀=11)

State sequence: 000→001→010→011→100→101→110→111→000

All T FFs clocked simultaneously — synchronous design.

5.6

Assume each FF has t_FF = 5 ns and each gate = 1 ns.

Ripple counter: Each FF clocked by previous FF output. Critical path through all 4 FFs: 4 × 5 ns = 20 ns. Max freq = 1/20 ns = 50 MHz.

Synchronous counter: All FFs share clock. Critical path = t_FF + t_AND (for T₃ logic) ≈ 5 + 1 = 6 ns. Max freq = 1/6 ns ≈ 167 MHz.

Synchronous counter is ~3× faster for 4-bit; advantage grows with bit width.

5.7
module counter_updown (
    input        clk, rst, up,
    output reg [3:0] count
);
    always @(posedge clk or posedge rst) begin
        if (rst)
            count <= 4'd0;
        else if (up)
            count <= count + 1;
        else
            count <= count - 1;
    end
endmodule
5.8

Blocking (=): Executes sequentially within always block; each assignment takes effect immediately for the next statement.

Non-blocking (<=): All RHS evaluated first, then all LHS updated simultaneously at end of time step. Models register behavior correctly.

Wrong type example — swap with blocking:

// WRONG: blocking swap in sequential logic
always @(posedge clk) begin
    a = b;   // a gets b's new value
    b = a;   // b gets a's NEW value (a already changed)
end
// CORRECT: non-blocking
always @(posedge clk) begin
    a <= b;  // RHS evaluated simultaneously
    b <= a;  // b gets original a
end
5.9
module dff_srst_en (
    input  clk, srst, en, d,
    output reg q
);
    always @(posedge clk) begin
        if (srst)
            q <= 1'b0;
        else if (en)
            q <= d;
        // else q holds
    end
endmodule

Synchronous reset: reset takes effect only on rising clock edge. Enable gates the data input.

5.10

Setup time (t_su): Minimum time the data input D must be stable before the active clock edge for reliable capture.

Hold time (t_h): Minimum time D must remain stable after the active clock edge.

Clock-to-Q delay (t_cQ): Time from active clock edge until the output Q reaches its new stable value.

Violations: setup violation → metastability (indeterminate output); hold violation → data captured incorrectly regardless of clock period.

5.11

Master-slave D FF: Two latches in series (master then slave), clocked by CLK and CLK̄ respectively.

  • When CLK=0: master is transparent (captures D), slave is held.
  • When CLK=1: master is held (locks captured value), slave is transparent (propagates to Q).

Data is captured at the rising clock edge (master closes, slave opens) — effectively edge-triggered.

Why edge-triggered: The double-latch structure means input can only affect output during a brief transition window at the clock edge, providing full edge-triggered behavior.

5.12

Metastability: When a flip-flop's setup or hold time is violated, the output may settle to an indeterminate voltage level between 0 and 1 for an unpredictable time. This can propagate errors through the circuit.

Synchronizer: A chain of two or more flip-flops that allows a metastable signal time to resolve before use. The second FF sees a stable input in most cases. A single FF is insufficient because its output could still be metastable when sampled by subsequent logic.

MTBF (mean time between failures) improves exponentially with each additional synchronizer stage.

5.36
module counter_load (
    input        clk, arst, load, en,
    input  [3:0] d,
    output reg [3:0] q
);
    always @(posedge clk or posedge arst) begin
        if (arst)
            q <= 4'd0;
        else if (load)
            q <= d;
        else if (en)
            q <= q + 1;
    end
endmodule

Async reset clears on arst edge regardless of clock. Load takes parallel data on clock edge. Enable controls counting.

5.37
JKQ(t+1)Action
00Q(t)Hold
010Reset
101Set
11Q̄(t)Toggle

Characteristic equation: Q(t+1) = J·Q̄ + K̄·Q

5.38

4-bit SISO (Serial-In Serial-Out) shift register: 4 D flip-flops in series. Input 1,0,1,1 (MSB first).

Clk  In   Q₀  Q₁  Q₂  Q₃(out)
 0   -     0   0   0   0
 1   1     1   0   0   0
 2   0     0   1   0   0
 3   1     1   0   1   0
 4   1     1   1   0   1  ← first bit out

After 4 clocks, the input sequence 1,0,1,1 appears at Q₃ in order.

5.39

4-bit ring counter, init = 1000. Each clock, the single 1 bit rotates right (or left).

Cycle:  Q₃Q₂Q₁Q₀
  0:    1  0  0  0
  1:    0  1  0  0
  2:    0  0  1  0
  3:    0  0  0  1
  4:    1  0  0  0  (repeats)

Period = 4. Only 4 of 16 states are used.

5.40

4-bit Johnson counter: complement of Q₃ fed back to D₀ (or Q₃ fed to rightmost). Init = 0000.

Cycle:  Q₃Q₂Q₁Q₀
  0:    0  0  0  0
  1:    1  0  0  0
  2:    1  1  0  0
  3:    1  1  1  0
  4:    1  1  1  1
  5:    0  1  1  1
  6:    0  0  1  1
  7:    0  0  0  1
  8:    0  0  0  0  (repeats)

Johnson counter has 2n = 8 valid states (for n=4 FFs); the other 8 states are unused/invalid.

5.41
module shift_reg8 (
    input        clk, s0, s1,  // mode: s1s0
    input        si_l, si_r,   // serial in left/right
    input  [7:0] d,
    output reg [7:0] q
);
    // 00=hold, 01=shift right, 10=shift left, 11=parallel load
    always @(posedge clk) begin
        case ({s1,s0})
            2'b00: q <= q;
            2'b01: q <= {si_r, q[7:1]};  // shift right
            2'b10: q <= {q[6:0], si_l};  // shift left
            2'b11: q <= d;
        endcase
    end
endmodule
5.42
module bcd_counter (
    input  clk, rst,
    output reg [3:0] count
);
    always @(posedge clk) begin
        if (rst || count == 4'd9)
            count <= 4'd0;
        else
            count <= count + 1;
    end
endmodule

Counts 0-9; synchronous reset to 0 when reaching 9 or when rst is asserted.

5.43
module counter_async_rst (
    input        clk, arst,
    output reg [3:0] q
);
    always @(posedge clk or posedge arst) begin
        if (arst)
            q <= 4'd0;
        else
            q <= q + 1;
    end
endmodule

Async reset: the posedge arst in sensitivity list causes immediate reset independent of clock.

5.44
module shift_detect (
    input  clk, rst, si,
    output detected
);
    reg [3:0] sr;
    always @(posedge clk or posedge rst) begin
        if (rst) sr <= 4'b0;
        else     sr <= {sr[2:0], si};
    end
    assign detected = (sr == 4'b1011);
endmodule

Shift register captures last 4 bits. Output asserts when pattern 1011 is in the register.

5.45

Modulo-6 counter sequences: 000→001→010→011→100→101→000.

State 110 and 111 unused. Using D FFs, derive next-state equations via K-maps:

D₂: K-map over present states (with don't cares at 6,7): D₂ = Q₂Q̄₀ + Q₁Q₀

D₁: D₁ = Q₁⊕Q₀ (standard counter rule for bit 1)

D₀: D₀ = Q̄₂Q̄₁Q̄₀ + Q₂Q̄₁Q̄₀... simplified: D₀ = Q̄₀·(Q̄₂+Q̄₁)

Output can be count value or a terminal count = Q₂Q̄₁Q₀ ... Verify by tracing all 6 states.

5.46

Given: t_su=2 ns, t_h=1 ns, t_cQ=3 ns, t_logic=5 ns, t_skew=0.5 ns.

Timing constraint: T_clk ≥ t_cQ + t_logic + t_su + t_skew

T_clk ≥ 3 + 5 + 2 + 0.5 = 10.5 ns

Max clock frequency = 1 / 10.5 ns ≈ 95.2 MHz

Hold constraint: t_cQ + t_logic_min ≥ t_h + t_skew → must also be verified separately.

5.47

LFSR with polynomial x³+x+1 (taps at positions 3 and 1). Feedback = Q₃⊕Q₁. Starting from 001:

State (Q₃Q₂Q₁): feedback = Q₃⊕Q₁
001 → fb=0⊕1=1 → 100...
Wait, standard LFSR: Q₁←Q₂, Q₂←Q₃, Q₃←fb
001: fb=Q₁⊕Q₃=1⊕0=1 → next: Q₃=1,Q₂=0,Q₁=0 → 100
100: fb=0⊕1=1 → 110
110: fb=0⊕1=1 → 111
111: fb=1⊕1=0 → 011... wait recheck taps x³+x+1: feedback into position 0 = Q₃⊕Q₁?
For right-shift LFSR: new_bit = Q[3]⊕Q[1]:
001→100→110→111→011→101→010→001 (7 states)

Period = 7 = 2³−1. Yes, maximal-length LFSR (2ⁿ−1 = 7 for n=3).

5.48

Divide-by-6 with 50% duty cycle: count 0-5, output high for 0-2, low for 3-5 (but this gives 3/6 = 50%).

module div6 (
    input  clk, rst,
    output reg out
);
    reg [2:0] cnt;
    always @(posedge clk or posedge rst) begin
        if (rst) begin cnt <= 0; out <= 0; end
        else if (cnt == 3'd5) begin cnt <= 0; out <= ~out; end
        else if (cnt == 3'd2) begin cnt <= cnt+1; out <= ~out; end
        else cnt <= cnt + 1;
    end
endmodule

Alternatively use two edges: toggle on count 0 and count 3 to achieve 50% duty cycle at f_clk/6.

5.13
module D_latch(input D, Clk, output reg Q);
  always @(D, Clk)
    if (Clk) Q = D;
endmodule
The if-without-else and level-sensitive sensitivity list infer a transparent latch: $Q$ tracks $D$ while Clk=1 and holds when Clk=0.
5.14
module flipflop(input D, Clock, output reg Q);
  always @(posedge Clock)
    Q <= D;
endmodule
5.15

With blocking assignments inside always @(posedge Clock), the statements execute in order, so $Q1$ is updated first to $D$, then $Q2$ is set to the new $Q1$ — i.e. both registers receive $D$ on the same edge. The synthesizer infers a single flip-flop driven by $D$ whose output fans out to both $Q1$ and $Q2$ (or two flip-flops with their D inputs tied together).

5.16

Non-blocking assignments evaluate all RHS at the edge, then update LHS. So $Q2$ samples the old $Q1$ (the value before this edge), then $Q1$ receives $D$. This is exactly the behavior of two cascaded flip-flops: $D \to Q1 \to Q2$ — a 2-stage shift register.

5.17

Blocking assignments execute sequentially, so when the synthesizer sees $f = x_1\,\&\, x_2$ followed by $g = f\,|\, x_3$, the variable $f$ is treated as a wire (its value is the AND result on this cycle). The result: $f$ is registered, but $g$'s flip-flop is fed by $(x_1 x_2)\,|\, x_3$ — i.e. the AND gate output goes through an OR with $x_3$ before the $g$ flip-flop, with no register between them on this path.

5.18

With non-blocking, $g \le f \,|\, x_3$ uses the previous value of $f$ (the flip-flop output). So the OR gate that feeds the $g$ flip-flop is driven by the registered $f$, not the live $x_1 x_2$ AND output. Effectively $g$ is one cycle delayed relative to the blocking version, and the AND output no longer feeds OR directly.

5.19
module dff_async_reset(input D, Clock, Resetn, output reg Q);
  always @(negedge Resetn, posedge Clock)
    if (!Resetn) Q <= 1'b0;
    else         Q <= D;
endmodule
5.20
module dff_sync_reset(input D, Clock, Resetn, output reg Q);
  always @(posedge Clock)
    if (!Resetn) Q <= 1'b0;
    else         Q <= D;
endmodule
5.21
module regn #(parameter n=8)(input [n-1:0] R, input Clock, Resetn,
                              output reg [n-1:0] Q);
  always @(negedge Resetn, posedge Clock)
    if (!Resetn) Q <= {n{1'b0}};
    else         Q <= R;
endmodule
5.22
module muxdff(input D0, D1, Sel, Clock, output reg Q);
  always @(posedge Clock) Q <= Sel ? D1 : D0;
endmodule

module shift4(input [3:0] R, input L, w, Clock, output [3:0] Q);
  muxdff s3(Q[3], R[3], L, Clock, Q[3]);  // bit 3: serial-in is w? -> see below
  // Correct wiring (left-shift serial-in = w):
  // bit3 D0 = Q[2] (shift), D1 = R[3] (load)
  muxdff u3(Q[2], R[3], L, Clock, Q[3]);
  muxdff u2(Q[1], R[2], L, Clock, Q[2]);
  muxdff u1(Q[0], R[1], L, Clock, Q[1]);
  muxdff u0(w,    R[0], L, Clock, Q[0]);
endmodule
Each muxdff picks parallel data $R[i]$ when $L=1$; otherwise it shifts in the lower neighbor (or $w$ for the LSB).
5.23
module shift4(input [3:0] R, input L, w, Clock, output reg [3:0] Q);
  always @(posedge Clock) begin
    if (L) Q <= R;
    else   Q <= {Q[2:0], w};   // shift left, w in at LSB
  end
endmodule
5.24
module shiftn #(parameter n=8)(input [n-1:0] R, input L, w, Clock,
                                 output reg [n-1:0] Q);
  integer k;
  always @(posedge Clock) begin
    if (L) Q <= R;
    else begin
      for (k = n-1; k > 0; k = k-1) Q[k] <= Q[k-1];
      Q[0] <= w;
    end
  end
endmodule
5.25
module upcnt4(input Clock, Resetn, E, output reg [3:0] Q);
  always @(negedge Resetn, posedge Clock)
    if (!Resetn) Q <= 4'b0;
    else if (E)  Q <= Q + 1;
endmodule
5.26
module upcnt4_load(input [3:0] R, input Clock, Resetn, L, E,
                    output reg [3:0] Q);
  always @(negedge Resetn, posedge Clock)
    if (!Resetn) Q <= 4'b0;
    else if (L)  Q <= R;
    else if (E)  Q <= Q + 1;
endmodule
5.27
module dncnt #(parameter n=4)(input [n-1:0] R, input Clock, Resetn, L, E,
                                output reg [n-1:0] Q);
  always @(negedge Resetn, posedge Clock)
    if (!Resetn) Q <= {n{1'b0}};
    else if (L)  Q <= R;
    else if (E)  Q <= Q - 1;
endmodule
5.28
module updncnt #(parameter n=4)(input [n-1:0] R, input Clock, Resetn, L, E,
                                  input up_down, output reg [n-1:0] Q);
  always @(negedge Resetn, posedge Clock)
    if (!Resetn) Q <= {n{1'b0}};
    else if (L)  Q <= R;
    else if (E)  Q <= up_down ? Q + 1 : Q - 1;
endmodule
5.29

Let $t_{skew} = \delta_2 - \delta_1$. The data launch time at $Q_1$ is $\delta_1 + t_{cQ}$; data must reach $Q_2$ before $\delta_2 + T - t_{su}$. (a) Setup: $\delta_1 + t_{cQ} + t_L + t_{su} \le \delta_2 + T$, so $T_{min} = t_{cQ} + t_L + t_{su} - t_{skew}$. (b) Hold: data from the same edge must not reach $Q_2$ before its hold time after the edge: $\delta_1 + t_{cQ} + t_l \ge \delta_2 + t_h$, i.e. $t_{cQ} + t_l \ge t_h + t_{skew}$. Negative skew increases the hold-time pressure.

5.30

With each gate adding delay $\Delta$, internal node $A$ (after one gate) lags $C$ by $\Delta$; $B$ (after two gates) lags by $2\Delta$. Edges that occur within a window of width $\Delta$ on $C$ produce glitches (hazards) on $B$ when an AND/OR re-converges paths of unequal delay. The waveforms show $A$ and $B$ as $C$ with phase shifts of $\Delta$ and $2\Delta$, and any glitch widths equal to the path-delay difference.

5.31

Build the excitation table for the JK pair given inputs $J_0=w$, $K_0=w$, $J_1=w Q_0$, $K_1=w$ (typical Figure 5.71 wiring). Starting at $Q_1 Q_0 = 00$: pulse → $01$; pulse → $10$; pulse → $00$; … sequence $00 \to 01 \to 10 \to 00 \dots$ — a modulo-3 (divide-by-3) counter. Output $Q_1 Q_0$ takes 3 distinct states.

5.32

Datapath: a 6-bit register $S$ accumulates the running total. On each Coin pulse, encode $\{N,D,Q\}$ to a 5-bit value $V \in \{5,10,25\}$: $V = N\cdot 5 + D\cdot 10 + Q\cdot 25$. A 6-bit adder forms $S + V$ and clocks the result back into $S$ on the negative edge of Coin. Reach-30 detection: $Z = 1$ when $S \ge 30$. Since $30 = 011110_2$, $Z = s_5 + s_4 s_3 s_2 s_1$ covers all values $\ge 30$ in the achievable range. Resetn asynchronously zeros the register.

5.33
module vending(input N, D, Q, Coin, Resetn, output Z);
  reg [5:0] S;
  wire [4:0] inc = N ? 5'd5 : D ? 5'd10 : Q ? 5'd25 : 5'd0;
  always @(negedge Resetn, negedge Coin)
    if (!Resetn) S <= 6'd0;
    else         S <= S + {1'b0, inc};
  assign Z = S[5] | (S[4] & S[3] & S[2] & S[1]);
endmodule
5.34

The straight design has cascaded ANDs with delay $(n-1)t_{AND}$ between $Q_0$ and the highest XOR. Refactor by using an XOR for each toggle bit and an AND tree of fan-in 2 driven directly from $Q_0\dots Q_{i-1}$, so the longest path is one AND followed by one XOR. Then $T_{min} = t_{cQ} + t_{AND} + t_{XOR} + t_{su} = 1.0 + 1.4 + 1.2 + 0.6 = 4.2$ ns, so $F_{max} = 1/4.2\,\text{ns} \approx 238$ MHz.

5.35

Worst-case path through the FSM: $T_{min}(i\to j) = t_{cQ} + t_{path} + t_{su} - (\delta_j - \delta_i)$. Hold check: $t_{cQ} + t_{min\,path} \ge t_h + (\delta_j - \delta_i)$. (i) zero skew: typical $T_{min}\approx 1.0+t_{path}+0.6$. (ii) skew on $\delta_2$: paths into FF2 gain $0.7$ ns slack, paths out of FF2 lose $0.7$ ns. Compute worst path; one of the data paths probably becomes the bottleneck, producing a slightly slower $F_{max}$. (iii) $\delta_1=1, \delta_2=0, \delta_3=0.5$: paths $1\to 2$ have $t_{skew}=-1$ ns (penalty), paths $2\to 3$ get +0.5 ns slack. The worst-case path tightens the clock; check hold: $0.8 + t_{l} \ge 0.4 + (\delta_j-\delta_i)$ — for $1\to 2$ with skew $-1$, hold is automatic. Compute each $F_{max}$ from the dominant path.

Chapter 6 — Finite State Machines
6.1

Moore FSM detecting 101 (overlapping). States: S0(initial), S1(got 1), S2(got 10), S3(got 101, output=1).

S0 --1--> S1 --0--> S2 --1--> S3(out=1)
S0 --0--> S0
S1 --1--> S1
S2 --0--> S0
S3 --1--> S1 (overlap: 101, last 1 starts new)
S3 --0--> S2 (overlap: 1010...)

Output z=1 only in S3 (Moore: output on state, not transition).

6.2

State encoding: S0=00, S1=01, S2=10, S3=11. Using D FFs:

StatewNextD₁D₀z
00000000
00101010
01010100
01101010
10000000
10111110
11010101
11101011

D₁ = Q₁Q̄₀w + Q̄₁Q₀w̄ + Q₁Q₀w̄; D₀ = Q̄₁w + Q₀; z = Q₁Q₀

6.3

Moore FSM: output 1 after three consecutive 1s. States represent count of consecutive 1s: A(0), B(1), C(2), D(3+, output=1).

A --0--> A, --1--> B
B --0--> A, --1--> C
C --0--> A, --1--> D
D --0--> A, --1--> D

Output: z=0 for A,B,C; z=1 for D.

4 states needed. D FF next-state equations derived from state table.

6.4

Mealy FSM for three consecutive 1s: output z=1 on the transition that completes the third 1.

States: A(0 ones), B(1 one), C(2 ones). Output on A→B→C→C (z=1 on C→C and all further 1s from C).

A --0/0--> A, --1/0--> B
B --0/0--> A, --1/0--> C
C --0/0--> A, --1/1--> C

State count comparison: Mealy needs 3 states; Moore needs 4 states. Mealy FSMs typically need fewer states because the output depends on both state and input.

6.5

Moore FSM: Output depends only on current state. Output is stable for entire clock period; simpler to analyze.

Mealy FSM: Output depends on current state AND current input. Output can change mid-cycle if input changes; typically needs fewer states; output arrives one cycle earlier than Moore for same sequence.

Moore advantages: Glitch-free outputs (registered), easier timing analysis.

Mealy advantages: Fewer states (more compact), faster response (output same cycle as input).

6.6

One-hot encoding: One flip-flop per state; exactly one FF is 1 at any time. Simple next-state logic (each state is directly a FF output).

5-state comparison:

  • Binary encoding: ⌈log₂5⌉ = 3 flip-flops.
  • One-hot encoding: 5 flip-flops (one per state).

One-hot uses more FFs but reduces combinational logic complexity, which is preferable on FPGAs where FFs are plentiful and LUTs are the scarce resource.

6.7
module seq_detect_101 (
    input  clk, rst, w,
    output z
);
    parameter S0=2'd0, S1=2'd1, S2=2'd2, S3=2'd3;
    reg [1:0] state, next;
    always @(posedge clk or posedge rst)
        state <= rst ? S0 : next;
    always @(*) begin
        case (state)
            S0: next = w ? S1 : S0;
            S1: next = w ? S1 : S2;
            S2: next = w ? S3 : S0;
            S3: next = w ? S1 : S2;
            default: next = S0;
        endcase
    end
    assign z = (state == S3);
endmodule
6.8
module mealy_01detect (
    input  clk, rst, w,
    output z
);
    // Output 1 when last two inputs were 01
    parameter A=1'b0, B=1'b1;
    reg state;
    always @(posedge clk or posedge rst)
        state <= rst ? A : (w ? A : B);
    // state B = last input was 0
    // Mealy output: z=1 when in state B and w=1
    assign z = (state == B) & w;
endmodule

State A: last input was 1 (or initial). State B: last input was 0. Output z=1 when transitioning B→A on w=1 (sequence 0 then 1 = "01").

6.9

Given a state table with states, inputs, next states, and outputs, derive equations by:

  1. Assign binary codes to states.
  2. Build next-state table (D₁, D₀ for 2 FFs).
  3. Minimize each D function via K-map.
  4. Build output equation from output column.

For a specific table (example with 3 states, 1 input): the equations emerge directly from K-map minimization of each column (D₁, D₀, z) treating state bits and input as variables.

6.10

State minimization via partitioning (Myhill-Nerode / implication chart):

  1. Initial partition: group states by output values.
  2. Refine: within each group, if two states have transitions to different groups under same input, split them.
  3. Repeat until no more splits.
  4. States remaining in same partition class are equivalent — merge them.

For states A–F: build implication chart, mark incompatible pairs (different outputs), propagate implications. Remaining unmarked pairs are equivalent. Merge to minimal state machine.

6.11

Vending machine ASM: accepts nickels (N) and dimes (D); item costs 15¢; dispenses change.

States: S0(0¢), S5(5¢), S10(10¢), S15(dispense)
ASM blocks:
S0: if N→S5; if D→S10
S5: if N→S10; if D→S15(no change)
S10: if N→S15(no change); if D→S15+change(5¢)
S15: dispense item; if change needed→output nickel; →S0

Decision boxes for N, D inputs; conditional outputs for item and change; state boxes for each amount. ASM chart uses rectangles (states), diamonds (decisions), ovals (conditional outputs).

6.12
module traffic_light (
    input  clk, rst,
    output reg [1:0] light  // 00=red,01=green,10=yellow
);
    reg [4:0] cnt;
    // Green 20 cycles, Yellow 5, Red 20
    always @(posedge clk or posedge rst) begin
        if (rst) begin cnt<=0; light<=2'b01; end
        else begin
            cnt <= cnt + 1;
            case (light)
                2'b01: if(cnt==19) begin light<=2'b10; cnt<=0; end
                2'b10: if(cnt==4)  begin light<=2'b00; cnt<=0; end
                2'b00: if(cnt==19) begin light<=2'b01; cnt<=0; end
            endcase
        end
    end
endmodule
6.31

Detect 1001 or 1111 (overlapping). Build a state machine tracking the longest suffix of the input that is a prefix of either target:

States: S0, S1(1), S2(10), S3(100), S4(11), S5(111)
S0: 0→S0, 1→S1
S1: 0→S2, 1→S4
S2: 0→S0, 1→S3
S3: 0→S0, 1→S4; on completing 1001 at S3+input 1: output=1, goto S1
S4: 0→S2, 1→S5; completing 1001: S3→w=1→output+goto S1
S5: 0→S2, 1→S1; completing 1111: S5+1→output=1, goto S4

Output 1 when completing 1001 (state S3, input 1) or 1111 (state S5+, input 1). Moore output can be added with an accepting state.

6.32

A finite state machine is a 5-tuple M = (Q, Σ, δ, q₀, F) where:

  • Q — finite set of states
  • Σ — finite input alphabet
  • δ: Q × Σ → Q — transition function (next-state function)
  • q₀ ∈ Q — initial state
  • F ⊆ Q — set of accepting/output states (for Moore: output function λ: Q → Λ; for Mealy: λ: Q × Σ → Λ)
6.33

Given: D₁ = x⊕Q₂, D₂ = Q₁ (using Q₁,Q₂ as state, x as input).

Next state: Q₁⁺=x⊕Q₂, Q₂⁺=Q₁.

Q₁Q₂x=0: Q₁⁺Q₂⁺x=1: Q₁⁺Q₂⁺
000010
011000
100111
111101

State diagram: 4 states, each with two transitions. No output specified → count states/cycles for analysis or add output function.

6.34

Arbiter FSM for r₁, r₂: grants access one at a time.

States: IDLE, GRANT1, GRANT2
IDLE: if r₁&r₂→GRANT1 (r₁ priority); if r₁ only→GRANT1; if r₂ only→GRANT2; else→IDLE
GRANT1: g₁=1; if ~r₁→IDLE (r₁ releases); else hold
GRANT2: g₂=1; if ~r₂→IDLE; else hold

Outputs: g₁=1 in GRANT1, g₂=1 in GRANT2. The arbiter ensures mutual exclusion: only one grant active at a time. Priority given to r₁ when both assert simultaneously.

6.35

Advantages of ASM charts over state diagrams:

  • Clearly show data operations (register transfers) alongside control flow.
  • Conditional outputs (on arcs/diamonds) are explicit without cluttering state bubbles.
  • More readable for hardware designers familiar with flowcharts.
  • Directly model datapath+control interactions; easier to derive RTL from ASM block structure.
  • Timing is implicit: each ASM block executes in one clock cycle.
6.36
  1. State diagram / state table: Capture desired behavior with states, inputs, transitions, outputs.
  2. State minimization: Merge equivalent states to reduce hardware.
  3. State assignment: Assign binary codes to states (binary, Gray, one-hot).
  4. Flip-flop selection: Choose FF type (D, JK, T); derive excitation equations.
  5. Minimization: Minimize next-state and output equations (K-maps or Quine-McCluskey).
  6. Circuit implementation: Realize equations with gates and FFs; verify with simulation.
6.37
// Binary encoding (3 FFs for 8 states)
parameter [2:0] S0=3'd0, S1=3'd1, ..., S7=3'd7;

// Gray encoding (3 FFs, adjacent states differ by 1 bit - reduces glitches)
parameter [2:0] S0=3'b000, S1=3'b001, S2=3'b011, S3=3'b010,
                S4=3'b110, S5=3'b111, S6=3'b101, S7=3'b100;

// One-hot (8 FFs, simplest next-state logic - preferred for FPGAs)
parameter [7:0] S0=8'b00000001, S1=8'b00000010, S2=8'b00000100,
                S3=8'b00001000, S4=8'b00010000, S5=8'b00100000,
                S6=8'b01000000, S7=8'b10000000;

One-hot: 8 FFs but next-state = OR of incoming state FFs (no decoding needed). Best for FPGAs. Binary: 3 FFs but complex decode. Gray: reduces output glitches for counters.

6.38

Modulo-8 up counter via sequential design. States 000–111, next state = present state + 1 (mod 8). Using D FFs:

State table same as binary counter. K-maps for D₂,D₁,D₀:

D₀ = Q̄₀ (toggles every cycle)

D₁ = Q₁⊕Q₀

D₂ = Q₂⊕(Q₁Q₀)

Output = state value (Q₂Q₁Q₀). Implementation: D₀=NOT Q₀; D₁=XOR(Q₁,Q₀); D₂=XOR(Q₂,AND(Q₁,Q₀)).

6.39

Mod-8 counter with JK FFs. JK excitation table: J=0,K=x (hold 0); J=x,K=0 (hold 1); J=1,K=x (set); J=x,K=1 (reset).

J₀=1, K₀=1 (always toggle for LSB).

J₁=Q₀, K₁=Q₀ (toggle when Q₀=1).

J₂=Q₁Q₀, K₂=Q₁Q₀ (toggle when Q₁Q₀=1).

Gate count comparison: JK implementation uses same XOR structure but expressed as J/K. D FF version needs explicit XOR gates; JK version has simpler excitation equations (J₀=K₀=1 is trivially wired). Total gates similar; JK can save gates when J≠K not needed.

6.40

Output 1 when w₁=w₂ for four consecutive cycles. States track count of consecutive equal cycles: 0,1,2,3,4(output).

5 states, 2 inputs. Let eq = (w₁ XNOR w₂).

S0 --eq=1--> S1, --eq=0--> S0
S1 --eq=1--> S2, --eq=0--> S0
S2 --eq=1--> S3, --eq=0--> S0
S3 --eq=1--> S4, --eq=0--> S0
S4 --eq=1--> S4, --eq=0--> S0

Moore output: z=1 in S4. Need 3 FFs (⌈log₂5⌉=3). Reduce by noting the counter simply counts eq=1 consecutive cycles.

6.41

Serial adder FSM: Adds two serial bit streams A, B. State = carry. Inputs: aᵢ, bᵢ. Output: sᵢ = aᵢ⊕bᵢ⊕carry.

Moore version: 2 states (carry=0, carry=1). Output sᵢ must depend on input too, so pure Moore would need 4 states. Mealy is more natural.

Mealy version (2 states):

CarryabNext carrys (output)
00000
001/1001
01110
10001
101/1010
11111
6.42

Converting Mealy FSM to Moore FSM:

  1. For each Mealy state-input pair (s, i) that produces output z, create a new Moore state s_z.
  2. Any transition leading to s under input i now leads to s_z; s_z has output z.
  3. Transitions from s_z for all inputs are the same as from s in the Mealy machine.

Result: Moore FSM typically has more states (one per unique (state, output) combination). If the Mealy FSM has n states and 2 outputs, the Moore FSM can have up to 2n states.

6.43

Detect 110 or 101 (overlapping). States track suffix matching either pattern:

S0: initial
S1: saw 1
S2: saw 11
S3: saw 10
S0 --1--> S1, --0--> S0
S1 --1--> S2, --0--> S3
S2 --1--> S2(output), --0--> S3(output for 110)
S3 --1--> S1(output for 101), --0--> S0

Moore output: z=1 in states reached when pattern completed. Minimal: 4 states. Output state added or Moore output on S2(w=0) and S3(w=1).

For Mealy: output on transitions S2→(0) and S3→(1).

6.13

Four states $A, B, C, D$. State $A$ idles; on $w=1$ go to $B$, then $C$, then $D$ unconditionally, then back to $A$. Outputs (Moore): $B$: $R2_{out}=R3_{in}=1$ (copy R2→R3); $C$: $R1_{out}=R2_{in}=1$ (R1→R2); $D$: $R3_{out}=R1_{in}=Done=1$ (R3→R1). State assignment $A=00, B=01, C=10, D=11$. With $y_2 y_1$ as state bits: $Y_1 = w\overline{y_2}\overline{y_1} + y_2$, $Y_2 = y_1 + y_2\overline{y_1}$ (and so on). The four-cycle sequence performs the swap via R3 as scratch.

6.14

Swapping $C$ and $D$ assigns $C=11, D=10$. Recompute next-state K-maps: $Y_1$ now requires $w\overline{y_2}\overline{y_1}$ for $A\to B$ and additional terms for $B\to D$ and $C\to A$ that no longer combine as nicely. Output expressions also become more complex. The total gate-input cost rises by ~3 inputs versus the straightforward assignment, illustrating that state-assignment choice matters.

6.15

One-hot: $y_1=A, y_2=B, y_3=C, y_4=D$. Next-state: $Y_1 = (y_1\overline{w}) + y_4$, $Y_2 = w y_1$, $Y_3 = y_2$, $Y_4 = y_3$. Outputs come directly: e.g. $R1_{out} = y_3$, Done = $y_4$. Each transition is one product term. Trade-off: more flip-flops (4 vs 2), but simpler combinational logic and faster speed.

6.16

Mealy version uses 3 states $A, B, C$. In $A$, on $w=1$, output $R2_{out}=R3_{in}=1$ and go to $B$. In $B$, output $R1_{out}=R2_{in}=1$ and go to $C$. In $C$, output $R3_{out}=R1_{in}=Done=1$ and go to $A$. The output is generated combinationally with the transition (one clock cycle earlier than Moore), saving one cycle. Total: 3 cycles instead of 4. Care must be taken so outputs do not glitch on combinational input changes.

6.17
module swap_fsm(input Clock, Resetn, w, output R1in,R1out,R2in,R2out,R3in,R3out,Done);
  reg [1:0] y, Y;
  parameter A=2'b00, B=2'b01, C=2'b10, D=2'b11;
  always @(*) case (y)
    A: Y = w ? B : A;
    B: Y = C;
    C: Y = D;
    D: Y = A;
  endcase
  always @(negedge Resetn, posedge Clock)
    if (!Resetn) y <= A; else y <= Y;
  assign R2out = (y==B), R3in = (y==B);
  assign R1out = (y==C), R2in = (y==C);
  assign R3out = (y==D), R1in = (y==D), Done = (y==D);
endmodule
6.18

Partition refinement (output classes first). $P_1$: split states by output → e.g. $\{S_1, S_3, S_5\}$ (output 0) and $\{S_2, S_4, S_6, S_7\}$ (output 1). $P_2$: refine by where each state's transitions go (which $P_1$ block). After several iterations $P_3 = P_4$ and the equivalent classes form 4 states. The reduced FSM has 4 states with the same I/O behavior.

6.19

States track cumulative deposit modulo 25 (with credit): $S_0=0$¢, $S_5, S_{10}, S_{15}, S_{20}, S_{25}$. Inputs: nickel ($n$), dime ($d$). Transitions: $S_0$: n→$S_5$, d→$S_{10}$; $S_5$: n→$S_{10}$, d→$S_{15}$; $S_{10}$: n→$S_{15}$, d→$S_{20}$; $S_{15}$ (dispense)→$S_0$; $S_{20}$ (dispense + 5¢ credit) goes to $S_5$. Apply partitioning to merge $S_{15}$ and $S_{20}$ if their behaviors match — they don't (different next states), so 5 states minimum after dispense logic added.

6.20

Four unspecified entries can be set to 0 or 1 to maximize state merging. With both = 0: partitioning yields a coarser refinement and merges 7 states down to (e.g.) 4. With both = 1: a different merging produces (e.g.) 5 states. The exact counts depend on the table; the lesson is that completing don't-cares strategically minimizes states.

6.21

Four states $00, 01, 10, 11$. Compute $Y_1 Y_2$ for each $(y_1, y_2, w)$: Substitute and tabulate. The state transitions trace: $00 \xrightarrow{w=1} 10 \xrightarrow{w=1} 11 \xrightarrow{w=1} 11$ (with $z=1$). On $w=0$ from any state, return to $00$ or $01$. Sequence detection: three consecutive 1s drive the FSM to state $11$ where $z=1$. Hence the FSM detects the pattern 111.

6.22

Excitation $J_1=w$, $K_1=\overline{w}+y_2$, $J_2=wy_1$, $K_2=\overline{w}$. Compute next-state from JK rules ($Q^+=J\overline{Q}+\overline{K}Q$): $y_1^+ = w\overline{y_1} + (w\overline{y_2}) y_1$, $y_2^+ = wy_1\overline{y_2} + wy_2$. Tabulate four states. The same input sequence $w=111\dots$ produces $00\to 10\to 11\to 11$ with $z=1$ in state $11$ — the same three-1s detector as Example 6.9.

6.23

$Y_1^+ = D_1 = w(y_1+y_2)$. $Y_2^+ = y_2 \oplus T_2$ for the T flip-flop, where $T_2 = \overline{w}y_2 + wy_1\overline{y_2}$. Build the excitation table: starting at 00, with $w=1\to 00, 10, 11, 11$… The output $z = y_1 y_2$ asserts in state 11. Same FSM behavior as 6.9 and 6.10 — three consecutive 1s detector.

6.24

States: $A$ (idle), $B$ (just saw 0), $C$ (saw 00, output $z=1$), $D$ (just saw 1), $E$ (saw 11, output $z=1$). Transitions: $A$: 0→$B$, 1→$D$. $B$: 0→$C$, 1→$D$. $C$: 0→$C$, 1→$D$. $D$: 0→$B$, 1→$E$. $E$: 0→$B$, 1→$E$. Output $z=1$ in $C$ and $E$. State assignment for 5 states needs 3 flip-flops. Derive $Y_3 Y_2 Y_1$ next-state from K-maps.

6.25

FSM_1 (detect 11): states $A_1$ (idle), $B_1$ (saw 1), $C_1$ (saw 11, $z_1=1$). FSM_2 (detect 00): mirror. Output $z = z_1 + z_2$. Each FSM has 3 states, total 6 states, but they run independently and combine more cleanly than the monolithic 5-state version. The cost trade-off depends on shared inputs.

6.26

Mealy: 3 states $A$ (idle), $B$ (just saw 0), $C$ (just saw 1). $A$: 0/0→$B$, 1/0→$C$. $B$: 0/1→$B$, 1/0→$C$. $C$: 0/0→$B$, 1/1→$C$. Output asserts on the input edge that completes the pair. With 2 flip-flops $y_1 y_2$: $Y_1 = w$, $Y_2 = \overline{w}y_2 + wy_1\dots$ (assignment-dependent), $z = wy_1 + \overline{w}y_2$ (output high when current input matches the previous one).

6.27

For each present-state/next-state transition, JK excitation is: $00\to 0$: J=0, K=X; $0\to 1$: J=1, K=X; $1\to 0$: J=X, K=1; $1\to 1$: J=X, K=0. Build K-maps for $J_1, K_1, J_2, K_2, J_3, K_3$ from the assigned table. Resulting expressions typically simpler than D-FF case because of the X cells. The book's solution shows a ~30% input-count reduction over D realization.

6.28
module seq_moore(input Clock, Resetn, w, output reg z);
  reg [2:0] y, Y;
  parameter A=0, B=1, C=2, D=3, E=4;
  always @(*) case (y)
    A: Y = w ? D : B;
    B: Y = w ? D : C;
    C: Y = w ? D : C;
    D: Y = w ? E : B;
    E: Y = w ? E : B;
    default: Y = A;
  endcase
  always @(negedge Resetn, posedge Clock)
    if (!Resetn) y <= A; else y <= Y;
  always @(*) z = (y == C) || (y == E);
endmodule
6.29
module seq_mealy(input Clock, Resetn, w, output reg z);
  reg [1:0] y, Y;
  parameter A=0, B=1, C=2;
  always @(*) begin
    z = 0;
    case (y)
      A: if (w) Y = C; else Y = B;
      B: if (w) Y = C; else begin Y = B; z = 1; end
      C: if (w) begin Y = C; z = 1; end else Y = B;
      default: Y = A;
    endcase
  end
  always @(negedge Resetn, posedge Clock)
    if (!Resetn) y <= A; else y <= Y;
endmodule
6.30

Frame: 1 start bit (0) + 7 data bits + 1 stop bit (1) = 9 bits. State machine with 11 states: idle, start, $b_0\dots b_6$, stop, done. A counter cycles through bit positions; on each clock the output line presents the next bit of the shift register holding the byte. Done asserts after the stop bit. Verilog uses a parallel-load shift register and a state-FSM controller.

Chapter 7 — Datapaths & Controllers
7.1

Tri-state bus: Multiple drivers share a wire; only one enabled at a time via OE (output-enable). Bus floats when all disabled. Simple wiring but requires careful control; floating bus can pick up noise.

Mux-based bus: A multiplexer selects one of several sources; no tri-state buffers needed. Cleaner logic, easier to synthesize for FPGAs (which have no tri-state internal routing), but requires a physical mux and select signals.

FPGAs prefer mux-based; external PCB buses often use tri-state.

7.2

Simple processor datapath with 4 registers R0–R3, ALU, and bus:

Registers R0-R3 ──┐
                  ├──► MUX_A ──► ALU_A
                  └──► MUX_B ──► ALU_B
ALU: ADD/SUB/AND/OR with opcode input
ALU result ──► Result register ──► Write-back MUX ──► Rn
Control signals: RegSel_A[2], RegSel_B[2], ALUop[2],
                 WE (write enable), RegDest[2]

The controller FSM sequences: fetch operands → execute ALU op → write back to destination register.

7.3

Arithmetic mean of four 8-bit numbers: sum A+B+C+D (10-bit result), then divide by 4 (right-shift 2).

ASM chart:
IDLE ──start──► LOAD: Sum:=0, cnt:=4, ptr:=0
ACCUM: Sum:=Sum+Data[ptr]; ptr:=ptr+1; cnt:=cnt-1
  ──(cnt≠0)──► ACCUM
  ──(cnt=0)──► COMPUTE: Mean:=Sum>>2
COMPUTE ──► DONE: output Mean; done:=1 ──► IDLE

Datapath: 10-bit accumulator, 4-element memory or 4 input ports, 2-bit right shifter, done flag.

7.4

Why debouncing is needed: Mechanical switches bounce for 1–20 ms, generating multiple transitions. Without debouncing, a single press registers as multiple pulses.

Hardware approach: SR latch with two SPDT switch positions; once set/reset, further bounces have no effect. Alternatively: RC low-pass filter + Schmitt trigger.

Software approach: Sample the switch; if value is stable for N consecutive samples (e.g., 20 ms at 1 ms intervals), accept it as a valid press. Implemented with a counter in software or HDL.

7.5

Clock skew: Difference in arrival time of the clock signal at different flip-flops. Caused by wire delays, buffer delays.

Setup violation due to skew: If the destination FF clock arrives earlier than the source FF clock, the effective cycle time is reduced. Constraint: T_clk + t_skew_neg ≥ t_cQ + t_logic + t_su.

Hold violation due to skew: If destination FF clock arrives later, data may change before being captured. Constraint: t_cQ + t_logic_min ≥ t_h + t_skew_pos. Hold violations cannot be fixed by slowing the clock — they require adding buffers on the data path.

7.6

Microinstructions for a simple processor (horizontal microcode):

InstructionMicrooperations
Load Rn, MMAR←PC; PC←PC+1; MDR←Mem[MAR]; Rn←MDR
Move Rd, RsRd←Rs
Add Rd, RsT←Rd+Rs; Rd←T
Sub Rd, RsT←Rd−Rs; Rd←T (using 2's complement adder)

Each microinstruction specifies: source register(s), ALU operation, destination register, memory operation, and next microaddress.

7.7

Register Transfer Level (RTL) design describes a digital system as registers storing data and combinational logic transferring data between registers in each clock cycle.

Key concepts: registers hold state; data operations described as register transfers (e.g., A ← B + C); controller FSM determines which transfers occur each cycle; datapath implements the hardware to perform those operations.

RTL abstraction sits between algorithmic level and gate level — high enough for synthesis tools to optimize, detailed enough to specify hardware behavior precisely.

7.8

GCD using Euclidean algorithm: GCD(A,B) = GCD(B, A mod B). In hardware use repeated subtraction: GCD(A,B): while A≠B, if A>B then A←A−B else B←B−A.

ASM chart:
IDLE ──start──► LOAD: A:=a, B:=b
TEST: if A==B → DONE: gcd:=A
      if A>B → SUBA: A:=A-B → TEST
      else → SUBB: B:=B-A → TEST

Datapath: two registers A, B; subtractor; comparator. Cycles for worst case: O(max(a,b)).

7.9
module counter_param #(parameter N=8) (
    input              clk, rst, en, load,
    input  [N-1:0]     d,
    output reg [N-1:0] q
);
    always @(posedge clk or posedge rst) begin
        if (rst)       q <= {N{1'b0}};
        else if (load) q <= d;
        else if (en)   q <= q + 1'b1;
    end
endmodule
7.10

An ASM block consists of three elements:

  1. State box (rectangle): Represents one state of the FSM. Contains the state name and any Moore (unconditional) outputs. Executes in one clock cycle.
  2. Decision box (diamond): Tests a condition (input or status signal). Has two exit paths (Yes/No or 1/0). Does not consume clock cycles — purely combinational.
  3. Conditional output box (oval/rounded rectangle): Contains Mealy-type outputs that are asserted only when the associated decision condition is true. Also combinational (no additional clock cycle).
7.11
module bit_counter (
    input        clk, rst, start,
    input  [7:0] data,
    output reg [3:0] count,
    output reg done
);
    reg [7:0] sr;
    reg [2:0] cnt;
    reg [1:0] state; // 0=IDLE,1=LOAD,2=COUNT,3=DONE
    always @(posedge clk or posedge rst) begin
        if (rst) begin state<=0; done<=0; count<=0; end
        else case (state)
            0: if (start) begin sr<=data; cnt<=0; count<=0; state<=2; end
            2: begin
                   count <= count + sr[0];
                   sr <= sr >> 1;
                   cnt <= cnt + 1;
                   if (cnt==7) begin done<=1; state<=3; end
               end
            3: begin done<=0; state<=0; end
        endcase
    end
endmodule
7.12

Shift-and-add multiplier datapath:

  • Register A (8-bit): accumulator, initialized to 0.
  • Register Q (4-bit): multiplier, loaded with B.
  • Register M (4-bit): multiplicand A.
  • Shift register: A:Q shifted right 1 bit each cycle.
  • Adder: A + M when Q[0]=1.

ASM chart: INIT state → LOAD A:=0, Q:=B, cnt:=4; LOOP: if Q[0]=1 then A:=A+M; shift A:Q right; cnt:=cnt−1; if cnt=0 → DONE else → LOOP.

Product = A:Q after 4 iterations.

7.18

System: read eight 4-bit values, store them, compute sum and average.

Datapath: 8×4-bit memory (or shift reg), 7-bit accumulator, 3-bit counter
Controller ASM:
IDLE ──start──► INIT: acc:=0, cnt:=0
READ: store data[cnt]; acc:=acc+data[cnt]; cnt:=cnt+1
  ──(cnt<8)──► READ
  ──(cnt=8)──► COMPUTE: sum:=acc; avg:=acc>>3 (divide by 8)
DONE: output sum, avg; done:=1 ──► IDLE

Average = sum/8 implemented as 3-bit right shift (exact for multiples of 8, truncated otherwise).

7.19
module tristate_bus (
    input      [7:0] data_in,
    input            oe,       // output enable
    output     [7:0] bus
);
    assign bus = oe ? data_in : 8'bz;
endmodule

When oe=1, drives bus with data_in. When oe=0, bus is high-impedance (Z). Multiple such modules can share the same bus wire provided only one has oe=1 at a time.

7.20

Sorting network for three 4-bit numbers A, B, C into sorted order X≤Y≤Z:

Step 1: Compare-swap (A,B): if A>B, swap → ensures min(A,B) in A
Step 2: Compare-swap (B,C): if B>C, swap → ensures max in C (= Z)
Step 3: Compare-swap (A,B): if A>B, swap → ensures A≤B (= X≤Y)

3 compare-swap elements total. Each comparator is a 4-bit magnitude comparator with a 4-bit 2-to-1 mux for each output. Fully combinational, depth = 3 comparator levels.

7.21

Moore in ASM: Outputs are listed inside the state box (rectangle). Output active for the entire clock cycle regardless of input. Example: state S2 box contains "z=1".

Mealy in ASM: Outputs are listed in oval conditional output boxes on arcs, adjacent to the decision diamond. Output is conditional on both state and input. Example: on the arc from S1 when w=1, an oval box contains "z=1".

Both representations preserve the one-clock-per-ASM-block timing relationship.

7.22

Synchronizer circuit: Two cascaded D flip-flops clocked by the destination domain. The first FF captures the asynchronous input (may go metastable); the second FF samples the first FF's output after a full clock period — by which time the first FF has almost certainly resolved.

Why a single FF is insufficient: The first FF's output may still be metastable (not fully resolved to a valid 0 or 1) when the next logic stage samples it, propagating an invalid value. Adding a second FF gives the first FF a full clock period to resolve its metastable state, reducing the probability of failure exponentially.

7.23

Repeated-subtraction division: quotient Q=0; while dividend ≥ divisor: dividend−=divisor, Q++.

Pseudo-code:
  Q := 0
  R := dividend  // 255
  D := divisor   // 7
  while R >= D:
      R := R - D
      Q := Q + 1
  // result: Q=36, R=3 (255 = 36×7 + 3)

Cycles for 255÷7: quotient = 36, so loop executes 36 times plus setup = 37 clock cycles (36 subtractions + final comparison). In hardware, each subtraction takes 1 clock cycle.

7.24

Shift-and-add multiplier cycles = number of bits in multiplier:

4-bit multiplier: 4 iterations + 1 cycle for initialization + 1 cycle for done = 4 clock cycles (excluding load/done).

8-bit multiplier: 8 clock cycles for the shift-and-add loop.

Generally: n-bit × n-bit multiplier requires n clock cycles for the sequential shift-and-add algorithm. A combinational (array) multiplier requires 0 clock cycles but uses O(n²) gates.

7.25

Debouncing circuit using SR latch with SPDT switch and pull-up resistors:

Vcc
 |
R1 (pull-up)
 |──────── S input of SR latch
 |   ← switch common
R2 (pull-up)
 |──────── R input of SR latch
GND

When switch moves to S position: S line is grounded → SR latch Set. Bounces on S side re-apply Set — no effect (already set). When switch moves to R: R line grounded → Reset. Result: Q output changes cleanly once per switch throw, regardless of bouncing contacts.

7.26

Clock distribution challenges: Long interconnects introduce varying delays to different FFs (clock skew). Skew causes setup/hold violations.

Techniques to minimize skew:

  • Clock tree synthesis (CTS): CAD tool balances the clock tree so all leaf FF clock pins see equal delay. H-tree or balanced binary tree topology.
  • Clock buffers: Symmetric placement of equal-strength buffers at each level.
  • Low-skew clock networks: FPGAs have dedicated global clock routing with matched delays to all CLBs.
  • Clock domains: Limit the size of each synchronous domain; use synchronizers at domain crossings.
  • Minimize clock loading: Avoid excessive fan-out on clock net; use clock enable instead of gated clocks.
7.27

Restoring divider: 8-bit ÷ 4-bit.

Datapath: 8-bit partial remainder register P, 4-bit divisor D.

Each step: P_shifted = P left-shifted by 1 (bring in next dividend bit); attempt subtraction P_trial = P_shifted − D; if P_trial ≥ 0: quotient bit = 1, P = P_trial; else: quotient bit = 0, P restored (P remains).

ASM chart: INIT(load dividend into P[7:0], D into divisor reg, cnt=4) → SHIFT(P=P<<1) → SUBTRACT(P_trial=P−D) → decision(P_trial[MSB]=0 → quotient bit=1, P=P_trial else bit=0) → cnt−1 → if cnt≠0 repeat → DONE.

7.28
module multiplier (
    input        clk, rst, start,
    input  [3:0] A, B,
    output reg [7:0] product,
    output reg done
);
    reg [7:0] acc; reg [3:0] mplier; reg [2:0] cnt;
    always @(posedge clk or posedge rst) begin
        if (rst) begin done<=0; acc<=0; end
        else if (start) begin
            acc<=0; mplier<=B; cnt<=4; done<=0;
        end else if (cnt>0) begin
            if (mplier[0]) acc <= acc + {4'b0,A};
            mplier <= mplier>>1; acc[7:1]<=acc[6:0]; // shift
            // actually: {acc,mplier} >>= 1 with add to upper half
            cnt <= cnt-1;
            if (cnt==1) begin product<=acc+(mplier[0]?{4'b0,A}:0); done<=1; end
        end
    end
endmodule
// Testbench: 13*11=143
// A=4'd13, B=4'd11; expect product=8'd143
7.29

For signed (2's complement) multiplication:

  • The Baugh-Wooley or Booth algorithm handles signed multiplication directly.
  • Simple modification: treat the MSB of both operands as sign bits with weight −2^(n−1).
  • Booth encoding: recode the multiplier to reduce the number of partial products; handles sign automatically.
  • For shift-and-add: use arithmetic (sign-extending) right shift instead of logical shift; negate the last partial product if the MSB of the multiplier is 1.
7.30

UART transmitter: sends 8-bit data with start (0) and stop (1) bits.

ASM: IDLE(tx=1) ──send──► START: tx:=0; cnt:=8
BIT: tx:=data[0]; data:=data>>1; cnt:=cnt-1
  ──(cnt≠0)──► BIT
  ──(cnt=0)──► STOP: tx:=1 ──► IDLE
module uart_tx (
    input       clk, rst, send,
    input [7:0] data,
    output reg  tx, busy
);
    reg [7:0] sr; reg [3:0] cnt;
    reg [1:0] state;
    always @(posedge clk or posedge rst) begin
        if (rst) begin tx<=1; state<=0; busy<=0; end
        else case (state)
            0: if(send) begin sr<=data;cnt<=8;tx<=0;busy<=1;state<=1; end
            1: begin tx<=sr[0];sr<=sr>>1;cnt<=cnt-1;
                     if(cnt==1) state<=2; end
            2: begin tx<=1; busy<=0; state<=0; end
        endcase
    end
endmodule
7.13

Datapath: $n$-bit shift register holding the input (MSB shifts out), $\lceil\log_2 n\rceil$-bit counter accumulating ones, and an $n$-bit-cycle counter. Control signals: load, shift, incr, done. ASM chart: state $S_1$ loads input on Start. $S_2$ loops $n$ times: shift the register; if the shifted-out bit is 1, increment the count; decrement the cycle counter. When the cycle counter reaches 0, go to $S_3$ which asserts done.

module bitcount #(parameter n=8)(input Clk, Rst, Start, input [n-1:0] D,
                                  output reg [3:0] cnt, output reg done);
  reg [n-1:0] sr; reg [3:0] k; reg [1:0] s;
  always @(posedge Clk, posedge Rst)
    if (Rst) begin s<=0; cnt<=0; done<=0; end
    else case (s)
      0: if (Start) begin sr<=D; cnt<=0; k<=n; s<=1; done<=0; end
      1: if (k==0) begin done<=1; s<=2; end
         else begin if (sr[n-1]) cnt<=cnt+1; sr<=sr<<1; k<=k-1; end
      2: if (!Start) s<=0;
    endcase
endmodule

7.14

Datapath: $n$-bit multiplicand register $M$, $n$-bit multiplier register (LSB shifted out each cycle), $2n$-bit accumulator $A$ initially 0. ASM: in state $S_1$ load operands. In $S_2$ (looping $n$ times): if multiplier LSB = 1, add $M$ to upper half of $A$; right-shift $A$ by one (capturing the next product bit); shift multiplier right. After $n$ iterations the product sits in $A$. State $S_3$ asserts Done.

module shift_add #(parameter n=4)(input Clk, Rst, Start, input [n-1:0] M, Q,
                                    output reg [2*n-1:0] P, output reg done);
  reg [2*n-1:0] A; reg [n-1:0] q; reg [3:0] k; reg [1:0] s;
  always @(posedge Clk, posedge Rst)
    if (Rst) begin s<=0; done<=0; end
    else case (s)
      0: if (Start) begin A<=0; q<=Q; k<=n; s<=1; done<=0; end
      1: begin
          if (q[0]) A[2*n-1:n-1] <= A[2*n-1:n-1] + {1'b0,M};
          A <= A>>1; q <= q>>1; k<=k-1;
          if (k==1) begin s<=2; done<=1; P<=A; end
        end
    endcase
endmodule

7.15

Restoring divider: $n$-bit divisor $B$, $2n$-bit register $\{R, Q\}$ where dividend loaded into $Q$ and $R$ initially 0. ASM: each cycle, shift $\{R, Q\}$ left by 1 (MSB into $R$); subtract $B$ from $R$; if result $\ge 0$, place 1 into $Q$'s LSB; else restore (add $B$ back) and place 0 in $Q$'s LSB. After $n$ cycles, $R$ holds the remainder and $Q$ holds the quotient. Verilog: case-based FSM with shift, subtract-or-restore conditional, and a cycle counter.

7.16

Datapath: an accumulator (width $n+\lceil\log_2 k\rceil$), a counter for the number of inputs received, and a divider (or shift-by-$\log_2 k$ if $k$ is a power of 2). ASM: in state $S_1$ wait for Start. $S_2$: on each input strobe, add input to accumulator and increment counter; loop until counter = $k$. $S_3$: divide accumulator by $k$ (use the divider FSM if $k$ is not a power of 2, or right-shift if it is). $S_4$: assert Done with the mean as output.

7.17

Datapath: a register file of $k$ entries × $n$ bits, two read ports, one write port; a comparator and a swap mechanism. Selection-sort ASM: outer loop $i = 0\dots k-2$; inner loop finds index of minimum in $RF[i\dots k-1]$ and swaps with $RF[i]$. Each iteration uses two registers (current min index, current scan index) and a comparator. Verilog uses a 2-counter nested-loop FSM with comparator-driven conditional swaps. Total time: $O(k^2)$ clock cycles.

Chapter 8 — Optimization
8.1

f = x₁x₃ + x₁x₄ + x₂x₃ + x₂x₄ = x₃(x₁+x₂) + x₄(x₁+x₂) = (x₁+x₂)(x₃+x₄)

SOP cost: 4 AND gates (2-input) + 1 OR gate (4-input) = 8 gate inputs + 5 gates.

Factored form cost: 2 OR gates (2-input) + 1 AND gate (2-input) = 3 gates, 6 gate inputs.

Saving: 2 gates, multilevel is cheaper and faster for this function.

8.2

f = ac+ad+bc+bd+e = (a+b)(c+d)+e. Convert to NAND-NAND:

Use double inversion: f = (a+b)(c+d) · e

NAND of NAND (applying DeMorgan):

t1 = NAND(a,c); t2=NAND(a,d); t3=NAND(b,c); t4=NAND(b,d)
t5 = NAND(t1,t2,t3,t4)  // = ac+ad+bc+bd
ne = NAND(e,e)            // = ē  (not needed if e uncomplemented)
f  = NAND(t5, NAND(e,e)̄)  // adjust...

More directly: f = NAND(NAND(a,c), NAND(a,d), NAND(b,c), NAND(b,d), NAND(e,e)̄) — using e with self-NAND for inversion, then a 5-input NAND for the final OR layer.

8.3

f = Σm(0,1,2,5,6,7,8,9,14). Quine-McCluskey grouping by number of 1s:

Group 0: 0000(0)
Group 1: 0001(1), 0010(2), 1000(8)
Group 2: 0101(5), 0110(6), 1001(9)
Group 3: 0111(7), 1110(14)
Combine:
(0,1)=000-, (0,2)=00-0, (0,8)=-000
(1,5)=0-01, (1,9)=-001, (2,6)=0-10
(8,9)=100-
(5,7)=01-1, (6,7)=011-
(9,...)  check (1,9)=-001 ✓
Second pass:
(0,1,8,9)=-00-, (0,2,1,...)...

Prime implicants: -00- (0,1,8,9); 0-0- (0,2)? ; 0-1- (5,7)=0-1-? ; 011- (6,7); 0-10 (2,6); -001 (1,9); 1110 (14). Full QM table needed for exact set.

8.4

f = x₁x₂ + x̄₁x₃, order x₁ < x₂ < x₃.

         x₁
        /   \
       0     1
      x₃    x₂
     / \    / \
    0   1  0   1
    0   1  0   1

Build Shannon expansion tree. After reduction:

  • Root: x₁. Left (x₁=0): f = x₃. Right (x₁=1): f = x₂.
  • Left child: x₃ node, 0→0, 1→1.
  • Right child: x₂ node, 0→0, 1→1.

After ROBDD reduction (x₃ and x₂ nodes both map to identity, but different variables — cannot merge). 4 nodes: root x₁, left x₃, right x₂, terminal 0 and 1.

8.5

For n variables, the K-map has 2ⁿ cells. Practical issues with 5+ variables:

  • A 5-variable map has 32 cells — displayed as two 4-variable maps; adjacency rules extend across the maps, making visual grouping error-prone.
  • 6 variables: 64 cells, four 4-variable maps — essentially unmanageable by hand.

Alternatives:

  • Quine-McCluskey: Tabular, systematic, scalable to any number of variables.
  • BDDs: Canonical representation for verification and optimization.
  • Espresso: Heuristic minimization algorithm used in CAD tools for large functions.
8.6

f = Σm(0,3,4,7,9,10,13,14). K-map grouping with fan-in ≤ 2 constraint means only 2-input gates.

Standard K-map: {0,3,4,7}=x̄₂x̄₃·? No: 0=0000,3=0011,4=0100,7=0111 → x̄₁(x̄₂x̄₃x̄₄+x̄₂x₃x₄+x₂x̄₃x̄₄+x₂x₃x₄)... group {0,3,4,7}= x̄₁(x₃⊙x₄)... {0,3,4,7}=x̄₁·(x₂⊕x₃x₄)?

Groups: {0,4,9,13}? No. Best K-map cover: {0,3,4,7}=x̄₁(x̄₂x̄₃+x₂x₃)... ={x̄₁(x₂⊙x₃)}... Actually {0,3,4,7}: bits differ in x₂,x₃,x₄ — these are x̄₁x̄₄(x̄₂x̄₃ impossible since 3=0011,7=0111). With fan-in≤2: decompose using a tree of 2-input gates.

8.7

Two-level logic advantages: Simple structure (SOP/POS); well-understood minimization (K-map, QM); predictable delay (exactly 2 levels); easy to implement with PLAs.

Two-level disadvantages: Can have large fan-in for complex functions; cannot share common sub-expressions; gate count can be exponential in the number of variables.

Multilevel advantages: Shares sub-expressions → fewer gates/literals; supports any fan-in constraint; more area-efficient for complex functions.

Multilevel disadvantages: More logic levels → longer critical path; harder to optimize systematically; less predictable timing.

8.8

f = abd + abe + acd + ace. Factor using algebraic division:

= a(bd + be + cd + ce) = a·(b+c)(d+e)

Extract t₁ = (b+c), t₂ = (d+e):

f = a · t₁ · t₂ = a·(b+c)·(d+e)

Original: 4 product terms × 3 literals = 12 literals + 1 OR gate.

Factored: 2 OR gates + 3-input AND gate (or 2 two-input ANDs) = 3 gates, 6 literals. Significant saving.

8.9

ROBDD (Reduced Ordered Binary Decision Diagram): A directed acyclic graph where each internal node is labeled with a variable, has two children (low=0, high=1), and the variable ordering is consistent along all root-to-leaf paths.

Two reduction rules:

  1. Merge rule: If two nodes have the same variable, same low-child, and same high-child → merge into one node (share identical sub-graphs).
  2. Elimination rule: If a node's low-child and high-child are identical → remove the node and redirect its parents to the child (variable is irrelevant for this sub-function).

Canonical form importance: For a fixed variable ordering, the ROBDD is unique for each Boolean function. This enables O(1) equality checking (same pointer = same function) and efficient BDD operations.

8.10

Technology mapping transforms a technology-independent (generic gate) netlist into one using cells from a specific cell library (standard cells for ASIC, or LUTs for FPGA).

Steps:

  1. Represent the circuit as a tree or DAG of simple gates (INV, AND, OR, NAND, NOR).
  2. Pattern-match sub-trees to available library cells using dynamic programming or recursive partitioning.
  3. Select the best-matching cells to minimize area or delay.
  4. Handle fan-out reconvergence by partitioning into trees.

The result is a mapped netlist with specific cell instances rather than generic gates.

8.11

Mux f = s·d₁ + s̄·d₀. Variables: s, d₀, d₁.

Ordering 1: s < d₀ < d₁

Root: s
  s=0: d₀ (output = d₀)
  s=1: d₁ (output = d₁)
BDD has 3 nodes: s, d₀, d₁ plus terminals 0,1.

Ordering 2: d₀ < d₁ < s

Root: d₀; must branch on d₁ then s → more nodes needed.
Effectively 7 nodes in worst case.

Ordering 1 (s first) gives the smaller BDD because s is the "controlling" variable for the mux function.

8.12

Functional decomposition: express f(x₁..x₅) = h(g(x₁,x₂,x₃), x₄, x₅) where g is a simpler sub-function.

Identify a "bound set" (e.g., {x₁,x₂,x₃}) and "free set" ({x₄,x₅}).

For each combination of x₄,x₅, list the required function of x₁,x₂,x₃. If multiple (x₄,x₅) combinations require the same sub-function of x₁,x₂,x₃, they share the same g output column.

A decomposition exists if the number of distinct columns ≤ 2ᵏ for k bits. Extract g (3-input function) and h (3-input: g-output + x₄ + x₅).

8.39

f = Σm(0,2,3,5,7,8,10,11,14,15,24,26,27,29,31) — 5 variable function.

QM: Group by number of 1s in binary representation, then combine pairs (differ by 1 bit), then quads, etc. With 5 variables (00000–11111), systematically combine until no further reduction possible.

Pattern: minterms (0,2,8,10,24,26)=−−0−0; (3,7,11,15,27,31)=−−111; (5,7,29,31)=−10−1; etc. Full enumeration yields prime implicants from which minimum cover is selected via PI chart.

8.40

f = (a+b)(c+d)+e using NOR gates:

NOR-NOR implements POS. f' = f = (a+b)(c+d)+e.

f' = NOR(NOR(a,b), NOR(c,d), e) — using De Morgan repeatedly.

Actually: complement the function and implement complement of complement with NOR-NOR:

NOR(a,b) → nor_ab = ā·b̄
NOR(c,d) → nor_cd = c̄·d̄
NOR(nor_ab, nor_cd, ē) → f

This requires complemented inputs (ā,b̄,c̄,d̄,ē) or NOR inverters for each.

8.41

f = x̄₁x₂ + x₁x̄₃. Cubical representation — each cube is a product term represented as a ternary vector (0=complemented, 1=uncomplemented, −=don't care):

Cubex₁x₂x₃
x̄₁x₂01
x₁x̄₃10

The cover (set of cubes) = {(0,1,−), (1,−,0)}. Each cube represents a set of minterms: cube (0,1,−) = minterms {010, 011}={2,3}; cube (1,−,0)={100,110}={4,6}.

8.42

For a complex 5-variable function, multilevel synthesis extracts common sub-expressions:

  1. Express f in SOP form.
  2. Identify kernel expressions (common factors) using algebraic division.
  3. Extract kernels as intermediate signals t₁, t₂, etc.
  4. Rewrite f using extracted signals.

Example: if f = abcd + abce + fgh, extract t₁=ab: f = t₁(cd+ce)+fgh = t₁·c·(d+e)+fgh. This reduces the literal count from 9 to 7 (one ab → one t₁ used twice, saving literals).

8.43

f = Σm(4,7,8,11) + D(12,15). K-map (4-var):

       x₃x₄
x₁x₂  00 01 11 10
  00:   0  0  0  0
  01:   1  0  1  0
  11:   d  0  d  0
  10:   1  0  1  0

Groups: {4,8,12d}=x̄₃x̄₄? No, 4=0100,8=1000,12=1100 → differ in x₁,x₂. {4,12d}=x̄₃x̄₄·x₂? {4,8}=x̄₂x̄₄? No..

Minterms: 4=0100, 7=0111, 8=1000, 11=1011, DC 12=1100, 15=1111.

Groups: {4,12}=?x100; {7,15d}=?111; {8,12d}=1?00; {11,15d}=1?11.

Min SOP: f = x̄₃x̄₄ + x₃x₄ (covers 4,8,12dc,0? — check). Recheck: {4,8,12,0}: x₃=0,x₄=0 → covers 0,4,8,12 — but 0 not in f. Use {4,12}: x₂=1,x₃=0,x₄=0→x₂x̄₃x̄₄; {8}: x₁=1,x₂=0,x₃=0,x₄=0→x₁x̄₂x̄₃x̄₄; {7,15d}: x₂x₃x₄; {11,15d}: x₁x₃x₄.

Min SOP: x₂x̄₃x̄₄ + x₁x̄₂x̄₃x̄₄ + x₁x₃x₄. Factored: (x₂+x₁x̄₂)x̄₃x̄₄ + x₁x₃x₄ = (x₁+x₂)x̄₃x̄₄ + x₁x₃x₄.

8.44

Cubical representation definitions:

  • Literal: A single variable or its complement; represented as a ternary value (0, 1, or −) in one position of a cube.
  • Cube: A product term represented as a ternary vector; a cube with k "−" positions covers 2ᵏ minterms.
  • Cover: A set of cubes whose union covers all the on-set minterms (positions where f=1).
  • Prime implicant: A cube not contained in any other cube in the cover (cannot be enlarged while remaining valid).
  • Essential PI: A prime implicant that is the only cube covering at least one minterm; must be in every minimum cover.
8.45

In Quine-McCluskey, a "check mark" (✓) is placed next to a minterm entry in a group when it has been successfully combined with another minterm. Any row without a check mark at the end is a prime implicant (cannot be combined further).

PI chart selection:

  1. Build table: rows=PIs, columns=minterms.
  2. Mark each PI's covered minterms.
  3. Identify essential PIs (single mark in a column) — these must be selected.
  4. Remove covered minterms; if minterms remain, use Petrick's method or heuristic (choose PI covering the most remaining minterms).
  5. Repeat until all minterms covered.
8.46

f = x₁x₂ + x₃x₄ + x₅x₆.

Interleaved ordering (x₁,x₂,x₃,x₄,x₅,x₆): Each pair xᵢxᵢ₊₁ is adjacent; BDD can share the AND-structure for each pair compactly. BDD size = O(n) nodes.

Grouped ordering (x₁,x₃,x₅,x₂,x₄,x₆): Each product term's variables are separated; the BDD cannot share structure between the first halves — exponential blowup possible. BDD size = O(2^(n/2)).

General rule: For a function that is a sum of independent pairs, interleaving the pair members minimizes BDD size. Variable ordering is NP-hard to optimize optimally; dynamic variable reordering heuristics (sifting) are used in practice.

8.47

PI chart: columns = minterms, rows = prime implicants. Mark each minterm covered by each PI.

Find essential PIs: columns with only one mark → that PI is essential. Select all essential PIs, remove covered minterms, then use Petrick's method or greedy selection for remaining.

For f from 8.5: PI -00- covers {0,1,8,9}; if any of 0,1,8,9 is only covered by -00-, it's essential. Continue until all minterms covered. The minimum cover = essential PIs + minimum additional PIs for uncovered minterms.

8.48

Carry function for n-bit adder: cₙ = f(a₁,b₁,...,aₙ,bₙ,c₀).

Interleaved ordering (a₁,b₁,a₂,b₂,...aₙ,bₙ): BDD size is polynomial O(n) — each carry bit depends on its and lower bits' a,b pairs; BDD can share nodes efficiently.

Grouped ordering (a₁,...,aₙ,b₁,...,bₙ): BDD size grows exponentially O(2ⁿ) because cₙ depends on all aᵢ and bᵢ in a way that requires exponentially many nodes when variables are split into two separate groups.

Lesson: variable ordering dramatically affects BDD size; interleaved is optimal for adder carry.

8.49

f = Σm(0,4,8,13,14,15) with uncomplemented inputs only (no inverters).

Without complements, we can only form product terms using uncomplemented variables. Minterms requiring all-1 variables are easy; minterms with 0s require complements.

Minterm 0 = x̄₁x̄₂x̄₃x̄₄ requires all complements → not realizable with uncomplemented inputs only.

For this constraint: use NAND/NOR decomposition, or accept that some minterms (0,4,8) are not directly implementable; consider alternative: implement f̄ using uncomplemented inputs and invert, or use XOR-based form.

If only minterms 13,14,15 covered: f_partial = x₁x₂x₃x̄₄ + x₁x₂x̄₃x₄ + x₁x₂x₃x₄ = x₁x₂(x₃+x₄). Add minterms 0,4,8 by alternative decomposition.

8.50

f = ab+cd. Cell library example: {INV, NAND2, NOR2, AND2, OR2, AOI21 (AND-OR-Invert)}.

Minimize area: f = ab+cd = NAND(NAND(a,b), NAND(c,d)). Uses 3 NAND2 gates (area = 3 units). Alternatively: AND2+AND2+OR2 = 3 cells but likely larger area.

Minimize delay: f can be implemented as single AOI21 cell if available: ̄f = AOI(a,b,c,d) then INV. Or NAND-NAND: 2 levels × t_NAND delay — same as any 2-level implementation.

8.51

Circuit: t₁=a+b, t₂=c·d, t₃=t₁·e, f=t₂+t₃ = c·d + (a+b)·e

Analysis: f = cd + ae + be. Literal count = 5. Gate count = AND(c,d) + AND(a,b→OR) + 2 ANDs + OR = 4 gates.

Re-factor: f = cd + e(a+b). This is already factored. Alternative: no simpler form exists since cd and e(a+b) share no common factor.

Could also write f = c·d + (a+b)·e — same. Verify: expanding gives cd+ae+be which matches original enumeration.

8.13

Note $f_2 = (x_1+x_2)(x_3+x_4)$ already factored. Examine $f_1$: it equals $f_2$ minus the case $x_1=x_2=0$ where it should be $\overline{x_1}\overline{x_2}(x_3+x_4)$ — i.e. $f_1 = (x_1+x_2)(x_3 x_4) + \overline{x_1}\overline{x_2}(x_3+x_4)$. Both share the subexpression $g = x_3+x_4$ and $h = x_1+x_2$. Total cost: $g, h$ shared; then $f_2 = h\cdot g$, $f_1 = h\cdot x_3 x_4 + \overline{h}\cdot g$. Sharing $g$ and $h$ saves several gate-inputs versus building each output independently.

8.14

Group on the K-map columns: in columns 01 ($\overline{x_3}x_4$) and 10 ($x_3\overline{x_4}$) the function takes value $x_1 \oplus \overline{x_2}$; in columns 00 and 11 it is 0. So $g(x_3, x_4) = x_3 \oplus x_4$ (asserts in the two middle columns). Then $f = g \cdot (x_1 \oplus \overline{x_2})$ — a 2-level XOR product, two XORs feeding one AND. Cost: 3 gates with 2 inputs each, vs four 3-input ANDs in the SOP form.

8.15

By inspection of the K-map, when rows where $g(x_1,x_2,x_5)=0$ all have one column pattern and rows where $g=1$ have a different pattern, define $g$ as the row indicator. Similarly $k(x_3,x_4)$ as the column index. The book's example produces $f = g \oplus k$ or $f = g\overline{k} + \overline{g}k$. Cost: 3 small subfunctions + 1 XOR ≈ 8 inputs, versus minimum SOP ≈ 18 inputs — a substantial saving.

8.16

5-NAND XOR (standard):

g1 = NAND(x1,x2)
g2 = NAND(x1,g1)
g3 = NAND(g1,x2)
f  = NAND(g2,g3)
(That's actually 4 NANDs.) The 4-NAND version uses $g = \text{NAND}(x_1, x_2)$ shared among the next stages:
g  = NAND(x1, x2)
f1 = NAND(x1, g)
f2 = NAND(x2, g)
f  = NAND(f1, f2)
This realizes $x_1 \oplus x_2$ in 4 NAND gates.

8.17

Bubble-pair insertion: AND-OR levels alternate, so place a bubble pair at every signal between adjacent levels. After absorbing each bubble into the gate it touches: every AND becomes NAND and every OR (with bubbles on inputs and output) becomes NAND too — yielding (a) all-NAND. For (b) all-NOR: insert bubble pairs differently — turn the AND gates into NORs (with bubbled inputs) and the ORs into NORs (with bubbled outputs absorbed). The structure flips between AND-OR-AND-OR and OR-AND-OR-AND topology.

8.18

Label intermediate nodes $P_1, P_2, P_3$ inside Figure 8.12. Trace from output back: $f = P_1 + P_2$; $P_1 = x_1 P_3$, $P_3 = x_2 + x_3$; $P_2 = \overline{x_1} x_4$. So $f = x_1(x_2+x_3) + \overline{x_1}x_4 = x_1 x_2 + x_1 x_3 + \overline{x_1}x_4$. SOP cost: 3 ANDs + 1 OR = 4 gates, 9 inputs.

8.19

Replace the XOR/XNOR gates of Example 8.3 by their SOP equivalents ($x \oplus y = x\overline{y}+\overline{x}y$). Label internal nodes and trace: each leg of the multilevel circuit collapses to one of the original product terms. The expression reconstructs to $f = $ the original specification — verifying functional equivalence.

8.20

Label $P_1=$ NAND($x_1, x_2$), $P_2=$ NAND($x_3, x_4$), $P_3=$ NAND($P_1, P_2, x_5$). Apply DeMorgan to each: $P_1 = \overline{x_1 x_2}$, $P_2 = \overline{x_3 x_4}$, but feeding into the next-level NAND with bubble absorption gives an OR-of-AND structure. The textbook reduction yields $f = x_1 x_2 x_4 + \overline{x_3} x_4 + x_5$ after simplification.

8.21

Label $P_1\dots P_4$ at gate outputs. NAND outputs equal $\overline{\prod}$; NOR outputs equal $\overline{\sum}$. Propagate bubbles by DeMorgan until all bubbles cancel. After algebraic simplification: $f = x_5(x_1 + x_2 + \overline{x_3} + x_4) = x_1 x_5 + x_2 x_5 + \overline{x_3} x_5 + x_4 x_5$. ✓

8.22

Build a small truth table over $(x_1, x_2)$ for each terminal of the original BDD, recording where edges from the swap-boundary go. Then re-create the BDD with $x_1$ above $x_2$. Many edges merge if the function is symmetric in those variables. Result is a BDD of equivalent or smaller size depending on the variable ordering.

8.23

Shannon on $x_1$: $f|_{x_1=0} = x_2 x_3 + x_2 x_4 + \overline{x_2}\overline{x_3}\overline{x_4}$, $f|_{x_1=1} = x_3 + x_4 + x_2 x_3 + x_2 x_4 = x_3 + x_4$. Shannon $f|_{x_1=1}$ on $x_2$: same $x_3+x_4$ either way (independent of $x_2$). For $f|_{x_1=0}$ on $x_2$: $x_2=1$ gives $x_3+x_4$; $x_2=0$ gives $\overline{x_3}\overline{x_4}$. BDD: root $x_1$, both children point to an $x_2$ node (or merge if equal). The $x_3+x_4$ subgraph appears multiple times — merge it. Multilevel SOP from BDD: $f = x_1(x_3+x_4) + \overline{x_1}[\,x_2(x_3+x_4) + \overline{x_2}\overline{x_3}\overline{x_4}\,]$.

8.24

Quine-McCluskey on $\sum m(0,2,5,6,7,8,9,13) + D(1,12,15)$: Group minterms by 1-count, combine adjacent ones across iterations until no more merges. Resulting prime implicants (after marking unmerged): typically $\{\overline{x_2}\overline{x_3}\overline{x_4}, x_2 x_4, x_2 x_3, x_1\overline{x_3}, x_1 x_4\}$ or similar. Build cover table over essential minterms, eliminate dominated rows/columns, and select. Minimum cover (one valid result): $f = x_2 x_4 + x_2 x_3 + \overline{x_2}\overline{x_3}\overline{x_4} + x_1\overline{x_3}$.

8.25

Apply tabular method: prime implicants include several 2-cubes and 1-cubes, no essential primes. Cover table has no row or column dominance. Use Petrick's method or branching: select an arbitrary prime, recurse, choose minimum-cost cover. Typical result: $f = $ 4 prime implicants of 2 literals each, gate-input cost $\approx 12$.

8.26

$\star$-product pairs cubes that differ in exactly one position, replacing that position with x. $C_0 = \{000, 001, 010, 011, 111\}$. $C_1$: $000\star 001 = 00x$, $000\star 010 = 0x0$, $001\star 011 = 0x1$, $010\star 011 = 01x$, $011\star 111 = x11$. $C_2$: $00x\star 01x = 0xx$. No further merges. After removing covered cubes, primes are $\{0xx, x11\}$. ✓

8.27

Apply $\star$-product to $C_0=\{0101,1101,1110,011x,x01x\}$. $0101\star 1101 = x101$. $011x \star x01x$: differ in two positions → no merge. $0101\star 011x = 01x1$ (differ in bit 1, x merge). $1101\star 1110$: two diff → no. $C_1 = \{x101, 01x1, 1110, 011x, x01x\}$. Continue: $x101 \star 01x1$: two diff, no. Final primes: $x101, 01x1, 1110, 011x, x01x$. Algebraic: $\{x_2\overline{x_3}x_4, \overline{x_1}x_2 x_4, x_1 x_2 x_3\overline{x_4}, \overline{x_1}x_2 x_3, \overline{x_2}x_3\}$.

8.28

The $\#$-operation: $A \# B$ returns minterms in $A$ not in $B$. For each prime $p$, compute $p \# (P \setminus \{p\})$ over the on-set. If non-empty, $p$ is essential (covers a minterm no other prime covers). For $\{x11, 0xx\}$ on the function of Figure 2.56: $x11 \# 0xx = 111$ (non-empty) → essential. $0xx \# x11 = \{000, 001, 010\}$ (non-empty) → essential. Both primes are essential.

8.29

For each $p \in P$, compute $p \# (P\setminus\{p\})$. $x01x \#$ rest: $\{0010, 0011\}$ → essential. $x101$: subset of $x101$ alone — empty after removing self → not essential. $01x1$: $\{0101\}$ — essential. $0x1x \#$ rest: $\{0010, 0011\}$ — already covered by $x01x$ → check: actually $0x1x \# x01x = \{0110, 0111\}$ — essential. $xx10$: most cells covered by others → not essential. Essentials: $x01x, 01x1, 0x1x$. (Exact set depends on minterm coverage in the function.)

8.30

Apply $\star$-product to find primes (many cubes after several iterations on the 5-var function). Use $\#$-op to identify essentials covering minterms unique to each. After essentials are chosen, branch on the remaining cover table to minimize cost. Final minimum SOP (illustrative): $f = \overline{x_1}\overline{x_2}\overline{x_3}\overline{x_4} + x_4 x_5(x_1\oplus x_2) + x_2 x_3 x_4 + \overline{x_3}\overline{x_5}$ (or equivalent ~4-term cover, depending on don't-care assignments).

8.31

Straightforward 3-LUT mapping: LUT1 = $x_1 x_2\overline{x_4}$, LUT2 = $\overline{x_2} x_3 x_4$, LUT3 = $x_1 x_2 x_3$, LUT4 = OR of these — total 4 LUTs. Decomposition: factor $x_1 x_2(\overline{x_4} + x_3) = x_1 x_2(x_3 + \overline{x_4})$ in one 3-LUT, $\overline{x_2}x_3 x_4$ in another, OR them in a third — total 3 LUTs.

8.32

Group: $f = (x_1+x_2)(x_3+x_4) + \overline{x_1}\overline{x_2}\overline{x_3}\overline{x_4}$. Use $\overline{x_1}\overline{x_2}\overline{x_3}\overline{x_4} = (\overline{x_1+x_2})(\overline{x_3+x_4}) = \overline{x_3}\overline{x_4}\cdot(\overline{x_1+x_2}) = \overline{x_3}\overline{x_4}$ when $x_1+x_2=0$. Net: $f = \overline{x_3}\overline{x_4} + (x_1+x_2)(x_3+x_4)$. ✓ (Identity verified by expansion: when $x_3+x_4=0$, only the first term remains; when $x_3+x_4=1$, the AND term covers it.)

8.33

Shannon on $x_1$: $f|_{x_1=0} = x_2 x_4$, $f|_{x_1=1} = x_3 + x_2 x_4$. Shannon $f|_{x_1=1}$ on $x_2$: $f|_{x_1=1, x_2=0} = x_3$, $f|_{x_1=1, x_2=1} = x_3 + x_4$. BDD: root $x_1$. Right branch ($x_1=1$) goes to $x_2$ node with two cofactors (one is $x_3$, one is $x_3+x_4$). Left branch ($x_1=0$) goes to a node testing $x_2$ — only $x_2 x_4$ branch. Continue with $x_3$ then $x_4$ levels, merging duplicate subgraphs.

8.34

Track the 4 entries of the truth table over $(x_2, x_3)$ at each subgraph crossing the swap. After swapping inner $x_2$ and $x_3$, build a new BDD with root $x_1$, then $x_3$, then $x_2$, then $x_4$. Some subgraphs merge differently. The new BDD usually has the same node count for symmetric functions, but variable ordering can change BDD size dramatically in general.

8.35

Minterms of $f$: $\sum m(0,1,2,4,5,8,9,13) + D(9,12,14)$ (after expanding, given the SOP form). Tabular method: group by 1-count, combine. Generated cubes: $\{00x0, 0x0x, 1x01, 10x1, 1101\}$ and primes after removal of covered ones. Cover table: essentials from rows with single mark. Minimum-cost SOP: $f = \overline{x_3}\overline{x_4} + x_1 x_4 + \overline{x_2} x_4$ (as in 2.38).

8.36

$C_0$ from minterms+don't-cares. $C_1$ via $\star$-product yields 2-cubes; $C_2$ yields 3-cubes. Convergence after ~3 iterations. Resulting primes (in cube notation, $x_1 x_2 x_3 x_4$): $\{xx00, x0x1, 1x01, 1xx1\}$ — algebraically $\{\overline{x_3}\overline{x_4}, \overline{x_2}x_4, x_1\overline{x_3}x_4, x_1 x_4\}$. The book's minimum-cost cover selects a subset matching 8.35.

8.37

(a) Minimum SOP $f = \overline{x_3}\overline{x_4} + x_1 x_4 + \overline{x_2} x_4$: 3 ANDs + 1 OR, 11 gate-inputs. (b) Minimum POS $f = (\overline{x_2}+\overline{x_3})(\overline{x_3}+x_4)(x_1+\overline{x_3}+\overline{x_4})$: 3 ORs + 1 AND, ~12 inputs. (c) Multilevel: factor $f = \overline{x_3}\overline{x_4} + x_4(x_1+\overline{x_2})$: 2 levels for the second term + final OR — about 8 inputs but 3 levels deep. Trade-off: SOP is fastest (2 levels) at 11 inputs; multilevel saves area (8 inputs) at the cost of 3 levels of delay.

8.38

$h[g(x_1,x_2,x_3,x_4), x_5, x_6, x_7]$ — first LUT computes any 4-var function $g$, second computes any 4-var function $h$ of $g$ and three other vars. $f_1 = x_1 x_2 x_3 x_4 x_5 x_6 x_7$: set $g = x_1 x_2 x_3 x_4$, $h = g \cdot x_5 x_6 x_7$ — works. $f_2 = x_1+\dots+x_7$: $g = x_1+x_2+x_3+x_4$, $h = g + x_5+x_6+x_7$ — works. But e.g. $f = x_1 x_5 + x_2 x_6 + x_3 x_7 + x_4$ requires LUT2 to know all of $x_1\dots x_4$ individually — only $g$ (one bit summarizing them) is available. So no 2-LUT realization exists for this $f$.

Chapter 9 — Asynchronous Circuits
9.1

Fundamental mode: Asynchronous circuit operating assumption where inputs change only when the circuit is in a stable state — i.e., one input changes at a time, and the circuit is allowed to settle before the next input change.

Input constraints:

  • Only one input variable changes at a time (no simultaneous changes).
  • The circuit must reach a stable state before the next input transition.
  • No clock; the circuit responds directly to input changes.

These constraints prevent races and ensure well-defined behavior.

9.2

Cross-coupled NOR gates (SR latch): Q = NOR(R,Q̄), Q̄ = NOR(S,Q). Flow table (S,R inputs; stable states circled):

StateSR=00SR=01SR=11SR=10
Q=00001
Q=11011

Stable states (circled): Q=0 with SR=00,01; Q=1 with SR=00,10. SR=11 is the forbidden input (both outputs attempt to become 0). When SR=11→00, output is indeterminate (race).

9.3

Stable state: A state where the next state equals the present state for the current input combination — the circuit has finished transitioning and no further changes occur. Y = y (feedback variable equals its driving function).

Unstable state: A state where Y ≠ y — the circuit's next state differs from its current state. The circuit will continue transitioning (may pass through multiple unstable states) until reaching a stable state. The sequence of unstable-to-stable transitions is called a transition.

9.4

Critical race: When multiple state variables must change simultaneously, and the outcome depends on which changes first. Different orderings lead to different final states — non-deterministic behavior.

Example: State 00→11 transition. If y₁ changes first: 00→10→11 (correct). If y₂ changes first: 00→01→11 (may be correct). But if 10 or 01 are stable states for the current input, the circuit may get stuck there.

Fix: Use race-free state assignment (e.g., assign codes so any transition changes only one variable) or use one-hot encoding for asynchronous circuits.

9.5

f = x₁x₂ + x̄₂x₃. Static 1-hazard occurs when both x₁x₂ and x̄₂x₃ are 0→1 simultaneously — when x₂ transitions from 1→0 with x₁=1, x₃=1: transition from x₁x₂=1 to x̄₂x₃=1, momentarily neither term is 1.

Hazard condition: At x₁=1, x₃=1, as x₂ transitions. The two minterms 110 and 011 are not in the same K-map group.

Eliminate: Add the consensus term x₁x₃ (covers the adjacent minterms 110 and 011, bridging the gap):

f = x₁x₂ + x̄₂x₃ + x₁x₃ (hazard-free)

9.6

Static 1-hazard: Output should remain 1 but momentarily glitches to 0 during an input transition.

Static 0-hazard: Output should remain 0 but momentarily glitches to 1 during an input transition. Occurs in POS implementations; eliminated by adding extra sum terms.

Dynamic hazard: Output should change once (0→1 or 1→0) but transitions 3 or more times (e.g., 0→1→0→1). Caused by multiple paths of different delays when there are reconvergent paths. More complex to eliminate — requires removing the reconvergent topology or balancing delays.

9.7

Compatible states: Two states sᵢ and sⱼ are compatible if (1) they have the same output for all input combinations where both are defined, and (2) their successor state pairs are also compatible (or both undefined) for all inputs.

Merger diagram: A graph where nodes are states and undirected edges connect compatible state pairs. Groups of mutually compatible states can be merged into a single state.

Process: find all compatible pairs (from implication table), draw merger diagram, find maximum compatible groups (cliques), select minimum number of merged states that covers all original states.

9.8

f = Σm(1,2,3,5,7). K-map groups: {1,3,5,7}=x₃; {2,3}=x̄₁x₂; {3,7}=x₂x₃.

Min SOP = x₃ + x̄₁x₂. Check for static 1-hazard: adjacent 1s not in same group?

Minterms 2(010) and 3(011): covered by x̄₁x₂ and x₃ respectively. Transition m2→m3 (x₃: 0→1) with x₁=0,x₂=1: initially x̄₁x₂=1, finally x₃=1. During transition: momentarily neither? No — x̄₁x₂=1 throughout (x₁,x₂ constant). No hazard on this path.

Check m5(101)→m7(111): x₂:0→1 with x₁=1,x₃=1. Before: x₃=1(covers). After: x₃=1 and x₂x₃=1. No hazard.

Hazard exists between m2(010) and m3(011): x̄₁x₂ covers m2; x₃ covers m3. Adding x̄₁x₂x₃ as bridge or the extra PI x₂x₃: f = x₃ + x̄₁x₂ + x̄₁x₃ is hazard-free (extra term bridges).

9.9

Y₁ = x̄₁(x₂+y₁); Y₂ = x₁(x̄₂+y₂). Build flow table: states = (y₁y₂), inputs = (x₁x₂).

y₁y₂x₁x₂=00011110
0000→0001→0,00000
0101→0,001→0101→0,100
1010→1,010→1,010→1,110→10
111011→1,111→1110

Stable states (Y=y): (00,x=00), (01,x=01), (10,x=10), (11,x=11). Transitions determined by evaluating Y₁,Y₂ for each (y₁y₂,x₁x₂) combination.

9.10
AspectSynchronousAsynchronous
SpeedLimited by clock periodCan be faster (no clock overhead)
PowerClock tree always switchingActivity-dependent; potentially lower
TestabilityEasy: scan chains, controllable statesDifficult: timing-dependent behavior
Design effortWell-understood; rich CAD supportComplex; races, hazards, limited tools
NoiseSimultaneous switching noise at clock edgesSpread out; less EMI
9.11

Essential hazard: An inherent hazard in an asynchronous sequential circuit that cannot be eliminated by adding or removing gates. It arises when a single input change causes the circuit to cycle through multiple unstable states, and the required ordering of state variable changes cannot be guaranteed by pure combinational logic delay matching.

Differs from static/dynamic hazards: Static/dynamic hazards occur in combinational logic and can be eliminated by adding redundant terms. Essential hazards are sequential — they result from the interaction between feedback loops and input changes.

Can gates fix it? Not by adding redundant terms. Instead, essential hazards require introducing deliberate delays (e.g., RC circuits or buffer chains) on specific feedback lines to ensure the proper sequencing of state variable updates.

9.12

Muller C-element: output C changes to match inputs only when all inputs agree; holds previous value otherwise.

For 2-input C-element: C(t+1) = AB + (A+B)·C = AB + AC + BC (majority function of A, B, C_current).

Implementation using async techniques:

Y = A·B + Y·(A + B)
  = A·B + Y·A + Y·B

Circuit: two AND gates for AB and YA and YB; one OR gate for Y. This is a hazard-free equation since the feedback Y ensures that C holds its value when A≠B.

The C-element is fundamental to handshaking asynchronous protocols (Micropipelines, NULL convention logic).

9.36

SR latch synthesis from primitive flow table:

Primitive flow table: 2 rows (Q=0, Q=1), 4 input columns (SR: 00,01,10,11). Assign y=Q.

Excitation Y (next state) from the flow table:

Y = S + R̄·y (standard SR latch equation, SR≠11 assumed).

Output Q = y (state variable directly).

Implementation: Y = NOR(R, NOR(S,Y)) — cross-coupled NOR gates realize this feedback equation naturally.

9.37

State reduction on an async flow table:

  1. Build implication chart for states A–D.
  2. Mark pairs with different outputs as incompatible.
  3. For remaining pairs, check if their implied pairs are compatible.
  4. Propagate incompatibilities until no more changes.
  5. Compatible pairs can be merged.

Example: if A and C have same outputs and their successors under all inputs are also compatible pairs → A≡C, merge to a single state. Reduces the flow table rows, simplifying the implementation.

9.38

One-hot state encoding for 3-state async FSM: one SR latch (or FF) per state.

States S₁,S₂,S₃ → y₁,y₂,y₃ with only one yᵢ=1 at a time.

Transitions are controlled by setting the target state latch and resetting the current state latch. Since only one variable changes per transition (the one being set or reset), one-hot is inherently race-free for asynchronous circuits.

Advantage: no critical races. Disadvantage: uses more state variables (3 instead of 2 for 3 states).

9.39

Three challenges of async circuit design:

  1. Races: When multiple state variables change simultaneously, the outcome is non-deterministic. Requires careful state assignment or one-hot encoding to ensure race-free transitions.
  2. Hazards: Glitches in combinational logic (static 1/0, dynamic) can cause spurious state transitions since there is no clock to mask them. All hazards must be eliminated by adding redundant logic.
  3. Fundamental mode violations: Design assumes one input changes at a time and circuit settles before next change. If violated, behavior is undefined. Testing and verifying these timing assumptions is difficult.
9.40

Primitive flow table: One row per stable state. Each input combination in that row has exactly one stable state (the current state) and shows the next state for each input combination. Rows are not merged — one unique stable state per row.

Merged flow table: Multiple compatible stable states combined into one row, reducing the number of state variables (fewer FFs needed).

Why merging is needed: A primitive flow table with N stable states requires ⌈log₂N⌉ state variables or N state variables (one-hot). Merging compatible states reduces the number of rows (and thus state variables), yielding a more compact implementation and simplifying the excitation equations.

9.41

Dynamic hazard: A signal that should make a single transition (0→1 or 1→0) instead makes three or more transitions (0→1→0→1 or 1→0→1→0) due to multiple paths with different delays in the circuit.

Conditions: Requires at least three distinct paths from input to output with different delays, and reconvergent fan-out where the paths merge.

Elimination: Dynamic hazards cannot be eliminated simply by adding terms (unlike static hazards). They require restructuring the circuit — either eliminating reconvergent paths, ensuring that no competing paths exist, or using hazard-free logic design techniques such as implementing in a single fan-in stage.

9.42

"Don't happen" input combinations in async design are input state combinations that cannot physically occur — either due to circuit constraints or by design convention.

They appear as blanks or "–" in the flow table cells. For example, if inputs are R and S of a latch, the combination R=1, S=1 may be defined as a "don't happen" condition (never applied simultaneously).

These are treated as don't-care conditions during excitation equation minimization — may be assigned 0 or 1 freely to minimize logic cost — provided the circuit designer guarantees they never actually occur.

9.43

Async arbiter for two requestors r₁, r₂. Must grant mutual exclusion — only one grant active at a time.

The arbiter is an inherently asynchronous element. A simple implementation uses a cross-coupled set-reset circuit:

g₁ = r₁ AND NOT(g₂)  // can only grant 1 if 2 not granted
g₂ = r₂ AND NOT(g₁)

But this has a combinational loop (metastable when both r₁,r₂=1 simultaneously). A proper async arbiter uses a Muller C-element or bistable circuit with metastability resolution time built in. The circuit is not truly deterministic when requests arrive simultaneously — this is fundamental (proven by Lamport).

9.44

Race-free state assignment for 4-state async FSM. States A,B,C,D need binary codes such that any required transition changes only 1 bit (to avoid critical races).

Draw the transition diagram. Required transitions: e.g., A→B, B→C, C→D, D→A.

Assign codes so each transition differs by 1 bit (Gray code sequence):

A=00, B=01, C=11, D=10 (standard Gray code).

If transitions A→C or B→D are needed (2-bit change), add intermediate states or use shared-row technique (extra state codes that serve as transition intermediaries).

9.45

Async vending machine controller: primitive flow table has one row per stable state-input combination.

Example states: IDLE, GOT_NICKEL, GOT_DIME, DISPENSE. Input variables: N (nickel inserted), D (dime inserted). Output: dispense, change.

Primitive flow table: each row is a unique (state, input) pair with a stable state. Adjacent rows that are compatible are merged using the merger diagram. After merging, assign race-free state codes and derive excitation equations for each state variable using K-maps.

9.46

For a 5-state async FSM, a race-free assignment may not exist with ⌈log₂5⌉=3 bits if required transitions involve multi-bit changes.

Shared-row technique: Add "extra" (intermediate) states between problematic transitions. The extra states have unique codes that differ by 1 bit from both the source and destination, converting a 2-bit transition into two consecutive 1-bit transitions.

For example, transition A(001)→C(110) requires 3-bit change. Add intermediate state X(011) or (101): A→X→C, each step changes 1 bit. X is an unstable state for the relevant input — the circuit passes through X instantaneously on its way to C.

9.47

For a 6-row flow table (6 stable states):

  1. Build merger diagram: connect compatible state pairs.
  2. Find maximum cliques in the merger diagram — groups of mutually compatible states.
  3. Select minimum number of groups (cliques) that cover all states.
  4. Assign binary codes to merged rows; ensure race-free assignment.
  5. Derive excitation equations Y₁, Y₂ and output equations from the merged flow table using K-maps.

With 6 states, ideally merge to 2–3 rows (2 state variables), though constraints may require more.

9.48

Proof that two-level SOP has no static 0-hazards:

A static 0-hazard occurs when the output should remain 0 but briefly goes to 1. In a two-level SOP, the output is 1 only when at least one product term is 1. If the output should remain 0, all product terms must be 0 both before and after the transition. During the transition, each product term is a static function of individual gate delays — a product term can only glitch 0→1 if both its inputs are 1 simultaneously, but that would mean the function value is actually 1, not 0. Therefore, a product term cannot produce a 1-glitch when both its pre- and post-transition values are 0. Hence no static 0-hazard in SOP. ∎

When do static 0-hazards appear? In two-level POS (product of sums) implementations — hazards in the sum terms can produce 0-glitches on the output when the output should remain 0.

9.13

Treat $C, D$ as inputs and $y$ (latch state) as the only state variable. Next-state: $Y = CD + \overline{C}y$ (when $C=1$, $Y=D$; when $C=0$, $Y=y$). Excitation table over $(C,D,y)$: $Y = 0$ for $(00,0),(01,0),(10,0),(11,0)$; $Y=1$ for $(00,1),(01,1),(10,1),(11,1)$ — i.e. stable when $C=0$ regardless of $D$, transparent when $C=1$. Flow table: 2 stable states $S_1$ ($y=0$) and $S_2$ ($y=1$); $S_1\to S_2$ when $CD=11$; $S_2\to S_1$ when $CD=10$.

9.14

Two state variables $y_m, y_s$. $Y_m = CD + \overline{C}y_m$ (master latch transparent when $C=1$); $Y_s = Cy_m + \overline{C}y_s$ (slave transparent when $C=0$, copies $y_m$ when $C=1$ — actually, slave copies when $C=0$, so $Y_s = \overline{C}y_m + Cy_s$). Use the textbook's exact form. Four states $S_1\ldots S_4$ correspond to $(y_m, y_s) \in \{00, 01, 10, 11\}$. Excitation table tracks each transition under input changes; flow table shows the master loads on $C=1$, slave outputs on $C=0$ — i.e. proper edge-triggered behavior.

9.15

Tabulate $(Y_1, Y_2)$ for each $(w_1, w_2, y_1, y_2)$ combination using the given equations. Stable states (where $Y_i = y_i$): identify rows with no change. Output $z = y_1\overline{y_2}$. States: $(00)$ idle, $(01)$ first coin, $(10)$ second coin (vend pulse), back to $(00)$. On input $w_1$ (a coin), the FSM advances; on $w_2$ (a separate coin) likewise. State diagram: 3 reachable states, $z=1$ in state $10$ — vending machine that dispenses after two coins.

9.16

Four states $A, B, C, D$ (states between rising and falling edges of even/odd pulses). $A$ ($w=0$, $z=0$, even count), on $w$ rising → $B$; $B$ ($w=1$, $z=1$, odd count), on $w$ falling → $C$; $C$ ($w=0$, $z=1$), on $w$ rising → $D$; $D$ ($w=1$, $z=0$), on $w$ falling → $A$. Race-free assignment: $A=00, B=01, C=11, D=10$ (Gray code, single-bit changes around the loop). Next-state expressions: $Y_1 = w y_2 + y_1 w$ (etc., derive from K-map), output $z = y_2 \oplus y_1$ (or similar simple expression).

9.17

Eight states (rising and falling edge pair for each of 4 counts). Use a 3-bit Gray-code assignment so each transition changes one bit: $S_0 = 000, S_1 = 001, S_2 = 011, S_3 = 010, S_4 = 110, S_5 = 111, S_6 = 101, S_7 = 100$. Next-state equations $Y_3, Y_2, Y_1$ derived from the cycle $S_0\to S_1\to S_2\to\dots\to S_7\to S_0$ on alternating $w$ edges. Outputs $z_2 z_1$ encode the count modulo 4: $z_2 z_1 = 00$ in $\{S_0, S_1\}$, $01$ in $\{S_2, S_3\}$, $10$ in $\{S_4, S_5\}$, $11$ in $\{S_6, S_7\}$.

9.18

States: idle $A$, granted-1 $B$, granted-2 $C$. Diagonal transition $B \to C$ when $r_1$ falls and $r_2$ rises simultaneously is unsafe. Insert state $D$ (transient): $B \to D$ on $\overline{r_1}$, $D \to C$ on $r_2$. State assignment $A=00, B=01, C=11, D=10$ (Gray code). Outputs (Moore): $g_1=1$ in $B$ only; $g_2=1$ in $C$ only; $D$ has $g_1=g_2=0$ (safe value during transient).

9.19

Primitive flow table has many rows (one per input combination per state). Apply partitioning: group rows with the same outputs and same next-state pattern. Then build the merger diagram showing which rows have compatible (i.e., agreeing-where-defined) entries; merge maximal cliques. Result: 4 rows representing states $A$ (idle, 0¢), $B$ (5¢), $C$ (10¢ → dispense), $D$ (transient if needed). Output asserts in $C$.

9.20

Apply partitioning first: split the 12 rows by output equivalence, then by next-state equivalence iteratively. Once partitioning stabilizes, draw the merger diagram (vertices = remaining rows, edges = compatibility). Find a clique cover; merge each clique into one row. After 2-3 reductions the table typically shrinks from 12 → 6 → 4 rows.

9.21

Moore-style merging: outputs must agree row-by-row. Mealy-style merging: outputs may differ on transient transitions, so more rows are compatible. Apply partitioning first. Then compute Moore merger graph and Mealy merger graph. Mealy yields fewer states because flexibility on outputs lets more row-pairs merge; e.g., 8 rows reduce to 5 (Moore) or 3 (Mealy). Mealy wins when outputs depend strongly on input transitions.

9.22

Partition the 8 rows by output-equivalence. Build Mealy merger graph; identify a 2-clique that covers all rows (only possible if all rows are pairwise compatible after relaxing on don't-care entries). Merge to 2 rows. The reduced FSM has only 2 states; the input-output sequence is recovered by the Mealy outputs differing on transitions.

9.23

On a 2-cube vertices $00, 01, 10, 11$. Assignment $A=00, B=01, C=10, D=11$: transition $B\to C$ goes from $01$ to $10$ — diagonal (Hamming distance 2). Alternative $A=00, B=01, C=11, D=10$: transitions $A\to B$ ($00\to 01$, dist 1), $B\to C$ ($01\to 11$, dist 1), $C\to D$ ($11\to 10$, dist 1), $D\to A$ ($10\to 00$, dist 1). All single-bit changes — race free.

9.24

3 states need at least 2 state variables. Vertices on 2-cube: $00, 01, 10, 11$. With 3 used, the unused vertex isolates one transition pair. Some pair of states must lie on a diagonal — Hamming-distance-2 — causing race. Add unstable state $D$ to break the diagonal: transitions $B\to D\to C$ each Hamming distance 1. Modify the flow table accordingly: $D$ has next-state $C$ on the input that previously took $B\to C$, with output set to a safe value (e.g., both grants 0).

9.25

Flow table has 7 stable states across 4 logical states and 4 input columns. Relabel each stable instance separately ($S_1@col_1, S_1@col_2,\dots$) to enumerate 7 placements. Draw a transition diagram between the 4 logical states; identify the unspecified entry as a free placement. Use it to break a diagonal transition by routing through an empty cell. State assignment maps the 4 states onto a 2-cube without diagonals. Specify Mealy outputs in unstable cells to match the destination's stable output.

9.26

4 states all pairwise reachable → in 2-cube some transitions must be diagonal. Add 3 unstable states $E, F, G$ on the 3-cube to break each diagonal. On a 3-cube (8 vertices), place 4 logical states at vertices forming an independent-set pattern (Hamming distance 2 apart), then route each diagonal through one of $E, F, G$. The new flow table has 7 rows (4 logical + 3 unstable), and the excitation table for $Y_1, Y_2, Y_3$ implements all transitions with single-bit changes.

9.27

Replace each of the 4 states with a pair (e.g., $A\to A_1, A_2$). Now 8 states fill the 3-cube. Arrange transitions so each move is single-bit Hamming. The resulting transition diagram has no diagonal paths — every original transition between logical states maps to a 2-step path through one of the new vertex pairs. Modify the flow table to specify the second member of each pair as a transient with the same outputs.

9.28

When $C$ falls from 1 to 0, the master output $Y_m$ should hold the captured $D$ value, but the unequal delays on the $CD$ vs $\overline{C}y_m$ paths cause a momentary $Y_m=0$ glitch. The slave samples this glitch and settles into the wrong state. Fix: add the redundant prime implicants $D y_m$ to $Y_m$ (covering the adjacent 1-cells across the $C$ boundary) and $y_m y_s$ to $Y_s$. The hazard-free expressions: $Y_m = CD + \overline{C}y_m + D y_m$, $Y_s = Cy_m + \overline{C}y_s + y_m y_s$.

9.29

A static-1 hazard arises when an input change causes the only product term covering a minterm to drop momentarily before another term takes over. Only product terms covering pairs of adjacent 1s in the K-map (with the changing variable) are needed for hazard-free coverage — not all primes. For Figure 9.64, the changing-variable adjacencies are covered by $\{x_1\overline{x_3}, \overline{x_2}\overline{x_3}, x_3 x_4\}$. So $f = x_1\overline{x_3} + \overline{x_2}\overline{x_3} + x_3 x_4$ is hazard-free.

9.30

When $x_1=x_3=0$ and $x_2$ rises, sum term $(x_1+\overline{x_2}+\dots)$ drops from 1 to 0; another sum term takes over with delay, producing a $0\to 1\to 0$ glitch on the AND output. Fix: add the sum term that covers the 0-cell pair across the $x_2$ boundary — typically $(x_1+\overline{x_2}+x_3)$ (or analogous, using POS K-map adjacent zeros). The hazard-free POS includes that extra factor.

9.31

Substitute the given expressions into the excitation table over $(w_1, w_2, y_1, y_2)$. Identify stable cells (where $Y_i = y_i$). Label states. Some transitions cause both $y_1$ and $y_2$ to change simultaneously (race). For each, check if the destination is the same regardless of which variable changes first — these are safe races. The output $z=y_2$ tracks which state the FSM is in.

9.32

Plot $Y_1$ and $Y_2$ on K-maps. Identify 1-cells that are adjacent in the K-map but covered by different product terms. The pair-coverage rule says a hazard-free SOP must cover every such adjacency with some single product term. If a prime implicant is missing that covers a needed adjacency, add it. For $Y_1$, add e.g. $w_1 y_1$ as the missing implicant. For $Y_2$ similarly. Resulting hazard-free expressions include all minimum primes plus the extra ones for adjacency coverage.

9.33

4 states — $S_0$ (idle, even count), $S_1$ (just saw rising edge of 1st pulse), $S_2$ (after 1st pulse, even count, no output), $S_3$ (just saw rising edge of 2nd pulse, output asserted). Output $z=1$ in $S_3$ and during its falling edge. Race-free Gray code: $S_0=00, S_1=01, S_2=11, S_3=10$. Derive $Y_1, Y_2$ from K-map; output $z = y_1\overline{y_2}$ (or similar).

9.34

Apply partitioning: split rows by output, then refine by next-state equivalence. Suppose 8 rows → 4 after partitioning. Build Moore merger diagram; find compatible-row cliques. After merging, ~4 logical states remain. State assignment on a 3-cube: pick vertices with Hamming distance 1 between transitioning pairs (some require unstable intermediate states). Derive excitation table from the assigned next-state values.

9.35

Plot $f$ on a 5-var K-map ($\sum m + D$). Find minimum prime cover: a typical cover is $\{\overline{x_1}\overline{x_2}x_3, x_1\overline{x_2}x_4 x_5, x_1 x_2\overline{x_4}x_5, x_1\overline{x_3}x_4\}$ (4 primes). Then check pair-of-adjacent-1s coverage: identify any adjacency not covered by a single prime and add an extra prime implicant to cover it. Final hazard-free SOP includes those extras.