2017 Book IntroductionToLogicCircuitsLog PDF
2017 Book IntroductionToLogicCircuitsLog PDF
LaMeres
Introduction to
Logic Circuits
& Logic Design
with Verilog
INTRODUCTION TO LOGIC CIRCUITS &
LOGIC DESIGN WITH VERILOG
INTRODUCTION TO LOGIC CIRCUITS &
LOGIC DESIGN WITH VERILOG
1 ST E DITION
Brock J. LaMeres
Brock J. LaMeres
Department of Electrical & Computer Engineering
Montana State University
Bozeman, MT, USA
This new book addresses the lower level foundational void by providing a comprehensive, bottoms-
up, coverage of digital systems. This book begins with a description of lower level hardware including
binary representations, gate-level implementation, interfacing, and simple combinational logic design.
Only after a foundation has been laid in the underlying hardware theory is the Verilog language
introduced. The Verilog introduction gives only the basic concepts of the language in order to model,
simulate, and synthesize combinational logic. This allows the students to gain familiarity with the
language and the modern design approach without getting overwhelmed by the full capability of the
language. This book then covers sequential logic and finite state machines at the structural level. Once
this secondary foundation has been laid, the remaining capabilities of Verilog are presented that allow
sophisticated, synchronous systems to be modeled. An entire chapter is then dedicated to examples of
sequential system modeling, which allows the students to learn by example. The second part of this
textbook introduces the details of programmable logic, semiconductor memory, and arithmetic circuits.
This book culminates with a discussion of computer system design, which incorporates all of the
v
vi • Preface
knowledge gained in the previous chapters. Each component of a computer system is described with an
accompanying Verilog implementation, all while continually reinforcing the underlying hardware beneath
the HDL abstraction.
This incremental, just-in-time presentation of material allows the book to follow the way the material
is actually taught in the classroom. This design also avoids the need for the instructor to assign sections
that move back-and-forth through the text. This not only reduces course design effort for the instructor
but allows the student to know where they are in the sequence of learning. At any point, the student
should know the material in prior chapters and be moving toward understanding the material in
subsequent ones.
An additional advantage of this book’s organization is that it supports giving the student hands-on
experience with digital circuitry for courses with an accompanying laboratory component. The flow is
designed to support lab exercises that begin using discrete logic gates on a breadboard and then move
into HDL-based designs implemented on off-the-shelf FPGA boards. Using this approach to a laboratory
experience gives the student experience with the basic electrical operation of digital circuits, interfacing,
and HDL-based designs.
Learning Outcomes
Each chapter begins with an explanation of its learning objective followed by a brief preview of the
chapter topics. The specific learning outcomes are then presented for the chapter in the form of concise
statements about the measurable knowledge and/or skills the student will possess by the end of the
chapter. Each section addresses a single, specific learning outcome. This eases the process of
assessment and gives specific details on student performance. There are 600+ exercise problems
and concept check questions for each section tied directly to specific learning outcomes for both
formative and summative assessment.
Teaching by Example
With over 200 worked examples, concept checks for each section, 200+ supporting figures, and 600+
exercise problems, students are provided with multiple ways to learn. Each topic is described in a clear,
concise written form with accompanying figures as necessary. This is then followed by annotated worked
examples that match the form of the exercise problems at the end of each chapter. Additionally, concept
check questions are placed at the end of each section in this book to measure the student’s general
Preface • vii
understanding of the material using a concept inventory assessment style. These features provide the
student multiple ways to learn the material and build an understanding of digital circuitry.
Course Design
This book can be used in multiple ways. The first is to use the book to cover two, semester-based
college courses in digital logic. The first course in this sequence is an introduction to logic circuits and
covers Chaps. 1, 2, 3, 4, 5, 6, and 7. This introductory course, which is found in nearly all accredited
electrical and computer engineering programs, gives students a basic foundation in digital hardware and
interfacing. Chapters 1, 2, 3, 4, 5, 6 and 7 only cover relevant topics in digital circuits to make room for a
thorough introduction to Verilog. At the end of this course, students have a solid foundation in digital
circuits and are able to design and simulate Verilog models of concurrent and hierarchical systems. The
second course in this sequence covers logic design using Chaps. 8, 9, 10, 11, 12, and 13. In this second
course, students learn the advanced features of Verilog such as procedural assignments, sequential
behavioral modeling, system tasks, and test benches. This provides the basis for building larger digital
systems such as registers, finite state machines, and arithmetic circuits. Chapter 13 brings all of the
concepts together through the design of a simple 8-bit computer system that can be simulated and
implemented using many off-the-shelf FPGA boards.
This book can also be used in a more accelerated digital logic course that reaches a higher level of
abstraction in a single semester. This is accomplished by skipping some chapters and moving quickly
through others. In this use model, it is likely that Chap. 2 on numbers systems and Chap. 3 on digital
circuits would be quickly referenced but not covered in detail. Chapters 4 and 7 could also be covered
quickly in order to move rapidly into Verilog modeling without spending significant time looking at the
underlying hardware implementation. This approach allows a higher level of abstraction to be taught but
provides the student with the reference material so that they can delve in the details of the hardware
implementation if interested.
All exercise and concept problems that do not involve a Verilog model are designed so that they can
be implemented as a multiple choice or numeric entry question in a standard course management
system. This allows the questions to be automatically graded. For the Verilog design questions, it is
expected that the students will upload their Verilog source files and screenshots of their simulation
waveforms to the course management system for manual grading by the instructor or teaching assistant.
Instructor Resources
Instructors adopting this book can request a solution manual that contains a graphic-rich description
of the solutions for each of the 600+ exercise problems. Instructors can also receive the Verilog solutions
and test benches for each Verilog design exercise. A complementary lab manual has also been
developed to provide additional learning activities based on both the 74HC discrete logic family and
an off-the-shelf FPGA board. This manual is provided separately from the book in order to support the
ever-changing technology options available for laboratory exercises.
Dr. LaMeres is eternally grateful to his family for their support of this project. To JoAnn, your love
and friendship makes everything possible. To Alexis, your kindness and caring brings joy to my
heart. To Kylie, your humor and spirit fills me with laughter and pride. Thank you so much.
Dr. LaMeres would also like to thank the 400+ engineering students at Montana State University
that helped proof read this book in preparation for the first edition.
ix
Contents
1: INTRODUCTION: ANALOG VS. DIGITAL ........................................................... 1
1.1 DIFFERENCES BETWEEN ANALOG AND DIGITAL SYSTEMS ............................................. 1
1.2 ADVANTAGES OF DIGITAL SYSTEMS OVER ANALOG SYSTEMS ........................................ 2
2: NUMBER SYSTEMS ............................................................................................ 7
2.1 POSITIONAL NUMBER SYSTEMS ................................................................................ 7
2.1.1 Generic Structure ........................................................................................ 8
2.1.2 Decimal Number System (Base 10) ........................................................... 9
2.1.3 Binary Number System (Base 2) ................................................................ 9
2.1.4 Octal Number System (Base 8) .................................................................. 10
2.1.5 Hexadecimal Number System (Base 16) ................................................... 10
2.2 BASE CONVERSION ................................................................................................. 11
2.2.1 Converting to Decimal ................................................................................. 11
2.2.2 Converting From Decimal ........................................................................... 14
2.2.3 Converting Between 2n Bases .................................................................... 17
2.3 BINARY ARITHMETIC ................................................................................................ 21
2.3.1 Addition (Carries) ........................................................................................ 21
2.3.2 Subtraction (Borrows) ................................................................................. 22
2.4 UNSIGNED AND SIGNED NUMBERS ............................................................................ 23
2.4.1 Unsigned Numbers ..................................................................................... 24
2.4.2 Signed Numbers ......................................................................................... 24
3: DIGITAL CIRCUITRY AND INTERFACING .......................................................... 37
3.1 BASIC GATES ......................................................................................................... 37
3.1.1 Describing the Operation of a Logic Circuit ................................................ 37
3.1.2 The Buffer .................................................................................................... 39
3.1.3 The Inverter ................................................................................................. 40
3.1.4 The AND Gate ............................................................................................. 40
3.1.5 The NAND Gate .......................................................................................... 41
3.1.6 The OR Gate ............................................................................................... 41
3.1.7 The NOR Gate ............................................................................................ 41
3.1.8 The XOR Gate ............................................................................................. 42
3.1.9 The XNOR Gate .......................................................................................... 43
3.2 DIGITAL CIRCUIT OPERATION .................................................................................... 44
3.2.1 Logic Levels ................................................................................................ 44
3.2.2 Output DC Specifications ............................................................................ 45
3.2.3 Input DC Specifications ............................................................................... 46
3.2.4 Noise Margins ............................................................................................. 47
3.2.5 Power Supplies ........................................................................................... 48
3.2.6 Switching Characteristics ............................................................................ 51
3.2.7 Data Sheets ................................................................................................. 51
xi
xii • Contents
Figure 1.1 shows an example analog signal (left) and an example digital signal (right). While the
digital signal is in reality continuous, it represents a series of discrete 1 and 0 values.
Fig. 1.1
Analog (left) vs. digital (right) signals
CONCEPT CHECK
CC1.1 If a digital signal is only a discrete representation of real information, how is it possible to
produce high quality music without hearing “gaps” in the output due to the digitization
process?
(A) The gaps are present but they occur so quickly that the human ear can’t
detect them.
(B) When the digital music is converted back to analog sound the gaps are smoothed
out since an analog signal is by definition continuous.
(C) Digital information is a continuous, time-varying signal so there aren’t gaps.
(D) The gaps can be heard if the music is played slowly, but at normal speed, they
can’t be.
actual distortion of the music as it was played at the radio station, but rather electrical noise that was
coupled onto the analog signal transmitted to your radio prior to being converted back into sound by the
speakers. Since the signal in this case is analog, the speaker simply converts it in its entirety (noise +
music) into sound. In the case of digital signaling, a significant amount of noise can be added to the
signal while still preserving the original 1’s and 0’s that are being transmitted. For example, if the signal is
representing a 0, the receiver will still interpret the signal as a 0 as long as the noise doesn’t cause the
level to exceed the threshold. Once the receiver interprets the signal as a 0, it stores the encoded value
as a 0 thus ignoring any noise present during the original transmission. Figure 1.2 shows the exact same
noise added to the analog and digital signals from Fig. 1.1. The analog signal is distorted; however, the
digital signal is still able to transmit the 0’s and 1’s that represent the information.
Fig. 1.2
Noise on analog (left) and digital (right) signals
Another reason that digital systems are preferred over analog ones is the simplicity of the circuitry. In
order to produce a 1 and 0, you simply need an electrical switch. If the switch connects the output to a
voltage below the threshold, then it produces a 0. If the switch connects the output to a voltage above the
threshold, then it produces a 1. It is relatively simple to create such a switching circuit using modern
transistors. Analog circuitry, however, needs to perform the conversion of the physical quantity it is
representing (e.g., pressure, sound) into an electrical signal all the while maintaining a direct correspon-
dence between the input and output. Since analog circuits produce a direct, continuous representation of
information, they require more complicated designs to achieve linearity in the presence of environmental
variations (e.g., power supply, temperature, fabrication differences). Since digital circuits only produce a
discrete representation of the information, they can be implemented with simple switches that are only
altered when information is produced or retrieved. Figure 1.3 shows an example comparison between an
analog inverting amplifier and a digital inverter. The analog amplifier uses dozens of transistors (inside
the triangle) and two resistors to perform the inversion of the input. The digital inverter uses two
transistors that act as switches to perform the inversion.
4 • Chapter 1: Introduction: Analog vs. Digital
Fig. 1.3
Analog (left) vs. digital (right) circuits
A final reason that digital systems are being widely adopted is their reduced power consumption.
With the advent of Complementary Metal Oxide Transistors (CMOS), electrical switches can be created
that consume very little power to turn on or off and consume relatively negligible amounts of power to
keep on or off. This has allowed large scale digital systems to be fabricated without excessive levels of
power consumption. For stationary digital systems such as servers and workstations, extremely large
and complicated systems can be constructed that consume reasonable amounts of power. For portable
digital systems such as smart phones and tablets, this means useful tools can be designed that are able
to run on portable power sources. Analog circuits, on the other hand, require continuous power to
accurately convert and transmit the electrical signal representing the physical quantity. Also, the circuit
techniques that are required to compensate for variances in power supply and fabrication processes in
analog systems require additional power consumption. For these reasons, analog systems are being
replaced with digital systems wherever possible to exploit their noise immunity, simplicity and low power
consumption. While analog systems will always be needed at the transition between the physical (e.g.,
microphones, camera lenses, sensors, video displays) and the electrical world, it is anticipated that the
push toward digitization of everything in between (e.g., processing, transmission, storage) will continue.
CONCEPT CHECK
CC1.2 When does the magnitude of electrical noise on a digital signal prevent the original informa-
tion from being determined?
(A) When it causes the system to draw too much power.
(B) When the shape of the noise makes the digital signal look smooth and continuous
like a sine wave.
(C) When the magnitude of the noise is large enough that it causes the signal to
inadvertently cross the threshold voltage.
(D) It doesn’t. A digital signal can withstand any magnitude of noise.
Exercise Problems • 5
Summary
v An analog system uses a direct mapping v Using a discrete representation allows the dig-
between an electrical quantity and the infor- ital signals to be more immune to noise in
mation being processed. A digital system, on addition to requiring simple circuits that require
the other hand, uses a discrete representa- less power to perform the computations.
tion of the information.
Exercise Problems
Section 1.1: Differences Between Analog 1.1.9 Is the physical interface on the touch display of
an iPod analog or digital?
and Digital Systems
1.1.10 Take a look around right now and identify two
1.1.1 If an electrical signal is a direct function of a
digital technologies in use.
physical quantity, is it considered analog or
digital? 1.1.11 Take a look around right now and identify two
analog technologies in use.
1.1.2 If an electrical signal is a discrete representa-
tion of information, is it considered analog or
digital? Section 1.2: Advantages of Digital
1.1.3 What part of any system will always require an Systems over Analog Systems
analog component? 1.2.1 Give three advantages of using digital systems
1.1.4 Is the sound coming out of earbuds analog or over analog.
digital? 1.2.2 Name a technology or device that has evolved
1.1.5 Is the MP3 file stored on an iPod analog or from analog to digital in your lifetime.
digital? 1.2.3 Name an analog technology or device that has
1.1.6 Is the circuitry that reads the MP3 file from become obsolete in your lifetime.
memory in an iPod analog or digital? 1.2.4 Name an analog technology or device that has
1.1.7 Is the electrical signal that travels down ear- been replaced by digital technology but is still
phone wires analog or digital? in use due to nostalgia.
1.1.8 Is the voltage coming out of the battery in an 1.2.5 Name a technology or device invented in your
iPod analog or digital? lifetime that could not have been possible with-
out digital technology.
Chapter 2: Number Systems
Logic circuits are used to generate and transmit 1’s and 0’s to compute and convey information. This
two-valued number system is called binary. As presented earlier, there are many advantages of using a
binary system; however, the human brain has been taught to count, label and measure using the
decimal number system. The decimal number system contains 10 unique symbols (0 ! 9) commonly
referred to as the Arabic numerals. Each of these symbols is assigned a relative magnitude to the other
symbols. For example, 0 is less than 1, 1 is less than 2, etc. It is often conjectured that the 10 symbol
number system that we humans use is due to the availability of our 10 fingers (or digits) to visualize
counting up to 10. Regardless, our brains are trained to think of the real world in terms of a decimal
system. In order to bridge the gap between the way our brains think (decimal) and how we build our
computers (binary), we need to understand the basics of number systems. This includes the formal
definition of a positional number system and how it can be extended to accommodate any arbitrarily large
(or small) value. This also includes how to convert between different number systems that contain
different numbers of symbols. In this chapter, we cover 4 different number systems: decimal
(10 symbols), binary (2 symbols), octal (8 symbols), and hexadecimal (16 symbols). The study of
decimal and binary is obvious as they represent how our brains interpret the physical world (decimal)
and how our computers work (binary). Hexadecimal is studied because it is a useful means to represent
large sets of binary values using a manageable number of symbols. Octal is rarely used but is studied as
an example of how the formalization of the number systems can be applied to all systems regardless of
the number of symbols they contain. This chapter will also discuss how to perform basic arithmetic in the
binary number system and represent negative numbers. The goal of this chapter is to provide an
understanding of the basic principles of binary number systems.
Learning Outcomes—After completing this chapter, you will be able to:
First, let’s look at the formation of a number system. The first thing that is needed is a set of symbols.
The formal term for one of the symbols in a number system is a numeral. One or more numerals are used
to form a number. We define the number of numerals in the system using the terms radix or base.
For example, our decimal number system is said to be base 10, or have a radix of 10 because it consists
of 10 unique numerals or symbols.
The next thing that is needed is the relative value of each numeral with respect to the other numerals
in the set. We can say 0 < 1 < 2 < 3 etc. to define the relative magnitudes of the numerals in this set. The
numerals are defined to be greater or less than their neighbors by a magnitude of 1. For example, in the
decimal number system each of the subsequent numerals is greater than its predecessor by exactly
1. When we define this relative magnitude we are defining that the numeral 1 is greater than the numeral
0 by a magnitude of 1; the numeral 2 is greater than the numeral 1 by a magnitude of 1, etc. At this point
we have the ability to count from 0 to 9 by 1’s. We also have the basic structure for mathematical
operations that have results that fall within the numeral set from 0 to 9 (e.g., 1 + 2 ¼ 3). In order to expand
the values that these numerals can represent, we need define the rules of a positional number system.
Fig. 2.1
Definition of radix point
Next, we need to define the position of each numeral with respect to the radix point. The position of
the numeral is assigned a whole number with the number to the left of the radix point having a position
value of 0. The position number increases by 1 as numerals are added to the left (2, 3, 4. . .) and
decreased by 1 as numerals are added to the right (1, 2, 3). We will use the variable p to represent
position. The position number will be used to calculate the value of each numeral in the number based on
its relative position to the radix point. Figure 2.2 shows the example number with the position value of
each numeral highlighted.
Fig. 2.2
Definition of position number (p) within the number
2.1 Positional Number Systems • 9
In order to create a generalized format of a number, we assign the term digit (d) to each of the
numerals in the number. The term digit signifies that the numeral has a position. The position of the digit
within the number is denoted as a subscript. The term digit can be used as a generic term to describe a
numeral across all systems, although some number systems will use a unique term instead of digit which
indicates its base. For example, the binary system uses the term bit instead of digit; however, using the
term digit to describe a generic numeral in any system is still acceptable. Figure 2.3 shows the generic
subscript notation used to describe the position of each digit in the number.
Fig. 2.3
Digit notation
We write a number from left to right starting with the highest position digit that is greater than 0 and
end with the lowest position digit that is greater than 0. This reduces the amount of numerals that are
written; however, a number can be represented with an arbitrary number of 0’s to the left of the highest
position digit greater than 0 and an arbitrary number of 0’s to the right of the lowest position digit greater
than 0 without affecting the value of the number. For example, the number 132.654 could be written as
0132.6540 without affecting the value of the number. The 0’s to the left of the number are called leading
0’s and the 0’s to the right of the number are called trailing 0’s. The reason this is being stated is because
when a number is implemented in circuitry, the number of numerals is fixed and each numeral must have
a value. The variable n is used to represent the number of numerals in a number. If a number is defined
with n ¼ 4, that means 4 numerals are always used. The number 0 would be represented as 0000 with
both representations having an equal value.
Due to the need for multiple bits to represent meaningful information, there are terms dedicated to
describe the number of bits in a group. When 4 bits are grouped together, they are called a nibble. When
8 bits are grouped together, they are called a byte. Larger groupings of bits are called words. The size of
the word can be stated as either an n-bit word or omitted if the size of the word is inherently implied. For
example, if you were using a 32-bit microprocessor, using the term word would be interpreted as a 32-bit
word. For example, if there was a 32-bit grouping, it would be referred to as a 32-bit word. The leftmost bit
10 • Chapter 2: Number Systems
in a binary number is called the Most Significant Bit (MSB). The rightmost bit in a binary number is
called the Least Significant Bit (LSB).
At this point, it becomes necessary to indicate the base of a written number. The number 10 has an
entirely different value if it is a decimal number or binary number. In order to handle this, a subscript is
typically included at the end of the number to denote its base. For example, 1010 indicates that this
number is decimal “ten”. If the number was written as 102, this number would represent binary “one zero”.
Table 2.1 lists the equivalent values in each of the 4 number systems just described for counts from 010 to
1510. The left side of the table does not include leading 0’s. The right side of the table contains the same
information but includes the leading zeros. The equivalencies of decimal, binary and hexadecimal in this
table are typically committed to memory.
Table 2.1
Number system equivalency
2.2 Base Conversion • 11
CONCEPT CHECK
CC2.1 The base of a number system is arbitrary and is commonly selected to match a particular
aspect of the physical system in which it is used (e.g., base 10 corresponds to our 10 fingers,
base 2 corresponds to the 2 states of a switch). If a physical system contained 3 unique
modes and a base of 3 was chosen for the number system, what is the base 3 equivalent of
the decimal number 3?
(A) 310 ¼ 113 (B) 310 ¼ 33 (C) 310 ¼ 103 (D) 310 ¼ 213
Weight ¼ ðRadixÞp
This expression gives the number system the ability to represent fractional numbers since an
expression with a negative exponent (e.g., xy) is evaluated as one over the expression with the
exponent change to positive (e.g., 1/xy). Figure 2.4 shows the generic structure of a number with its
positional weight highlighted.
Fig. 2.4
Weight definition
In order to find the decimal value of each of the numerals in the number, its individual numeral value
is multiplied by its positional weight. In order to find the value of the entire number, each value of the
individual numeral-weight products is summed. The generalized format of this conversion is written as:
X
pmax
Total Decimal Value ¼ di ðradixÞi
i¼pmin
In this expression, pmax represents the highest position number that contains a numeral greater
than 0. The variable pmin represents the lowest position number that contains a numeral greater than 0.
These limits are used to simplify the hand calculations; however, these terms theoretically could be +1
12 • Chapter 2: Number Systems
to 1 with no effect on the result since the summation of every leading 0 and every trailing 0 contributes
nothing to the result.
As an example, let’s evaluate this expression for a decimal number. The result will yield the original
number but will illustrate how positional weight is used. Let’s take the number 132.65410. To find the
decimal value of this number, each numeral is multiplied by its positional weight and then all of
the products are summed. The positional weight for the digit 1 is (radix)p or (10)2. In decimal this is
called the hundred’s position. The positional weight for the digit 3 is (10)1, referred to as the ten’s position.
The positional weight for digit 2 is (10)0, referred to as the one’s position. The positional weight for digit
6 is (10)1, referred to as the tenth’s position. The positional weight for digit 5 is (10)2, referred to as the
hundredth’s position. The positional weight for digit 4 is (10)3, referred to as the thousandth’s position.
When these weights are multiplied by their respective digits and summed, the result is the original
decimal number 132.65410. Example 2.1 shows this process step-by-step.
Example 2.1
Converting decimal to decimal
Example 2.2
Converting binary to decimal
Example 2.3
Converting octal to decimal
14 • Chapter 2: Number Systems
Example 2.4
Converting hexadecimal to decimal
The process for converting the fractional portion is to multiply just the fractional component of the
number by the base. This will result in a product that contains a whole number and a fraction. The whole
number is recorded as the most significant digit of the new converted number. The new fractional portion
is then multiplied again by the base with the whole number portion being recorded as the next lower order
numeral. This process is repeated until the product yields a fractional component equal to zero or the
desired level of accuracy has been achieved. The level of accuracy is specified by the number of
numerals in the new converted number. For example, the conversion would be stated as “convert this
decimal number to binary with a fractional accuracy of 4 bits”. This means the algorithm would stop once
4-bits of fraction had been achieved in the conversion.
2.2 Base Conversion • 15
Example 2.5
Converting decimal to binary
Example 2.6
Converting decimal to octal
Example 2.7
Converting decimal to hexadecimal
Example 2.8
Converting binary to octal
Example 2.9
Converting binary to hexadecimal
from the converted number once complete. Example 2.10 shows the step-by-step process of converting
an octal number to binary.
Example 2.10
Converting octal to binary
Example 2.11
Converting hexadecimal to binary
Example 2.12
Converting octal to hexadecimal
Example 2.13
Converting hexadecimal to octal
2.3 Binary Arithmetic • 21
CONCEPT CHECK
CC2.2 A “googol” is the term for the decimal number 1e100. When written out manually this number
is a 1 with 100 zeros after it (e.g., 10,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000).
This term is more commonly associated with the search engine company Google, which uses a
different spelling but is pronounced the same. How many bits does it take to represent a googol in
binary?
(A) 100 bits (B) 256 bits (C) 332 bits (D) 333 bits
Example 2.14
Single bit binary addition
When performing binary addition, the width of the inputs and output is fixed (i.e., n-bits). Carries that
exist within the n-bits are treated in the normal fashion of including them in the next higher position sum;
however, if the highest position summation produces a carry, this is a uniquely named event. This event
is called a carry out or the sum is said to generate a carry. The reason this type of event is given special
terminology is because in real circuitry, the number of bits of the inputs and output is fixed in hardware
and the carry out is typically handled by a separate circuit. Example 2.15 shows this process when
adding two 4-bit numbers.
22 • Chapter 2: Number Systems
Example 2.15
Multiple bit binary addition
The largest decimal sum that can result from the addition of two binary numbers is given by
2(2n1). For example, two 8-bit numbers to be added could both represent their highest decimal value
of (2n1) or 25510 (i.e., 1111 11112). The sum of this number would result in 51010 or (1 1111 11102).
Notice that the largest sum achievable would only require one additional bit. This means that a single
carry bit is sufficient to handle all possible magnitudes for binary addition.
Example 2.16
Single bit binary subtraction
As with binary addition, binary subtraction is accomplished on fixed widths of inputs and output (i.e.,
n-bits). The minuend and subtrahend are aligned at the radix point and subtraction begins at the least
significant bit position. Borrows are used as necessary as the subtractions move from the least signifi-
cant position to the most significant position. If the most significant position requires a borrow, this is a
uniquely named event. This event is called a borrow in or the subtraction is said to require a borrow.
Again, the reason this event is uniquely named is because in real circuitry, the number of bits of the input
2.4 Unsigned and Signed Numbers • 23
and output is fixed in hardware and the borrow in is typically handled by a separate circuit. Example 2.17
shows this process when subtracting two 4-bit numbers.
Example 2.17
Multiple bit binary subtraction
Notice that if the minuend is less than the subtrahend, then the difference will be negative. At this
point, we need a way to handle negative numbers.
CONCEPT CHECK
CC2.3 If an 8-bit computer system can only perform unsigned addition on 8-bit inputs and produce an
8-bit sum, how is it possible for this computer to perform addition on numbers that are larger than
what can be represented with 8-bits (e.g., 1,00010 + 1,00010 ¼ 2,00010)?
(A) There are multiple 8-bit adders in a computer to handle large numbers.
(B) The result is simply rounded to the nearest 8-bit number.
(C) The computer returns an error and requires smaller numbers to be entered.
(D) The computer keeps track of the carry out and uses it in a subsequent 8-bit
addition, which enables larger numbers to be handled.
For example, if we had an unsigned number with n ¼ 4, it could take on a range of values from +010
(00002) to +1510 (11112). Notice that while this number has 16 unique possible codes, the highest
decimal value it can represent is 1510. This is because one of the unique codes represents 010. This is
the reason that the highest decimal value that can be represented is given by (2n1). Example 2.18
shows this process for a 16-bit number.
Example 2.18
Finding the range of an unsigned number
Example 2.19
Decimal values that a 4-bit, signed magnitude code can represent
There are drawbacks of signed magnitude encoding that are apparent from this example. First, the
value of 010 has two signed magnitude codes (00002 and 10002). This is an inefficient use of the
available codes and leads to complexity when building arithmetic circuitry since it must account for
two codes representing the same number.
The second drawback is that addition using the negative numbers does not directly map to how
decimal addition works. For example, in decimal if we added (5) + (1), the result would be 4. In signed
magnitude, adding these numbers using a traditional adder would produce (5) + (1) ¼ (6). This is
because the traditional addition would take place on the magnitude portion of the number. A 510 is
represented with 1012. Adding 1 to this number would result in the next higher binary code 1102 or 610.
Since the sign portion is separate, the addition is performed on |5|, thus yielding 6. Once the sign bit is
included, the resulting number is 6. It is certainly possible to build an addition circuit that works on
signed magnitude numbers, but it is more complex than a traditional adder because it must perform a
different addition operation for the negative numbers versus the positive numbers. It is advantageous to
have a single adder that works across the entire set of numbers.
Due to the duplicate codes for 0, the range of decimal numbers that signed magnitude can represent
is reduced by 1 compared to unsigned encoding. For an n-bit number, there are 2n unique binary codes
available but only 2n1 can be used to represent unique decimal numbers. If we use the notation NSM to
represent any possible value that an n-bit, signed magnitude number can take on, the range would be
defined as:
Range of a SIGNED MAGNITUDE number ) 2n1 1 NSM þ 2n1 1
26 • Chapter 2: Number Systems
Example 2.20 shows how to use this expression to find the range of decimal values that an 8-bit,
signed magnitude code can represent.
Example 2.20
Finding the range of a signed magnitude number
The process to determine the decimal value from a signed magnitude binary code involves treating
the sign bit separately from the rest of the code. The sign bit provides the polarity of the decimal number
(0 ¼ Positive, 1 ¼ Negative). The remaining bits in the code are treated as unsigned numbers and
converted to decimal using the standard conversion procedure described in the prior sections. This
conversion yields the magnitude of the decimal number. The final decimal value is found by applying the
sign. Example 2.21 shows an example of this process.
Example 2.21
Finding the decimal value of a signed magnitude number
the value of the number, but in this encoding scheme the negative number values are less intuitive. As an
example of this approach, let’s look at the decimal values that a 4-bit, one’s complement number can
take on. These are shown in Example 2.22.
Example 2.22
Decimal values that a 4-bit, one’s complement code can represent
Again, we notice that there are two different codes for 010 (00002 and 11112). This is a drawback of
one’s complement because it reduces the possible range of numbers that can be represented from 2n to
(2n1) and requires arithmetic operations that take into account the gap in the number system. There are
advantages of one’s complement, however. First, the numbers are ordered such that traditional addition
works on both positive and negative numbers (excluding the double 0 gap). Taking the example of
(5) + (1) again, in one’s complement the result yields 4, just as in a traditional decimal system. Notice
in one’s complement, 510 is represented with 10102. Adding 1 to this entire binary code would result in
the next higher binary code 10112 or 410 from the above table. This makes addition circuitry less
complicated, but still not as simple as if the double 0 gap was eliminated. Another advantage of one’s
complement is that as the numbers are incremented beyond the largest value in the set, they roll over
and start counting at the lowest number. For example, if you increment the number 01112 (710), it goes to
the next higher binary code 10002, which is 710. The ability to have the numbers roll over is a useful
feature for computer systems.
If we use the notation N1comp to represent any possible value that an n-bit, one’s complement
number can take on, the range is defined as:
Range of a ONE’S COMPLEMENT number ) 2n1 1 N1’s comp þ 2n1 1
Example 2.23 shows how to use this expression to find the range of decimal values that a 24-bit,
one’s complement code can represent.
28 • Chapter 2: Number Systems
Example 2.23
Finding the range of a 1’s complement number
The process of finding the decimal value of a one’s complement number involves first identifying
whether the number is positive or negative by looking at the sign bit. If the number is positive (i.e., the sign
bit is 0), then the number is treated as an unsigned code and is converted to decimal using the standard
conversion procedure described in prior sections. If the number is negative (i.e., the sign bit is 1), then the
number sign is recorded separately and the code is complemented in order to convert it to its positive
magnitude equivalent. This new positive number is then converted to decimal using the standard conver-
sion procedure. As the final step, the sign is applied. Example 2.24 shows an example of this process.
Example 2.24
Finding the decimal value of a 1’s complement number
that the double 0 gap is eliminated. Taking the two’s complement of a positive number will give its
negative counterpart and vice versa. Let’s look at the decimal values that a 4-bit, two’s complement
number can take on. These are shown in Example 2.25.
Example 2.25
Decimal values that a 4-bit, two’s complement code can represent
There are many advantages of two’s complement encoding. First, there is no double 0 gap, which
means that all possible 2n unique codes that can exist in an n-bit number are used. This gives the largest
possible range of numbers that can be represented. Another advantage of two’s complement is that
addition with negative numbers works exactly the same as decimal. In our example of (5) + (1), the
result (4). Arithmetic circuitry can be built to mimic the way our decimal arithmetic works without the
need to consider the double 0 gap. Finally, the rollover characteristic is preserved from one’s comple-
ment. Incrementing +7 by +1 will result in 8.
If we use the notation N2comp to represent any possible value that an n-bit, two’s complement
number can take on, the range is defined as:
Range of a TWO’S COMPLEMENT number ) 2n1 N2’s comp þ 2n1 1
Example 2.26 shows how to use this expression to find the range of decimal values that a 32-bit,
two’s complement code can represent.
30 • Chapter 2: Number Systems
Example 2.26
Finding the range of a two’s complement number
The process of finding the decimal value of a two’s complement number involves first identifying
whether the number is positive or negative by looking at the sign bit. If the number is positive (i.e., the
sign bit is 0), then the number is treated as an unsigned code and is converted to decimal using
the standard conversion procedure described in prior sections. If the number is negative (i.e., the sign
bit is 1), then the number sign is recorded separately and a two’s complement is performed on the code in
order to convert it to its positive magnitude equivalent. This new positive number is then converted to
decimal using the standard conversion procedure. The final step is to apply the sign. Example 2.27
shows an example of this process.
Example 2.27
Finding the decimal value of a two’s complement number
To convert a decimal number into its two’s complement code, the range is first checked to determine
whether the number can be represented with the allocated number of bits. The next step is to convert the
decimal number into unsigned binary. The final step is to apply the sign bit. If the original decimal number
was positive, then the conversion is complete. If the original decimal number was negative, then the
two’s complement is taken on the unsigned binary code to find its negative equivalent. Example 2.28
shows this procedure when converting 9910 to its 8-bit, two’s complement code.
2.4 Unsigned and Signed Numbers • 31
Example 2.28
Finding the two’s complement code of a decimal number
There are specific rules for performing two’s complement arithmetic that must be followed to ensure
proper results. First, any carry or borrow that is generated is ignored. The second rule that must be
followed is to always check if two’s complement overflow occurred. Two’s complement overflow refers
to when the result of the operation falls outside of the range of values that can be represented by the
number of bits being used. For example, if you are performing 8-bit, two’s complement addition,
the range of decimal values that can be represented is 12810 to +12710. Having two input terms of
12710 (0111 11112) is perfectly legal because they can be represented by the 8-bits of the two’s
32 • Chapter 2: Number Systems
complement number; however, the summation of 12710 + 12710 ¼ 25410 (1111 11102). This number does
not fit within the range of values that can be represented and is actually the two’s complement code for
210, which is obviously incorrect. Two’s complement overflow occurs if any of the following occurs:
• The sum of like signs results in an answer with opposite sign (i.e., Positive + Positive ¼ Neg-
ative or Negative + Negative ¼ Positive)
• The subtraction of a positive number from a negative number results in a positive number (i.e.,
Negative – Positive ¼ Positive)
• The subtraction of a negative number from a positive number results in a negative number (i.e.,
Positive – Negative ¼ Negative)
Computer systems that use two’s complement have a dedicated logic circuit that monitors for any of
these situations and lets the operator know that overflow has occurred. These circuits are straightforward
since they simply monitor the sign bits of the input and output codes. Example 2.29 shows how to use
two’s complement in order to perform subtraction using an addition operation.
Example 2.29
Two’s complement addition
Exercise Problems • 33
CONCEPT CHECK
CC2.4 A 4-bit, two’s complement number has 16 unique codes and can represent decimal numbers
between 810 to +710. If the number of unique codes is even, why is it that the range of
integers it can represent is not symmetrical about zero?
(A) One of the positive codes is used to represent zero. This prevents the highest
positive number from reaching +810 and being symmetrical.
(B) It is asymmetrical because the system allows the numbers to roll over.
(C) It isn’t asymmetrical if zero is considered a positive integer. That way there are
eight positive numbers and eight negatives numbers.
(D) It is asymmetrical because there are duplicate codes for 0.
Summary
v The base, or radix, of a number system refers v Binary codes can represent both unsigned
to the number of unique symbols within its and signed numbers. For an arbitrary n-bit
set. The definition of a number system binary code, it is important to know the
includes both the symbols used and the rela- encoding technique and the range of values
tive values of each symbol within the set. that can be represented.
v The most common number systems are base v Signed numbers use the most significant
10 (decimal), base 2 (binary), and base position to represent whether the number is
16 (hexadecimal). Base 10 is used because negative (0 ¼ positive, 1 ¼ negative). The
it is how the human brain has been trained to width of a signed number is always fixed.
treat numbers. Base 2 is used because the v Two’s complement is the most common
two values are easily represented using elec- encoding technique for signed numbers. It
trical switches. Base 16 is a convenient way has an advantage that there are no duplicate
to describe large groups of bits. codes for zero and that the encoding
v A positional number system allows larger approach provides a monotonic progression
(or smaller) numbers to be represented of codes from the most negative number that
beyond the values within the original symbol can be represented to the most positive. This
set. This is accomplished by having each posi- allows addition and subtraction to work the
tion within a number have a different weight. same on two’s complement numbers as it
v There are specific algorithms that are used to does on unsigned numbers.
convert any base to or from decimal. There v When performing arithmetic using two’s com-
are also algorithms to convert between num- plement codes, the carry bit is ignored.
ber systems that contain a power-of-two v When performing arithmetic using two’s com-
symbols (e.g., binary to hexadecimal and plement codes, if the result lies outside of the
hexadecimal to binary). range that can be represented it is called
v Binary arithmetic is performed on a fixed width two’s complement overflow. Two’s comple-
of bits (n). When an n-bit addition results in a ment overflow can be determined by looking
sum that cannot fit within n-bits, it generates a at the sign bits of the input arguments and the
carry out bit. In an n-bit subtraction, if the min- sign bit of the result.
uend is smaller than the subtrahend, a borrow
in can be used to complete the operation.
Exercise Problems
Section 2.1: Positional Number Systems 2.1.3 What is the radix of the hexadecimal number
system?
2.1.1 What is the radix of the binary number system?
2.1.4 What is the radix of the octal number system?
2.1.2 What is the radix of the decimal number
system? 2.1.5 For the number 261.367, what position (p) is
the number 2 in?
34 • Chapter 2: Number Systems
2.1.6 For the number 261.367, what position (p) is 2.2.11 Convert 6710 to binary. Treat all numbers as
the number 1 in? unsigned.
2.1.7 For the number 261.367, what position (p) is 2.2.12 Convert 252.98710 to binary. Treat all numbers
the number 3 in? as unsigned. Use an accuracy of 4 fractional
2.1.8 For the number 261.367, what position (p) is bits and don’t round up.
the number 7 in? 2.2.13 Convert 6710 to octal. Treat all numbers as
2.1.9 What is the name of the number system unsigned.
containing 102? 2.2.14 Convert 252.98710 to octal. Treat all numbers
2.1.10 What is the name of the number system as unsigned. Use an accuracy of 4 fractional
containing 1010? digits and don’t round up.
2.1.11 What is the name of the number system 2.2.15 Convert 6710 to hexadecimal. Treat all num-
containing 1016? bers as unsigned.
2.1.12 What is the name of the number system 2.2.16 Convert 252.98710 to hexadecimal. Treat all
containing 108? numbers as unsigned. Use an accuracy of
4 fractional digits and don’t round up.
2.1.13 Which of the four number systems covered in
this chapter (i.e., binary, decimal, hexadecimal, 2.2.17 Convert 1 0000 11112 to octal. Treat all num-
and octal) could the number 22 be part of? bers as unsigned.
Give all that are possible. 2.2.18 Convert 1 0000 1111.0112 to hexadecimal.
2.1.14 Which of the four number systems covered in Treat all numbers as unsigned.
this chapter (i.e., binary, decimal, hexadecimal, 2.2.19 Convert 778 to binary. Treat all numbers as
and octal) could the number 99 be part of? unsigned.
Give all that are possible. 2.2.20 Convert F.A16 to binary. Treat all numbers as
2.1.15 Which of the four number systems covered in unsigned.
this chapter (i.e., binary, decimal, hexadecimal, 2.2.21 Convert 668 to hexadecimal. Treat all numbers
and octal) could the number 1F be part of? as unsigned.
Give all that are possible.
2.2.22 Convert AB.D16 to octal. Treat all numbers as
2.1.16 Which of the four number systems covered in unsigned.
this chapter (i.e., binary, decimal, hexadecimal,
and octal) could the number 88 be part of?
Give all that are possible. Section 2.3: Binary Arithmetic
2.3.1 Compute 10102 + 10112 by hand. Treat all
Section 2.2: Base Conversions numbers as unsigned. Provide the 4-bit sum
and indicate whether a carry out occurred.
2.2.1 If the number 101.111 has a radix of 2,
what is the weight of the position containing 2.3.2 Compute 1111 11112 + 0000 00012 by hand.
the bit 0? Treat all numbers as unsigned. Provide the 8-bit
sum and indicate whether a carry out occurred.
2.2.2 If the number 261.367 has a radix of 10, what is
the weight of the position containing the 2.3.3 Compute 1010.10102 + 1011.10112 by hand.
numeral 2? Treat all numbers as unsigned. Provide the 8-bit
sum and indicate whether a carry out occurred.
2.2.3 If the number 261.367 has a radix of 16, what is
the weight of the position containing the 2.3.4 Compute 1111 1111.10112 + 0000 0001.11002
numeral 1? by hand. Treat all numbers as unsigned. Pro-
vide the 12-bit sum and indicate whether a
2.2.4 If the number 261.367 has a radix of 8, what is carry out occurred.
the weight of the position containing the
numeral 3? 2.3.5 Compute 10102 10112 by hand. Treat all
numbers as unsigned. Provide the 4-bit differ-
2.2.5 Convert 1100 11002 to decimal. Treat all num- ence and indicate whether a borrow in
bers as unsigned. occurred.
2.2.6 Convert 1001.10012 to decimal. Treat all num- 2.3.6 Compute 1111 11112 0000 00012 by hand.
bers as unsigned. Treat all numbers as unsigned. Provide the
2.2.7 Convert 728 to decimal. Treat all numbers as 8-bit difference and indicate whether a borrow
unsigned. in occurred.
2.2.8 Convert 12.578 to decimal. Treat all numbers 2.3.7 Compute 1010.10102 1011.10112 by hand.
as unsigned. Treat all numbers as unsigned. Provide the
2.2.9 Convert F316 to decimal. Treat all numbers as 8-bit difference and indicate whether a borrow
unsigned. in occurred.
2.2.10 Convert 15B.CEF16 to decimal. Treat all num- 2.3.8 Compute 1111 1111.10112 0000 0001.11002
bers as unsigned. Use an accuracy of 7 frac- by hand. Treat all numbers as unsigned. Pro-
tional digits. vide the 12-bit difference and indicate whether
a borrow in occurred.
Exercise Problems • 35
Section 2.4: Unsigned and Signed 2.4.17 Compute 410 – 510 using 4-bit two’s comple-
ment addition. You will need to first convert
Numbers
each number into its 4-bit two’s complement
2.4.1 What range of decimal numbers can be code and then perform binary addition (i.e.,
represented by 8-bit, two’s complement 410 + (510)). Provide the 4-bit result and indi-
numbers? cate whether two’s complement overflow
2.4.2 What range of decimal numbers can be occurred. Check your work by converting the
represented by 16-bit, two’s complement 4-bit result back to decimal.
numbers? 2.4.18 Compute 710 710 using 4-bit two’s comple-
2.4.3 What range of decimal numbers can be ment addition. You will need to first convert
represented by 32-bit, two’s complement each decimal number into its 4-bit two’s com-
numbers? plement code and then perform binary addition
(i.e., 710 + (710)). Provide the 4-bit result and
2.4.4 What range of decimal numbers can be
indicate whether two’s complement overflow
represented by 64-bit, two’s complement
occurred. Check your work by converting the
numbers?
4-bit result back to decimal.
2.4.5 What is the 8-bit, two’s complement code for
2.4.19 Compute 710 + 110 using 4-bit two’s comple-
+8810?
ment addition. You will need to first convert
2.4.6 What is the 8-bit, two’s complement code for each decimal number into its 4-bit two’s com-
8810? plement code and then perform binary addi-
2.4.7 What is the 8-bit, two’s complement code tion. Provide the 4-bit result and indicate
for 12810? whether two’s complement overflow occurred.
2.4.8 What is the 8-bit, two’s complement code Check your work by converting the 4-bit result
for 110? back to decimal.
2.4.9 What is the decimal value of the 4-bit, two’s 2.4.20 Compute 6410 10010 using 8-bit two’s com-
complement code 00102? plement addition. You will need to first convert
each number into its 8-bit two’s complement
2.4.10 What is the decimal value of the 4-bit, two’s code and then perform binary addition (i.e.,
complement code 10102? 6410 + (10010)). Provide the 8-bit result and
2.4.11 What is the decimal value of the 8-bit, two’s indicate whether two’s complement overflow
complement code 0111 11102? occurred. Check your work by converting the
2.4.12 What is the decimal value of the 8-bit, two’s 8-bit result back to decimal.
complement code 1111 11102? 2.4.21 Compute (99)10 1110 using 8-bit two’s com-
2.4.13 Compute 11102 + 10112 by hand. Treat all plement addition. You will need to first convert
numbers as 4-bit, two’s complement codes. each decimal number into its 8-bit two’s com-
Provide the 4-bit sum and indicate whether plement code and then perform binary addition
two’s complement overflow occurred. (i.e., (9910) + (1110)). Provide the 8-bit result
and indicate whether two’s complement over-
2.4.14 Compute 1101 11112 + 0000 00012 by hand. flow occurred. Check your work by converting
Treat all numbers as 8-bit, two’s complement the 8-bit result back to decimal.
codes. Provide the 8-bit sum and indicate
whether two’s complement overflow occurred. 2.4.22 Compute 5010 + 10010 using 8-bit two’s com-
plement addition. You will need to first convert
2.4.15 Compute 1010.10102 + 1000.10112 by hand. each decimal number into its 8-bit two’s com-
Treat all numbers as 8-bit, two’s complement plement code and then perform binary addi-
codes. Provide the 8-bit sum and indicate tion. Provide the 8-bit result and indicate
whether two’s complement overflow occurred. whether two’s complement overflow occurred.
2.4.16 Compute 1110 1011.10012 + 0010 0001.11012 Check your work by converting the 8-bit result
by hand. Treat all numbers as 12-bit, two’s back to decimal.
complement codes. Provide the 12-bit sum
and indicate whether two’s complement over-
flow occurred.
Chapter 3: Digital Circuitry
and Interfacing
Now we turn our attention to the physical circuitry and electrical quantities that are used to represent
and operate on the binary codes 1 and 0. In this chapter we begin by looking at how logic circuits are
described and introduce the basic set of gates used for all digital logic operations. We then look at the
underlying circuitry that implements the basic gates including digital signaling and how voltages are used
to represent 1’s and 0’s. We then look at interfacing between two digital circuits and how to ensure that
when one circuit sends a binary code, the receiving circuit is able to determine which code was sent.
Logic families are then introduced and the details of how basic gates are implemented at the switch level
are presented. Finally, interfacing considerations are covered for the most common types of digital loads
(i.e., other gates, resistors, and LEDs). The goal of this chapter is to provide an understanding of the
basic electrical operation of digital circuits.
Learning Outcomes—After completing this chapter, you will be able to:
3.1 Describe the functional operation of a basic logic gate using truth tables, logic expressions,
and logic waveforms.
3.2 Analyze the DC and AC behavior of a digital circuit to verify it is operating within
specification.
3.3 Describe the meaning of a logic family and the operation of the most common technologies
used today.
3.4 Determine the operating conditions of a logic circuit when driving various types of loads.
Fig. 3.1
Example logic symbols
Fig. 3.2
Truth table formation
Fig. 3.3
Logic function formation
Fig. 3.4
Example logic waveform
Fig. 3.5
Buffer symbol, truth table, logic function and logic waveform
40 • Chapter 3: Digital Circuitry and Interfacing
Fig. 3.6
Inverter symbol, truth table, logic function and logic waveform
Fig. 3.7
2-Input AND gate symbol, truth table, logic function and logic waveform
Ideal AND gates can have any number of inputs. The operation of an n-bit, AND gates still follows
the rule that the output will only be true when all of the inputs are true. Later sections will discuss the
limitations on expanding the number of inputs of these basic gates indefinitely.
3.1 Basic Gates • 41
Fig. 3.8
2-Input NAND gate symbol, truth table, logic function and logic waveform
Fig. 3.9
2-Input OR gate symbol, truth table, logic function and logic waveform
Fig. 3.10
2-Input NOR gate symbol, truth table, logic function and logic waveform
Fig. 3.11
2-Input XOR gate symbol, truth table, logic function and logic waveform
Using the formal definition of an XOR gate (i.e., the output is true if any of the input codes are
different from one another), an XOR gate with more than two inputs can be built. The truth table for a
3-bit, XOR gate using this definition is shown in Fig. 3.12. In modern electronics, this type of gate has
found little use since it is much simpler to build this functionality using a combination of AND and OR
gates. As such, XOR gates with greater than two inputs do not implement the difference function.
Instead, a more useful functionality has been adopted in which the output of the n-bit, XOR gate is the
result of a cascade of 2-input XOR gates. This results in an ultimate output that is true when there is an
ODD number of 1’s on the inputs. This functionality is much more useful in modern electronics for error
correction codes and arithmetic. As such, this is the functionality that is seen in modern n-bit, XOR gates.
This functionality is also shown in Fig. 3.12.
3.1 Basic Gates • 43
Fig. 3.12
3-Input XOR gate implementation
Fig. 3.13
2-Input XNOR gate symbol, truth table, logic function and logic waveform
44 • Chapter 3: Digital Circuitry and Interfacing
CONCEPT CHECK
CC3.1 Given the following logic diagram, which is the correct logic expression for F?
L
(A) F ¼ (AB)0 C
L
(B) F ¼ (A0 B0 ) C
0 0
L
(C) F ¼ (A B C)
L
(D) F ¼ AB0 C
Fig. 3.14
Generic digital transmitter/receiver circuit
the signal (Vsig) is above this threshold, it is considered a logic HIGH. If the voltage is below this
threshold, it is considered a logic LOW. A graphical depiction of this is shown in Fig. 3.15. The terms
HIGH and LOW are used to describe which logic level corresponds to the higher or lower voltage.
Fig. 3.15
Definition of logic HIGH and LOW
It is straightforward to have the HIGH level correspond to the binary code 1 and the LOW level
correspond to the binary code 0; however, it is equally valid to have the HIGH level correspond to the
binary code 0 and the LOW level correspond to the binary code 1. As such, we need to define how the
logic levels HIGH and LOW map to the binary codes 1 and 0. We define two types of digital assignments:
Positive Logic and Negative Logic. In Positive Logic, the logic HIGH level represents a binary 1 and the
logic LOW level represents a binary 0. In Negative Logic, the logic HIGH level represents a binary 0 and
the logic LOW level represents a binary 1. Table 3.1 shows the definition of positive and negative logic.
There are certain types of digital circuits that benefit from using negative logic; however, we will focus
specifically on systems that use positive logic since it is more intuitive when learning digital design for the
first time. The transformation between positive and negative logic is straightforward and will be covered
in Chap. 4.
Table 3.1
Definition of positive and negative logic
logic LOW (or logic 0 when using positive logic). In the subscripts for these specifications, the “O”
signifies “output” and the “L” or “H” signifies “LOW” or “HIGH” respectively.
The maximum amount of current that can flow through the transmitter’s output (IO) is also specified.
The specification IOH-max is the maximum amount of current that can flow through the transmitter’s output
when sending a logic HIGH. The specification IOL-max is the maximum amount of current that can flow
through the transmitter’s output when sending a logic LOW. When the maximum output currents are
violated, it usually damages the part. Manufacturers will also provide a recommended amount of current
for IO that will guarantee the specified operating parameters throughout the life of the part. Figure 3.16
shows a graphical depiction of these DC specifications. When the transmitter output is providing current
to the receiving circuit (a.k.a., the load), it is said to be sourcing current. When the transmitter output is
drawing current from the receiving circuit, it is said to be sinking current. In most cases, the transmitter
sources current when driving a logic HIGH and sinks current when driving a logic LOW. Figure 3.16
shows a graphical depiction of these specifications.
Fig. 3.16
DC Specifications of a digital circuit
1 when using positive logic). The VIL-max and VIL-min specifications provide the range of voltages that the
receiver will interpret as a logic LOW (or logic 0 when using positive logic). In the subscripts for these
specifications, the “I” signifies “input”.
The maximum amount of current that the receiver will draw, or take in, when connected is also
specified II). The specification IIH-max is the maximum amount of current that the receiver will draw when it
is being driven with a logic HIGH. The specification IIL-max is the maximum amount of current that the
receiver will draw when it is being driven with a logic LOW. Again, Fig. 3.16 shows a graphical depiction
of these DC specifications.
Figure 3.16 includes the graphical depiction of the noise margins. Notice in this figure that there is a
region of voltages that the receiver will not interpret as either a HIGH or LOW. This region lies between
the VIH-min and VIL-max specifications. This is the uncertainty region and should be avoided. Signals in
this region will cause the receiver’s output to go to an unknown voltage. Digital transmitters are designed
to transition between the LOW and HIGH states quickly enough so that the receiver does not have time to
react to the input being in the uncertainty region.
48 • Chapter 3: Digital Circuitry and Interfacing
There are two components of power supply current. The first is the current that is required for the
functional operation of the device. This is called the quiescent current (Iq). The second component of the
power supply current is the output currents (IO). Any current that flows out of a digital circuit must also
flow into it. When a transmitting circuit sources current to a load on its output pin, it must bring in that
same amount of current on another pin. This is accomplished using the power supply pin (VCC).
Conversely, when a transmitting circuit sinks current from a load on its output pin, an equal amount of
current must exit the circuit on a different pin. This is accomplished using the GND pin. This means that
the amount of current flowing through the VCC and GND pins will vary depending on the logic states that
are being driven on the outputs. Since a digital circuit may contain numerous output pins, the maximum
amount of current flowing through the VCC and GND pins can scale quickly and care must be taken not to
damage the device.
The quiescent current is often specified using the term ICC. This should not be confused with the
specification for the maximum amount of current that can flow through the VCC pin, which is often called
ICC-max. It is easy to tell the difference because ICC (or Iq) is much smaller than ICC-max for CMOS parts.
ICC (or Iq) is specified in the uA to nA range while the maximum current that can flow through the VCC pin
is specified in the mA range. Example 3.1 shows the process of calculating the ICC and IGND currents
when sourcing multiple loads.
3.2 Digital Circuit Operation • 49
Example 3.1
Calculating ICC and IGND when sourcing multiple loads
50 • Chapter 3: Digital Circuitry and Interfacing
Example 3.2 shows the process of calculating the ICC and IGND currents when both sourcing and
sinking loads.
Example 3.2
Calculating ICC and IGND when both sourcing and sinking loads
3.2 Digital Circuit Operation • 51
Fig. 3.17
Switching characteristics of a digital circuit
Fig. 3.18
Example data sheet excerpt (1)
3.2 Digital Circuit Operation • 53
Fig. 3.19
Example data sheet excerpt (2)
54 • Chapter 3: Digital Circuitry and Interfacing
Fig. 3.20
Example data sheet excerpt (3)
3.2 Digital Circuit Operation • 55
CONCEPT CHECK
CC3.2(a) Given the following DC specifications for a driver/receiver pair, in what situation may a logic
signal transmitted not be successfully received?
CC3.2(b) For the following driver configuration, which of the following is a valid constraint that could
be put in place to prevent a violation of the maximum power supply currents (ICC-max and
IGND-max)?
(A) Modify the driver transistors so that they can’t provide more than 5 mA on any
output.
(B) Apply a cooling system (e.g., a heat sink or fan) to the driver chip.
(C) Design the logic so that no more than half of the outputs are HIGH at any
given time.
(D) Drive multiple receivers with the same output pin.
CC3.2(c) Why is it desirable to have the output of a digital circuit transition quickly between the logic
LOW and logic HIGH levels?
(A) So that the outputs are not able to respond as the input transitions through the
uncertainty region. This avoids unwanted transitions.
(B) So that all signals look like square waves.
(C) To reduce power by minimizing the time spent switching.
(D) Because the system can only have two states, a LOW and a HIGH.
56 • Chapter 3: Digital Circuitry and Interfacing
family will be associated with the power supply voltage. For example, a logic family may go by the name
“+3.3v CMOS” or “+2.5v CMOS”. These names give a first level description of the logic family operation,
but more details about the operation must be looked up in the data sheet.
There are two types of transistors used in CMOS. The transistors will be closed or open based on an
input logic level. The first transistor is called an N-type MOSFET, or NMOS. This transistor will turn on, or
close, when the voltage between the gate and source (VGS) is greater than its threshold voltage. The
threshold voltage (VT) is the amount of voltage needed to create a conduction path between the drain
and the source terminals. The threshold voltage of an NMOS transistor is typically between 0.2v to 1v
and much less than the VCC voltage in the system. The second transistor is called a P-type MOSFET, or
PMOS. This transistor turns on, or closes, when the voltage between the gate and the source (VGS) is
less than VT, where the VT for a PMOS is a negative value. This means that to turn on a PMOS transistor,
the gate terminal needs to be at a lower voltage than the source. The type of transistor (i.e., P-type or
N-type) has to do with the type of semiconductor material used to conduct current through the transistor.
An NMOS transistor uses negative charge to conduct current (i.e., Negative-Type) while a PMOS uses
positive charge (i.e., Positive-Type). Figure 3.21 shows the symbols for the PMOS and NMOS, the
fabrication cross-sections, and their switch level equivalents.
Fig. 3.21
CMOS transistors
58 • Chapter 3: Digital Circuitry and Interfacing
The basic operation of CMOS is that when driving a logic HIGH the switches are used to connect the
output to the power supply (VCC), and when driving a logic LOW the switches are used to connect
the output to GND. In CMOS, VCC is considered an ideal logic HIGH and GND is considered an ideal
logic LOW. VCC is typically much larger than VT so using these levels can easily turn on and off the
transistors. The design of the circuit must never connect the output to VCC and GND at the same time or
else the device itself will be damaged due to the current flowing directly from VCC to GND through the
transistors. Due to the device physics of the MOSFETS, PMOS transistors are used to form the network
that will connect the output to VCC (a.k.a., the pull-up network), and NMOS transistors are used to form
the network that will connect the output to GND (a.k.a., the pull-down network). Since PMOS transistors
are closed when the input is a 0 (thus providing a logic HIGH on the output) and NMOS transistors are
closed when the input is a 1 (thus providing a logic LOW on the output), CMOS implements negative
logic gates. This means CMOS can implement inverters, NAND and NOR gates but not buffers, AND
and OR gates directly. In order to create a CMOS AND gate, the circuit would implement a NAND gate
followed by an inverter and similarly for an OR gate and buffer.
Fig. 3.22
CMOS inverter schematic
The inputs of both the PMOS and NMOS are connected together. The PMOS is used to connect
the output to VCC and the NMOS is used to connect the output to GND. Since the inputs are
connected together and the switches operate in a complementary manner, this circuit ensures that
both transistors will never be on at the same time. When In ¼ 0, the PMOS switch is closed and the
NMOS switch is open. This connects the output directly to VCC, thus providing a logic HIGH on the
output. When In ¼ 1, the PMOS switch is open and the NMOS switch is closed. This connects the output
directly to GND, thus providing a logic LOW. This configuration yields an inverter. This operation is
shown graphically in Fig. 3.23.
3.3 Logic Families • 59
Fig. 3.23
CMOS inverter operation
Fig. 3.24
CMOS 2-input NAND gate schematic
60 • Chapter 3: Digital Circuitry and Interfacing
The pull-down network consists of two NMOS transistors in series (M1 and M2) and the pull-up
network consists of two PMOS transistors in parallel (M3 and M4). Let’s go through each of the input
conditions and examine which transistors are on and which are off and how they impact the output. The
first input condition is when A ¼ 0 and B ¼ 0. This condition turns on both M3 and M4 creating two parallel
paths between the output and VCC. At the same time, it turns off both M1 and M2 preventing a path
between the output and GND. This input condition results in an output that is connected to VCC resulting
in a logic HIGH. The second input condition is when A ¼ 0 and B ¼ 1. This condition turns on M3 in the
pull-up network and M2 in the pull-down network. This condition also turns off M4 in the pull-up network
and M1 in the pull-down network. Since the pull-up network is a parallel combination of PMOS
transistors, there is still a path between the output and VCC through M3. Since the pull-down network
is a series combination of NMOS transistors, both M1 and M2 must be on in order to connect the output
to GND. This input condition results in an output that is connected to VCC resulting in a logic HIGH. The
third input condition is when A ¼ 1 and B ¼ 0. This condition again provides a path between the output
and VCC through M4 and prevents a path between the output and ground by having M2 open. This input
condition results in an output that is connected to VCC resulting in a logic HIGH. The final input condition
is when A ¼ 1 and B ¼ 1. In this input condition, both of the PMOS transistors in the pull-up network
(M3 and M4) are off preventing the output from being connected to VCC. At the same time, this input turns
on both M1 and M2 in the pull-down network connecting the output to GND. This input condition results in
an output that is connected to GND resulting in a logic LOW. Based on the resulting output values
corresponding to the four input codes, this circuit yields the logic operation of a 2-Input NAND gate. This
operation is shown graphically in Fig. 3.25.
3.3 Logic Families • 61
Fig. 3.25
CMOS 2-input NAND gate operation
Creating a CMOS NAND gate with more than 2 inputs is accomplished by adding additional PMOS
transistors to the pull-up network in parallel and additional NMOS transistors to the pull-down network in
series. Figure 3.26 shows the schematic for a 3-Input NAND gate. This procedure is followed for creating
NAND gates with larger numbers of inputs.
62 • Chapter 3: Digital Circuitry and Interfacing
Fig. 3.26
CMOS 3-input NAND gate schematic
If the CMOS transistors were ideal switches, the approach of increasing the number of inputs could
be continued indefinitely. In reality, the transistors are not ideal switches and there is a limit on how many
transistors can be added in series and continue to operate. The limitation has to do with ensuring that
each transistor has enough voltage to properly turn on or off. This is a factor in the series network
because the drain terminals of the NMOS transistors are not all connected to GND. If a voltage develops
across one of the lower transistors (e.g., M3), then it takes more voltage on the input to turn on the next
transistor up (e.g., M2). If too many transistors are added in series, then the uppermost transistor in the
series may not be able to be turned on or off by the input signals. The number of inputs that a logic gate
can have within a particular logic family is called its fan-in specification. When a logic circuit requires a
number of inputs that exceeds the fan-in specification for a particular logic family, then additional logic
gates must be used. For example, if a circuit requires a 5-input NAND gate but the logic family has a
fan-in specification of 4, this means that the largest NAND gate available only has 4-inputs. The 5-input
NAND operation must be accomplished using additional circuit design techniques that use gates with
4 or less inputs. These design techniques will be covered in Chap. 4.
Fig. 3.27
CMOS 2-input NOR gate schematic
The series configuration of the pull-up network will only connect the output to VCC when both inputs
are 0. Conversely, the pull-down network prevents connecting the output to GND when both inputs are
0. When either or both of the inputs are true, the pull-up network is off and the pull-down network is
on. This yields the logic function for a NOR gate. This operation is shown graphically in Fig. 3.28. As with
the NAND gate, the number of inputs can be increased by adding more PMOS transistors in series in the
pull-up network and more NMOS transistors in parallel in the pull-down network.
64 • Chapter 3: Digital Circuitry and Interfacing
Fig. 3.28
CMOS 2-input NOR gate operation
The schematic for a 3-input NOR gate is given in Fig. 3.29. This approach can be used to increase
the number of inputs up until the fan-in specification of the logic family is reached.
3.3 Logic Families • 65
Fig. 3.29
CMOS 3-input NOR gate schematic
Fig. 3.30
PNP and NPN transistors
Figure 3.31 shows a simplified model of how TTL logic operates using BJTs and resistors. This
simplified model does not show all of the transistors that are used in modern TTL circuits but instead is
intended to provide a high-level overview of the operation. This gate is an inverter that is created with an
NPN transistor and a resistor. When the input is a logic HIGH, the NPN transistor turns on and conducts
current between its collector and emitter terminals. This in effect closes the switch and connects the
output to GND providing a logic LOW. During this state, current will also flow through the resistor to GND
through Q1 thus consuming more power than the equivalent gate in CMOS. When the input is a logic
LOW, the NPN transistor turns off and no current flows between its collector and emitter. This, in effect, is
an open circuit leaving only the resistor connected to the output. The resistor pulls the output up to VCC
providing a logic HIGH on the output. One drawback of this state is that there will be a voltage drop
across the resistor so the output is not pulled fully to VCC.
3.3 Logic Families • 67
Fig. 3.31
TTL inverter
Fig. 3.32
7400 series part numbering scheme
3.3 Logic Families • 69
Table 3.2
DC operating conditions for a sample of 7400 series logic families
Fig. 3.33
Pin-outs for a subset of basic gates from the 74HC logic family in DIP packages
3.4 Driving Loads • 71
CONCEPT CHECK
CC3.3 Why doesn’t the following CMOS transistor configuration yield a buffer?
(A) In order to turn on the NMOS transistor, VGS needs to be greater than zero. In the
given configuration, the gate terminal of the NMOS (G) needs to be driven above
the source terminal (S). If the source terminal was at +3.4v, then the input
(In) would never be able to provide a positive enough voltage to ensure the NMOS
is on because “In” doesn’t go above +3.4v.
(B) There is no way to turn on both transistors in this configuration.
(C) The power consumption will damage the device because both transistors will
potentially be on.
(D) The sources of the two devices can’t be connected together without causing a
short in the device.
Example 3.3
Determining if specifications are violated when driving another gate as a load
From this example, it is clear that there are no issues when a gate is driving another gate from the
same family. This is as expected because that is the point of a logic family. In fact, gates are designed to
drive multiple gates from within their own family. Based solely on the DC specifications for input and
output current, it could be assumed that the number of other gates that can be driven is simply IO-max/II-
max. For the example in Example 3.3, this would result in a 74HC gate being able to drive 25,000 other
gates (i.e., 25 mA/1 uA ¼ 25,000). In reality, the maximum number of gates that can be driven is dictated
by the switching characteristics. This limit is called the fan-out specification. The fan-out specification
states the maximum number of other gates from within the same family that can be driven. As discussed
earlier, the output signal needs to transition quickly through the uncertainty region so that the receiver
does not have time to react and go to an unknown state. As more and more gates are driven, this
transition time is slowed down. The fan-out specification provides a limit to the maximum number of
gates from the same family that can be driven while still ensuring that the output signal transitions
between states fast enough to avoid the receivers from going to an unknown state. Example 3.4 shows
the process of determining the maximum output current that a driver will need to provide when driving the
maximum number of gates allowed by the fan-out specification.
3.4 Driving Loads • 73
Example 3.4
Determining the output current when driving multiple gates as the load
Fig. 3.34
A primer on Ohm’s law
74 • Chapter 3: Digital Circuitry and Interfacing
Let’s see how we can use Ohm’s Law to analyze the impact of a resistive load in a digital circuit.
Consider the circuit configuration in Example 3.5 and how we can use Ohm’s Law to determine the
output current of the driver. The load in this case is a resistor connected between the output of the driver
and the power supply (+5v). When driving a logic HIGH, the output level will be approximately equal to
the power supply (i.e., +5v). Since in this situation both terminals of the resistor are at +5v, there is no
voltage difference present. That means when plugging into Ohm’s Law, the voltage component is 0v,
which gives 0 amps of current. In the case where the driver is outputting a logic LOW, the output will be
approximately GND. In this case, there is a voltage drop of +5v across the resistor (5v-0v). Plugging this
into Ohm’s Law yields a current of 50 mA flowing through the resistor. This can become problematic
because the current flows through the resistor and then into the output of the driver. For the 74HC logic
family, this would exceed the IO max specification of 25 mA and damage the part. Additionally, as more
current is drawn through the output, the output voltage becomes less and less ideal. In this example, the
first order analysis uses VO ¼ GND. In reality, as the output current increases, the output voltage will
move further away from its ideal value and may eventually reach a value within the uncertainty region.
Example 3.5
Determining the output current when driving a pull-up resistor as the load
3.4 Driving Loads • 75
A similar process can be used to determine the output current when driving a resistive load between
the output and GND. This process is shown in Example 3.6.
Example 3.6
Determining the output current when driving a pull-down resistor as the load
Fig. 3.35
Symbols for a diode and a light emitting diode
When designing an LED driver circuit, a voltage must be supplied in order to develop the forward
voltage across the LED so that current will flow. A resistor is included in series with the LED for two
reasons. The first reason is to provide a place for any additional voltage provided by the driver to develop
in the situation that Vo > Vf, which is most often the case. The second reason for the resistor is to set the
output current. Since the voltage across the resistor will be a fixed amount (i.e., Vo-Vf), then the value of
the resistor can be chosen to set the current. This current is typically set to an optimum value that turns
on the LED to a desired luminosity while also ensuring that the maximum output current of the driver is
not violated. Consider the LED driver configuration shown in Example 3.7 where the LED will be turned
on when the driver outputs a HIGH.
Example 3.7
Determining the output current when driving an LED where HIGH ¼ ON
3.4 Driving Loads • 77
Example 3.8 shows another example of driving an LED, but this time using a different configuration
where the LED will be on when the driver outputs a logic LOW.
Example 3.8
Determining the Output Current When Driving an LED where HIGH ¼ OFF
CONCEPT CHECK
CC3.4 A fan-out specification is typically around 6–12. If a logic family has a maximum output current
specification of IO-max ¼ 25 mA and a maximum input current specification of only II-max ¼ 1 uA,
a driver could conceivably source up to 25,000 gates (IO-max/II-max ¼ 25 mA/1 uA ¼ 25,000)
without violating its maximum output current specification. Why isn’t the fan-out specification
then closer to 25,000?
(A) The fan-out specification has significant margin built into it in order to protect the
driver.
(B) Connecting 25,000 loads to the driver would cause significant wiring congestion
and would be impractical.
(C) The fan-out specification is in place to reduce power, so keeping it small is
desirable.
(D) The fan-out specification is in place for AC behavior. It ensures that the AC loading
on the driver doesn’t slow down its output rise and fall times. If too many loads are
connected, the output transition will be too slow and it will reside in the uncertainty
region for too long leading to unwanted switching on the receivers.
78 • Chapter 3: Digital Circuitry and Interfacing
Summary
v The operation of a logic circuit can be exceeded, the circuit may not operate prop-
described using either a logic symbol, a truth erly or be damaged.
table, a logic expression, or a logic waveform. v The current exiting a logic circuit is equal to
v Logic gates represent the most basic the current entering.
operations that can be performed on binary v When a logic circuit sources current to a load,
numbers. They are BUF, INV, AND, NAND, an equivalent current is drawn into the circuit
OR, NOR, XOR, and XNOR. through its power supply pin.
v XOR gates that have a number of inputs v When a logic circuit sinks current from a load,
greater than two are created using a cascade an equivalent current flows out of the circuit
of 2-input XOR gates. This implementation through its ground pin.
has more practical applications such as arith- v The type of load that is connected to the
metic and error detection codes. output of a logic circuit dictates how much
v The logic level describes whether the electri- current will be drawn from the driver.
cal signal representing one of two states is v The quiescent current (Iq or Icc) is the current
above or below a switching threshold region. that the circuit always draws independent of
The two possible values that a logic level can the input/output currents.
be are HIGH or LOW. v Logic circuits have AC specifications that
v The logic value describes how the logic describe the delay from the input to the out-
levels are mapped into the two binary codes put (tPLH, tPHL) and also how fast the outputs
0 and 1. In positive logic a HIGH ¼ 1 and a transition between the HIGH and LOW levels
LOW ¼ 0. In negative logic a HIGH ¼ 0 and a (tr, tf).
LOW ¼ 1. v A logic family is a set of logic circuits that are
v Logic circuits have DC specifications that designed to operate with each other.
describe how input voltage levels are v The fan-in of a logic family describes the
interpreted as either HIGHs or LOWs maximum number of inputs that a gate
(VIH-max, VIH-min, VIL-max, and VIL-min). may have.
Specifications are also given on what output v The fan-out of a logic family describes the
voltages will be produced when driving a maximum number of other gates from within
HIGH or LOW (VOH-max, VOH-min, VOL-max, the same family that can be driven simulta-
and VOL-min). neously by one gate.
v In order to successfully transmit digital infor- v Complementary Metal Oxide Semiconductor
mation, the output voltages of the driver that (CMOS) logic is the most popular family
represent a HIGH and LOW must arrive at series in use today. CMOS logic use two
the receiver within the voltage ranges that transistors (NMOS and PMOS) that act as
are interpreted as a HIGH and LOW. If the complementary switches. CMOS transistors
voltage arrives at the receiver outside of draw very low quiescent current and can be
these specified input ranges, the receiver fabricated with extremely small feature sizes.
will not know whether a HIGH or LOW is v In CMOS, only inverters, NAND gates, and
being transmitted. NOR gates can be created directly. If it is
v Logic circuits also specify maximum current desired to create a buffer, AND gate, or OR
levels on the power supplies (IVCC, Ignd), gate, an inverter is placed on the output of
inputs (II-max), and outputs (IO-max) that may the original inverter, NAND, or NOR gate.
not be exceeded. If these levels are
Exercise Problems
Section 3.1: Basic Gates 3.1.4 Give the logic expression for a 3-input AND
gate with the input variables A, B, C and
3.1.1 Give the truth table for a 3-input AND gate with
output F.
the input variables A, B, C and output F.
3.1.5 Give the logic expression for a 3-input OR gate
3.1.2 Give the truth table for a 3-input OR gate with
with the input variables A, B, C and output F.
the input variables A, B, C and output F.
3.1.6 Give the logic expression for a 3-input XNOR
3.1.3 Give the truth table for a 3-input XNOR gate
gate with the input variables A, B, C and
with the input variables A, B, C and output F.
output F.
Exercise Problems • 79
maximum output current (IO) that the driver will 3.4.4 For the LED driver configuration shown in
need to source? Fig. 3.41 where an output of HIGH on the driver
will turn on the LED, calculate the value of the
resistor (R) in order to set the LED forward
current to 5 mA. The LED has a forward volt-
age of 1.9v.
Fig. 3.41
Driver configuration 6
Fig. 3.38
Driver configuration 3
3.4.5 For the LED driver configuration shown in
Fig. 3.42 where an output of LOW on the driver
3.4.2 For the pull-down driver configuration shown in will turn on the LED, calculate the value of the
Fig. 3.39, calculate the value of the pull-down resistor (R) in order to set the LED forward
resistor (R) in order to ensure that the output current to 5 mA. The LED has a forward volt-
current does not exceed 20 mA. age of 1.9v.
Fig. 3.39
Driver configuration 4
Fig. 3.42
3.4.3 For the pull-up driver configuration shown in Driver configuration 7
Fig. 3.40, calculate the value of the pull-up
resistor (R) in order to ensure that the output
current does not exceed 20 mA.
Fig. 3.40
Driver configuration 5
Chapter 4: Combinational Logic
Design
In this chapter we cover the techniques to synthesize, analyze, and manipulate logic functions. The
purpose of these techniques is to ultimately create a logic circuit using the basic gates described in
Chap. 3 from a truth table or word description. This process is called combinational logic design.
Combinational logic refers to circuits where the output depends on the present value of the inputs.
This simple definition implies that there is no storage capability in the circuitry and a change on the input
immediately impacts the output. To begin, we first define the rules of Boolean algebra, which provide the
framework for the legal operations and manipulations that can be taken on a two-valued number system
(i.e., a binary system). We then explore a variety of logic design and manipulation techniques. These
techniques allow us to directly create a logic circuit from a truth table and then to manipulate it to either
reduce the number of gates necessary in the circuit or to convert the logic circuit into equivalent forms
using alternate gates. The goal of this chapter is to provide an understanding of the basic principles of
combinational logic design.
Learning Outcomes—After completing this chapter, you will be able to:
4.1 Describe the fundamental principles and theorems of Boolean algebra and how to use
them to manipulate logic expressions.
4.2 Analyze a combinational logic circuit to determine its logic expression, truth table, and
timing information.
4.3 Synthesis a logic circuit in canonical form (Sum of Products or Product of Sums) from a
functional description including a truth table, minterm list, or maxterm list.
4.4 Synthesize a logic circuit in minimized form (Sum of Products or Product of Sums) through
algebraic manipulation or with a Karnaugh map.
4.5 Describe the causes of timing hazards in digital logic circuits and the approaches to
mitigate them.
4.1.1 Operations
In Boolean algebra there are two valid states (true and false) and three core operations. The
operations are conjunction (^, equivalent to the AND operation), disjunction (_, equivalent to the OR
operation), and negation (Ø, equivalent to the NOT operation). From these three operations, more
sophisticated operations can be created including other logic functions (i.e., BUF, NAND, NOR, XOR,
XNOR, etc.) and arithmetic. Engineers primarily use the terms AND, OR and NOT instead of conjunction,
disjunction and negation. Similarly, engineers primarily use the symbols for these operators described in
Chap. 3 (e.g., ∙, + and ‘) instead of ^, _, and Ø.
4.1.2 Axioms
An axiom is a statement of truth about a system that is accepted by the user. Axioms are very simple
statements about a system, but need to be established before more complicated theorems can be
proposed. Axioms are so basic that they do not need to be proved in order to be accepted. Axioms can
be thought of as the basic laws of the algebraic framework. The terms axiom and postulate are
synonymous and used interchangeably. In Boolean algebra there are five main axioms. These axioms
will appear redundant with the description of basic gates from Chap. 3, but must be defined in this
algebraic context so that more powerful theorems can be proposed.
Axiom #5 – Definition of Logical Precedence: NOT precedes AND, AND precedes OR.
To illustrate Axiom #5, consider the logic function F ¼ A0 ∙B + C. In this function, the first operation that
would take place is the NOT operation on A. This would be followed by the AND operation of A0 with
B. Finally, the result would be OR’d with C. The precedence of any function can also be explicitly stated
using parentheses such as F ¼ (((A0 ) ∙ B) + C).
4.1.3 Theorems
A theorem is a more sophisticated truth about a system that is not intuitively obvious. Theorems are
proposed and then must be proved. Once proved, they can be accepted as a truth about the system
going forward. Proving a theorem in Boolean algebra is much simpler than in our traditional decimal
system due to the fact that variables can only take on one of two values, true or false. Since the number
of input possibilities is bounded, Boolean algebra theorems can be proved by simply testing the theorem
using every possible input code. This is called proof by exhaustion. The following theorems are used
widely in the manipulation of logic expressions and reduction of terms within an expression.
Example 4.1
Proving DeMorgan’s theorem of duality using proof by exhaustion
Duality is important for two reasons. First, it doubles the impact of a theorem. If a theorem is proved
to be true, then the dual of that theorem is also proved to be true. This, in essence, gives twice the
theorem with the same amount of proving. Boolean algebra theorems are almost always given in pairs,
the original and the dual. That is why duality is covered as the first theorem.
The second reason that duality is important is because it can be used to convert between positive
and negative logic. Until now, we have used positive logic for all of our examples (i.e., a logic HIGH ¼
true ¼1 and a logic LOW ¼ false ¼0). As mentioned earlier, this convention is arbitrary and we could
have easily chosen a HIGH to be false and a LOW to be true (i.e., negative logic). Duality allows us to
take a logic expression that has been created using positive logic (F) and then convert it into an
equivalent expression that is valid for negative logic (FD). Example 4.2 shows the process for how this
works.
4.1 Boolean Algebra • 85
Example 4.2
Converting between positive and negative logic using duality
One consideration when using duality is that the order of precedence follows the original function.
This means that in the original function, the axiom for precedence states the order as NOT-AND-OR;
however, this is not necessarily the correct precedence order in the dual. For example, if the original
function was F ¼ AB + C, the AND operation of A and B would take place first, and then the result would
be OR’d with C. The dual of this expression is FD ¼ A + BC. If the expression for FD was evaluated using
traditional Boolean precedence, it would show that FD does NOT give the correct result per the definition
of a dual function (i.e., converting a function from positive to negative logic). The order of precedence for
FD must correlate to the precedence in the original function. Since in the original function A and B were
operated on first, they must also be operated on first in the dual. In order to easily manage this issue,
parentheses can be used to track the order of operations from the original function to the dual. If we put
parentheses in the original function to explicitly state the precedence of the operations, it would take the
form F ¼ (AB) + C. These parentheses can be mapped directly to the dual yielding FD ¼ (A + B)C. This
order of precedence in the dual is now correct.
86 • Chapter 4: Combinational Logic Design
Now that we have covered the duality operation, its usefulness and its pitfalls, we can formally
define this theorem as:
DeMorgan’s Duality: An algebraic equality will remain true if all 0’s and 1’s are interchanged and all
AND and OR operations are interchanged. Furthermore, taking the dual of a positive logic function will
produce the equivalent function using negative logic if the original order of precedence is maintained.
4.1.3.2 Identity
An identity operation is one that when performed on a variable will yield itself regardless of the
variable’s value. The following is the formal definition of identity theorem. Figure 4.1 shows the gate level
depiction of this theorem.
Identity: OR’ing any variable with a logic 0 will yield the original variable. The dual: AND’ing any variable
with a logic 1 will yield the original variable.
Fig. 4.1
Gate level depiction of the identity theorem
The identity theorem is useful for reducing circuitry when it is discovered that a particular input will
never change values. When this is the case, the static input variable can simply be removed from the
logic expression making the entire circuit a simple wire from the remaining input variable to the output.
Fig. 4.2
Gate level depiction of the null element theorem
4.1 Boolean Algebra • 87
The null element theorem is also useful for reducing circuitry when it is discovered that a particular
input will never change values. It is also widely used in computer systems in order to set (i.e., force to a
logic 1) or clear (i.e., force to a logic 0) the value of a storage element.
4.1.3.4 Idempotent
An idempotent operation is one that has no effect on the input, regardless of the number of times the
operation is applied. The following is the formal definition of idempotence. Figure 4.3 shows the gate
level depiction of this theorem.
Idempotent: OR’ing a variable with itself results in itself. The dual: AND’ing a variable with itself results in
itself.
Fig. 4.3
Gate level depiction of the idempotent theorem
This theorem also holds true for any number of operations such as A + A + A + . . ... + A ¼ A and
AAA. . ...A ¼ A.
4.1.3.5 Complements
This theorem describes an operation of a variable with the variable’s own complement. The
following is the formal definition of complements. Figure 4.4 shows the gate level depiction of this
theorem.
Complements: OR’ing a variable with its complement will produce a logic 1. The dual: AND’ing a
variable with its complement will produce a logic 0.
Fig. 4.4
Gate level depiction of the complements theorem
The complement theorem is again useful for reducing circuitry when these types of logic
expressions are discovered.
88 • Chapter 4: Combinational Logic Design
4.1.3.6 Involution
An involution operation describes the result of double negation. The following is the formal definition
of involution. Figure 4.5 shows the gate level depiction of this theorem.
Involution: Taking the double complement of a variable will result in the original variable.
Fig. 4.5
Gate level depiction of the involution theorem
This theorem is not only used to eliminate inverters but also provides us a powerful tool for inserting
inverters in a circuit. We will see that this is used widely with the second of DeMorgan’s Laws that will be
introduced at the end of this section.
Fig. 4.6
Gate level depiction of commutative property
One practical use of the commutative property is when wiring or routing logic circuitry together.
Example 4.3 shows how the commutative property can be used to untangle crossed wires when
implementing a digital system.
4.1 Boolean Algebra • 89
Example 4.3
Using the commutative property to untangle crossed wires
Associative Property: The grouping of variables doesn’t impact the result of an OR operation. The dual:
The grouping of variables doesn’t impact the result of an AND operation.
Fig. 4.7
Gate level depiction of the associative property
One practical use of the associative property is addressing fan-in limitations of a logic family. Since
the grouping of the input variables does not impact the result, we can accomplish operations with large
numbers of inputs using multiple gates with fewer inputs. Example 4.4 shows the process of using the
associative property to address a fan-in limitation.
Example 4.4
Using the associative property to address fan-in limitations
4.1 Boolean Algebra • 91
Fig. 4.8
Gate level depiction of the distributive property
The distributive property is used as a logic manipulation technique. It can be used to put a logic
expression into a form more suitable for direct circuit synthesis, or to reduce the number of logic gates
necessary. Example 4.5 shows how to use the distributive property to reduce the number of gates in a
logic circuit.
Example 4.5
Using the distributive property to reduce the number of logic gates in a circuit
92 • Chapter 4: Combinational Logic Design
4.1.3.10 Absorption
The term absorption refers to when multiple logic terms within an expression produce the same
results. This allows one of the terms to be eliminated from the expression, thus reducing the number of
logic operations. The remaining terms essentially absorb the functionality of the eliminated term. This
theorem is also called covering because the remaining term essentially covers the functionality of both
itself and the eliminated term. The following is the formal definition of the absorption theorem. Figure 4.9
shows the gate level depiction of this theorem.
Absorption: When a term within a logic expression produces the same output(s) as another term, the
second term can be removed without affecting the result.
Fig. 4.9
Gate level depiction of absorption
This theorem is better understood by looking at the evaluation of each term with respect to the
original expression. Example 4.6 shows how the absorption theorem can be proven through proof by
exhaustion by evaluating each term in a logic expression.
Example 4.6
Proving the absorption theorem using proof by exhaustion
4.1.3.11 Uniting
The uniting theorem, also called combining or minimization, provides a way to remove variables
from an expression when they have no impact on the outcome. This theorem is one of the most widely
4.1 Boolean Algebra • 93
used techniques for the reduction of the number of gates needed in a combinational logic circuit. The
following is the formal definition of the uniting theorem. Figure 4.10 shows the gate level depiction of this
theorem.
Uniting: When a variable (B) and its complement (B0 ) appear in multiple product terms with a common
variable (A) within a logical OR operation, the variable B does not have any effect on the result and can
be removed.
Fig. 4.10
Gate level depiction of uniting
This theorem can be proved using prior theorems. Example 4.7 shows how the uniting theorem can
be proved using a combination of the distributive property, the complements theorem, and the identity
theorem.
Example 4.7
Proving of the uniting theorem
DeMorgan’s Theorem: An OR operation with both inputs inverted is equivalent to an AND operation
with the output inverted. The dual: An AND operation with both inputs inverted is equivalent to an OR
operation with the output inverted.
Fig. 4.11
Gate level depiction of DeMorgan’s theorem
This theorem is used widely in modern logic design because it bridges the gap between the design
of logic circuitry using Boolean algebra and the physical implementation of the circuitry using CMOS.
Recall that Boolean algebra is defined for only three operations, the AND, the OR and inversion. CMOS,
on the other hand, can only directly implement negative-type gates such as NAND, NOR and NOT.
DeMorgan’s Theorem allows us to design logic circuitry using Boolean algebra and synthesize logic
diagrams with AND, OR, and NOT gates, and then directly convert the logic diagrams into an equivalent
form using NAND, NOR and NOT gates. As we’ll see in the next section, Boolean algebra produces logic
expressions in two common forms. These are the sum of products (SOP) and the product of sums
(POS) forms. Using a combination of involution and DeMorgan’s Theorem, SOP and POS forms can be
converted into equivalent logic circuits that use only NAND and NOR gates. Example 4.8 shows a
process to convert a sum of products form into one that uses only NAND gates.
4.1 Boolean Algebra • 95
Example 4.8
Converting a sum of products form into one that uses only NAND gates
96 • Chapter 4: Combinational Logic Design
Example 4.9 shows a process to convert a product of sums form into one that uses only NOR gates.
Example 4.9
Converting a product of sums form into one that uses only NOR gates
DeMorgan’s Theorem can also be accomplished algebraically using a process known as breaking
the bar and flipping the operator. This process again takes advantage of the Involution Theorem, which
allows double negation without impacting the result. When using this technique in algebraic form,
involution takes the form of a double inversion bar. If an inversion bar is broken, the expression will
remain true as long as the operator directly below the break is flipped (AND to OR, OR to AND).
Example 4.10 shows how to use this technique when converting an OR gate with its inputs inverted
into an AND gate with its output inverted.
4.1 Boolean Algebra • 97
Example 4.10
Using DeMorgan’s theorem in algebraic form (1)
Example 4.11 shows how to use this technique when converting an AND gate with its inputs inverted
into an OR gate with its output inverted.
Example 4.11
Using DeMorgan’s theorem in algebraic form (2)
98 • Chapter 4: Combinational Logic Design
Table 4.1 gives a summary of all the Boolean algebra theorems just covered. The theorems are
grouped in this table with respect to the number of variables that they contain. This grouping is the most
common way these theorems are presented.
Table 4.1
Summary of Boolean algebra theorems
Fig. 4.12
Configuration to use a NAND gate as an inverter
4.2 Combinational Logic Analysis • 99
This approach can also be used on a NOR gate to implement an inverter. Figure 4.13 shows how a
NOR gate can be configured to perform a NOT operation, thus also making it functionally complete.
Fig. 4.13
Configuration to use a NOR gate as an inverter
CONCEPT CHECK
CC4.1 If the logic expression F ¼ ABCDEFGH is implemented with only 2-input AND gates, how
many levels of logic will the final implementation have? Hint: Consider using the associative
property to manipulate the logic expression to use only 2-input AND operations.
based on the preceding logic operation(s). The logic expressions are written working left-to-right until the
output of the system is reached and the final logic expression of the circuit has been found. Consider the
example of this analysis in Example 4.12.
Example 4.12
Determining the logic expression from a logic diagram
Example 4.13
Determining the truth table from a logic diagram
Example 4.14
Determining the delay of a combinational logic circuit
CONCEPT CHECK
CC4.2 Does the delay specification of a combinational logic circuit change based on the input values
that the circuit is evaluating?
(A) Yes. There are times when the inputs switch between inputs codes that use paths
through the circuit with different delays.
(B) No. The delay is always specified as the longest delay path.
(C) Yes. The delay can vary between the longest delay path and zero. A delay of zero
occurs when the inputs switch between two inputs codes that produce the same
output.
(D) No. The output is always produced at a time equal to the longest delay path.
4.3 Combinational Logic Synthesis • 103
Fig. 4.14
Definition and gate level depiction of a minterm
For an arbitrary truth table, a minterm can be used for each row corresponding to a true output. If
each of these minterms’ outputs are fed into a single OR gate, then a sum of products logic circuit is
formed that will produce the logic listed in the truth table. In this topology, any input code that corresponds
to an output of 1 will cause its corresponding minterm to output a 1. Since a 1 on any input of an OR gate
will cause the output to go to a 1, the output of the minterm is passed to the final result. Example 4.15
shows this process. One important consideration of this approach is that no effort has been taken to
minimize the logic expression. This unminimized logic expression is also called the canonical sum. The
canonical sum is logically correct but uses the most amount of circuitry possible for a given truth table.
This canonical sum can be the starting point for minimization using Boolean algebra.
104 • Chapter 4: Combinational Logic Design
Example 4.15
Creating a canonical sum of products logic circuit using minterms
Example 4.16
Creating a minterm list from a truth table
A minterm list contains the same information as the truth table, the canonical sum and the canonical
sum of products logic diagram. Since the minterms themselves are formally defined for an input code, it
is trivial to go back and forth between the minterm list and these other forms. Example 4.17 shows how a
minterm list can be used to generate an equivalent truth table, canonical sum and canonical sum of
products logic diagram.
106 • Chapter 4: Combinational Logic Design
Example 4.17
Creating equivalent functional representations from a minterm list
Fig. 4.15
Definition and gate level depiction of a maxterm
For an arbitrary truth table, a maxterm can be used for each row corresponding to a false output. If
each of these maxterms outputs are fed into a single AND gate, then a product of sums logic circuit is
formed that will produce the logic listed in the truth table. In this topology, any input code that corresponds
to an output of 0 will cause its corresponding maxterm to output a 0. Since a 0 on any input of an AND
gate will cause the output to go to a 0, the output of the maxterm is passed to the final result. Example
4.18 shows this process. This approach is complementary to the sum of products approach. In the sum
of products approach based on minterms, the circuit operates by producing 1’s that are passed to the
output for the rows that require a true output. For all other rows, the output is false. A product of sums
approach based on maxterms operates by producing 0’s that are passed to the output for the rows that
require a false output. For all other rows, the output is true. These two approaches produce the
equivalent logic functionality. Again, at this point no effort has been taken to minimize the logic expres-
sion. This unminimized form is called a canonical product. The canonical product is logically correct,
but uses the most amount of circuitry possible for a given truth table. This canonical product can be the
starting point for minimization using the Boolean algebra theorems.
108 • Chapter 4: Combinational Logic Design
Example 4.18
Creating a product of sums logic circuit using maxterms
Example 4.19
Creating a maxterm list from a truth table
A maxterm list contains the same information as the truth table, the canonical product and the
canonical product of sums logic diagram. Example 4.20 shows how a maxterm list can be used to
generate these equivalent forms.
110 • Chapter 4: Combinational Logic Design
Example 4.20
Creating equivalent functional representations from a maxterm list
min to max, max to min) and then switching the row numbers between those listed and those not
listed. Example 4.21 shows multiple techniques for representing equivalent logic functionality as a truth
table.
Example 4.21
Creating equivalent forms to represent logic functionality
112 • Chapter 4: Combinational Logic Design
CONCEPT CHECK
CC4.3 All logic functions can be implemented equivalently using either a canonical sum of products
(SOP) or canonical product of sums (POS) topology. Which of these statements is true with
respect to selecting a topology that requires the least amount of gates.
(A) Since a minterm list and a maxterm list can both be written to describe the same
logic functionality, the number of gates in an SOP and POS will always be
the same.
(B) If a minterm list has over half of its row numbers listed, an SOP topology will
require fewer gates than a POS.
(C) A POS topology always requires more gates because it needs additional logic to
convert the inputs from positive to negative logic.
(D) If a minterm list has over half of its row numbers listed, a POS topology will
require fewer gates than SOP.
Example 4.22
Minimizing a logic expression algebraically
The primary drawback of this approach is that it requires recognition of where the theorems can be
applied. This can often lead to missed minimizations. Computer automation is often the best mechanism
to perform this minimization for large logic expressions.
Fig. 4.16
Formation of a 2-input K-map
When constructing a 3-input K-map, it is important to remember that each input code can only differ
from its neighbor by one bit. For example, the two codes 01 and 10 differ by two bits (i.e., the MSB is
different and the LSB is different), thus they could not be neighbors; however, the codes 01-11 and 11-10
can be neighbors. As such, the input codes along the top of the 3-input K-map must be ordered
accordingly (i.e., 00-01-11-10). Consider the construction of a 3-input K-map shown in Fig. 4.17. The
rows and columns that correspond to the input literals can now span multiple rows and columns. Notice
how in this 3-input K-map, the literals A, A0 , B and B0 all correspond to two columns. Also, notice that B0
spans two columns, but the columns are on different edges of the K-map. The side edges of the 3-input
K-map are still considered neighbors because the input codes for these columns only differ by one bit.
This is an important attribute once we get to the minimization of variables because it allows us to
examine an input literal’s impact not only within the obvious adjacent cells but also when the variables
wrap around the edges of the K-map.
4.4 Logic Minimization • 115
Fig. 4.17
Formation of a 3-input K-map
When constructing a 4-input K-map, the same rules apply that the input codes can only differ from
their neighbors by one bit. Consider the construction of a 4-input K-map in Fig. 4.18. In a 4-input K-map,
neighboring cells can wrap around both the top-to-bottom edges in addition to the side-to-side edges.
Notice that all 16 cells are positioned within the map so that their neighbors on the top, bottom and sides
only differ by one bit in their input codes.
116 • Chapter 4: Combinational Logic Design
Fig. 4.18
Formation of a 4-input K-map
Fig. 4.19
Observing how K-Maps visually highlight logic minimizations
These observations can be put into a formal process to produce a minimized SOP logic expression
using a K-map. The steps are as follows:
1. Circle groups of 1’s in the K-map following the rules:
• Each circle should contain the largest number of 1’s possible.
• The circles encompass only neighboring cells (i.e., side-to-side sides and/or top and
bottom).
• The circles must contain a number of 1’s that is a power of 2 (i.e., 1, 2, 4, 8 or 16).
• Enter as many circles as possible without having any circles fully cover another circle.
• Each circle is called a Prime Implicant.
2. Create a product term for each prime implicant following the rules:
• Each variable in the K-map is evaluated one-by-one.
• If the circle covers a region where the input variable is a 1, then include it in the product
term uncomplemented.
• If the circle covers a region where the input variable is a 0, then include it in the product
term complemented.
118 • Chapter 4: Combinational Logic Design
• If the circle covers a region where the input variable is both a 0 and 1, then the variable is
excluded from the product term.
3. Sum all of the product terms for each prime implicant.
Let’s apply this approach to our 2-input K-map example. Example 4.23 shows the process of finding
a minimized sum of products logic expression for a 2-input logic circuit using a K-map. This process
yielded the same SOP expression as the algebraic minimization and observations shown in Fig. 4.19,
but with a formalized process.
Example 4.23
Using a K-map to find a minimized sum of products expression (2-input)
Let’s now apply this process to our 3-input K-map example. Example 4.24 shows the process of
finding a minimized sum of products logic expression for a 3-input logic circuit using a K-map. This
example shows circles that overlap. This is legal as long as one circle does not fully encompass another.
Overlapping circles are common since the K-map process dictates that circles should be drawn that
group the largest number of ones possible as long as they are in powers of 2. Forming groups of ones
using ones that have already been circled is perfectly legal to accomplish larger groupings. The larger
the grouping of ones, the more chance there is for a variable to be excluded from the product term. This
results in better minimization of the logic.
4.4 Logic Minimization • 119
Example 4.24
Using a K-map to find a minimized sum of products expression (3-input)
Let’s now apply this process to our 4-input K-map example. Example 4.25 shows the process of
finding a minimized sum of products logic expression for a 4-input logic circuit using a K-map.
120 • Chapter 4: Combinational Logic Design
Example 4.25
Using a K-map to find a minimized sum of products expression (4-input)
final step in forming the minimized POS expression is to AND all of the sum terms together. The formal
process is as follows:
1. Circle groups of 0’s in the K-map following the rules:
• Each circle should contain the largest number of 0’s possible.
• The circles encompass only neighboring cells (i.e., side-to-side sides and/or top and
bottom).
• The circles must contain a number of 0’s that is a power of 2 (i.e., 1, 2, 4, 8 or 16).
• Enter as many circles as possible without having any circles fully cover another circle.
• Each circle is called a Prime Implicant.
2. Create a sum term for each prime implicant following the rules:
• Each variable in the K-map is evaluated one-by-one.
• If the circle covers a region where the input variable is a 1, then include it in the sum term
complemented.
• If the circle covers a region where the input variable is a 0, then include it in the sum term
uncomplemented.
• If the circles cover a region where the input variable is both a 0 and 1, then the variable is
excluded from the sum term.
3. Multiply all of the sum terms for each prime implicant.
Let’s apply this approach to our 2-input K-map example. Example 4.26 shows the process of finding
a minimized product of sums logic expression for a 2-input logic circuit using a K-map. Notice that this
process yielded the same logic expression as the SOP approach shown in Example 4.23. This illustrates
that both the POS and SOP expressions produce the correct logic for the circuit.
Example 4.26
Using a K-map to find a minimized product of sums expression (2-input)
122 • Chapter 4: Combinational Logic Design
Let’s now apply this process to our 3-input K-map example. Example 4.27 shows the process of
finding a minimized product of sums logic expression for a 3-input logic circuit using a K-map. Notice that
the logic expression in POS form is not identical to the SOP expression found in Example 4.24; however,
using a few steps of algebraic manipulation shows that the POS expression can be put into a form that is
identical to the prior SOP expression. This illustrates that both the POS and SOP produce equivalent
functionality for the circuit.
Example 4.27
Using a K-map to find a minimized product of sums expression (3-input)
4.4 Logic Minimization • 123
Let’s now apply this process to our 4-input K-map example. Example 4.28 shows the process of
finding a minimized product of sums logic expression for a 4-input logic circuit using a K-map.
Example 4.28
Using a K-map to find a minimized product of sums expression (4-input)
Fig. 4.20
Observing redundant prime implicants in a K-map
We need to define a formal process for identifying redundant prime implicants that can be removed
without impacting the result of the logic expression. Let’s start with examining the sum of products form.
First, we define the term essential prime implicant as a prime implicant that cannot be removed from
the logic expression without impacting its result. We then define the term minimal sum as a logic
expression that represents the most minimal set of logic operations to accomplish a sum of products
form. There may be multiple minimal sums for a given truth table, but each would have the same number
of logic operations. In order to determine if a prime implicant is essential, we first put in each and every
possible prime implicant into the K-map. This gives a logic expression known as the complete sum.
From this point we identify any cells that have only one prime implicant covering them. These cells are
4.4 Logic Minimization • 125
called distinguished one cells. Any prime implicant that covers a distinguished one cell is defined as an
essential prime implicant. All prime implicants that are not essential are removed from the K-map. A
minimal sum is then simply the sum of all remaining product terms associated with the essential prime
implicants. Example 4.29 shows how to use this process.
Example 4.29
Deriving the minimal sum from a K-map
This process is identical for the product of sums form to produce the minimal product.
Example 4.30
Using don’t cares to produce a minimal SOP logic expression
Fig. 4.21
XOR and XNOR checkerboard patterns observed in K-maps (2-input)
Fig. 4.22
XOR and XNOR checkerboard patterns observed in K-maps (3-input)
Fig. 4.23
XOR checkerboard pattern observed in K-maps (4-input)
128 • Chapter 4: Combinational Logic Design
Fig. 4.24
XNOR checkerboard pattern observed in K-maps (4-input)
CONCEPT CHECK
CC4.4(a) Logic minimization is accomplished by removing variables from the original canonical logic
expression that don’t impact the result. How does a Karnaugh map graphically show what
variables can be removed?
(A) K-maps contain the same information as a truth table but the data is formatted
as a grid. This allows variables to be removed by inspection.
(B) K-maps rearrange a truth table so that adjacent cells have one and only one
input variable changing at a time. If adjacent cells have the same output value
when an input variable is both a 0 and a 1, that variable has no impact on the
interim result and can be eliminated.
(C) K-maps list both the rows with outputs of 1’s and 0’s simultaneously. This allows
minimization to occur for a SOP and POS topology that each have the same, but
minimal, number of gates.
(D) K-maps display the truth table information in a grid format, which is a more
compact way of presenting the behavior of a circuit.
CC4.4(b) A “Don’t Care” can be used to minimize a logic expression by assigning the output of a row
to either a 1 or a 0 in order to form larger groupings within a K-map. How does the output of
the circuit behave when it processes the input code for a row containing a don’t care?
(A) The output will be whatever value was needed to form the largest grouping in
the K-map.
(B) The output will go to either a 0 or a 1, but the final value is random.
(C) The output can toggle between a 0 and a 1 when this input code is present.
(D) The output will be driven to exactly halfway between a 0 and a 1.
4.5 Timing Hazards & Glitches • 129
Fig. 4.25
Examining the source of a timing hazard (or glitch) in a combinational logic circuit
These timing hazards are given unique names based on the type of transition that occurs. A static
0 timing hazard is when the input switches between two input codes that both yield an output of 0 but the
output momentarily switches to a 1. A static 1 timing hazard is when the input switches between two
130 • Chapter 4: Combinational Logic Design
input codes that both yield an output of 1 but the output momentarily switches to a 0. A dynamic hazard
is when the input switches between two input codes that result in a real transition on the output (i.e., 0 to
1 or 1 to 0), but the output has a momentary glitch before reaching its final value. These definitions are
shown in Fig. 4.26.
Fig. 4.26
Timing hazard definitions
Timing hazards can be addressed in a variety of ways. One way is to try to match the propagation
delays through each path of the logic circuit. This can be difficult, particularly in modern logic families
such as CMOS. In the example in Fig. 4.25, the root cause of the different propagation delays was due to
an inverter on one of the variables. It seems obvious that this could be addressed by putting buffers on
the other inputs with equal delays as the inverter. This would create a situation where all input codes
would arrive at the first stage of AND gates at the same time regardless of whether they were inverted or
not and eliminate the hazards; however, CMOS implements a buffer as two inverters in series, so it is
difficult to insert a buffer in a circuit with an equal delay to an inverter. Addressing timing hazards in this
way is possible, but it involves a time-consuming and tedious process of adjusting the transistors used to
create the buffer and inverter to have equal delays.
Another technique to address timing hazards is to place additional circuitry in the system that will
ensure the correct output while the input codes switch. Consider how including a non-essential prime
implicant can eliminate a timing hazard in Example 4.31. In this approach, the minimal sum from Fig. 4.25
is instead replaced with the complete sum. The use of the complete sum instead of the minimal sum can
be shown to eliminate both static and dynamic timing hazards. The drawback of this approach is the
addition of extra circuitry in the combinational logic circuit (i.e., non-essential prime implicants).
4.5 Timing Hazards & Glitches • 131
Example 4.31
Eliminating a timing hazard by including non-essential product terms
CONCEPT CHECK
CC4.5 How long do you need to wait for all hazards to settle out?
(A) The time equal to the delay through the non-essential prime implicants.
(B) The time equal to the delay through the essential prime implicants.
(C) The time equal to the shortest delay path in the circuit.
(D) The time equal to the longest delay path in the circuit.
132 • Chapter 4: Combinational Logic Design
Summary
v Boolean algebra defines the axioms and v A Karnaugh map (K-map) is a graphical
theorems that guide the operations that can approach to minimizing logic expressions.
be performed on a two-valued number A K-map arranges a truth table into a grid in
system. which the neighboring cells have input codes
v Boolean algebra theorems allow logic that differ by only one bit. This allows the
expressions to be manipulated to make cir- impact of an input variable on a group of
cuit synthesis simpler. They also allow logic outputs to be quickly identified.
expressions to be minimized. v A minimized sum of products expression can
v The delay of a combinational logic circuit is be found from a K-map by circling neighbor-
always dictated by the longest delay path ing ones to form groups that can be produced
from the inputs to the output. by a single product term. Each product term
v The canonical form of a logic expression is (aka prime implicant) is then summed
one that has not been minimized. together to form the circuit output.
v A canonical sum of products form is a logic v A minimized product of sums expression can
synthesis technique based on minterms. A be found from a K-map by circling neighbor-
minterm is a product term that will output a ing zeros to form groups that can be pro-
one for only one unique input code. A duced by a single sum term. Each sum term
minterm is used for each row of a truth table (aka prime implicant) is then multiplied
corresponding to an output of a one. Each of together to form the circuit output.
the minterms are then summed together to v A minimal sum or minimal product is a logic
create the final system output. expression that contains only essential prime
v A minterm list is a shorthand way of describ- implicants and represents the smallest num-
ing the information in a truth table. The sym- ber of logic operations possible to produce
bol “Σ” is used to denote a minterm list. the desired output.
Each of the input variables are added to this v A don’t care (X) can be used when the output
symbol as comma delimited subscripts. The of a truth table row can be either a zero or a
row number is then listed for each row one without affecting the system behavior.
corresponding to an output of a one. This typically occurs when some of the input
v A canonical product of sums form is a logic codes of a truth table will never occur. The
synthesis technique based on maxterms. A value for the row of a truth table containing a
maxterm is a sum term that will output a zero don’t care output can be chosen to give the
for only one unique input code. A maxterm most minimal logic expression. In a K-map,
is used for each row of a truth table don’t cares can be included to form the larg-
corresponding to an output of a zero. Each est groupings in order to give the least
of the maxterms are then multiplied together amount of logic.
to create the final system output. v While exclusive-OR gates are not used in
v A maxterm list is a shorthand way of describ- Boolean algebra, they can be visually
ing the information in a truth table. The sym- identified in K-maps by looking for checker-
bol “Π” is used to denote a maxterm list. board patterns.
Each of the input variables are added to this v Timing hazards are temporary glitches that
symbol as comma delimited subscripts. occur on the output of a combinational logic
The row number is then listed for each row circuit due to timing mismatches through dif-
corresponding to an output of a zero. ferent paths in the circuit. Hazards can be
v Canonical logic expressions can be minimized by including additional circuitry in
minimized through a repetitive process of the system or by matching the delay of all
factoring common variables using the distrib- signal paths.
utive property and then eliminating remaining
variables using a combination of the
complements and identity theorems.
Exercise Problems • 133
Exercise Problems
Section 4.1: Boolean Algebra 4.1.17 Which Boolean algebra theorem describes the
situation where the order of variables in an
4.1.1 Which Boolean algebra theorem describes the
AND operation does not affect the result?
situation where any variable OR’d with itself
will yield itself? 4.1.18 Which Boolean algebra theorem describes the
situation where a variable OR’d with a 0 will
4.1.2 Which Boolean algebra theorem describes the
yield itself?
situation where any variable that is double
complemented will yield itself? 4.1.19 Use proof by exhaustion to prove that an OR
gate with its inputs inverted is equivalent to an
4.1.3 Which Boolean algebra theorem describes the
AND gate with its outputs inverted.
situation where any variable OR’d with a 1 will
yield a 1? 4.1.20 Use proof by exhaustion to prove that an AND
gate with its inputs inverted is equivalent to an
4.1.4 Which Boolean algebra theorem describes the
OR gate with its outputs inverted.
situation where a variable that exists in multiple
product terms can be factored out?
4.1.5 Which Boolean algebra theorem describes the
Section 4.2: Combinational Logic
situation where when output(s) corresponding Analysis
to a term within an expression are handled by 4.2.1 For the logic diagram given in Fig. 4.27, give
another term the original term can be the logic expression for the output F.
removed?
4.1.6 Which Boolean algebra theorem describes the
situation where any variable AND’d with its
complement will yield a 0?
4.1.7 Which Boolean algebra theorem describes the
situation where any variable AND’d with a 0 will
yield a 0?
4.1.8 Which Boolean algebra theorem describes the Fig. 4.27
situation where an AND gate with its inputs Combinational logic analysis 1
inverted is equivalent to an OR gate with its
outputs inverted? 4.2.2 For the logic diagram given in Fig. 4.27, give
4.1.9 Which Boolean algebra theorem describes the the truth table for the output F.
situation where a variable that exists in multiple 4.2.3 For the logic diagram given in Fig. 4.27, give
sum terms can be factored out? the delay.
4.1.10 Which Boolean algebra theorem describes the 4.2.4 For the logic diagram given in Fig. 4.28, give
situation where an OR gate with its inputs the logic expression for the output F.
inverted is equivalent to an AND gate with its
outputs inverted?
4.1.11 Which Boolean algebra theorem describes the
situation where the grouping of variables in an
OR operation does not affect the result?
4.1.12 Which Boolean algebra theorem describes the
situation where any variable AND’d with itself
will yield itself?
4.1.13 Which Boolean algebra theorem describes the
situation where the order of variables in an OR
operation does not affect the result?
4.1.14 Which Boolean algebra theorem describes the
Fig. 4.28
situation where any variable AND’d with a 1 will Combinational logic analysis 2
yield itself?
4.1.15 Which Boolean algebra theorem describes the 4.2.5 For the logic diagram given in Fig. 4.28, give
situation where the grouping of variables in an the truth table for the output F.
AND operation does not affect the result? 4.2.6 For the logic diagram given in Fig. 4.28, give
4.1.16 Which Boolean algebra theorem describes the the delay.
situation where any variable OR’d with its com- 4.2.7 For the logic diagram given in Fig. 4.29, give
plement will yield a 1? the logic expression for the output F.
134 • Chapter 4: Combinational Logic Design
4.3.22 For the 3-input truth table in Fig. 4.33, give the
canonical product of sums (POS) logic
expression.
4.3.23 For the 3-input truth table in Fig. 4.33, give the
canonical product of sums (POS) logic
diagram.
4.3.24 For the 3-input truth table in Fig. 4.33, give the
maxterm list.
4.3.25 For the 3-input minterm list in Fig. 4.34, give
the canonical sum of products (SOP) logic
expression.
4.3.26 For the 3-input minterm list in Fig. 4.34, give 4.3.38 For the 4-input truth table in Fig. 4.36, give the
the canonical sum of products (SOP) logic canonical sum of products (SOP) logic
diagram. diagram.
4.3.27 For the 3-input minterm list in Fig. 4.34, give 4.3.39 For the 4-input truth table in Fig. 4.36, give the
the truth table. minterm list.
4.3.28 For the 3-input minterm list in Fig. 4.34, give 4.3.40 For the 4-input truth table in Fig. 4.36, give the
the canonical product of sums (POS) logic canonical product of sums (POS) logic
expression. expression.
4.3.29 For the 3-input minterm list in Fig. 4.34, give 4.3.41 For the 4-input truth table in Fig. 4.36, give the
the canonical product of sums (POS) logic canonical product of sums (POS) logic
diagram. diagram.
4.3.30 For the 3-input minterm list in Fig. 4.34, give 4.3.42 For the 4-input truth table in Fig. 4.36, give the
the maxterm list. maxterm list.
4.3.31 For the 3-input maxterm list in Fig. 4.35, give 4.3.43 For the 4-input minterm list in Fig. 4.37, give
the canonical sum of products (SOP) logic the canonical sum of products (SOP) logic
expression. expression.
4.3.32 For the 3-input maxterm list in Fig. 4.35, give 4.3.44 For the 4-input minterm list in Fig. 4.37, give
the canonical sum of products (SOP) logic the canonical sum of products (SOP) logic
diagram. diagram.
4.3.33 For the 3-input maxterm list in Fig. 4.35, give 4.3.45 For the 4-input minterm list in Fig. 4.37, give
the minterm list. the truth Table.
4.3.34 For the 3-input maxterm list in Fig. 4.35, give 4.3.46 For the 4-input minterm list in Fig. 4.37, give
the canonical product of sums (POS) logic the canonical product of sums (POS) logic
expression. expression.
4.3.35 For the 3-input maxterm list in Fig. 4.35, give 4.3.47 For the 4-input minterm list in Fig. 4.37, give
the canonical product of sums (POS) logic the canonical product of sums (POS) logic
diagram. diagram.
4.3.36 For the 3-input maxterm list in Fig. 4.35, give 4.3.48 For the 4-input minterm list in Fig. 4.37, give
the truth table. the maxterm list.
4.3.37 For the 4-input truth table in Fig. 4.36, give 4.3.49 For the 4-input maxterm list in Fig. 4.38, give
the canonical sum of products (SOP) logic the canonical sum of products (SOP) logic
expression. expression.
136 • Chapter 4: Combinational Logic Design
Fig. 4.38
Combinational logic synthesis 9
Fig. 4.41
4.3.50 For the 4-input maxterm list in Fig. 4.38, give Logic minimization 3
the canonical sum of products (SOP) logic
diagram. 4.4.6 For the 2-input truth table in Fig. 4.41, use a
4.3.51 For the 4-input maxterm list in Fig. 4.38, give K-map to derive a minimized product of sums
the minterm list. (POS) logic expression.
4.3.52 For the 4-input maxterm list in Fig. 4.38, give 4.4.7 For the 2-input truth table in Fig. 4.42, use a
the canonical product of sums (POS) logic K-map to derive a minimized sum of products
expression. (SOP) logic expression.
4.3.53 For the 4-input maxterm list in Fig. 4.38, give
the canonical product of sums (POS) logic
diagram.
4.3.54 For the 4-input maxterm list in Fig. 4.38, give
the truth table.
Fig. 4.39
Logic minimization 1
Fig. 4.44
Logic minimization 6
Exercise Problems • 137
4.4.12 For the 3-input truth table in Fig. 4.44, use a 4.4.18 For the 4-input truth table in Fig. 4.47, use a
K-map to derive a minimized product of sums K-map to derive a minimized product of sums
(POS) logic expression. (POS) logic expression.
4.4.13 For the 3-input truth table in Fig. 4.45, use a 4.4.19 For the 4-input truth table in Fig. 4.48, use a
K-map to derive a minimized sum of products K-map to derive a minimized sum of products
(SOP) logic expression. (SOP) logic expression.
Fig. 4.45
Logic minimization 7
Fig. 4.46
Logic minimization 8
Fig. 4.49
Logic minimization 11
Fig. 4.47
Logic minimization 9 4.4.22 For the 4-input truth table in Fig. 4.49, use a
K-map to derive a minimized product of sums
(POS) logic expression.
138 • Chapter 4: Combinational Logic Design
Fig. 4.52
Logic minimization 14
Fig. 4.51
Logic minimization 13
Gordon Moore, cofounder of Intel, predicted in 1965 that the number of transistors on an integrated
circuit would double every two years. This prediction, now known as Moore’s Law, has held true since the
invention of the integrated circuit. As the number of transistors on an integrated circuit grew, so did the
size of the design and the functionality that could be implemented. Once the first microprocessor was
invented in 1971, the capability of CAD tools increased rapidly enabling larger designs to be accom-
plished. These larger designs, including newer microprocessors, enabled the CAD tools to become even
more sophisticated and, in turn, yield even larger designs. The rapid expansion of electronic systems
based on digital integrated circuits required that different manufacturers needed to produce designs that
were compatible with each other. The adoption of logic family standards helped manufacturers ensure
their parts would be compatible with other manufacturers at the physical layer (e.g., voltage and current);
however, one challenge that was encountered by the industry was a way to document the complex
behavior of larger systems. The use of schematics to document large digital designs became too
cumbersome and difficult to understand by anyone besides the designer. Word descriptions of the
behavior were easier to understand, but even this form of documentation became too voluminous to
be effective for the size of designs that were emerging. Simultaneously there was a need to begin
simulating the functionality of these large systems prior to fabrication to verify accuracy. Due to the
complexity of these systems and the vast potential for design error, it became impractical to verify design
accuracy through prototyping.
In 1983, the US Department of Defense (DoD) sponsored a program to create a means to document
the behavior of digital systems that could be used across all of its suppliers. This program was motivated
by a lack of adequate documentation for the functionality of application specific integrated circuits
(ASICs) that were being supplied to the DoD. This lack of documentation was becoming a critical
issue as ASICs would come to the end of their life cycle and need to be replaced. With the lack of a
standardized documentation approach, suppliers had difficulty reproducing equivalent parts to those that
had become obsolete. The DoD contracted three companies (Texas Instruments, IBM, and Intermetrics)
to develop a standardized documentation tool that provided detailed information about both the interface
(i.e., inputs and outputs) and the behavior of digital systems. The new tool was to be implemented in a
format similar to a programming language. Due to the nature of this type of language-based tool, it was a
natural extension of the original project scope to include the ability to simulate the behavior of a digital
system. The simulation capability was desired to span multiple levels of abstraction to provide maximum
flexibility. In 1985, the first version of this tool, called VHDL, was released. In order to gain widespread
adoption and ensure consistency of use across the industry, VHDL was turned over to the Institute of
Electrical and Electronic Engineers (IEEE) for standardization. IEEE is a professional association that
defines a broad range of open technology standards. In 1987, IEEE released the first industry standard
version of VHDL. The release was titled IEEE 1076–1987. Feedback from the initial version resulted in a
major revision of the standard in 1993 titled IEEE 1076–1993. While many minor revisions have been
5.1 History of Hardware Description Languages • 143
made to the 1993 release, the 1076–1993 standard contains the vast majority of VHDL functionality in
use today. The most recent VHDL standard is IEEE 1076–2008.
Also in 1983, the Verilog HDL was developed by Automated Integrated Design Systems as a logic
simulation language. The development of Verilog took place completely independent from the VHDL
project. Automated Integrated Design Systems (renamed Gateway Design Automation in 1985) was
acquired by CAD tool vendor Cadence Design Systems in 1990. In response to the popularity of Verilog’s
intuitive programming and superior simulation support, and also to stay competitive with the emerging
VHDL standard, Cadence made the Verilog HDL open to the public. IEEE once again developed the
open standard for this HDL, and in 1995 released the Verilog standard titled IEEE 1364–1995. This
release has undergone numerous revisions with the most significant occurring in 2001. It is common to
refer to the major releases as “Verilog 1995” and “Verilog 2001” instead of their official standard numbers.
The development of CAD tools to accomplish automated logic synthesis can be dated back to the
1970’s when IBM began developing a series of practical synthesis engines that were used in the design
of their mainframe computers; however, the main advancement in logic synthesis came with the founding
of a company called Synopsis in 1986. Synopsis was the first company to focus on logic synthesis
directly from HDLs. This was a major contribution because designers were already using HDLs to
describe and simulate their digital systems, and now logic synthesis became integrated in the same
design flow. Due to the complexity of synthesizing highly abstract functional descriptions, only lower-
levels of abstraction that were thoroughly elaborated were initially able to be synthesized. As CAD tool
capability evolved, synthesis of higher levels of abstraction became possible, but even today not all
functionality that can be described in an HDL can be synthesized.
The history of HDLs, their standardization, and the creation of the associated logic synthesis tools is
key to understanding the use and limitations of HDLs. HDLs were originally designed for documentation
and behavioral simulation. Logic synthesis tools were developed independently and modified later to
work with HDLs. This history provides some background into the most common pitfalls that beginning
digital designers encounter, that being that most any type of behavior can be described and simulated in
an HDL, but only a subset of well-described functionality can be synthesized. Beginning digital designers
are often plagued by issues related to designs that simulate perfectly but that will not synthesize
correctly. In this book, an effort is made to introduce Verilog at a level that provides a reasonable amount
of abstraction while preserving the ability to be synthesized. Figure 5.1 shows a timeline of some of the
major technology milestones that have occurred in the past 150 years in the field of digital logic and
HDLs.
144 • Chapter 5: Verilog (Part 1)
Fig. 5.1
Major milestones in the advancement of Digital Logic and HDLs
CONCEPT CHECK
CC5.1 Why does Verilog support modeling techniques that aren’t synthesizable?
(A) There wasn’t enough funding available to develop synthesis capability as it all went
to the VHDL project.
(B) At the time Verilog was created, synthesis was deemed too difficult to implement.
(C) To allow Verilog to be used as a generic programming language.
(D) Verilog needs to support all steps in the modern digital design flow, some of which
are unsynthesizable such as test pattern generation and timing verification.
5.2 HDL Abstraction • 145
Fig. 5.2
Levels of design abstraction
The highest level of abstraction is the system level. At this level, behavior of a system is described
by stating a set of broad specifications. An example of a design at this level is a specification such as “the
computer system will perform 10 Tera Floating Point Operations per Second (10 TFLOPS) on double
146 • Chapter 5: Verilog (Part 1)
precision data and consume no more than 100 Watts of power”. Notice that these specifications do not
dictate the lower level details such as the type of logic family or the type of computer architecture to use.
One level down from the system level is the algorithmic level. At this level, the specifications begin to be
broken down into sub-systems, each with an associated behavior that will accomplish a part of the
primary task. At this level, the example computer specifications might be broken down into sub-systems
such as a central processing unit (CPU) to perform the computation and random access memory (RAM)
to hold the inputs and outputs of the computation. One level down from the algorithmic level is the
register transfer level (RTL). At this level, the details of how data is moved between and within
sub-systems are described in addition to how the data is manipulated based on system inputs. One
level down from the RTL level is the gate level. At this level, the design is described using basic gates and
registers (or storage elements). The gate level is essentially a schematic (either graphically or text-
based) that contains the components and connections that will implement the functionality from the
above levels of abstraction. One level down from the gate level is the circuit level. The circuit level
describes the operation of the basic gates and registers using transistors, wires and other electrical
components such as resistors and capacitors. Finally, the lowest level of design abstraction is the
material level. This level describes how different materials are combined and shaped in order to
implement the transistors, devices and wires from the circuit level.
HDLs are designed to model behavior at all of these levels with the exception of the material level.
While there is some capability to model circuit level behavior such as MOSFETs as ideal switches and
pull-up/pull-down resistors, HDLs are not typically used at the circuit level. Another graphical depiction of
design abstraction is known as the Gajski and Kuhn’s Y-chart. A Y-chart depicts abstraction across
three different design domains: behavioral, structural and physical. Each of these design domains
contains levels of abstraction (i.e., system, algorithm, RTL, gate, and circuit). An example Y-chart is
shown in Fig. 5.3.
5.2 HDL Abstraction • 147
Fig. 5.3
Y-Chart of design abstraction
A Y-chart also depicts how the abstraction levels of different design domains are related to each
other. A top-down design flow can be visualized in a Y-chart by spiraling inward in a clockwise direction.
Moving from the behavioral domain to the structural domain is the process of synthesis. Whenever
synthesis is performed, the resulting system should be compared with the prior behavioral description.
This checking is called verification. The process of creating the physical circuitry corresponding to the
structural description is called implementation. The spiral continues down through the levels of abstrac-
tion until the design is implemented at a level that the geometries representing circuit elements
(transistors, wires, etc.) are ready to be fabricated in silicon. Figure 5.4 shows the top-down design
process depicted as an inward spiral on the Y-chart.
148 • Chapter 5: Verilog (Part 1)
Fig. 5.4
Y-Chart illustrating top-down design approach
The Y-chart represents a formal approach for large digital systems. For large systems that are
designed by teams of engineers, it is critical that a formal, top-down design process is followed to
eliminate potentially costly design errors as the implementation is carried out at lower levels of
abstraction.
CONCEPT CHECK
Fig. 5.5
Generic digital design flow
This generic design process flow can be used across classical and modern digital design, although
modern digital design allows additional verification at each step using automated CAD tools. Figure 5.6
shows how this flow is used in the classical design approach of a combinational logic circuit.
150 • Chapter 5: Verilog (Part 1)
Fig. 5.6
Classical digital design flow
The modern design flow based on HDLs includes the ability to simulate functionality at each step of
the process. Functional simulations can be performed on the initial behavioral description of the system.
At each step of the design process the functionality is described in more detail, ultimately moving toward
the fabrication step. At each level, the detailed information can be included in the simulation to verify that
the functionality is still correct and that the design is still meeting the original specifications. Figure 5.7
shows the modern digital design flow with the inclusion of simulation capability at each step.
5.3 The Modern Digital Design Flow • 151
Fig. 5.7
Modern digital design flow
CONCEPT CHECK
CC5.3 Why did digital designs move from schematic-entry to text-based HDLs?
(A) HDL models could be much larger by describing functionality in text similar to
traditional programming language.
(B) Schematics required sophisticated graphics hardware to display correctly.
(C) Schematics symbols became too small as designs became larger.
(D) Text was easier to understand by a broader range of engineers.
152 • Chapter 5: Verilog (Part 1)
A Verilog design describes a single system in a single file. The file has the suffix *.v. Within the file,
the system description is contained within a module. The module includes the interface to the system
(i.e., the inputs and outputs) and the description of the behavior. Figure 5.8 shows a graphical depiction
of a Verilog file.
Fig. 5.8
The anatomy of a Verilog file
Verilog is case sensitive. Also, each Verilog assignment, definition or declaration is terminated with
a semicolon (;). As such, line wraps are allowed and do not signify the end of an assignment, definition or
declaration. Line wraps can be used to make Verilog more readable. Comments in Verilog are supported
in two ways. The first way is called a line comment and is preceded with two slashes (i.e., //). Everything
after the slashes is considered a comment until the end of the line. The second comment approach is
called a block comment and begins with /* and ends with a */. Everything between /* and */ is considered
a comment. A block comment can span multiple lines. All user-defined names in Verilog must start with
an alphabetic letter, not a number. User-defined names are not allowed to be the same as any Verilog
keyword. This chapter contains many definitions of syntax in Verilog. The following notations will be used
throughout the chapter when introducing new constructs.
Value Description
0 A logic zero, or false condition.
1 A logic one, or true condition.
x or X Unknown or uninitialized.
z or Z High impedance, tri-stated, or floating.
In Verilog, these values also have an associated strength. The strengths are used to resolve the
value of a signal when it is driven by multiple sources. The names, syntax and relative strengths are
given below.
When a signal is driven by multiple drivers, it will take on the value of the driver with the highest
strength. If the two drivers have the same strength, the value will be unknown. If the strength is not
specified, it will default to strong drive, or level 6.
Type Description
wire A simple connection between components.
wor Wired-OR. If multiple drivers, their values are OR’d together.
wand Wired-AND’d. If multiple drivers, their values are AND’d together.
supply0 Used to model the VSS, (GND), power supply (supply strength inherent).
supply1 Used to model the VCC power supply (supply strength inherent).
tri Identical to wire. Used for readability for a net driven by multiple sources.
trior Identical to wor. Used for readability for nets driven by multiple sources.
triand Identical to wand. Used for readability for nets driven by multiple sources.
tri1 Pulls up to logic one when tri-stated.
tri0 Pulls down to logic zero when tri-stated.
trireg Holds last value when tri-stated (capacitance strength inherent).
Each of these net types can also have an associated drive strength. The strength is used in
determining the final value of the net when it is connected to multiple drivers.
Type Description
reg A variable that models logic storage. Can take on values 0, 1, X, and Z.
integer A 32-bit, 2’s complement variable representing whole numbers between
2,147,483,64810 to +2,147,483,647.
real A 64-bit, floating point variable representing real numbers between –(2.2x10308)10
to +(2.2x10308)10.
time An unsigned, 64-bit variable taking on values from 010 to +(9.2x1018).
realtime Same as time. Just used for readability.
5.4.1.4 Vectors
In Verilog, a vector is a one-dimensional array of elements. All of the net data types, in addition to the
variable type reg, can be used to form vectors. The syntax for defining a vector is as follows:
<type> [<MSB_index>:<LSB_index>] vector_name
While any range of indices can be used, it is common practice to have the LSB index start at zero.
Example:
wire [7:0] Sum; // This defines an 8-bit vector called “Sum” of type wire. The
// MSB is given the index 7 while the LSB is given the index 0.
reg [15:0] Q; // This defines a 16-bit vector called “Q” of type reg.
Individual bits within the vector can be addressed using their index. Groups of bits can be accessed
using an index range.
Sum[0]; // This is the least significant bit of the vector “Sum” defined
above.
Q[15:8]; // This is the upper 8-bits of the 16-bit vector “Q” defined
above.
5.4 Verilog Constructs • 155
5.4.1.5 Arrays
An array is a multi-dimensional array of elements. This can also be thought of as a “vector of
vectors”. Vectors within the array all have the same dimensions. To declare an array, the element type
and dimensions are defined first followed by the array name and its dimensions. It is common practice to
place the start index of the array on the left side of the “:” when defining its dimensions. The syntax for the
creation of an array is shown below.
<element_type> [<MSB_index>:<LSB_index>] array_name [<array_start_index>:
<array_end_index>];
Example:
reg[7:0] Mem[0:4095]; // Defines an array of 4096, 8-bit vectors of type reg.
integer A[1:100]; // Defines an array of 100 integers.
When accessing an array, the name of the array is given first, followed by the index of the element. It
is also possible to access an individual bit within an array by adding appending the index of element.
Example:
Mem[2]; // This is the 3rd element within the array named “Mem”.
// This syntax represents an 8-bit vector of type reg.
Mem[2][7]; // This is the MSB of the 3rd element within the array named “Mem”.
// This syntax represents a single bit of type reg.
A[2]; // This is the 2nd element within the array named “A”. Recall
// that A was declared with a starting index of 1.
// This syntax represents a 32-bit, signed integer.
<size_in_bits>’<base><value>
Note that specifying the size is optional. If it is omitted, the number will default to a 32-bit vector with
leading zeros added as necessary. The supported bases are as follows:
Syntax Description
‘b Unsigned binary
‘o Unsigned octal
‘d Unsigned decimal
‘h Unsigned hexadecimal
‘sb Signed binary
‘so Signed octal
‘sd Signed decimal
‘sh Signed hexadecimal
156 • Chapter 5: Verilog (Part 1)
Example:
10 // This is treated as decimal 10, which is a 32-bit signed vector.
4’b1111 // A 4-bit number with the value 11112.
8’b1011_0000 // An 8-bit number with the value 101100002.
8’hFF // An 8-bit number with the value 111111112.
8’hff // An 8-bit number with the value 111111112.
6’hA // A 6-bit number with the value 0010102. Note that leading zeros
// were added to make the value 6-bits.
8’d7 // An 8-bit number with the value 000001112.
32’d0 // A 32-bit number with the value 0000_000016.
’b1111 // A 32-bit number with the value 0000_000F16.
8’bZ // An 8-bit number with the value ZZZZ_ZZZZ.
or
module module_name (port_list and port_definitions); // Verilog-2001 and after
// module_items
endmodule
registers, and integers are synthesizable. Port names with the same type and direction can be listed on
the same line separated by commas.
There are two different port definition styles supported in Verilog. Prior to the Verilog-2001 release,
the port names were listed within parentheses after the module name. Then within the module, the
directionality and type of the ports were listed. Starting with the Verilog-2001 release, the port directions
and types could be included alongside the port names within the parenthesis after the module name.
This approach mimicked more of an ANSCI-C approach to passing inputs/outputs to a system. In this
text, the newer approach to port definition will be used. Example 5.1 shows multiple approaches for
defining a module and its ports.
Example 5.1
Declaring Verilog module ports
Example:
wire node1; // declare a signal named “node1” of type wire
reg Q2, Q1, Q0; // declare three signals named “Q2”, “Q1”, and “Q0”, all of
type reg
wire [63:0] bus1; // declare a 64-bit vector named “bus1” with all bits of
type wire
integer i,j; // declare two integers called “i” and “j”
Verilog supports a hierarchical design approach, thus signal names can be the same within a
sub-system as those at a higher level without conflict. Figure 5.9 shows an example of legal signal
naming in a hierarchical design.
Fig. 5.9
Verilog signals and systems
Note that the type is optional and can only be integer, time, real, or realtime. If a type is provided,
the parameter will have the same properties as a variable of the same time. If the type is excluded, the
parameter will take on the type of the value assigned to it.
Example:
Once declared, the constant name can be used throughout the module. The following example
illustrates how we can use a constant to define the size of a vector. Notice that since we defined the
constant to be the actual width of the vector (i.e., 32-bits), we need to subtract one from its value when
defining the indices (i.e., [31:0]).
Example:
wire [BUS_WIDTH-1:0] BUS_A; // It is acceptable to add a “space”
for readability
5.4 Verilog Constructs • 159
Syntax Description
`timescale < unit>,<precision> Defines the timescale of the delay unit and its smallest precision
`include < filename> Includes additional files in the compilation
`define < macroname > <value> Declares a global constant
Example:
‘timescale 1ns/1ps // Declares the unit of time is 1 ns with a precision of 1ps.
// The precision is the smallest amount that the time can
// take on. For example, with this directive the number
// 0.001 would be interpreted as 0.001 ns, or 1 ps.
// However, the number 0.0001 would be interpreted as 0 since
// it is smaller than the minimum precision value.
Example:
F1 ¼ A; // F1 is assigned the signal A
F2 ¼ 4’hAA; // F2 is an 8-bit vector and is assigned the value 101010102
Syntax Operation
~ Negation
& AND
| OR
^ XOR
~^ or ^~ XNOR
<< Logical shift left (fill empty LSB location with zero)
>> Logical shift right (fill empty MSB location with zero)
160 • Chapter 5: Verilog (Part 1)
Example:
~X // invert each bit in X
X&Y // AND each bit of X with each bit of Y
X|Y // OR each bit of X with each bit of Y
X^Y // XOR each bit of X with each bit of Y
X ~^ Y // XNOR each bit of X with each bit of Y
X << 3 // Shift X left 3 times and fill with zeros
Y >> 2 // Shift Y right 2 times and fill with zeros
Syntax Operation
& AND all bits in the vector together (1-bit result)
~& NAND all bits in the vector together (1-bit result)
| OR all bits in the vector together (1-bit result)
~| NOR all bits in the vector together (1-bit result)
^ XOR all bits in the vector together (1-bit result)
~^ or ^~ XNOR all bits in the vector together (1-bit result)
Example:
&X // AND all bits in vector X together
~&X // NAND all bits in vector X together
|X // OR all bits in vector X together
~|X // NOR all bits in vector X together
^X // XOR all bits in vector X together
~^X // XNOR all bits in vector X together
Syntax Operation
! Negation
&& AND
|| OR
Example:
!X // TRUE if all values in X are 0, FALSE otherwise
X && Y // TRUE if the bitwise AND of X and Y results in all ones, FALSE otherwise
X || Y // TRUE if the bitwise OR of X and Y results in all ones, FALSE otherwise
Syntax Description
¼¼ Equality
!¼ Inequality
< Less than
> Greater than
<¼ Less than or equal
>¼ Greater than or equal
Example:
X ¼¼ Y // TRUE if X is equal to Y, FALSE otherwise
X !¼ Y // TRUE if X is not equal to Y, FALSE otherwise
X<Y // TRUE if X is less than Y, FALSE otherwise
X>Y // TRUE if X is greater than Y, FALSE otherwise
X <¼ Y // TRUE if X is less than or equal to Y, FALSE otherwise
X >¼ Y // TRUE if X is greater than or equal to Y, FALSE otherwise
This operator specifies a Boolean condition in which if evaluated TRUE, the true_assignment will be
assigned to the target. If the Boolean condition is evaluated FALSE, the false_assignment portion of the
operator will be assigned to the target. The values in this assignment can be signals or logic values. The
Boolean condition can be any combination of the Boolean operators described above. Nested condi-
tional operators can also be implemented by inserting subsequent conditional operators in place of the
false_value.
Example:
F ¼ (A ¼¼ 1’b0) ? 1’b1 : 1’b0; // If A is a zero, F¼1, otherwise F¼0.
This models an inverter.
Example:
Bus1[7:0] ¼ {Bus2[7:4], Bus3[3:0]}; // Assuming Bus1, Bus2, and Bus3 are all 8-bit
// vectors, this operation takes the upper
4-bits of
// Bus2, concatenates them with the lower
4-bits of
// Bus3, and assigns the 8-bit combination
to Bus1.
BusC ¼ {BusA, BusB}; // If BusA and BusB are 4-bits, then BusC
// must be 8-bits.
BusC[7:0] ¼ {4’b0000, BusA}; // This pads the 4-bit vector BusA with 4x
leading
// zeros and assigns to the 8-bit vector
BusC.
Example:
BusX ¼ {4{Bus1}}; // This is equivalent to: BusX ¼ {Bus1, Bus1, Bus1, Bus1};
BusY ¼ {2{A,B}}; // This is equivalent to: BusY ¼ {A, B, A, B};
BusZ ¼ {Bus1, {2{Bus2}}}; // This is equivalent to: BusZ ¼ {Bus1, Bus2, Bus2};
Syntax Operation
+ Addition
Subtraction (when placed between arguments)
2’s complement negation (when placed in front of an argument)
* Multiplication
/ Division
% Modulus
** Raise to the power
<<< Shift to the left, fill with zeros
<<< Shift to the right, fill with sign bit
Example:
X+Y // Add X to Y
X-Y // Subtract Y from X
-X // Take the two’s complement negation of X
X*Y // Multiply X by Y
X/Y // Divide X by Y
X%Y // Modulus X/Y
X ** Y // Raise X to the power of Y
X <<< 3 // Shift X left 3 times, fill with zeros
X >>> 2 // Shift X right 2 times, fill with sign bit
5.4 Verilog Constructs • 163
Verilog will allow the use of these operators on arguments of different sizes, types and signs. The
rules of the operations are as follows:
• If two vectors are of different sizes, the smaller vector is expanded to the size of the larger
vector.
– If the smaller vector is unsigned, it is padded with zeros.
– If the smaller vector is signed, it is padded with the sign bit.
• If one of the arguments is real, then the arithmetic will take place using real numbers.
• If one of the arguments is unsigned, then all arguments will be treated as unsigned.
CONCEPT CHECK
CC5.4(a) What revision of Verilog added the ability to list the port names, types, and directions just
once after the module name?
(A) Verilog-1995.
(B) Verilog-2001.
(C) Verilog-2005.
(D) SystemVerilog.
CC5.4(b) What is the difference between types wire and reg?
(A) They are the same.
(B) The type wire is a simple interconnection while reg will hold the value of its last
assignment.
(C) The type wire is for scalars while the type reg is for vectors.
(D) Only wire is synthesizable.
164 • Chapter 5: Verilog (Part 1)
Each individual assignment will be executed concurrently and synthesized as separate logic
circuits. Consider the following example.
Example:
assign X ¼ A;
assign Y ¼ B;
assign Z ¼ C;
When simulated, these three lines of Verilog will make three separate signal assignments at the
exact same time. This is different from a programming language that will first assign A to X, then B to Y
and finally C to Z. In Verilog this functionality is identical to three separate wires. This description will be
directly synthesized into three separate wires.
Below is another example of how continuous signal assignments in Verilog differ from a sequentially
executed programming language.
Example:
assign A ¼ B;
assign B ¼ C;
In a Verilog simulation, the signal assignments of C to B and B to A will take place at the same time.
This means during synthesis, the signal B will be eliminated from the design since this functionality
describes two wires in series. Automated synthesis tools will eliminate this unnecessary signal name.
This is not the same functionality that would result if this example was implemented as a sequentially
executed computer program. A computer program would execute the assignment of B to A first, then
assign the value of C to B second. In this way, B represents a storage element that is passed to A before
it is updated with C.
Example 5.2
Modeling combinational logic using continuous assignment with logical operators
Example 5.3
Modeling combinational logic using continuous assignment with conditional operators (1)
In the prior example, the conditional operator was based on a truth table. Conditional operators can
also be used to model logic expressions. Example 5.4 shows how to design a Verilog model of a
combinational logic circuit when the logic expression is already known. Note that this example again
uses the same truth table as in Example 5.2 and Example 5.3 to illustrate a comparison between
approaches.
5.5 Modeling Concurrent Functionality in Verilog • 167
Example 5.4
Modeling combinational logic using continuous assignment with conditional operators (2)
Example:
assign #1 F ¼ A; // Delay of 1 on all transitions.
assign #(2,3) F ¼ A; // Delay of 2 for rising transitions and 3 for falling.
assign #(2,3,4) F ¼ A; // Delay of 2 for rising, 3 for falling, and 4 for off
transitions.
When using delay, it is typical to include the `timescale directive to provide the units of the delay
being specified. Example 5.5 shows a graphical depiction of using delay with continuous assignments
when modeling combinational logic circuits.
168 • Chapter 5: Verilog (Part 1)
Example 5.5
Modeling delay in continuous assignments
Verilog also provides a mechanism to model a range of delays that are selected by a switch set in the
CAD compiler. There are three delays categories that can be specified: minimum, typical, and maximum.
The delays are separated by a “:”. The following is the syntax of how to use the delay range capability.
assign #(<min>:<typ>:<max>) <target_net> ¼ <RHS_nets, operators, etc.. . .>;
Example:
assign #(1:2:3) F ¼ A;
// Specifying a range of delays for all
transitions.
assign #(1:1:2, 2:2:3) F ¼ A; // Specifying a range of delays for rising/
falling.
assign #(1:1:2, 2:2:3, 4:4:5) F ¼ A; // Specifying a range of delays for each
transition.
5.5 Modeling Concurrent Functionality in Verilog • 169
The delay modeling capability in continuous assignment is designed to model the behavior of real
combinational logic with respect to short duration pulses. When a pulse is shorter than the delay of the
combinational logic gate, the pulse is ignored. Ignoring brief input pulses on the input accurately models
the behavior of on-chip gates. When the input pulse is faster than the delay of the gate, the output of
the gate does not have time to respond. As a result, there will not be a logic change on the output. This
is called inertial delay modeling and is the default behavior when using continuous assignments.
Example 5.6 shows a graphical depiction of inertial delay behavior in Verilog.
Example 5.6
Inertial delay modeling when using continuous assignment
CONCEPT CHECK
The first portion of the instantiation is the module name that is being called. This must match the
lower level module name exactly, including case. The second portion of the instantiation is an optional
instance identifier. Instance identifier are useful when instantiating multiple instances of the same lower-
level module. The final portion of the instantiation is the port mapping. There are two techniques to
connect signals to the ports of the lower-level module, explicit and positional.
Example 5.7 shows how to design a Verilog model of a hierarchical system that consists of two
lower-level modules.
5.6 Structural Design and Hierarchy • 171
Example 5.7
Verilog structural design using explicit port mapping
Example 5.8 shows how to create the same structural Verilog model as in Example 5.7, but using
positional port mapping instead.
172 • Chapter 5: Verilog (Part 1)
Example 5.8
Verilog structural design using positional port mapping
Example 5.9
Modeling combinational logic circuits using gate level primitives
A UDP must list its output(s) first in the port definition. It also does not require types to be defined for
the ports. For combinational logic UDPs, all ports are assumed to be of type wire. Example 5.10 shows
how to design a user-defined primitive to implement a combinational logic circuit.
174 • Chapter 5: Verilog (Part 1)
Example 5.10
Modeling combinational logic circuits with a user-defined primitive
Example:
not #2 U0 (An, A); // Gate level primitive for an inverter with delay
of 2.
and #3 U3 (m0, An, Bn, Cn); // Gate level primitive for an AND gate with delay
of 3.
SystemX_UDP #1 U0 (F, A, B, C); // UDP with a delay of 1.
5.7 Overview of Simulation Test Benches • 175
CONCEPT CHECK
CC5.6 Does the use of lower-level sub-modules model concurrent functionality? Why?
(A) No. Since the lower-level behavior of the module being instantiated may contain
non-concurrent behavior, it is not known what functionality will be modeled.
(B) Yes. The modules are treated like independent sub-systems whose behavior runs
in parallel just as if separate parts were placed in a design.
Fig. 5.10
Overview of Verilog test benches
176 • Chapter 5: Verilog (Part 1)
CONCEPT CHECK
CC5.7 How can the output of a DUT be verified when it is connected to a signal that does not go
anywhere?
(A) It can’t. The output must be routed to an output port on the test bench.
(B) The values of any dangling signal are automatically written to a text file.
(C) It is viewed in the logic simulator as either a waveform or text listing.
(D) It can’t. A signal that does not go anywhere will cause an error when the Verilog file
is compiled.
Summary
v The modern digital design flow relies on com- v Instantiating other modules from within a
puter aided engineering (CAE) and computer higher-level module is how Verilog
aided design (CAD) tools to manage the size implements hierarchy. A lower-level module
and complexity of today’s digital designs. can be instantiated as many times as
v Hardware description languages (HDLs) desired. An instance identifier is useful is
allow the functionality of digital systems to keeping track of each instantiation. The
be entered using text. VHDL and Verilog are ports of the component can be connected
the two most common HDLs in use today. using either explicit or positional port
v In the 1980’s, two major HDLs emerged, mapping.
VHDL and Verilog. VHDL was sponsored by v Concurrency is the term that describes
the Department of Defense while Verilog was operations being performed in parallel. This
driven by the commercial industry. Both were allows real-world system behavior to be
later standardized by IEEE. modeled.
v The ability to automatically synthesize a logic v Verilog provides the continuous assignment
circuit from a Verilog behavioral description operator to support modeling concurrent
became possible approximately 10 years systems. Complex logic circuits can be
after the original definition of Verilog. As implemented by using continuous assign-
such, only a sub-set of the behavioral ment with logical operators or conditional
modeling techniques in Verilog can be auto- operators.
matically synthesized. v Verilog sub-systems are also treated as con-
v HDLs can model digital systems at different current sub-systems.
levels of design abstraction. These include v Delay can be modeled in Verilog for all
the system, algorithmic, RTL, gate, and cir- transitions, or for individual transitions (rise,
cuit levels. Designing at a higher level of fall, off). A range of delays can also be
abstraction allows more complex systems to provided (min:typ:max). Delay can be
be modeled without worrying about the added to continuous assignments and
details of the implementation. sub-system instantiations.
v In a Verilog source file, all functionality is v Gate level primitives are provided in Verilog
contained within a module. The first portion to implement basic logic functions (not, and,
of the module is the port definition. The sec- nand, or, nor, xor, xnor). These primitives are
ond portion contains declarations of internal instantiated just like any other lower-level
signals/constants/parameters. The third por- sub-system.
tion contains the description of the behavior. v User Defined Primitives are supported in
v A port is an input or output to a system that is Verilog that allow the functionality of a circuit
defined as part of the initial module state- to be described in table form.
ment. A signal, or net, is an internal connec- v A simulation test bench is a Verilog file that
tion within the system that is declared inside drives stimulus into a device under test
of the module. A signal is not visible outside (DUT). Test benches do not have inputs or
of the system. outputs and are not synthesizable.
Exercise Problems • 177
Exercise Problems
Section 5.1: History of HDLs 5.3.2 Which step in the modern digital design flow
does the following statement relate to: after
5.1.1 What was the original purpose of Verilog?
realistic gate and wiring delays are determined,
5.1.2 Can all of the functionality that can be one last simulation should be performed to
described in Verilog be simulated? make sure the design meets the original timing
5.1.3 Can all of the functionality that can be requirements.
described in Verilog be synthesized? 5.3.3 Which step in the modern digital design flow
does the following statement relate to: if the
Section 5.2: HDL Abstraction memory is distributed around the perimeter of
the CPU, the wiring density will be minimized.
5.2.1 Give the level of design abstraction that the
following statement relates to: if there is ever 5.3.4 Which step in the modern digital design flow
an error in the system, it should return to the does the following statement relate to: the
reset state. design meets all requirements so now I’m
building the hardware that will be shipped.
5.2.2 Give the level of design abstraction that the
following statement relates to: once the design 5.3.5 Which step in the modern digital design flow
is implemented in a sum of products form, does the following statement relate to: the sys-
DeMorgan’s Theorem will be used to convert tem will be broken down into three
it to a NAND-gate only implementation. sub-systems with the following behaviors.
5.2.3 Give the level of design abstraction that the 5.3.6 Which step in the modern digital design flow
following statement relates to: the design will does the following statement relate to: this sys-
be broken down into two sub-systems, one that tem needs to have 10 Gbytes of memory.
will handle data collection and the other that 5.3.7 Which step in the modern digital design flow
will control data flow. does the following statement relate to: to meet
5.2.4 Give the level of design abstraction that the the power requirements, the gates will be
following statement relates to: the interconnect implemented in the 74HC logic family.
on the IC should be changed from aluminum to
copper to achieve the performance needed in Section 5.4: Verilog Constructs
this design.
5.4.1 What is the name of the main design unit in
5.2.5 Give the level of design abstraction that the Verilog?
following statement relates to: the MOSFETs
5.4.2 What portion of the Verilog module describes
need to be able to drive at least 8 other loads in
the inputs and outputs.
this design.
5.4.3 What step is necessary if a system requires
5.2.6 Give the level of design abstraction that the
internal connections?
following statement relates to: this system will
contain 1 host computer and support up to 5.4.4 What are all the possible values that a Verilog
1000 client computers. net type can take on?
5.2.7 Give the design domain that the following activ- 5.4.5 What is the highest strength that a value can
ity relates to: drawing the physical layout of the take on in Verilog.
CPU will require six months of engineering 5.4.6 What is the range of decimal numbers that can
time. be represented using the type integer in
5.2.8 Give the design domain that the following activ- Verilog?
ity relates to: the CPU will be connected to 5.4.7 What is the width of the vector defined using
4 banks of memory. the type [63:0] wire?
5.2.9 Give the design domain that the following activ- 5.4.8 What is the syntax for indexing the most signif-
ity relates to: the fan-in specifications for this icant bit in the type [31:0] wire? Assume the
logic family require excessive logic circuitry to vector is named example.
be used.
5.4.9 What is the syntax for indexing the least signif-
5.2.10 Give the design domain that the following activ- icant bit in the type [31:0] wire? Assume the
ity relates to: the performance specifications vector is named example.
for this system require 1 TFLOP at < 5W.
5.4.10 What is the difference between a wire and reg
type?
Section 5.3: The Modern Digital 5.4.11 How many bits is the type integer by default?
Design Flow 5.4.12 How many bits is the type real by default?
5.3.1 Which step in the modern digital design flow
does the following statement relate to: a CAD
tool will convert the behavioral model into a
gate-level description of functionality.
178 • Chapter 5: Verilog (Part 1)
Fig. 5.13
System G functionality
Fig. 5.14
System I functionality
Fig. 5.15
System J functionality
Exercise Problems • 179
5.5.10 Design a Verilog model to implement the This is considered structural because you will
behavior described by the 4-input maxterm need to instantiate the user defined primitive
list shown in Fig. 5.15. Use continuous assign- just like a traditional sub-system. You will need
ment and conditional operators. Declare your to create both the upper level module and the
module and ports to match the block diagram lower-level UDP. Declare your module and
provided. Use the type wire for your ports. ports to match the block diagram provided.
5.5.11 Design a Verilog model to implement the Use the type wire for your ports.
behavior described by the 4-input truth table 5.6.3 Design a Verilog model to implement the
shown in Fig. 5.16. Use continuous assign- behavior described by the 3-input maxterm
ment and logical operators. Declare your mod- list shown in Fig. 5.12. Use a structural design
ule and ports to match the block diagram approach based on gate level primitives. This
provided. Use the type wire for your ports. is considered structural because you will need
to instantiate the gate level primitives just like a
traditional sub-system; however, you don’t
need to create the gate level modules as they
are already built into the Verilog standard. You
will need to determine a logic expression for
the system prior to connecting the gate level
primitives. You can use whatever approach
you prefer to create the logic expression (i.e.,
canonical SOP/POS, minimized SOP/POS,
etc.). Declare your module and ports to match
the block diagram provided. Use the type wire
for your ports.
5.6.4 Design a Verilog model to implement the
behavior described by the 3-input maxterm
list shown in Fig. 5.12. Use a structural design
approach based on a user defined primitive.
This is considered structural because you will
need to instantiate the user defined primitive
Fig. 5.16 just like a traditional sub-system. You will need
System K functionality to create both the upper level module and the
lower-level UDP. Declare your module and
ports to match the block diagram provided.
5.5.12 Design a Verilog model to implement the Use the type wire for your ports.
behavior described by the 4-input truth table
shown in Fig. 5.16. Use continuous assign- 5.6.5 Design a Verilog model to implement the
ment and conditional operators. Declare your behavior described by the 3-input truth table
module and ports to match the block diagram shown in Fig. 5.13. Use a structural design
provided. Use the type wire for your ports. approach based on gate level primitives. This
is considered structural because you will need
to instantiate the gate level primitives just like a
Section 5.6: Structural Design in Verilog traditional sub-system; however, you don’t
5.6.1 Design a Verilog model to implement the need to create the gate level modules as they
behavior described by the 3-input minterm list are already built into the Verilog standard. You
shown in Fig. 5.11. Use a structural design will need to determine a logic expression for
approach based on gate level primitives. This the system prior to connecting the gate level
is considered structural because you will need primitives. You can use whatever approach
to instantiate the gate level primitives just like a you prefer to create the logic expression (i.e.,
traditional sub-system; however, you don’t canonical SOP/POS, minimized SOP/POS,
need to create the gate level modules as they etc.). Declare your module and ports to match
are already built into the Verilog standard. You the block diagram provided. Use the type wire
will need to determine a logic expression for for your ports.
the system prior to connecting the gate level 5.6.6 Design a Verilog model to implement the
primitives. You can use whatever approach behavior described by the 3-input truth table
you prefer to create the logic expression (i.e., shown in Fig. 5.13. Use a structural design
canonical SOP/POS, minimized SOP/POS, approach based on a user defined primitive.
etc.). Declare your module and ports to match This is considered structural because you will
the block diagram provided. Use the type wire need to instantiate the user defined primitive
for your ports. just like a traditional sub-system. You will need
5.6.2 Design a Verilog model to implement the to create both the upper level module and the
behavior described by the 3-input minterm list lower-level UDP. Declare your module and
shown in Fig. 5.11. Use a structural design ports to match the block diagram provided.
approach based on a user defined primitive. Use the type wire for your ports.
180 • Chapter 5: Verilog (Part 1)
5.6.7 Design a Verilog model to implement the list shown in Fig. 5.15. Use a structural design
behavior described by the 4-input minterm list approach based on a user defined primitive.
shown in Fig. 5.14. Use a structural design This is considered structural because you will
approach based on gate level primitives. This need to instantiate the user defined primitive
is considered structural because you will need just like a traditional sub-system. You will need
to instantiate the gate level primitives just like a to create both the upper level module and the
traditional sub-system; however, you don’t lower-level UDP. Declare your module and
need to create the gate level modules as they ports to match the block diagram provided.
are already built into the Verilog standard. You Use the type wire for your ports.
will need to determine a logic expression for 5.6.11 Design a Verilog model to implement the
the system prior to connecting the gate level behavior described by the 4-input truth table
primitives. You can use whatever approach shown in Fig. 5.16. Use a structural design
you prefer to create the logic expression (i.e., approach based on gate level primitives. This
canonical SOP/POS, minimized SOP/POS, is considered structural because you will need
etc.). Declare your module and ports to match to instantiate the gate level primitives just like a
the block diagram provided. Use the type wire traditional sub-system; however, you don’t
for your ports. need to create the gate level modules as they
5.6.8 Design a Verilog model to implement the are already built into the Verilog standard. You
behavior described by the 4-input minterm list will need to determine a logic expression for
shown in Fig. 5.14. Use a structural design the system prior to connecting the gate level
approach based on a user defined primitive. primitives. You can use whatever approach
This is considered structural because you will you prefer to create the logic expression (i.e.,
need to instantiate the user defined primitive canonical SOP/POS, minimized SOP/POS,
just like a traditional sub-system. You will need etc.). Declare your module and ports to match
to create both the upper level module and the the block diagram provided. Use the type wire
lower-level UDP. Declare your module and for your ports.
ports to match the block diagram provided. 5.6.12 Design a Verilog model to implement the
Use the type wire for your ports. behavior described by the 4-input truth table
5.6.9 Design a Verilog model to implement the shown in Fig. 5.16. Use a structural design
behavior described by the 4-input maxterm approach based on a user defined primitive.
list shown in Fig. 5.15. Use a structural design This is considered structural because you will
approach based on gate level primitives. This need to instantiate the user defined primitive
is considered structural because you will need just like a traditional sub-system. You will need
to instantiate the gate level primitives just like a to create both the upper level module and the
traditional sub-system; however, you don’t lower-level UDP. Declare your module and
need to create the gate level modules as they ports to match the block diagram provided.
are already built into the Verilog standard. You Use the type wire for your ports.
will need to determine a logic expression for
the system prior to connecting the gate level Section 5.7: Overview of Simulation Test
primitives. You can use whatever approach
you prefer to create the logic expression (i.e., Benches
canonical SOP/POS, minimized SOP/POS, 5.7.1 What is the purpose of a test bench?
etc.). Declare your module and ports to match 5.7.2 Does a test bench have input and output ports?
the block diagram provided. Use the type wire
for your ports. 5.7.3 Can a test bench be simulated?
5.6.10 Design a Verilog model to implement the 5.7.4 Can a test bench be synthesized?
behavior described by the 4-input maxterm
Chapter 6: MSI Logic
This chapter introduces a group of combinational logic building blocks that are commonly used in
digital design. As we move into systems that are larger than individual gates, there are naming
conventions that are used to describe the size of the logic. Table 6.1 gives these naming conventions.
In this chapter we will look at medium scale integrated circuit (MSI) logic. Each of these building blocks
can be implemented using the combinational logic design steps covered in Chaps. 4 and 5. The goal of
this chapter is to provide an understanding of the basic principles of MSI logic.
Table 6.1
Naming convention for the size of digital systems
6.1 Design a decoder circuit using both the classical digital design approach and the modern
HDL-based approach.
6.2 Design an encoder circuit using both the classical digital design approach and the modern
HDL-based approach.
6.3 Design a multiplexer circuit using both the classical digital design approach and the
modern HDL-based approach.
6.4 Design a demultiplexer circuit using both the classical digital design approach and the
modern HDL-based approach.
6.1 Decoders
A decoder is a circuit that takes in a binary code and has outputs that are asserted for specific values
of that code. The code can be of any type or size (e.g., unsigned, two’s complement, etc.). Each output
will assert for only specific input codes. Since combinational logic circuits only produce a single output,
this means that within a decoder, there will be a separate combinational logic circuit for each output.
any given time. Example 6.1 shows the process of designing a 2-to-4 one-hot decoder by hand
(i.e., using the classical digital design approach).
Example 6.1
2-to-4 One-hot decoder – logic synthesis by hand
As decoders get larger, it is necessary to use hardware description languages to model their
behavior. Example 6.2 shows how to model a 3-to-8 one-hot decoder in Verilog with continuous
assignment and logic operators.
6.1 Decoders • 183
Example 6.2
3-to-8 One-hot decoder – Verilog modeling using logical Operators
This description can be further simplified by using vector notation for the ports and describing the
functionality using conditional operators. Example 6.3 shows how to model the 3-to-8 one-hot decoder in
Verilog using continuous assignment with conditional operators.
184 • Chapter 6: MSI Logic
Example 6.3
3-to-8 One-hot decoder – Verilog modeling using conditional operators
Example 6.4
7-Segment display decoder – truth table
If we wish to design this decoder by hand we need to create seven separate combinational logic
circuits. Each of the outputs (Fa – Fg) can be put into a 3-input K-map to find the minimized logic
expression. Example 6.5 shows the design of the decoder from the truth table in Example 6.4 by hand.
186 • Chapter 6: MSI Logic
Example 6.5
7-Segment display decoder – logic synthesis by hand
This same functionality can be implemented in Verilog using concurrent modeling techniques.
Example 6.6 shows how to model the 7-segment decoder in Verilog using continuous assignment with
logic operators.
6.1 Decoders • 187
Example 6.6
7-Segment display decoder – Verilog modeling using logical operators
Again, a more compact description of the decoder can be accomplished if the ports are described
as vectors and a conditional operator is used. Example 6.7 shows how to model the 7-segment decoder
in Verilog using continuous assignment with conditional operators.
Example 6.7
7-Segment display decoder – Verilog modeling using conditional operators
188 • Chapter 6: MSI Logic
CONCEPT CHECK
CC6.1 In a decoder, a logic expression is created for each output. Once all of the output logic
expressions are found, how can the decoder logic be further minimized?
(A) By using K-maps to find the output logic expressions.
(B) By buffering the inputs so that they can drive a large number of other gates.
(C) By identifying any logic terms that are used in multiple locations (inversions,
product terms, and sum terms) and sharing the interim results among multiple
circuits in the decoder.
(D) By ignoring fan-out.
6.2 Encoders
An encoder works in the opposite manner as a decoder. An assertion on a specific input port
corresponds to a unique code on the output port.
Example 6.8
4-to-2 Binary encoder – logic synthesis by hand
In Verilog, an encoder can be implemented using continuous assignment with either logical or
conditional operators. Example 6.9 shows how to model the encoder in Verilog using these techniques.
190 • Chapter 6: MSI Logic
Example 6.9
4-to-2 Binary encoder – Verilog modeling using logical and conditional operators
CONCEPT CHECK
CC6.2 If it is desired to have the outputs of an encoder produce 0’s for all input codes not defined in
the truth table, can “don’t cares” be used when deriving the minimized logic expressions?
Why?
(A) No. Don’t cares aren’t used in encoders.
(B) Yes. Don’t cares can always be used in K-maps.
(C) Yes. All that needs to be done is to treat each X as a 0 when forming the most
minimal prime implicant.
(D) No. Each cell in the K-map corresponding to an undefined input code needs to
contain a 0 so don’t cares are not applicable.
6.3 Multiplexers
A multiplexer is a circuit that passes one of its multiple inputs to a single output based on a select
input. This can be thought of as a digital switch. The multiplexer has n select lines, 2n inputs, and one
output. Example 6.10 shows the process of designing a 2-to-1 multiplexer by hand (i.e., using the
classical digital design approach).
6.3 Multiplexers • 191
Example 6.10
2-to-1 Multiplexer – logic synthesis by hand
In Verilog, a multiplexer can be implemented using continuous assignment with either logical or
conditional operators. Example 6.11 shows how to model the multiplexer in Verilog using these
techniques.
192 • Chapter 6: MSI Logic
Example 6.11
4-to-1 Multiplexer – Verilog modeling using logical and conditional operators
CONCEPT CHECK
CC6.3 How are the product terms in a multiplexer based on the identity theorem?
(A) Only the select product term will pass its input to the final sum term. Since all of the
unselected product terms output 0, the input will be passed through the sum term
because anything OR’d with a 0 is itself.
(B) The select lines are complemented such that they activate only one OR gate.
(C) The select line inputs will produce 1’s on the inputs of the selected product term.
This allows the input signal to pass through the selected AND gate because
anything AND’d with a 1 is itself.
(D) The select line inputs will produce 0’s on the inputs of the selected sum term. This
allows the input signal to pass through the selected OR gate because anything
OR’d with a 0 is itself.
6.4 Demultiplexers • 193
6.4 Demultiplexers
A demultiplexer works in a complementary fashion to a multiplexer. A demultiplexer has one input
that is routed to one of its multiple outputs. The output that is active is dictated by a select input. A demux
has n select lines that chooses to route the input to one of its 2n outputs. When an output is not selected,
it outputs a logic 0. Example 6.12 shows the process of designing a 1-to-2 demultiplexer by hand
(i.e., using the classical digital design approach).
Example 6.12
1-to-2 Demultiplexer – logic synthesis by hand
In Verilog, a demultiplexer can be implemented using continuous assignment with either logical or
conditional operators. Example 6.13 shows how to model the demultiplexer in Verilog using these
techniques
194 • Chapter 6: MSI Logic
Example 6.13
1-to-4 Demultiplexer – Verilog modeling using logical and conditional operators
CONCEPT CHECK
Summary
v The term medium scale integrated circuit v A decoder is a system that has a greater
(MSI) logic refers to a set of basic combina- number of outputs than inputs. The behavior
tional logic circuits that implement simple, of each output is based on each unique
commonly used functions such as decoders, input code.
encoders, multiplexers, and demultiplexers. v An encoder a system that has a greater num-
MSI logic can also include operations such ber of inputs than outputs. A compressed
as comparators and simple arithmetic output code is produced based on which
circuits. input(s) lines are asserted.
v While an MSI logic circuit may have multiple v A multiplexer is a system that has one output
outputs, each output requires its own unique and multiple inputs. At any given time, one
logic expression that is based on the system and only one input is routed to the output
inputs. based on the value on a set of select lines.
Exercise Problems • 195
For n select lines, a multiplexer can support 2n v HDLs are particularly useful for describing
inputs. MSI logic due to their abstract modeling
v A demultiplexer is a system that has one capability. Through the use of Boolean
input and multiple outputs. The input is conditions and vector assignments, the
routed to one of the outputs depending on behavior of MSI logic can be modeled in a
the value on a set of select lines. For n select compact and intuitive manner.
lines, a demultiplexer can support 2n outputs.
Exercise Problems
Section 6.1: Decoders 6.1.2 Design a Verilog model for a 4-to-16 one-hot
decoder using continuous assignment and
6.1.1 Design a 4-to-16 one-hot decoder by hand.
gate level primitives. Use the module port defi-
The block diagram and truth table for the
nition given in Fig. 6.2.
decoder are given in Fig. 6.1. Give the
minimized logic expressions for each output
(i.e., F0, F1, . . ., F15) and the full logic diagram
for the system.
Fig. 6.2
4-to-16 one-hot module definition
Fig. 6.3
7-segment display decoder truth table
Exercise Problems • 197
6.1.6 Design a Verilog model for a 4-input, 7-seg- for each output and the full logic diagram for
ment HEX character decoder using continuous the system.
assignment and logical operators. Use the
module port definition given in Fig. 6.4 for
your design. The system has a 4-bit input
vector called ABCD and a 7-bit output vector
called F. The individual scalars within the out-
put vector (i.e., F[6:0]) correspond to the char-
acter display segments a, b, c, d, e, f, and g
respectively. A logic 1 on an output
corresponds to the LED being ON. The display
will show the HEX characters 0–9, A, b, c, d, E,
and F corresponding to the 4-bit input code on
A. A template for creating the truth table is
provided in Fig. 6.3. The signals in this table
correspond to the ports in this problem as
follows: Fa ¼ F(6), Fb ¼ F(5), Fc ¼ F(4), Fig. 6.5
Fd ¼ F(3), Fe ¼ F(2), Ff ¼ F(1), and Fg ¼ F(0). 8-to-3 one-hot encoder functionality
Fig. 6.7
8-to-1 multiplexer functionality
Fig. 6.9
1-to-8 demultiplexer functionality
Fig. 7.1
Storage using a cross-coupled inverter pair
7.1.2 Metastability
The cross-coupled inverter pair in Fig. 7.1 exhibits what is called metastable behavior due to its
positive feedback configuration. Metastability refers to when a system can exist in a state of equilibrium
when undisturbed but can be moved to a different, more stable state of equilibrium when sufficiently
disturbed. Systems that exhibit high levels of metastability have an equilibrium state that is highly
unstable, meaning that if disturbed even slightly the system will move rapidly to a more stable point of
equilibrium. The cross-coupled inverter pair is a highly metastable system. This system actually contains
three equilibrium states. The first is when the input of U1 is exactly between a logic 0 and logic 1 (i.e.,
VCC/2). In this state, the output of U1 is also exactly VCC/2. This voltage is fed back to the input of U2, thus
producing an output of exactly VCC/2 on U2. This in turn is fed back to the original input on U1 reinforcing
the initial state. Despite this system being at equilibrium in this condition, this state is highly unstable.
With minimal disturbance to any of the nodes within the system, it will move rapidly to one of two more
stable states. The two stable states for this system are when Q ¼ 0 or when Q ¼ 1 (see Fig. 7.1). Once
the transition begins between the unstable equilibrium state toward one of the two more stable states, the
positive feedback in the system continually reinforces the transition until the system reaches its final
state. In electrical systems, this initial disturbance is caused by the presence of noise, or unwanted
voltage in the system. Noise can come from many sources including random thermal motion of charge
carriers in the semiconductor materials, electromagnetic energy, or naturally occurring ionizing particles.
Noise is present in every electrical system so the cross-coupled inverter pair will never be able to stay in
the unstable equilibrium state where all nodes are at VCC/2.
The cross-coupled inverter pair has two stable states, thus it is called a bistable element. In order to
understand the bistable behavior of this circuit, let’s look at its behavior when the initial input value on U1
is set directly between a logic 0 and logic 1 (i.e., VCC/2) and how a small amount of noise will cause the
system to move toward a stable state. Recall that an inverter is designed to have an output that quickly
transitions between a logic LOW and HIGH in order to minimize the time spent in the uncertainty region.
This is accomplished by designing the inverter to have what is called gain. Gain can be thought of as a
multiplying factor that is applied to the input of the circuit when producing the output (i.e., Vout ¼ gain∙Vin).
The gain for an inverter will be negative since the output moves in the opposite direction of the input. The
inverter is designed to have a very high gain such that even the smallest change on the input when in the
transition region will result in a large change on the output. Consider the behavior of this circuit shown in
Fig. 7.2. In this example, let’s represent the gain of the inverter as –g and see how the system responds
when a small positive voltage noise (Vn) is added to the VCC/2 input on U1.
7.1 Sequential Logic Storage Devices • 201
Fig. 7.2
Examining metastability moving toward the state Q ¼ 0
Figure 7.3 shows how the system responds when a small negative voltage noise (Vn) is added to
the VCC/2 input on U1.
202 • Chapter 7: Sequential Logic Design
Fig. 7.3
Examining metastability moving toward the state Q ¼ 1
Fig. 7.4
SR Latch behavior – store state (S ¼ 0, R ¼ 0)
The SR Latch has two input conditions that will force the outputs to known values. The first condition
is called the set state. In this state, the inputs are configured as S ¼ 1 and R ¼ 0. This input condition will
force the outputs to Q ¼ 1 (e.g. setting Q) and Qn ¼ 0. The second input condition is called the reset
state. In this state the inputs are configured as S ¼ 0 and R ¼ 1. This input condition will force the outputs
to Q ¼ 0 (i.e., resetting Q) and Qn ¼ 1. Consider the behavior of the SR Latch during its set and reset
states shown in Fig. 7.5.
204 • Chapter 7: Sequential Logic Design
Fig. 7.5
SR Latch behavior – set (S ¼ 1, R ¼ 0) and reset (S ¼ 0, R ¼ 1) states
The final input condition for the SR Latch leads to potential metastability and should be avoided.
When S ¼ 1 and R ¼ 1, the outputs of the SR Latch will both go to logic 0’s. The problem with this state is
that if the inputs subsequently change to the store state (S ¼ 0, R ¼ 0), the outputs will go metastable and
then settle in one of the two stable states (Q ¼ 0 or Q ¼ 1). The reason this state is avoided is because
the final resting state of the SR Latch is random and unknown. Consider this operation shown in Fig. 7.6.
Fig. 7.6
SR Latch behavior – don’t use state (S ¼ 1 and R ¼ 1)
7.1 Sequential Logic Storage Devices • 205
Figure 7.7 shows the final truth table for the SR Latch.
Fig. 7.7
SR Latch truth table
The SR Latch has some drawbacks when it comes to implementation with real circuitry. First, it takes
two independent inputs to control the outputs. Second, the state where S ¼ 1 and R ¼ 1 causes
problems when real propagation delays are considered through the gates. Since it is impossible to
match the delays exactly between U1 and U2, the SR Latch may occasionally enter this state and
experience momentary metastable behavior. In order to address these issues, a number of
improvements can be made to this circuit to create two of the most commonly used storage devices in
sequential logic, the D-Latch and the D-Flip-Flop. In order to understand the operation of these storage
devices, two incremental modifications are made to the SR Latch. The first is called the S’R’ Latch and
the second is the SR Latch with enable. These two circuits are rarely implemented and are only
explained to understand how the SR Latch is modified to create a D-Latch and ultimately a D-Flip-Flop.
Fig. 7.8
S’R’ Latch behavior – store state (S0 ¼ 1, R’ ¼ 1)
Just as with the SR Latch, the S’R’ Latch has two input configurations to control the values of the
outputs. Consider the behavior of the S’R’ Latch during its set and reset states shown in Fig. 7.9.
7.1 Sequential Logic Storage Devices • 207
Fig. 7.9
S’R’ Latch behavior – set (S00 ¼ 0, R” ¼ 1) and Reset (S00 ¼ 1, R” ¼ 0) states
And finally, just as with the SR Latch, the S’R’ Latch has a state that leads to potential metastability
and should be avoided. Consider the operation of the S’R’ Latch when the inputs are configured as S0 ¼ 0
and R’ ¼ 0 shown in Fig. 7.10.
Fig. 7.10
S’R’ Latch behavior – don’t use state (S00 ¼ 0 and R” ¼ 0)
208 • Chapter 7: Sequential Logic Design
The final truth table for the S’R’ Latch is given in Fig. 7.11.
Fig. 7.11
S00 R” Latch truth table
Fig. 7.12
SR Latch with enable schematic
Recall that any time a 0 is present on one of the inputs to a NAND gate, the output will always be a
1 regardless of the value of the other inputs. In the SR Latch with enable configuration, any time C ¼ 0,
the outputs of U3 and U4 will be 1’s and will be fed into the inputs of the cross-coupled NAND gate
configuration (U1 and U2). Recall that the cross-coupled configuration of U1 and U2 is an S’R’ Latch and
will be put into a store state when S0 ¼ 1 and R’ ¼ 1. This is the store state (C ¼ 0). When C ¼ 1, it has the
effect of inverting the values of the S and R inputs before they reach U1 and U2. This condition allows the
set state to be entered when S ¼ 1, R ¼ 0, C ¼ 1 and the reset state to be entered when S ¼ 0, R ¼ 1,
C ¼ 1. Consider this operation in Fig. 7.13.
7.1 Sequential Logic Storage Devices • 209
Fig. 7.13
SR Latch with enable behavior – store, set, and reset
Again, there is a potential metastable state when S ¼ 1, R ¼ 1 and C ¼ 1 that should be avoided.
There is also a second store state when S ¼ 0, R ¼ 0 and C ¼ 1 that is not used because storage is to be
dictated by the C input.
driven with an inverted version of the S input. This prevents the S and R inputs from ever being the same
value and removes the two “Don’t Use” states in the truth table shown in Fig. 7.12. The new, single input
is renamed D to stand for data. This new circuit still has the behavior that it will store the last value of Q
and Qn when C ¼ 0. When C ¼ 1, the output will be Q ¼ 1 when D ¼ 1 and will be Q ¼ 0 when D ¼ 0. The
behavior of the output when C ¼ 1 is called tracking the input. The D-Latch schematic, symbol and truth
table are given in Fig. 7.14.
Fig. 7.14
D-Latch schematic, symbol and truth table
Fig. 7.15
D-Latch timing diagram
7.1 Sequential Logic Storage Devices • 211
Fig. 7.16
D-Flip-Flop (rising edge triggered) schematic, symbol, and truth table
The D-Flip-Flop schematic shown above is called a master/slave configuration because of how the
data is passed through the two D-Latches (U1 and U2). Due to the U4 inverter, the two D-Latches will
always be in complementary modes. When U1 is in hold mode, U2 will be in track mode and vice versa.
When the clock signal transitions HIGH, U1 will store the last value of data. During the time when the
clock is HIGH, U2 will enter track mode and pass this value to Q. In this way, the data is latched into the
storage device on the rising edge of the clock and is present on Q. This is the master operation of the
device because U1, or the first D-Latch, is holding the value, and the second D-Latch (the slave) is simply
passing this value to the output Q. When the clock transitions LOW, U2 will store the output of U1. Since
there is a finite delay through U1, the U2 D-Latch is able to store the value before U1 fully enters track
mode. U2 will drive Q for the duration of the time that the clock is LOW. This is the slave operation of the
device because U2, or the second D-Latch, is holding the value. During the time the clock is LOW, U1 is
in track mode, which passes the input data to the middle of the D-Flip-Flop preparing for the next rising
edge of the clock. The master / slave configuration creates a behavior where the Q output of the D-Flip-
Flop is only updated with the value of D on a rising edge of the clock. At all other times, Q holds the last
value of D. An example timing diagram for the operation of a rising edge D-Flip-Flop is given in Fig. 7.17.
212 • Chapter 7: Sequential Logic Design
Fig. 7.17
D-Flip-Flop (rising edge triggered) timing diagram
D-Flip-Flops often have additional signals that will set the initial conditions of the outputs that are
separate from the clock. A reset input is used to force the outputs to Q ¼ 0, Qn ¼ 1. A preset input is used
to force the outputs to Q ¼ 1, Qn ¼ 0. In most modern D-Flip-Flops, these inputs are active LOW,
meaning that the line is asserted when the input is a 0. Active LOW inputs are indicated by placing an
inversion bubble on the input pin of the symbol. These lines are typically asynchronous, meaning that
when they are asserted, action is immediately taken to alter the outputs. This is different from a
synchronous input in which action is only taken on the edge of the clock. Fig. 7.18 shows the symbols
and truth tables for two D-Flip-Flop variants, one with an active LOW reset and another with both an
active LOW reset and active LOW preset.
7.1 Sequential Logic Storage Devices • 213
Fig. 7.18
D-Flip-Flop with asynchronous reset and preset
D-Flip-Flops can also be created with an enable line. An enable line controls whether or not the
output is updated. Enable lines are synchronous, meaning that when they are asserted, the outputs will
be updated on the rising edge of the clock. When de-asserted, the outputs are not updated. This
behavior in effect ignores the clock input when de-asserted. Fig. 7.19 shows the symbol and truth
table for a D-Flip-Flop with a synchronous enable.
Fig. 7.19
D-Flip-Flop with synchronous enable
The behavior of the D-Flip-Flop allows us to design systems that are synchronous to a clock signal.
A clock signal is a periodic square wave that dictates when events occur in a digital system. A
synchronous system based on D-Flip-Flops will allow the outputs of its storage devices to be updated
upon a rising edge of the clock. This is advantageous because when the Q outputs are storing values
they can be used as inputs for combinational logic circuits. Since combinational logic circuits contain a
certain amount of propagation delay before the final output is calculated, the D-Flip-Flop can hold the
inputs at a steady value while the output is generated. Since the input on a D-Flip-Flop is ignored during
all other times, the output of a combinational logic circuit can be fed back as an input to a D-Flip-Flop.
214 • Chapter 7: Sequential Logic Design
This gives a system the ability to generate outputs based on the current values of inputs in addition to
past values of the inputs that are being held on the outputs of D-Flip-Flops. This is the definition of
sequential logic. An example synchronous, sequential system is shown in Fig. 7.20.
Fig. 7.20
An example synchronous system based on a D-Flip-Flop
CONCEPT CHECK
CC7.1(a) What will always cause a digital storage device to come out of metastability and settle in
one of its two stable states? Why?
(A) The power supply. The power supply provides the necessary current for the
device to overcome metastability.
(B) Electrical noise. Noise will always push the storage device toward one state or
another. Once the storage device starts moving toward one of its stable states,
the positive feedback of the storage device will reinforce the transition until the
output eventually comes to rest in a stable state.
(C) A reset. A reset will put the device into a known stable state.
(D) A rising edge of clock. The clock also puts the device into a known stable
state.
CC7.1(b) What was the purpose of replacing the inverters in the cross-coupled inverter pair with
NOR gates to form the SR Latch?
(A) NOR gates are easier to implement in CMOS.
(B) To provide the additional output Qn.
(C) To provide more drive strength for storing.
(D) To provide inputs to explicitly set the value being stored.
needs to be at a steady state after the clock event. If these specifications are violated (i.e., the input
transitions too close to the clock transition), the storage device will not be able to determine whether the
input was a 1 or 0 and will go metastable. The time a storage device will remain metastable is a
deterministic value and is specified by the part manufacturer (tmeta). In general, metastability should be
avoided; however, knowing the maximum duration of metastability for a storage device allows us to
design circuits to overcome potential metastable conditions. During the time the device is metastable,
the output will have random behavior. It may go to a steady state 1, a steady state 0, or toggle between a
0 and 1 uncontrollably. Once the device comes out of metastability, it will come to rest in one of its two
stable states (Q ¼ 0 or Q ¼ 1). The final resting state is random and unknown. Another specification for
sequential storage devices is the delay from the time a clock transition occurs to the point that the data is
present on the Q output. This specification is called the Clock-to-Q delay and is given the notation tCQ.
These specifications are shown in Fig. 7.21.
Fig. 7.21
Sequential storage device timing specifications
CONCEPT CHECK
CC7.2 Which D-flop-flop timing specification requires all of combinational logic circuits in the system
to settle on their final output before a triggering clock edge can occur?
(A) tsetup (B) thold (C) tCQ (D) tmeta
216 • Chapter 7: Sequential Logic Design
Fig. 7.22
Toggle flop clock frequency divider
7.3 Common Circuits Based on Sequential Storage Devices • 217
Fig. 7.23
3-bit ripple counter
The primary cause of these unclean logic transitions is due to the physical vibrations of the metal
contacts when they collide with each other during a button press or switch actuation. Within a mechanical
switch, there is typically one contact that is fixed and another that is designed to move when the button is
pressed. The contact that is designed to move can be thought of as a beam that is fixed on one side and
free on the other. As the free side of the beam moves toward the fixed contact in order to close the circuit,
it will collide and then vibrate just as a tuning fork does when struck. The vibration will eventually diminish
and the contact will come to rest, thus making a clean electrical connection; however, during the vibration
period the moving contact will bounce up and down on the destination contact. This bouncing causes the
switch to open and close multiple times before coming to rest in the closed position. This phenomenon is
accurately referred to as switch bounce. Switch bounce is present in all mechanical switches and gets
progressively worse as the switches are used more and more.
Figure 7.24 shows some of the common types of switches found in digital systems. The term pole is
used to describe the number of separate circuits controlled by the switch. The term throw is used to
describe the number of separate closed positions the switch can be in.
Fig. 7.24
Common types of mechanical switches
Let’s look at switch bounce when using a SPST switch to provide an input to a logic gate. A SPST
requires a resistor and can be configured to provide either a logic HIGH or LOW when in the open
position and the opposite logic level when in the closed position. The example configuration in Fig. 7.25
provides a logic LOW when in the open position and a logic HIGH when in the closed position. In the
open position, the input to the gate (SW) is pulled to GND to create a logic LOW. In the closed position,
the input to the gate is pulled to VCC to create a logic HIGH. A resistor is necessary to prevent a short
circuit between VCC and GND when the switch is closed. Since the input current specification for a logic
gate is very small, the voltage developed across the resistor due to the gate input current is negligible.
This means that the resistor can be inserted in the pull-down network without developing a noticeable
voltage. When the switch closes, the free-moving contact will bounce off of the destination contact
numerous times before settling in the closed position. During the time while the switch is bouncing, the
switch will repeatedly toggle between the open (HIGH) and closed (LOW) positions.
7.3 Common Circuits Based on Sequential Storage Devices • 219
Fig. 7.25
Switch bouncing in a single pole, single throw switch
A possible solution to eliminate this switch bounce is to instead use a SPDT switch in conjunction
with a sequential storage device. Before looking at this solution, we need to examine an additional
condition introduced by the SPDT switch. The SPDT switch has what is known as break-before-make
behavior. The term break is used to describe when a switch is open while the term make is used to
describe when the switch is closed. When a SPDT switch is pressed, the input will be floating during the
time when the free-moving contact is transitioning toward the destination contact. During this time, the
output of the switch is unknown and can cause unwanted logic transitions if it is being used to drive the
input of a logic gate.
Let’s look at switch bounce when using a SPDT switch without additional circuitry to handle
bouncing. A SPDT has two positions that the free-moving contact can make a connection to (i.e., double
throw). When using this switch to drive a logic level into a gate, one position is configured as a logic HIGH
and the other a logic LOW. Consider the SPDT switch configuration in Fig. 7.26. Position 1 of the SPDT
switch is connected to GND, while position 2 is connect to VCC. When unpressed the switch is in position
1. When pressed, the free-moving contact will transition from position 1 to 2. During the transition the
free-moving contact is floating. This creates a condition where the input to the gate (SW) is unknown.
This floating input will cause unpredictable behavior on the output of the gate. Upon reaching position
2, the free-moving contact will bounce off of the destination contact. This will cause the input of the logic
gate to toggle between a logic HIGH and floating repeatedly until the free-moving contact comes to rest
in position 2.
220 • Chapter 7: Sequential Logic Design
Fig. 7.26
Switch bouncing in a single pole, double throw switch
The SPDT switch is ideal for use with an S’R’ Latch in order to produce a clean logic transition. This
is because during the break portion of the transition, an S’R’ Latch can be used to hold the last value of
the switch. This is unique to the SPDT configuration. The SPST switch in comparison does not have the
break characteristic, rather it always drives a logic level in both of its possible positions. Consider the
debounce circuit for a SPDT switch in Fig. 7.27. This circuit is based on an S’R’ Latch with two pull-up
resistors. Since the S’R’ Latch is created using NAND gates, this circuit is commonly called a NAND-
Debounce circuit. In the unpressed configuration, the switch drives S0 ¼ 0 and the R2 pull-up resistor
drives R’ ¼ 1. This creates a logic 0 on the output of the circuit (Qn ¼ 0). During a switch press, the free-
moving contact is floating, thus it is not driving in a logic level into the S’R’ Latch. Instead, both pull-up
resistors pull S0 and R’ to 1’s. This puts the latch into its hold mode and the output will remain at a logic
0 (Qn ¼ 0). Once the free-moving contact reaches the destination contact, the switch will drive R’ ¼ 0.
Since at this point the R1 pull-up is driving S0 ¼ 1, the latch outputs a logic 1 (Qn ¼ 1). When the free-
moving contact bounces off of the destination contact, it will put the latch back into the hold mode;
however, this time the last value that will be held is Qn ¼ 1. As the switch continues to bounce, the latch
will move between the Qn ¼ 1 and Qn ¼ “Last Qn” states, both of which produce an output of 1. In this
way, the SPDT switch in conjunction with the S’R’ Latch produces a clean 0 to 1 logic transition despite
the break-before-make behavior of the switch and the contact bounce.
7.3 Common Circuits Based on Sequential Storage Devices • 221
Fig. 7.27
NAND debounce circuit for a SPDT switch
commonly used to convert a serial string of data into a parallel format. If an n-bit, serial sequence of
information is clocked into the shift register, after n clocks the data will be held on each of the D-Flip-Flop
outputs. At this moment, the n-bits can be read as a parallel value. Consider the shift register configura-
tion shown in Fig. 7.28.
Fig. 7.28
4-bit shift register
CONCEPT CHECK
CC7.3 Which D-flip-flop timing specification is most responsible for the ripple delay in a ripple
counter?
(A) tsetup (B) thold (C) tCQ (D) tmeta
7.4 Finite State Machines • 223
Example 7.1
Push-button window controller – word description
There are two different types of output conditions for a state machine. The first is when the output
only depends on the current state of the machine. This type of system is called a Moore Machine. In this
case, the outputs of the system are written inside of the state circles. This indicates the output value that
will be generated for each specific state. The second output condition is when the outputs depend on
both the current state and the system inputs. This type of system is called a Mealy Machine. In this case,
the outputs of the system are written next to the state transitions corresponding to the appropriate input
values. Outputs in a state diagram are typically written inside of parentheses. Example 7.2 shows the
construction of the state diagram for our push-button window controller design.
Example 7.2
Push-button window controller – state diagram
7.4 Finite State Machines • 225
Example 7.3
Push-button window xontroller – state transition table
Fig. 7.29
Main components of a finite state machine
Example 7.4
Solving for the number of bits needed for binary state encoding
The second type of state encoding is called gray code encoding. A gray code is one in which the
value of a code differs by only one bit from any of its neighbors, (i.e., 00, 01, 11, 10. . .). A gray code is
useful for reducing the number of bit transitions on the state codes when the machine has a transition
sequence that is linear. Reducing the number of bit transitions can reduce the amount of power
consumption and noise generated by the circuit. When the state transitions of a machine are highly
non-linear, a gray code encoding approach does not provide any benefit. Gray code is also an efficient
coding approach. With n D-Flip-Flops, 2n states can be encoded just as in binary encoding. Figure 7.30
shows the process of creating n-bit, gray code patterns.
228 • Chapter 7: Sequential Logic Design
Fig. 7.30
Creating an n-bit gray code pattern
The third common technique to encode states is using one-hot encoding. In this approach, a
separate D-Flip-Flop is asserted for each state in the machine. For an n-state machine, this encoding
approach requires n D-Flip-Flops. For example, if a machine had three states, the one-hot state codes
would be “001”, “010” and “100”. This approach has the advantage that the next state logic circuitry is
very simple; further, there is less chance that the different propagation delays through the next state logic
will cause an inadvertent state to be entered. This approach is not as efficient as binary and gray code in
terms of minimizing the number of D-Flip-Flops because it requires one D-Flip-Flop for each state;
however, in modern digital integrated circuits that have abundant D-Flip-Flops, one-hot encoding is
commonly used.
Figure 7.31 shows the differences between these three state encoding approaches.
Fig. 7.31
Comparison of different state encoding approaches
Once the codes have been assigned to the state names, each of the bits within the code must be
given a unique signal name. The signal names are necessary because the individual bits within the state
7.4 Finite State Machines • 229
code are going to be implemented with real circuitry so each signal name will correspond to an actual
node in the logic diagram. These individual signal names are called state variables. Unique variable
names are needed for both the current state and next state signals. The current state variables are driven
by the Q outputs of the D-Flip-Flops holding the state codes. The next state variables are driven by the
next state logic circuitry and are connected to the D inputs of the D-Flip-Flops. State variable names are
commonly chosen that are descriptive both in terms of their purpose and connection location. For
example, current state variables are often given the names Q, Q_cur or Q_current to indicate that they
come from the Q outputs of the D-Flip-Flops. Next state variables are given names such as Q*, Q_nxt or
Q_next to indicate that they are the next value of Q and are connected to the D input of the D-Flip-Flops.
Once state codes and state variable names are assigned, the state transition table is updated with the
detailed information.
Returning to our push-button window controller example, let’s encode our states in straight binary
and use the state variable names of Q_cur and Q_nxt. Example 7.5 shows the process of state encoding
and the new state transition table.
Example 7.5
Push-button window controller – state encoding
In our push-button window controller example, we only need to create one combinational logic
circuit because there is only one next state variable (Q_nxt). The inputs to the combinational logic circuit
are Q_cur and Press. Notice that the state transition table was created such that the order of the input
values are listed in a binary count just as in a formal truth table formation. This makes synthesizing the
combinational logic circuit straightforward. Example 7.6 shows the steps to synthesize the next state
logic for this the push-button window controller.
Example 7.6
Push-button window controller – next state logic
Example 7.7
Push-button window controller – output logic
Example 7.8 shows the process for creating the final logic diagram for our push-button window
controller. Notice that the state memory is implemented with one D-Flip-Flop since there is only 1-bit in
the current state code (Q_cur). The next state logic is a combinational logic circuit that computes Q_nxt
based on the values of Q_cur and Press. Finally, the output logic consists of two separate combinational
logic circuits to compute the system outputs Open_CW and Close_CCW based on Q_cur and Press. In
this diagram the Qn output of the D-Flip-Flop could have been used for the inverted versions of Q_cur;
however, inversion bubbles were used instead in order to make the diagram more readable.
Example 7.8
Push-button window controller – logic diagram
Fig. 7.32
Finite state machine design flow
Example 7.9
Serial bit sequence detector (part 1)
7.4 Finite State Machines • 235
Example 7.10 provides the state encoding and next state logic synthesis for the 3-bit serial bit
sequence detector.
Example 7.10
Serial bit sequence detector (part 2)
236 • Chapter 7: Sequential Logic Design
Example 7.11 shows the output logic synthesis and final logic diagram for the 3-bit serial bit
sequence detector.
Example 7.11
Serial bit sequence detector (part 3)
Example 7.12
Vending machine controller (part 1)
238 • Chapter 7: Sequential Logic Design
Example 7.13 provides the state encoding and next state logic synthesis for the simple vending
machine controller.
Example 7.13
Vending machine controller (part 2)
7.4 Finite State Machines • 239
Example 7.14 shows the output logic synthesis and final logic diagram for the vending machine
controller.
Example 7.14
Vending machine controller (part 3)
240 • Chapter 7: Sequential Logic Design
CONCEPT CHECK
CC7.4(a) What allows a finite state machine to make more intelligent decisions about the system
outputs compared to combinational logic alone?
(A) A finite state machine has knowledge about the past inputs.
(B) The D-flip-flops allow the outputs to be generated more rapidly.
(C) The next state and output logic allows the finite state machine to be more
complex and implement larger truth Tables.
(D) A synchronous system is always more intelligent.
CC7.4(b) When designing a finite state machine, many of the details of the implementation can be
abstracted. At what design step do the details of the implementation start being
considered?
(A) The state diagram step.
(B) The state transition table step.
(C) The state memory synthesis step.
(D) The word description.
CC7.4(c) What impact does adding an additional state have on the implementation of the state
memory logic in a finite state machine?
(A) It adds an additional D-flip-flop.
(B) It adds a new state code that must be supported.
(C) It adds more combinational logic to the logic diagram.
(D) It reduces the speed that the machine can run at.
CC7.4(d) Which of the following statements about the next state logic is FALSE?
(A) It is always combinational logic.
(B) It always uses the current state as one of its inputs.
(C) Its outputs are connected to the D inputs of the D-flip-flops in the state memory.
(D) It uses the results of the output logic as part of its inputs.
CC7.4(e) Why does the output logic stage of a finite state machine always use the current state as
one of its inputs?
(A) If it didn’t, it would simply be a separate combinational logic circuit and not be
part of the finite state machine.
(B) To make better decisions about what the system outputs should be.
(C) Because the next state logic is located too far away.
(D) Because the current state is produced on every triggering clock edge.
CC7.4(f) What impact does asserting a reset have on a finite state machine?
(A) It will cause the output logic to produce all zeros.
(B) It will cause the next state logic to produce all zeros.
(C) It will set the current state code to all zeros.
(D) It will start the system clock.
7.5 Counters • 241
7.5 Counters
A counter is a special type of finite state machine. A counter will traverse the states within a state
diagram in a linear fashion continually circling around all states. This behavior allows a special type of
output topology called state-encoded outputs. Since each state in the counter represents a unique
counter output, the states can be encoded with the associated counter output value. In this way, the
current state code of the machine can be used as the output of the entire system.
Example 7.15
2-bit binary up counter (part 1)
242 • Chapter 7: Sequential Logic Design
Example 7.16 shows the next state and output logic synthesis, the final logic diagram, and resultant
representative timing diagram for the 2-bit binary up counter.
Example 7.16
2-bit binary up counter (part 2)
Moore machine and use state-encoded outputs. Example 7.17 provides the word description, state
diagram, state transition table, and state encoding for this counter.
Example 7.17
2-bit binary up/down counter (part 1)
244 • Chapter 7: Sequential Logic Design
Example 7.18 shows the next state and output logic synthesis, the final logic diagram, and resultant
representative timing diagram for the 2-bit binary up/down counter.
Example 7.18
2-bit binary up/down counter (part 2)
7.5 Counters • 245
Example 7.19
2-bit gray code up counter (part 1)
246 • Chapter 7: Sequential Logic Design
Example 7.20 shows the next state and output logic synthesis, the final logic diagram, and resultant
representative timing diagram for the 2-bit gray code up counter.
Example 7.20
2-bit gray code up counter (part 2)
7.5 Counters • 247
Example 7.21
2-bit gray code up/down counter (part 1)
248 • Chapter 7: Sequential Logic Design
Example 7.22 shows the next state and output logic synthesis, the final logic diagram, and resultant
representative timing diagram for the 2-bit gray code up/down counter.
Example 7.22
2-bit gray code up/down counter (part 2)
7.5 Counters • 249
Example 7.23
3-bit one-hot up counter (part 1)
250 • Chapter 7: Sequential Logic Design
Example 7.24 shows the next state and output logic synthesis, the final logic diagram, and resultant
representative timing diagram for the 3-bit one-hot up counter.
Example 7.24
3-bit one-hot up counter (part 2)
Example 7.25
3-bit one-hot up/down counter (part 1)
252 • Chapter 7: Sequential Logic Design
Example 7.26 shows the next state and output logic synthesis for the 3-bit one-hot up/down counter.
Example 7.26
3-bit one-hot up/down counter (part 2)
7.5 Counters • 253
Finally, Example 7.27 shows the logic diagram and resultant representative timing diagram for the
counter.
Example 7.27
3-bit one-hot up/down counter (part 3)
CONCEPT CHECK
CC7.5 What characteristic of a counter makes it a special case of a finite state machine?
(A) The state transitions are mostly linear, which reduces the implementation
complexity.
(B) The outputs are always a gray code.
(C) The next state logic circuitry is typically just sum terms.
(D) There is never a situation where a counter could be a Mealy machine.
254 • Chapter 7: Sequential Logic Design
Fig. 7.33
Finite state machine reset state
7.7 Sequential Logic Analysis • 255
Resets are most often asynchronous so that they can immediately alter the state of the FSM. If a
reset was implemented in a synchronous manner and there was a clock failure, the system could not be
reset since there would be no more subsequent clock edges that would recognize that the reset line was
asserted. An asynchronous reset allows the system to be fully restarted even in the event of a clock
failure.’
CONCEPT CHECK
CC7.6 What is the downside of using D-flip-flops that do not have preset capability in a finite state
machine?
(A) The finite state machine will run slower.
(B) The next state logic will be more complex.
(C) The output logic will not be able to support both Mealy and Moore type machine
architectures.
(D) The start-up state can never have a 1 in its state code.
7.7.1 Finding the State Equations and Output Logic Expressions of a FSM
When given the logic diagram for a finite state machine and it is desired to reverse-engineer its
behavior, the first step is to determine the next state logic and output logic expressions. This can be
accomplished by first labeling the current and next state variables on the inputs and outputs of the D-flip-
flops that are implementing the state memory of the FSM. The outputs of the D-flip-flops are labeled with
arbitrary current state variable names (e.g., Q1_cur, Q0_cur, etc.) and the inputs are labeled with
arbitrary next state variable names (e.g., Q1_nxt, Q0_nxt, etc.). The numbering of the state variables
can be assigned to the D-flip-flops arbitrarily as long as the current and next state bit numbering is
matched. For example, if a D-flip-flop is labeled to hold bit 0 of the state code, its output should be labeled
Q0_cur and its input should be labeled Q0_nxt.
Once the current state variable nets are labeled in the logic diagram, the expressions for the next
state logic can be found by analyzing the combinational logic circuity driving the next state variables
(e.g., Q1_nxt, Q0_nxt). The next state logic expressions will be in terms of the current state variables
(e.g., Q1_cur, Q0_cur) and any inputs to the FSM.
The output logic expressions can also be found by analyzing the combinational logic driving the
outputs of the FSM. Again, these will be in terms of the current state variables and potentially the inputs
to the FSM. When analyzing the output logic, the type of machine can be determined. If the output logic
only depends on combinational logic that is driven by the current state variables, the FSM is a Moore
machine. If the output logic depends on both the current state variables and the FSM inputs, the FSM is a
Mealy machine. An example of this analysis approach is given in Example 7.28.
256 • Chapter 7: Sequential Logic Design
Example 7.28
Determining the next state logic and output logic expression of a FSM
The next state codes and output logic values can then be populated by evaluating the next state logic
and output logic expressions found earlier. An example of this analysis is shown in Example 7.29.
Example 7.29
Determining the state transition table of a FSM
Example 7.30
Determining the state diagram of a FSM
must exist between clock edges to allow the logic computations to settle so that on the next clock edge
the D-flip-flops can latch in a new value on their inputs.
Let’s examine all of the sources of delay in a FSM. Let’s begin by assuming that all logic values are
at a stable value and we experience a rising clock edge. The value present on the D input of the D-flip-
flop is latched into the storage device and will appear on the Q output after one clock-to-Q delay of the
device (tCQ). Once the new value is produced on the output of the D-flip-flop, it is then used by a variety of
combinational logic circuits to produce the next state codes and the outputs of the FSM. The next state
code computation is typically longer than the output computation so let’s examine that path. The new
value on Q propagates through the combinational logic circuitry and produces the next state code at the
D input of the D-flip-flop. The delay to produce this next state code includes wiring delay in addition to
gate delay. When analyzing the delay of the combinational logic circuitry (tcmb) and the delay of the
interconnect (tint), the worst case path is always considered. Once the new logic value is produced by the
next state logic circuitry, it must remain stable for a certain amount of time in order to meet the D-flip-flop’s
setup specification (tsetup). Once this specification is met, the D-flip-flop could be clocked with the next
clock edge; however, this represents a scenario without any margin in the timing. This means that if
anything in the system caused the delay to increase even slightly, the D-flip-flop could go metastable. To
avoid this situation, margin is included in the delay (tmargin). This provides some padding so that the
system can reliably operate. A margin of 10% is typical in digital systems. The time that must exist
between rising clock edges is then simply the sum of all of these sources of delay
(tCQ + tcmb + tint + tsetup + tmargin). Since the time between rising clock edges is defined as the period of
the signal (T), this value is also the definition of the period of the fastest clock. Since the frequency of a
signal is simply f ¼ 1/T, the maximum clock frequency for the FSM is the reciprocal of the sum of the
delay.
One specification that is not discussed in the above description is the hold time of the D-flip-flop
(thold). The hold specification is the amount of time that the input to the D-flip-flop must remain constant
after the clock edge. In modern storage devices, this time is typically very small and considerably less
than the tCQ specification. If the hold specification is less than tCQ it can be ignored because the output of
the D-flip-flop will not change until after one tCQ anyway. This means that the hold requirements are
inherently met. This is the situation with the majority of modern D-flip-flops. In the rare case that the hold
time is greater than tCQ, then it is used in place of tCQ in the summation of delays. Figure 7.34 gives the
summary of the maximum clock frequency calculation when analyzing a FSM.
260 • Chapter 7: Sequential Logic Design
Fig. 7.34
Timing analysis of a finite state machine
Let’s take a look at an example of how to use this analysis. Example 7.31 shows this analysis for the
FSM analyzed in prior sections but this time considering the delay specifications of each device.
7.7 Sequential Logic Analysis • 261
Example 7.31
Determining the maximum clock frequency of a FSM
CONCEPT CHECK
CC7.7 What is the risk of running the clock above its maximum allowable frequency in a finite state
machine?
(A) The power consumption may drop below the recommended level.
(B) The setup and hold specifications of the D-flip-flops may be violated, which may
put the machine into an unwanted state.
(C) The states may transition too quickly to be usable.
(D) The crystal generating the clock may become unstable.
262 • Chapter 7: Sequential Logic Design
Summary
v Sequential logic refers to a circuit that bases v A finite state machine (FSM) is a system that
its outputs on both the present and past produces outputs based on the current value
values of the inputs. Past values are held in of the inputs and a history of past inputs. The
sequential logic storage device. history of inputs are recorded as states that the
v All sequential logic storage devices are machine has been in. As the machine
based on a cross-coupled feedback loop. responds to new inputs, it transitions between
The positive feedback loop formed in this states. This allows a finite state machine to
configuration will hold either a 1 or a 0. This make more sophisticated decisions about
is known as a bistable device. what outputs to produce by knowing its history.
v If the inputs of the feedback loop in a sequen- v A state diagram is a graphical way to
tial logic storage device are driven to exactly describe the behavior of a FSM. States are
between a 1 and a 0 (i.e., Vcc/2) and then represented using circles and transitions are
released, the device will go metastable. represented using arrows. Outputs are listed
Metastability refers to the behavior where either inside of the state circle or next to the
the device will ultimately be pushed toward transition arrow.
one of the two stable states in the system, v A state transition table contains the same
typically by electrical noise. Once the device information as a state diagram, but in tabular
begins moving toward one of the stable format. This allows the system to be more
states, the positive feedback will reinforce easily synthesized because the information
the transition until it reaches the stable is in a form similar to a truth table.
state. The stable state that the device will v The first step in FSM synthesis is creating the
move toward is random and unknown. state memory. The state memory consists of
v Cross-coupled inverters are the most basic a set of D-flip-flops that hold the current state
form of the positive feedback loop configura- of the FSM. Each state in the FSM must be
tion. To give the ability to drive the outputs of assigned a binary code. The type of
the storage device to known values, the encoding is arbitrary; however, there are cer-
inverters are replaced with NOR gates to tain encoding types that are commonly used
form the SR Latch. A variety of other such as binary, gray code, and one-hot.
modifications can be made to the loop con- Once the codes are assigned, state variables
figuration to ultimately produce a D-latch and need to be defined for each bit position for
D-flip-flop. both the current state and the next state
v A D-flip-flop will update its Q output with the codes. The state variables for the current
value on its D input on every triggering edge state represent the Q outputs of the D-flip-
of a clock. The amount of time that it takes for flops, which hold the current state code. The
the Q output to update after a triggering clock state variables for the next state code repre-
edge is called the “t-clock-to-Q” (tCQ) sent the D inputs of the D-flip-flops. A D-flip-
specification. flop is needed for each bit in the state code.
v The setup and hold times of a D-flip-flop On the triggering edge of a clock, the current
describe how long before (tsetup) and after state will be updated with the next state code.
(thold) the triggering clock edge that the data v The second step in FSM synthesis is creating
on the D input of the device must be stable. If the next state logic. The next state logic is
the D input transitions too close to the trigger- combinational logic circuitry that produces
ing clock edge (i.e., violating a setup or hold the next state codes based on the current
specification) then the device will go meta- state variables and any system inputs. The
stable and the ultimate value on Q is next state logic drives the D inputs of the D-
unknown. flip-flops in the state memory.
v A synchronous system is one in which all v The third step in FSM synthesis is creating
logic transitions occur based on a single the output logic. The output logic is combina-
timing event. The timing event is typically tional logic circuitry that produces the system
the triggering edge of a clock. outputs based on the current state, and
v There are a variety of common circuits that potentially, the system inputs.
can be accomplished using just sequential v The output logic always depends on the cur-
storage devices. Examples of these circuits rent state of a FSM. If the output logic also
include switch debouncing, toggle-flops, rip- depends on the system inputs, the machine
ple counters, and shift registers. is a Mealy machine. If the output logic does
Exercise Problems • 263
not depend on the system inputs, the calculate the possible number of state codes
machine is a Moore machine. that the machine has. The state codes are
v A counter is a special type of finite state then used to calculate the next state logic
machine in which the states are traversed and output values. From this information a
linearly. The linear progression of states state transition table can be created and in
allows the next state logic to be simplified. turn, the state diagram.
The complexity of the output logic in a counter v The maximum frequency of a FSM is found
can also be reduced by encoding the states by summing all sources of time delay that
with the desired counter output for that state. must be accounted for before the next trig-
This technique, known as state-encoded gering edge of the clock can occur. These
outputs, allows the system outputs to simply sources include tCQ, the worst case combina-
be the current state of the FSM. tional logic path, the worst case interconnect
v The reset state of a FSM is the state that the delay path, the setup/hold time of the D-flip-
machine will go to when it begins operation. flops, and any margin that is to be included.
The state code for the reset state must be The sum of these timing delays represents
configured using the reset and/or preset lines the smallest period (T) that the clock can
of the D-flip-flops. If only reset lines are used have. This is then converted to frequency.
on the D-flip-flops, the reset state must be v If the tCQ time is greater than or equal to the
encoded using only zeros. hold time, the hold time can be ignored in the
v Given the logic diagram for a state machine, maximum frequency calculation. This is
the logic expression for the next state memory because the outputs of the D-flip-flops are
and the output logic can be determined by inherently held while the D-flip-flops are pro-
analyzing the combinational logic driving the ducing the next output value. The time it
D inputs of the state memory (i.e., the next takes to change the outputs after a triggering
state logic) and the combinational logic driving clock edge is defined as tCQ. This means as
the system outputs (i.e., the output logic). long as tCQ thold, the hold time specification
v Given the logic diagram for a state diagram, is inherently met since the logic driving the
the state diagram can be determined by first next state codes uses the Q outputs of the
finding the logic expressions for the next D-flip-flops.
state and output logic. The number of D-flip-
flops in the logic diagram can then be used to
Exercise Problems
For some of the following exercise problems normal behavior. The details of how to create
you will be asked to design a Verilog model your own model of a D-Flip-Flop are provided
and perform a functional simulation. You will later in Chap. 8.
be provided with a test bench for each of
these problems. The details of how to create
your own Verilog test bench are provided later
in Chap. 8. For some of the following exercise
problems you will be asked to use D-Flip-
Flops as part of a Verilog design. You will be
provided with the model of the D-Flip-Flop
and can declare it as a component in your
design. The Verilog module port definitions
for a D-Flip-Flop is given in Fig. 7.35. Keep
in mind that this D-Flip-Flop has an active
LOW reset. This means that when the reset
line is pulled to a 0, the outputs will go to
Q ¼ 0, Qn ¼ 1. When the reset line is LOW, Fig. 7.35
the incoming clock is ignored. Once the reset D-Flip-Flop module definition
line goes HIGH, the D-Flip-Flop resumes
264 • Chapter 7: Sequential Logic Design
Section 7.1: Sequential Logic Storage 7.1.11 For the timing diagram shown in Fig. 7.38,
draw the outputs Q and Qn for a rising edge
Devices
triggered D-flip-flop with active LOW.
7.1.1 What does the term metastability refer to in a
sequential storage device?
7.1.2 What does the term bistable refer to in a
sequential storage device?
7.1.3 You are given a cross-coupled inverter pair in
which all nodes are set to Vcc/2. Why will this
configuration always move to a more stable
state?
7.1.4 An SR Latch essentially implements the same
cross-coupled feedback loop to store informa-
tion as in a cross-coupled inverter pair. What is
the purpose of using NOR gates instead of
inverters in the SR Latch configuration?
7.1.5 Why isn’t the input condition S ¼ R ¼ 1 used in Fig. 7.38
an SR Latch? D-Flip-Flop timing diagram exercise 3
7.1.6 How will the output Q behave in an SR Latch if
Section 7.2: Sequential Logic Timing
the inputs continuously switch between S ¼ 0,
R ¼ 1 and S ¼ 1, R ¼ 1 every 10 ns? Considerations
7.1.7 How do D-flip-flops enable synchronous 7.2.1 What timing specification is violated in a D-flip-
systems? flop when the data is not held long enough
before the triggering clock edge occurs?
7.1.8 What signal in the D-flip-flop in Fig. 7.35 has
the highest priority? 7.2.2 What timing specification is violated in a D-flip-
flop when the data is not held long enough after
7.1.9 For the timing diagram shown in Fig. 7.36,
the triggering clock edge occurs?
draw the outputs Q and Qn for a rising edge
triggered D-flip-flop with active LOW. 7.2.3 What is the timing specification for a D-flip-flop
that describes how long after the triggering
clock edge occurs that the new data will be
present on the Q output?
7.2.4 What is the timing specification for a D-flip-flop
that describes how long after the device goes
metastable that the outputs will settle to known
states.
7.2.5 If the Q output of a D-flip-flop is driving the D
input of another D-flip-flop from the same logic
family, can the hold time be ignored if it is less
than the clock-to-Q delay? Provide an expla-
nation as to why or why not.
clock, bit(2) has a frequency that is exactly 1/8 (a) How many D-Flip-Flops will this machine
of the incoming clock, etc. This behavior can take if the states are encoded in binary?
be exploited to create a divided down output (b) How many D-Flip-Flops will this machine
clock that is divided by multiples of 2n by take if the states are encoded in gray
selecting a particular bit of the counter. The code?
typical configuration of this programmable
clock divider is to route each bit of the counter (c) How many D-Flip-Flops will this machine
to an input of a multiplexer. The select lines take if the states are encoded in one-
going to the multiplexer choose which bit of hot?
the counter are used as the divided down
clock output. This architecture is shown in
Fig. 7.39. Design a Verilog model to implement
the programmable clock divider shown in this
figure. Use the module port definition provided
in this figure for your design. Use a 4-bit ripple
counter to produce four divided versions of the
clock (1/2, 1/4, 1/8, and 1/16). Your system will
take in two select lines that will choose which
version of the clock is to be routed to the out-
put. Instantiate the D-flip-flop model provided
to implement the ripple counter. Implement the
4-to-1 multiplexer using continuous assign-
ment. The multiplexer does not need to be its
own sub-system.
Fig. 7.40
FSM 1 state diagram
Fig. 7.41
FSM 1 module definition
Fig. 7.42
FSM 2 state diagram
7.4.5 Design a Verilog model to implement the
behavior described by the state diagram in 7.4.8 For the state diagram in Fig. 7.42, is this a
Fig. 7.40. Use the module port definition Mealy or Moore machine?
provided in Fig. 7.41 for your design. Name 7.4.9 Design the finite state machine circuitry by
the current state variables Q1_cur and hand to implement the behavior described by
Q0_cur and name the next state variables the state diagram in Fig. 7.42. Name the cur-
Q1_nxt and Q0_nxt. Instantiate the D-Flip- rent state variables Q1_cur and Q0_cur and
Flop model provided to implement your state name the next state variables Q1_nxt and
memory. Use continuous assignment with con- Q0_nxt. Also, use the following state codes:
ditional operators for the implementation of
S0 ¼ “00”
your next state and output logic.
S1 ¼ “01”
7.4.6 Design a Verilog model to implement the
behavior described by the state diagram in S2 ¼ “10”
Fig. 7.40. Use the module port definition S3 ¼ “11”
provided in Fig. 7.41 for your design. Name
(a) What is the next state logic expression
the current state variables Q1_cur and
for Q1_nxt?
Q0_cur and name the next state variables
Q1_nxt and Q0_nxt. Instantiate the D-Flip- (b) What is the next state logic expression
Flop model provided to implement your state for Q0_nxt?
memory. Use User-Defined Primitives for the (c) What is the output logic expression for
implementation of your next state and output Dout?
logic.
(d) Draw the final logic diagram for this
7.4.7 For the state diagram in Fig. 7.42, answer the machine.
following questions regarding the number of D-
7.4.10 Design a Verilog model to implement the
Flip-Flops needed to implement the state
behavior described by the state diagram in
memory of the finite state machine.
Fig. 7.42. Use the module port definition
(a) How many D-Flip-Flops will this machine provided in Fig. 7.43 for your design. Name
take if the states are encoded in binary? the current state variables Q1_cur and
(b) How many D-Flip-Flops will this machine Q0_cur and name the next state variables
take if the states are encoded in gray Q1_nxt and Q0_nxt. Instantiate the D-Flip-
code? Flop model provided to implement your state
memory. Use continuous assignment with logi-
(c) How many D-Flip-Flops will this machine
cal operators for the implementation of your
take if the states are encoded in one-
next state and output logic.
hot?
Exercise Problems • 267
Section 7.5: Counters (f) What is the output logic expression for
Count(0)?
7.5.1 Design a 3-bit binary up counter by hand. This
state machine will need eight states and (g) Draw the logic diagram for this counter.
require three bits for the state variable codes. 7.5.4 Design a Verilog model for a 3-bit binary
Name the current state variables Q2_cur, up/down counter. Instantiate the D-Flip-Flop
Q1_cur, and Q0_cur and the next state model provided to implement your state mem-
variables Q2_nxt, Q1_nxt, and Q0_nxt. The ory. Use whatever concurrent modeling
output of your counter will be a 3-bit vector approach you wish to model the next state
called Count. and output logic. Use the module port definition
(a) What is the next state logic expression provided in Fig. 7.45 for your design.
for Q2_nxt?
(b) What is the next state logic expression
for Q1_nxt?
(c) What is the next state logic expression
for Q0_nxt?
(d) What is the output logic expression for
Count(2)?
(e) What is the output logic expression for
Count(1)?
Fig. 7.45
(f) What is the output logic expression for
Count(0)? 3-Bit binary up/down counter module definition
(g) Draw the logic diagram for this counter.
7.5.5 Design a 3-bit gray code up counter by hand.
7.5.2 Design a Verilog model for a 3-bit binary up This state machine will need eight states and
counter. Instantiate the D-Flip-Flop model require three bits for the state variable codes.
provided to implement your state memory. Name the current state variables Q2_cur,
Use whatever concurrent modeling approach Q1_cur, and Q0_cur and the next state variables
you wish to model the next state and output Q2_nxt, Q1_nxt, and Q0_nxt. The output of your
logic. Use the module port definition provided counter will be a 3-bit vector called Count.
in Fig. 7.44 for your design.
(a) What is the next state logic expression
for Q2_nxt?
(b) What is the next state logic expression
for Q1_nxt?
(c) What is the next state logic expression
for Q0_nxt?
(d) What is the output logic expression for
Count(2)?
Fig. 7.44 (e) What is the output logic expression for
3-Bit binary up counter module definition Count(1)?
(f) What is the output logic expression for
7.5.3 Design a 3-bit binary up/down counter by hand. Count(0)?
The counter will have an input called “Up” that (g) Draw the logic diagram for this counter.
will dictate the direction of the counter. When
Up ¼ 1, the counter should increment and when 7.5.6 Design a Verilog model for a 3-bit gray code up
Up ¼ 0 it should decrement. This state machine counter. Instantiate the D-Flip-Flop model
will need eight states and require three bits for provided to implement your state memory.
the state variable codes. Name the current state Use whatever concurrent modeling approach
variables Q2_cur, Q1_cur, and Q0_cur and the you wish to model the next state and output
next state variables Q2_nxt, Q1_nxt, and logic. Use the module port definition provided
Q0_nxt. The output of your counter will be a in Fig. 7.46 for your design.
3-bit vector called Count.
(a) What is the next state logic expression
for Q2_nxt?
(b) What is the next state logic expression
for Q1_nxt?
(c) What is the next state logic expression
for Q0_nxt?
(d) What is the output logic expression for Fig. 7.46
Count(2)? 3-Bit gray code up counter module definition
(e) What is the output logic expression for
Count(1)?
Exercise Problems • 269
7.5.7 Design a 3-bit gray code up/down counter by 7.6.5 If a finite state machine has eight unique states
hand. The counter will have an input called that are encoded in binary and all D-flip-flops
“Up” that will dictate the direction of the used for the state memory use their reset lines,
counter. When Up ¼ 1, the counter should what is the state code that the machine will go
increment and when Up ¼ 0 it should decre- to upon reset?
ment. This state machine will need eight states
and require three bits for the state variable Section 7.7: Sequential Logic Analysis
codes. Name the current state variables
Q2_cur, Q1_cur, and Q0_cur and the next 7.7.1 For the finite state machine logic diagram in
state variables Q2_nxt, Q1_nxt, and Q0_nxt. Fig. 7.48, give the next state logic expression
The output of your counter will be a 3-bit vector for Q_nxt.
called Count.
(a) What is the next state logic expression
for Q2_nxt?
(b) What is the next state logic expression
for Q1_nxt?
(c) What is the next state logic expression
for Q0_nxt?
(d) What is the output logic expression for Fig. 7.48
Count(2)? Sequential logic analysis 1
(e) What is the output logic expression for
Count(1)? 7.7.2 For the finite state machine logic diagram in
(f) What is the output logic expression for Fig. 7.48, give the output logic expression
Count(0)? for Tout.
(g) Draw the logic diagram for this counter. 7.7.3 For the finite state machine logic diagram in
7.5.8 Design a Verilog model for a 3-bit gray code Fig. 7.48, give the state transition table.
up/down counter. Instantiate the D-Flip-Flop 7.7.4 For the finite state machine logic diagram in
model provided to implement your state mem- Fig. 7.48, give the state diagram.
ory. Use whatever concurrent modeling 7.7.5 For the finite state machine logic diagram in
approach you wish to model the next state Fig. 7.48, give the maximum clock frequency.
and output logic. Use the module port definition
provided in Fig. 7.47 for your design. 7.7.6 For the finite state machine logic diagram in
Fig. 7.49, give the next state logic expression
for Q_nxt.
Fig. 7.47
3-Bit gray code up/down counter module
definition Fig. 7.49
Sequential logic analysis 2
Section 7.6: Finite State Machine’s Reset
Condition 7.7.7 For the finite state machine logic diagram in
Fig. 7.49, give the output logic expression for F.
7.6.1 Are resets typically synchronous or
asynchronous? 7.7.8 For the finite state machine logic diagram in
Fig. 7.49, give the state transition table.
7.6.2 Why is it necessary to have a reset/preset
condition in a finite state machine? 7.7.9 For the finite state machine logic diagram in
Fig. 7.49, give the state diagram.
7.6.3 How does the reset/preset condition corre-
spond to the behavior described in the state 7.7.10 For the finite state machine logic diagram in
diagram? Fig. 7.49, give the maximum clock frequency.
7.6.4 When is it necessary to also use the preset line 7.7.11 For the finite state machine logic diagram in
(s) of a D-flip-flop instead of just the reset line Fig. 7.50, give the next state logic expressions
(s) when implementing the state memory of a for Q1_nxt and Q0_nxt.
finite state machine?
270 • Chapter 7: Sequential Logic Design
Fig. 7.50
Sequential logic analysis 3
Chapter 8: Verilog (Part 2)
In Chap. 5 Verilog was presented as a way to describe the behavior of concurrent systems. The
modeling techniques presented were appropriate for combinational logic because these types of circuits
have outputs dependent only on the current values of their inputs. This means a model that continuously
performs signal assignments provides an accurate model of this circuit behavior. In Chap. 7 sequential
logic storage devices were presented that did not continuously update their outputs based on the
instantaneous values of their inputs. Instead, sequential storage devices only update their outputs
based upon an event, most often the edge of a clock signal. The modeling techniques presented in
Chap. 5 are unable to accurately describe this type of behavior. In this chapter, we describe the Verilog
constructs to model signal assignments that are triggered by an event in order to accurately model
sequential logic. We can then use these techniques to describe more complex sequential logic circuits
such as finite state machines and register transfer level systems. This chapter will also present how to
create test benches and look at more advanced features that are commonly used in Verilog to model
modern systems. The goal of this chapter is to give an understanding of the full capability of hardware
description languages.
Learning Outcomes—After completing this chapter, you will be able to:
8.1 Describe the behavior of Verilog procedural assignment and how they are used to model
sequential logic circuits.
8.2 Model combinational logic circuits using a Verilog procedural assignment and conditional
programming constructs.
8.3 Describe the functionality of common Verilog system tasks.
8.4 Design a Verilog test bench to verify the functional operation of a system.
initial
begin // an optional “: name” can be added after the begin keyword
signal_assignment_1
signal_assignment_2
:
end
Let’s look at a simple model of how an initial block is used to model the reset line in a test bench. In
the following example, the signal “Reset_TB” is being driven into a DUT. At the beginning of the
simulation, the initial value of Reset_TB is set to a logic zero. The second assignment will take place
after a delay of 15 time units. The second assignment statement sets Reset_TB to a logic one. The
assignments in this example are evaluated in sequence in the order they are listed due to the delay
operator. Since the initial block executes only once, Reset_TB will stay at the value of its last assignment
for the remainder of the simulation.
Example:
initial
begin
Reset_TB ¼ 1’b0;
#15 Reset_TB ¼ 1’b1;
end
always
begin
signal_assignment_1
signal_assignment_2
:
end
Let’s look at a simple model of how an always block can be used to model a clock line in a test
bench. In the following example, the value of the signal Clock_TB will continuously change its logic value
every 10 time units.
Example:
always
begin
#10 Clock_TB ¼ ~Clock_TB;
end
By itself, the above always block will not work because when the simulation begins, Clock_TB does
not have an initial value so the simulator will not know what the value of Clock_TB is at time zero. It
will also not know what the output of the negation operation (~) will be at time unit 10. The following
example shows the correct way of modeling a clock signal using a combination of initial and always
8.1 Procedural Assignment • 273
blocks. Verilog allows assignments to the same variable from multiple procedural blocks, so the following
example is valid. Note that when the simulation begins, Clock_TB is assigned a logic zero. This provides
a known value for the signal at time zero and also allows the always block negation to have a
deterministic value. The example below will create a clock signal that will toggle every 10 time units.
Example:
initial
begin
Clock_TB ¼ 1’b0;
end
always
begin
#10 Clock_TB ¼ ~Clock_TB;
end
In this syntax, any transition on any of the signals listed within the parenthesis will cause the always
block to trigger and all of its assignments to take place one time. After the always block ends, it will await
the next signal transition in the sensitivity list to trigger again. The following example shows how to model
a simple 3-input AND gate. In this example, any transition on inputs A, B, or C will cause the block to
trigger and the assignment to F to occur.
Example:
always @ (A, B, C)
begin
F ¼ A & B & C;
end
Verilog also supports keywords to limit triggering of the block to only rising edge or falling edge
transitions. The keywords are posedge and negedge. The following is the base syntax for an edge
sensitive block. In this syntax, only rising edge transitions on signal1 or falling edge transitions on signal2
will cause the block to trigger.
always @ (posedge signal1, negedge signal2)
begin
signal_assignment_1
signal_assignment_2
:
end
Sensitivity lists can also contain Boolean operators to more explicitly describe behavior. The
following syntax is identical to the syntax above.
274 • Chapter 8: Verilog (Part 2)
The ability to model edge sensitivity allows us to model sequential circuits. The following example
shows how to model a simple D-flip-flop.
Example:
In Verilog-2001, the syntax to support sensitivity lists that will trigger based on any signal listed on
the right-hand-side of any assignment within the block was added. This syntax is @*. The following
example how to use this modeling approach to model a 3-input AND gate.
Example:
always @*
begin
F ¼ A & B & C;
end
Example 8.1
Using blocking assignments to model combinational logic
Example 8.2
Using non-blocking assignments to model sequential logic
The difference between blocking and non-blocking assignments is subtle and is often one of the
most difficult concepts to grasp when first learning Verilog. One source of confusion comes from the fact
that blocking and non-blocking assignments can produce the same results when they either contains a
276 • Chapter 8: Verilog (Part 2)
single assignment or a list of assignments that don’t have any signal interdependencies. A signal
interdependency refers to when a signal that is the target of an assignment (i.e., on the LHS of an
assignment) is used as an argument (i.e., on the RHS of an assignment) in subsequent statements.
Example 8.3 shows two models that produce the same results regardless of whether a blocking or
non-blocking assignment is used.
Example 8.3
Identical behavior when using blocking vs. non-blocking assignments
When a list of statements within a procedural block does have signal interdependencies, blocking
and non-blocking assignments will have different behavior. Example 8.4 shows how signal
interdependencies will cause different behavior between blocking and non-blocking assignments. In
this example, all inputs are listed in the sensitivity list with the intent of modeling combinational logic.
8.1 Procedural Assignment • 277
Example 8.4
Different behavior when using blocking vs. non-blocking assignments (1)
Example 8.5 shows another case where signal interdependencies will cause different behavior
between blocking and non-blocking assignments. In this example, the procedural block is triggered by
the rising edge of a clock signal with the intent of modeling two stages of sequential logic.
278 • Chapter 8: Verilog (Part 2)
Example 8.5
Different behavior when using blocking vs. non-blocking assignments (2)
While the behavior of these procedural assignments can be confusing, there are two design
guidelines that can make creating accurate, synthesizable models straightforward. They are:
1. When modeling combinational logic, use blocking assignments and list every input in the
sensitivity list.
2. When modeling sequential logic, use non-blocking assignments and only list the clock and
reset lines (if applicable) in the sensitivity list.
8.1 Procedural Assignment • 279
Example 8.6
Behavior of statement groups begin/end vs. fork/join
Example:
initial
begin: stim_block // it is required to name the block when declaring
local variables
integer i; // local variables can only be of variable type
i¼2;
end
280 • Chapter 8: Verilog (Part 2)
CONCEPT CHECK
CC8.1 If a model of a combinational logic circuit excludes one of its inputs from the sensitivity list,
what is the implied behavior?
(A) A storage element because the output will be held at its last value when the
unlisted input transitions.
(B) An infinite loop.
(C) A don’t care will be used to form the minimal logic expression.
(D) Not applicable because this syntax will not compile.
if (<boolean_condition>)
true_statement
else
false_statement
The syntax for an if-else statement with multiple true/false statements is as follows:
if (<boolean_condition>)
begin
true_statement_1
true_statement_2
end
else
begin
false_statement_1
false_statement_2
end
If more than one Boolean condition is required, additional if-else statements can be embedded
within the else clause of the preceding if statement. The following shows an example of if-else
statements implementing two Boolean conditions.
8.2 Conditional Programming Constructs • 281
if (<boolean_condition_1>)
true_statement_1
else if (<boolean_condition_2>)
true_statement_2
else
false_statement
Let’s look at using an if-else statement to describe the behavior of a combinational logic circuit.
Recall that a combinational logic circuit is one in which the output depends on the instantaneous values
of the inputs. This behavior can be modeled by placing all of the inputs to the circuit in the sensitivity list of
an always block and using blocking assignments. Using this approach, a change on any of the inputs in
the sensitivity list will trigger the block and the assignments will take place immediately. Example 8.7
shows how to model a 3-input combinational logic circuit using if-else statements within a procedural
always block.
Example 8.7
Using if-else statements to model combinational logic
case (<input_name>)
input_val_1 : statement_1
input_val_2 : statement_2
:
input_val_n : statement_n
default : default_statement
endcase
Example 8.8 shows how to model a 3-input combinational logic circuit using a case statement within
a procedural block. Note in this example the inputs are scalars so they must be concatenated so that the
input values can be listed as 3-bit vectors. In this example, there are three versions of the model
provided. The first explicitly lists out all binary input codes. This approach is more readable because it
mirrors a truth table form. The second approach only lists the input codes corresponding to an output of
one and uses the default clause to handle all other input codes. The third approach shows how to list
multiple input codes with the same assignment on the same line using a comma-delimited series.
Example 8.8
Using case statements to model combinational logic
8.2 Conditional Programming Constructs • 283
If-else statements can be embedded within a case statement and, conversely, case statements can
be embedded within an if-else statement.
forever
begin
statement_1
statement_2
:
statement_n
end
Consider the following example of a forever loop that generates a clock signal (CLK) with a period of
10 time units. In this example, the forever loop is embedded within an initial block. This allows the initial
value of CLK to be set to zero upon the beginning of the simulation. Once the forever loop is entered, it
will execute indefinitely. Notice that since there is only one statement after the forever keyword, a
statement group (i.e., begin/end) is not needed.
Example:
initial
begin
CLK ¼ 0;
forever
#10 CLK ¼ ~CLK;
end
while (<boolean_condition>)
begin
statement_1
statement_2
:
statement_n
end
Let’s implement the previous example of a loop that generates a clock signal (CLK) with a period of
10 time units as long as EN ¼ 1. The TRUE Boolean condition for the while loop is EN ¼ 1. When EN ¼ 0,
the while loop will be skipped. When the loop becomes inactive, CLK will hold its last assigned value.
Example:
initial
begin
CLK ¼ 0;
while (EN ¼¼ 1)
#10 CLK ¼ ~CLK;
end
repeat (<number_of_loops>)
begin
statement_1
statement_2
:
statement_n
end
Let’s implement the previous example of a loop that generates a clock signal (CLK) with a period of
10 time units, except this time we’ll use a repeat loop to only produce 10 clock transitions, or 5 full periods
of CLK.
Example:
initial
begin
CLK ¼ 0;
repeat (10)
#10 CLK ¼ ~CLK;
end
The following is an example of creating a simple counter using the loop variable. The loop variable
i was declared as an integer prior to this block. The signal Count is also of type integer. The loop variable
will start at 0 and increment by 1 each time through the loop. The loop will execute as long as i < 15, or
16 times total. For loops allow the loop variable to be used in signal assignments within the block.
Example:
initial
begin
for (i¼0; i<15; i¼i+1)
#10 Count ¼ i;
end
8.2.8 disable
Verilog provides the ability to stop a loop using the keyword disable. The disable function only works
on named statement groups. The disable function is typically used after a certain fixed amount of time or
within a conditional construct such as an if-else or case statement that is triggered by a control signal.
Consider the following forever loop example that will generate a clock signal (CLK), but only when an
enable (EN) is asserted. When EN ¼ 0, the loop will disable and the simulation will end.
Example:
initial
begin
CLK ¼ 0;
forever
begin: loop_ex
if (EN ¼¼ 1)
#10 CLK ¼ ~CLK;
else
disable loop_ex; // The group name to be disabled comes after the
keyword
end
end
CONCEPT CHECK
CC8.2 When using an if-else statement to model a combinational logic circuit, is using the else
clause the same as using don’t cares when minimizing a logic expression with a K-map?
(A) Yes. The else clause allows the synthesizer to assign whatever output values are
necessary in order to create the most minimal circuit.
(B) No. The else clause explicitly states the output values for all input codes not listed
in the if portion of the statement. This is the same as filling in the truth table with
specific values for all input codes covered by the else clause and the synthesizer
will create the logic expression accordingly.
286 • Chapter 8: Verilog (Part 2)
Task Description
$display() Print text string when statement is encountered and append a newline.
$displayb() Same as $display, but default format of any arguments is binary.
$displayo() Same as $display, but default format of any arguments is octal.
$displayh() Same as $display, but default format of any arguments is hexadecimal.
$write() Same as $display, but the string is printed without a newline.
$writeb() Same as $write, but default format of any arguments is binary.
$writeo() Same as $write, but default format of any arguments is octal.
$writeh() Same as $write, but default format of any arguments is hexadecimal.
$strobe() Same as $display, but printing occurs after all simulation events are executed.
$strobeb() Same as $strobe, but default format of any arguments is binary.
$strobeo() Same as $strobe, but default format of any arguments is octal.
$strobeh() Same as $strobe, but default format of any arguments is hexadecimal.
$monitor() Same as $display, but printing occurs when the value of an argument changes.
$monitorb() Same as $monitor, but default format of any arguments is binary.
$monitoro() Same as $monitor, but default format of any arguments is octal.
$monitoron Begin tracking argument changes in subsequent $monitor tasks.
$monitoroff Stop tracking argument changes in subsequent $monitor tasks.
The following is a list of the most common text formatting codes for printing variables within a string.
Code Format
%b Binary values
%o Octal values
%d Decimal values
%h Hexadecimal values
%f Real values using decimal form
%e Real values using exponential form
%t Time values
%s Character strings
%m Hierarchical name of scope (no argument required when printing)
%l Configuration library binding (no argument required when printing)
8.3 System Tasks • 287
The format letters in these codes are not case sensitive (i.e., %d and %D are equivalent). Each of
these formatting codes can also contain information about truncation of leading and trailing digits.
Rounding will take place when numbers are truncated. The formatting syntax is as follows:
There are also a set of string formatting and character escapes that are supported for use with the
text output system tasks.
Code Description
\n Print a new line.
\t Print a tab.
\” Print a quote (“).
\\ Print a backslash (\).
%% Print a percent sign (%).
The following is a set of examples using common text output system tasks. For these examples,
assume two variables have been declared and initialized as follow: A ¼ 3 (integer) and B ¼ 45.6789
(real). Recall that Verilog uses 32-bit codes to represent type integer and real.
Example:
$display("Hello World"); // Will print: Hello World
$display("A ¼ %b", A); // This will print: A ¼ 00000000000000000000000000000011
$display("A ¼ %o", A); // This will print: A ¼ 00000000003
$display("A ¼ %d", A); // This will print: A ¼ 3
$display("A ¼ %h", A); // This will print: A ¼ 00000003
$display("A ¼ %4.0b", A); // This will print: A ¼ 0011
Task Description
$fopen() Opens a file and returns a unique file descriptor.
$fclose() Closes the file associated with the descriptor.
$fdisplay() Same as $display but statements are directed to the file descriptor.
$fwrite() Same as $write but statements are directed to the file descriptor.
$fstrobe() Same as $strobe but statements are directed to the file descriptor.
$fmonitor() Same as $monitor but statements are directed to the file descriptor.
$readmemb() Read binary data from file and insert into previously defined memory array.
$readmemh() Read hexadecimal data from file and insert into previously defined memory array.
The $fopen() function will either create and open, or open an existing file. Each file that is opened is
given a unique integer called a file descriptor that is used to identify the file in other I/O functions. The
integer must be declared prior to the first use of $fopen. A file name argument is required and provided
within double quotes. By default, the file is opened for writing. If the file name doesn’t exist, it will be
created. If the file name does exist, it will be overwritten. An optional file_type can be provided that gives
specific action for the file opening including opening an existing file and appending to a file. The following
are the supported codes for $fopen().
Once a fie is open, data can be written to it using the $fdisplay(), $fwrite(), $fstrobe(), and
$fmonitor() tasks. These functions require two arguments. The first argument is the file descriptor and
the second is the information to be written. The information follows the same syntax as the I/O system
tasks. The following example shows how to create a file and write data to it. This example will create a
new file called “Data_out.txt” and write two lines of text to it with the values of variables A and B.
Example:
integer A ¼ 3;
real B ¼ 45.6789;
integer FILE_1;
initial
begin
FILE_1 ¼ $fopen("Data_out.txt", "w");
$fdisplay(FILE_1, "A is %d", A);
$fdisplay(FILE_1, "B is %f", B);
$fclose(FILE_1);
end
When reading data from a file, the functions $readmemb() and $readmemh() can be used. These
tasks require that a storage array be declared that the contents of the file can be read into. These tasks
have two arguments, the first being the name of the file and the second being the name of the storage
array to store the file contents into. The following example shows how to read the contents of a file into a
storage array called “memory”. Assume the file contains eight lines, each containing a 3-bit vector. The
vectors start at 000 and increment to 111 and each symbol will be interpreted as binary using the
$readmemb() task. The storage array “memory” is declared to be an 8x3 array of type reg. The
8.3 System Tasks • 289
$readmemb() task will insert each line of the file into each 3-bit vector location within “memory”. To
illustrate how the data is stored, this example also contains a second procedural block that will print the
contents of the storage element to the transcript.
Example:
reg[2:0] memory[7:0];
initial
begin: Read_Block
$readmemb("Data_in.txt", memory);
end
initial
begin: Print_Block
$display("printing memory %b", memory[0]); // This will print “000”
$display("printing memory %b", memory[1]); // This will print “001”
$display("printing memory %b", memory[2]); // This will print “010”
$display("printing memory %b", memory[3]); // This will print “011”
$display("printing memory %b", memory[4]); // This will print “100”
$display("printing memory %b", memory[5]); // This will print “101”
$display("printing memory %b", memory[6]); // This will print “110”
$display("printing memory %b", memory[7]); // This will print “111”
end
Task Description
$finish() Finishes simulation and exits.
$stop() Halts the simulation and enters an interactive debug mode.
$time() Returns the current simulation time as a 64-bit vector.
$stime() Returns the current simulation time as a 32-bit integer.
$realtime() Returns the current simulation time as a 32-bit real number.
$timeformat() Controls the format used by the %t code in print statements.
The arguments are: (<unit>, <precision>, <suffix>, <min_field_width>)
where:
<unit> 0 ¼ 1 sec
-1 ¼ 100 ms
-2 ¼ 10 ms
-3 ¼ 1 ms
-4 ¼ 100us
-5 ¼ 10us
-6 ¼ 1us
-7 ¼ 100 ns
-8 ¼ 10 ns
-9 ¼ 1 ns
-10 ¼ 100 ps
-11 ¼ 10 ps
-12 ¼ 1 ps
-13 ¼ 100 fs
-14 ¼ 10 fs
15 ¼ 1 fs
290 • Chapter 8: Verilog (Part 2)
Example:
initial
begin
This example will result in the following statements printed to the simulator transcript:
Stimulus starting at time: 0.00 ns
Simulation stopping at time: 80.00 ns
CONCEPT CHECK
CC8.3 How can Verilog system tasks be included in synthesizable circuit models when they provide
inherently unsynthesizable functionality?
(A) They can’t. System tasks can only be used in test benches.
(B) The “$” symbol tells the CAD tool that the task can be ignored during synthesis.
(C) The designer must only use system tasks that model sequential logic.
Example 8.9
Test bench for a combinational logic circuit
Multiple procedural blocks can be used within a Verilog module to provide parallel functionality.
Using both initial and always blocks allows the test bench to drive both repetitive and aperiodic signals.
Initial and always blocks can also be used to drive the same signal in order to provide a starting value and
a repetitive pattern. Example 8.10 shows a test bench for a rising edge triggered D-flip-flop with an
asynchronous, active LOW reset in which multiple procedural blocks are used to generate the stimulus
patterns for the DUT.
292 • Chapter 8: Verilog (Part 2)
Example 8.10
Test bench for a sequential logic circuit
Example 8.11
Printing test bench results to the transcript
Example 8.12
Test bench with automatic output checking
8.4 Test Benches • 295
Example 8.13
Using a loop to generate stimulus in a test bench
296 • Chapter 8: Verilog (Part 2)
Example 8.14
Printing test bench results to an external file
8.4 Test Benches • 297
It is often the case that the input vectors are either too large to enter manually or were created by a
separate program. In either case, a useful technique in test benches is to read input vectors from an
external file. Example 8.15 shows an example where the input stimulus vectors for a DUT are read from
an external file using the $readmemb() system task.
Example 8.15
Reading test bench stimulus vectors from an external file
298 • Chapter 8: Verilog (Part 2)
CONCEPT CHECK
CC8.4 Could a test bench ever use always blocks and sensitivity lists exclusively to create its
stimulus? Why or why not?
(A) Yes. The signal assignments will simply be made when the block ends.
(B) No. Since a sensitivity list triggers when there is a change on one or more of the
signals listed, the blocks in the test bench would never trigger because there is no
method to make the initial signal transition.
Summary
v To model sequential logic, an HDL needs to v Variables can be defined within a procedural
be able to trigger signal assignments based block as long as the block is named.
on an event. This is accomplished in Verilog v Procedural blocks allow more advanced
using procedural assignment. modeling constructs in Verilog. These
v There are two types of procedural blocks in include if-else statements, case statements,
Verilog, initial and always. An initial block and loops.
executes one time. An always block runs v Verilog provides numerous looping
continually. constructs including forever, while, repeat,
v A sensitivity list is a way to control when a and for. Loops can be terminated using the
Verilog procedural block is triggered. A sen- disable keyword.
sitivity list contains a list of signals. If any of v System Tasks provide additional functionality
the signals in the sensitivity list transitions it to Verilog models. Tasks begin with the $
will cause the block to trigger. If a sensitivity symbol and are omitted from synthesis. Sys-
list is omitted, the block will trigger immedi- tem tasks can be included in synthesizable
ately. Sensitivity lists are most commonly logic models.
used with always blocks. v There are three groups of system tasks: text
v Sensitivity lists and always blocks are used output, file input/output, and simulation con-
to model synthesizable logic. Initial blocks trol and monitoring.
are typically only used in test benches. v System tasks that perform printing functions
Always blocks are also used in test benches. can output strings in addition to variable
v There are two types of signal assignments values. Verilog provides a mechanism to
that can be used within a procedural block, print the variable values in a variety of format.
blocking and non-blocking. v A test bench is a way to simulate a device
v A blocking assignment is denoted with the ¼ under test (DUT) by instantiating it as a
symbol. All blocking assignments are made sub-system, driving in stimulus, and observ-
immediately within the procedural block. ing the outputs. Test benches do not have
Blocking assignments are used to model inputs or outputs and are unsynthesizable.
combinational logic. Combinational logic v Test benches for combinational logic typically
models list all input to the circuit in the exercise the DUT under an exhaustive set of
sensitivity list. stimulus vectors. These include all possible
v A non-blocking assignment is denoted with logic inputs in addition to critical transitions
the <¼ symbol. All non-blocking that could cause timing errors.
assignments are made when the procedural v Text I/O system tasks provide a way to print
block ends and are evaluated in the order the results of a test bench to the simulation
they appeared in the block. Blocking tool transcript.
assignments are used to model sequential v File I/O system tasks provide a way to print
logic. Sequential logic models list only the the results of a test bench to an external file
clock and reset in the sensitivity list. and also to read in stimulus vectors from an
external file.
Exercise Problems • 299
Exercise Problems
Section 8.1: Procedural Assignment
8.2.4 Design a Verilog model to implement the behav- 8.2.8 Design a Verilog model to implement the behav-
ior described by the 4-input minterm list in ior described by the 4-input truth table in Fig. 8.4.
Fig. 8.2. Use procedural assignment and a Use procedural assignment and a case state-
case statement. Declare the module to match ment. Declare the module to match the block
the block diagram provided. Use the type wire diagram provided. Use the type wire for the
for the inputs and type reg for the output. inputs and type reg for the output.
8.2.5 Design a Verilog model to implement the behav- 8.2.9 Fig. 8.5 shows the topology of a 4-bit shift regis-
ior described by the 4-input maxterm list in ter when implemented structurally using D-Flip-
Fig. 8.3. Use procedural assignment and an Flops. Design a Verilog model to describe this
if-then statement. Declare the module to match functionality using a single procedural block and
the block diagram provided. Use the type wire for non-blocking assignments instead of
the inputs and type reg for the output. instantiating D-Flip-Flops. The figure also
provides the block diagram for the module port
definition. Use the type wire for the inputs and
type reg for the outputs.
Fig. 8.3
System K functionality
Fig. 8.6
Integer counter block diagram
your count value, and then assign it to the out- whether the output of the DUT is correct. For
put variable of type reg[4:0]. each input vector, print a message using $dis-
play() that indicates the current input vector
being tested, the resulting output of your DUT,
and whether the DUT output is correct.
8.4.5 Design a Verilog test bench to verify the func-
tional operation of the system in Fig. 8.3. Your
test bench should drive in every possible input
code for the vector ABCD (i.e., “0000”, “0001”,
Fig. 8.7 “0010”, . . ., “1111”). Have your test bench change
5-bit binary counter block diagram the input pattern every 10 ns using delay within
your procedural block.
8.4.6 Design a Verilog test bench to verify the func-
Section 8.3: System Tasks tional operation of the system in Fig. 8.3 with
automatic checking. Your test bench should
8.3.1 Are system tasks synthesizable? Why or why drive in every possible input code for the vector
not? ABCD (i.e., “0000”, “0001”, “0010”, . . ., “1111”).
8.3.2 What is the difference between the tasks $dis- Have your test bench change the input pattern
play() and $write()? every 10 ns using delay within your procedural
block. Use conditional statements to check
8.3.3 What is the difference between the tasks $dis- whether the output of the DUT is correct. For
play() and $monitor()? each input vector, print a message using $dis-
8.3.4 What is the data type returned by the task play() that indicates the current input vector
$fopen()? being tested, the resulting output of your DUT,
and whether the DUT output is correct.
8.4.7 Design a Verilog test bench to verify the func-
Section 8.4: Test Benches tional operation of the system in Fig. 8.4. Your
test bench should drive in every possible input
8.4.1 Design a Verilog test bench to verify the func- code for the vector ABCD (i.e., “0000”, “0001”,
tional operation of the system in Fig. 8.1. Your “0010”, . . ., “1111”). Have your test bench change
test bench should drive in every possible input the input pattern every 10 ns using delay within
code for the vector ABCD (i.e., “0000”, “0001”, your procedural block.
“0010”, . . ., “1111”). Have your test bench change 8.4.8 Design a Verilog test bench to verify the func-
the input pattern every 10 ns using delay within tional operation of the system in Fig. 8.4 with
your procedural block. automatic checking. Your test bench should
8.4.2 Design a Verilog test bench to verify the func- drive in every possible input code for the vector
tional operation of the system in Fig. 8.1 with ABCD (i.e., “0000”, “0001”, “0010”, . . ., “1111”).
automatic checking. Your test bench should Have your test bench change the input pattern
drive in every possible input code for the vector every 10 ns using delay within your procedural
ABCD (i.e., “0000”, “0001”, “0010”, . . ., “1111”). block. Use conditional statements to check
Have your test bench change the input pattern whether the output of the DUT is correct. For
every 10 ns using delay within your procedural each input vector, print a message using $dis-
block. Use conditional statements to check play() that indicates the current input vector
whether the output of the DUT is correct. For being tested, the resulting output of your DUT,
each input vector, print a message using $dis- and whether the DUT output is correct.
play() that indicates the current input vector 8.5.9 Design a Verilog test bench to verify the functional
being tested, the resulting output of your DUT, operation of the system in Fig. 8.4. Your test bench
and whether the DUT output is correct. should drive in every possible input code for the
8.4.3 Design a Verilog test bench to verify the func- vector ABCD (i.e., “0000”, “0001”, “0010”, . . .,
tional operation of the system in Fig. 8.2. Your “1111”). Have your test bench change the input
test bench should drive in every possible input pattern every 10 ns using delay within your proce-
code for the vector ABCD (i.e., “0000”, “0001”, dural block. Print the results to an external file
“0010”, . . ., “1111”). Have your test bench change named “output_vectors.txt” using $fdisplay().
the input pattern every 10 ns using delay within 8.5.10 Design a Verilog test bench that reads in test
your procedural block. vectors from an external file to verify the func-
8.4.4 Design a Verilog test bench to verify the func- tional operation of the system in Fig. 8.4. Create
tional operation of the system in Fig. 8.2 with an input text file called “input_vectors.txt” that
automatic checking. Your test bench should contains each input code for the vector ABCD
drive in every possible input code for the vector (i.e., “0000”, “0001”, “0010”, . . ., “1111”), each on
ABCD (i.e., “0000”, “0001”, “0010”, . . ., “1111”). a separate line in the file. Your test bench should
Have your test bench change the input pattern read in the vectors using $readmemb(), drive
every 10 ns using delay within your procedural each code into the DUT, and print the results to
block. Use conditional statements to check the transcript using $display().
Chapter 9: Behavioral Modeling
of Sequential Logic
In this chapter, we will look at modeling sequential logic using the more sophisticated behavioral
modeling techniques presented in Chap. 8. We will begin by looking at modeling sequential storage
devices. Next, we will look at the behavioral modeling of finite state machines. Finally, we will look at
register transfer level, or RTL modeling. The goal of this chapter is to provide an understanding of how
hardware description languages can be used to create behavioral models of synchronous digital
systems.
Learning Outcomes—After completing this chapter, you will be able to:
9.1 Design a Verilog behavioral model for a sequential logic storage device.
9.2 Describe the process for creating a Verilog behavioral model for a finite state
machine.
9.3 Design a Verilog behavioral model for a finite state machine.
9.4 Design a Verilog behavioral model for a counter.
9.5 Design a Verilog register transfer level (RTL) model of a synchronous digital system.
Example 9.1
Behavioral model of a D-latch in Verilog
9.1.2 D-Flip-Flop
The rising edge behavior of a D-Flip-Flop is modeled using a (posedge Clock) Boolean condition in
the sensitivity list of a procedural block. Example 9.2 shows the behavioral model for a rising edge
triggered D-Flip-Flop with both Q and Qn outputs.
Example 9.2
Behavioral model of a D-flip-flop in Verilog
Example 9.3
Behavioral model of a D-flip-flop with asynchronous reset in Verilog
Example 9.4
Behavioral model of a D-flip-flop with asynchronous reset and preset in Verilog
Example 9.5
Behavioral model of a D-flip-flop with synchronous enable in Verilog
CONCEPT CHECK
CC9.1 Why is the D input not listed in the sensitivity list of a D-flip-flop?
(A) To simplify the behavioral model.
(B) To avoid a setup time violation if D transitions too closely to the clock.
(C) Because a rising edge of clock is needed to make the assignment.
(D) Because the outputs of the D-flip-flop are not updated when D changes.
finite state machine using this approach, let”s use the push-button window controller example from
Chap. 7. Example 9.6 gives the overview of the design objectives for this example and the state diagram
describing the behavior to be modeled in Verilog.
Example 9.6
Push-button window controller in Verilog – design description
Let”s begin by defining the ports of the module. The system has an input called Press and two
outputs called Open_CW and Close_CCW. The system also has clock and reset inputs. We will design
the system to update on the rising edge of the clock and have an asynchronous, active LOW, reset.
Example 9.7 shows the port definitions for this example. Note that outputs are declared as type reg while
inputs are declared as type wire.
Example 9.7
Push-button window controller in Verilog – port definition
9.2 Modeling Finite State Machines in Verilog • 309
Putting this all together yields a behavioral model for the FSM that can be simulated and
synthesized. Example 9.8 shows the entire model for this example.
9.2 Modeling Finite State Machines in Verilog • 311
Example 9.8
Push-button window controller in Verilog – full model
Example 9.9 shows the simulation waveform for this state machine. This functional simulation was
performed using ModelSim-Altera Starter Edition 10.1d. A macro file was used to display the current and
next state variables using their parameter names instead of their state codes. This allows the functional-
ity of the FSM to be more easily observed. This approach will be used for the rest of the FSM examples in
this book.
312 • Chapter 9: Behavioral Modeling of Sequential Logic
Example 9.9
Push-button window controller in Verilog – simulation waveform
Example 9.10
Push-button window controller in Verilog – changing state codes
9.3 FSM Design Examples in Verilog • 313
CONCEPT CHECK
CC9.2 Why is it always a good design approach to model a generic finite state machine using three
processes?
(A) For readability.
(B) So that it is easy to identify whether the machine is a Mealy or Moore.
(C) So that the state memory process can be re-used in other FSMs.
(D) Because each of the three sub-systems of a FSM has unique inputs and outputs
that should be handled using dedicated processes.
Example 9.11
Serial bit sequence detector in Verilog – design description and port definition
314 • Chapter 9: Behavioral Modeling of Sequential Logic
Example 9.12 shows the full model for the serial bit sequence detector. Notice that the states are
encoded in binary, which requires three bits for the variables current_state and next_state.
Example 9.12
Serial bit sequence detector in Verilog – full model
9.3 FSM Design Examples in Verilog • 315
Example 9.13 shows the functional simulation waveform for this design.
Example 9.13
Serial bit sequence detector in Verilog – simulation waveform
Example 9.14
Vending machine controller in Verilog – design description and port definition
316 • Chapter 9: Behavioral Modeling of Sequential Logic
Example 9.15 shows the full model for the vending machine controller. In this model, the descriptive
state names Wait, 25¢, and 50¢ cannot be used directly. This is because Verilog user-defined names
cannot begin with a number. Instead, the letter “s” is placed in front of the state names in order to make
them legal Verilog names (i.e., sWait, s25, s50).
Example 9.15
Vending machine controller in Verilog – full model
9.3 FSM Design Examples in Verilog • 317
Example 9.16 shows the resulting simulation waveform for this design.
Example 9.16
Vending machine controller in Verilog – simulation waveform
Example 9.17
2-bit up/down counter in Verilog – design description and port definition
Example 9.18 shows the full model for the 2-bit up/down counter using the three-block modeling
approach. Since a counter’s outputs only depend on the current state, counters are Moore machines.
This simplifies the output logic block since it only needs to contain the current state in its sensitivity list.
318 • Chapter 9: Behavioral Modeling of Sequential Logic
Example 9.18
2-bit up/down counter in Verilog – full model (three block approach)
Example 9.19 shows the resulting simulation waveform for this counter finite state machine.
Example 9.19
2-bit up/down counter in Verilog – simulation waveform
9.4 Modeling Counters in Verilog • 319
CONCEPT CHECK
CC9.3 The procedural block for the state memory is nearly identical for all finite state machines with
one exception. What is it?
(A) The sensitivity list may need to include a preset signal.
(B) Sometimes it is modeled using an SR latch storage approach instead of with D-flip-
flop behavior.
(C) The name of the reset state will be different.
(D) The current_state and next_state signals are often swapped.
Example 9.20
Binary counter using a single procedural block in Verilog
320 • Chapter 9: Behavioral Modeling of Sequential Logic
Example 9.21
Binary counter with range checking in Verilog
Example 9.22
Binary counter with enable in Verilog
Example 9.23
Binary counter with load in Verilog
CONCEPT CHECK
CC9.4 If a counter is modeled using only one procedural block in Verilog, is it still a finite state
machine? Why or why not?
(A) Yes. It is just a special case of a FSM that can easily be modeled using one block.
Synthesizers will recognize the single block model as a FSM.
(B) No. Using only one block will synthesize into combinational logic. Without the
ability to store a state, it is not a finite state machine.
allows vector data to be stored without getting into the details of the lower level implementation of the D-
Flip-Flops and combinational logic. Example 9.24 shows an RTL model of an 8-bit, synchronous register.
This circuit has an active LOW, asynchronous reset that will cause the 8-bit output Reg_Out to go to
0 when it is asserted. When the reset is not asserted, the output will be updated with the 8-bit input
Reg_In if the system is enabled (EN ¼ 1) and there is a rising edge on the clock. If the register is disabled
(EN ¼ 0), the input clock is ignored. At all other times, the output holds its last value.
Example 9.24
RTL model of an 8-bit register in Verilog
Example 9.25
Registers as agents on a data bus – system topology
This topology can be modeled using RTL abstraction by treating each register as a separate
procedural block. Example 9.26 shows how to describe this topology with an RTL model in Verilog.
Notice that the three procedural blocks modeling the A, B, and C registers are nearly identical to each
other except for the signal names they use.
Example 9.26
Registers as agents on a data bus – RTL model in Verilog
9.5 RTL Modeling • 325
Example 9.27 shows the resulting simulation waveform for this system. Each register is updated
with the value on the data bus whenever its dedicated enable line is asserted.
Example 9.27
Registers as agents on a data bus – simulation waveform
Example 9.28
RTL model of a 4-stage, 8-bit shift register in Verilog
CONCEPT CHECK
CC9.5 Does RTL modeling synthesize as combinational logic, sequential logic, or both? Why?
(A) Combinational logic. Since only one process is used for each register, it will be
synthesized using basic gates.
(B) Sequential logic. Since the sensitivity list contains clock and reset, it will synthesize
into only D-flip-flops.
(C) Both. The model has a sensitivity list containing clock and reset and uses an if-else
statement indicative of a D-flip-flop. This will synthesize a D-flip-flop to hold the
value for each bit in the register. In addition, the ability to manipulate the inputs into
the register (using either logical operators, arithmetic operators, or choosing dif-
ferent signals to latch) will synthesize into combinational logic in front of the D input
to each D-flip-flop.
Exercise Problems • 327
Summary
v A synchronous system is modeled with a signals are first declared called current_state
procedural block and a sensitivity list. The and next_state of type reg. Then a parameter
clock and reset signals are always listed by is defined for each unique state in the
themselves in the sensitivity list. Within the machine with the state name and desired
block is an if-else statement. The if clause of state code. Throughout the rest of the
the statement handles the asynchronous model, the unique state names can be used
reset condition while the else clause handles as both assignments to current_state/
the synchronous signal assignments. next_state and as inputs in case and if-else
v Edge sensitivity is modeled within a proce- statements. This approach allows the model
dural block using the (posedge Clock or to be designed using readable syntax while
negedge reset) syntax in the sensitivity lists. providing a synthesizable design.
v Most D-flip-flops and registers contain a syn- v Counters are a special type of finite state
chronous enable line. This is modeled using machine that can be modeled using a single
a nested if-else statement within the main procedural block. Only the clock and reset
procedural block’s if-else statement. The signals are listed in the sensitivity list of the
nested if-else goes beneath the clause for counter block.
the synchronous signal assignments. v Registers are modeled in Verilog in a similar
v Generic finite state machines are modeled manner to a D-flip-flop with a synchronous
using three separate procedural blocks that enable. The only difference is that the inputs
describe the behavior of the next state logic, and outputs are vectors.
the state memory, and the output logic. Sep- v Register Transfer Level, or RTL, modeling
arate blocks are used because each of the provides a higher level of abstraction for
three functions in a FSM are dependent on moving and manipulating vectors of data in
different input signals. a synchronous manner.
v In Verilog, descriptive state names can be
created for a FSM using parameters. Two
Exercise Problems
Section 9.1: Modeling Sequential Storage 9.2.3 When using the three-procedural block behav-
Devices in Verilog ioral modeling approach for finite state
machines, does the next state logic block
9.1.1 How does a Verilog model for a D-flip-flop han-
model combinational or sequential logic?
dle treating reset as the highest priority input?
9.2.4 When using the three-procedural block behav-
9.1.2 For a Verilog model of a D-flip-flop with a syn-
ioral modeling approach for finite state
chronous enable (EN), why isn’t EN listed in
machines, does the state memory block
the sensitivity list?
model combinational or sequential logic?
9.1.3 For a Verilog model of a D-flip-flop with a syn-
9.2.5 When using the three-procedural block behav-
chronous enable (EN), what is the impact of
ioral modeling approach for finite state
listing EN in the sensitivity list?
machines, does the output logic block model
9.1.4 For a Verilog model of a D-flip-flop with a syn- combinational or sequential logic?
chronous enable (EN), why is the behavior of
9.2.6 When using the three-procedural block behav-
the enable modeled using a nested if-else
ioral modeling approach for finite state
statement under the else clause handling the
machines, what inputs are listed in the sensi-
logic for the clock edge input?
tivity list of the next state logic block?
9.2.7 When using the three-procedural block behav-
Section 9.2: Modeling Finite State Machines
ioral modeling approach for finite state
in Verilog machines, what inputs are listed in the sensi-
9.2.1 What is the advantage of using parameters for tivity list of the state memory block?
the state when modeling a finite state 9.2.8 When using the three-procedural block behav-
machine? ioral modeling approach for finite state
9.2.2 What is the advantage of having to assign the machines, what inputs are listed in the sensi-
state codes during the parameter declaration tivity list of the output logic block?
for the state names when modeling a finite 9.2.9 When using the three-procedural block behav-
state machine? ioral modeling approach for finite state
328 • Chapter 9: Behavioral Modeling of Sequential Logic
Fig. 9.2
FSM 2 state diagram and module definition
modeling FSMs described in this chapter for Section 9.4: Modeling Counters in Verilog
your design. Your controller will take in nickels 9.4.1 Design a Verilog behavioral model for a 16-bit,
and dimes and dispense a product anytime the binary up counter using a single procedural
customer has entered 20 cents. Your FSM has block. The block diagram for the port definition
two inputs, Nin and Din. Nin is asserted when- is shown in Fig. 9.6.
ever the customer enters a nickel while Din is
asserted anytime the customer enters a dime.
Your FSM has two outputs, Dispense and
Change. Dispense is asserted anytime the
customer has entered at least 20 cents and
Change is asserted anytime the customer has
entered more than 20 cents and needs a nickel
in change. Model the states in this machine
with parameters. Choose any state encoding Fig. 9.6
approach you wish. 16-bit binary up counter block diagram
Fig. 9.5
Traffic light controller module definition
330 • Chapter 9: Behavioral Modeling of Sequential Logic
Fig. 9.10
32-bit register block diagram
Fig. 9.11
16-bit shift register block diagram
Chapter 10: Memory
This chapter introduces the basic concepts, terminology, and roles of memory in digital systems.
The material presented here will not delve into the details of the device physics or low-level theory of
operation. Instead, the intent of this chapter is to give a general overview of memory technology and its
use in computer systems in addition to how to model memory in Verilog. The goal of this chapter is to give
an understanding of the basic principles of semiconductor-based memory systems.
Learning Outcomes—After completing this chapter, you will be able to:
10.1 Describe the basic architecture and terminology for semiconductor-based memory
systems.
10.2 Describe the basic architecture of non-volatile memory systems.
10.3 Describe the basic architecture of volatile memory systems.
10.4 Design a Verilog behavioral model of a memory system.
Fig. 10.1
Memory map model
CONCEPT CHECK
CC10.1 An 8-bit wide memory has eight address lines. What is its capacity in bits?
(A) 64 (B) 256 (C) 1024 (D) 2048
10.2 Non-volatile Memory Technology • 333
Fig. 10.2
Basic architecture of read only memory (ROM)
Figure 10.3 shows the operation of a ROM when information is being read.
10.2 Non-volatile Memory Technology • 335
Fig. 10.3
ROM operation during a read
Fig. 10.4
Asynchronous vs. synchronous ROM operation during a read cycle
Fig. 10.5
MROM overview
Fig. 10.6
PROM overview
Fig. 10.7
Floating-gate transistor – programming
In order to change the floating-gate transistor back into its normal state, the device is exposed to a
strong ultra-violet light source. When the UV light strikes the trapped charge in the secondary oxide, it
transfers enough energy to the charge particles that they can move back into the metal plates in the gate.
This, in effect, erases the device and restores it back to a state with a high threshold voltage. EPROMs
contain a transparent window on the top of their package that allows the UV light to strike the devices.
The EPROM must be removed from its system to perform the erase procedure. When the UV light erase
procedure is performed, every device in the memory array is erased. EPROMs are a significant
improvement over PROMs because they can be programmed multiple times; however, the programming
and erase procedures are manually intensive and require an external programmer and external eraser.
Figure 10.8 shows the erase procedure for a floating-gate transistor using UV light.
340 • Chapter 10: Memory
Fig. 10.8
Floating-gate transistor – erasing with UV light
An EPROM array is created in the exact same manner as in a PROM array with the exception that
additional programming circuitry is placed on the IC and a transparent window is included on the
package to facilitate erasing. An EPROM is non-volatile and read only since the programming procedure
takes place outside of its destination system.
Fig. 10.9
Floating-gate transistor – erasing with electricity
10.2 Non-volatile Memory Technology • 341
Early EEPROMs were very slow and had a limited number of program/erase cycles, thus they were
classified into the category of non-volatile, read only memory. Modern floating-gate transistors are now
capable of access times on scale with other volatile memory systems, thus they have evolved into one of
the few non-volatile, read/write memory technologies used in computer systems today.
In order to provide individual word access, NOR FLASH was introduced. In NOR FLASH, circuitry is
added to provide individual access to data words. This architecture provided faster read times than
NAND FLASH, but the additional circuitry causes the write and erase times to be slower and the
individual storage cell size to be larger. Due to NAND FLASH having faster write times and higher
density, it is seeing broader scale adoption compared to NOR FLASH despite only being able to access
information in blocks. NOR FLASH is considered random access memory while NAND FLASH is
typically not; however, as the block size of NAND FLASH is continually reduced, its use for variable
storage is becoming more attractive. All FLASH memory is non-volatile and read/write.
CONCEPT CHECK
CC10.2 Which of the following is suitable for implementation in a read only memory?
(A) Variables that a computer program needs to continuously update.
(B) Information captured by a digital camera.
(C) A computer program on a spacecraft.
(D) Incoming digitized sound from a microphone.
342 • Chapter 10: Memory
Fig. 10.10
SRAM storage element (6T)
To build an SRAM memory system, cells are arranged in an array pattern. Figure 10.11 shows a
4 4 SRAM array topology. In this configuration, word lines are shared horizontally across the array in
order to provide addressing capability. An address decoder is used to convert the binary encoded
address into the appropriate word line assertions. N storage cells are attached to the word line to provide
the desired data word width. Bit lines are shared vertically across the array in order to provide data
access (either read or write). A data line controller handles whether data is read from or written to the
cells based on an external write enable (WE) signal. When WE is asserted (WE ¼ 1), data will be written
to the cells. When WE is de-asserted (WE ¼ 0), data will be read from the cells. The data line controller
also handles determining the correct logic value read from the cells by comparing BL to BLn. As more
cells are added to the bit lines, the signal magnitude being driven by the storage cells diminishes due to
the additional loading of the other cells. This is where having complementary data signals (BL and BLn)
10.3 Volatile Memory Technology • 343
is advantageous because this effectively doubles the magnitude of the storage cell outputs. The
comparison of BL to BLn is handled using a differential amplifier that produces a full logic level output
even when the incoming signals are very small.
SRAM is volatile memory because when the power is removed, the cross-coupled inverters are not
able to drive the feedback loop and the data is lost. SRAM is also read/write memory because the
storage cells can be easily read from or written to during normal operation.
Fig. 10.11
4 4 SRAM array topology
Let’s look at the operation of the SRAM array when writing the 4-bit word “0111” to address “01”.
Figure 10.12 shows a graphical depiction of this operation. In this write cycle, the row address decoder
observes the address input “01” and asserts WL1. Asserting this word line enables all of the access
transistors (i.e., M1 and M2 in Fig. 10.10) of the storage cells in this row. The line drivers are designed to
have a stronger drive strength than the inverters in the storage cells so that they can override their values
during a write. The information “0111” is present on the Data_In bus and the write enable control line is
344 • Chapter 10: Memory
asserted (WE ¼ 1) to indicate a write. The data line controller passes the information to be stored to the
line drivers, which in turn converts each input into complementary signals and drives the bit lines. This
overrides the information in each storage cell connected to WL1. The address decoder then de-asserts
WL1 and the information is stored.
Fig. 10.12
SRAM operation during a write cycle – storing “0111” to address “01”
Now let’s look at the operation of the SRAM array when reading a 4-bit word from address “10”. Let’s
assume that this row was storing the value “1010”. Figure 10.13 shows a graphical depiction of this
operation. In this read cycle, the row address decoder asserts WL2, which allows the SRAM cells to drive
their respective bit lines. Note that each cell drives a complementary version of its stored value. The input
control line is de-asserted (WE ¼ 0), which indicates that the sense amps will read the BL and BLn lines
in order to determine the full logic value stored in each cell. This logic value is then routed to the
Data_Out port of the array. In an SRAM array, reading from the cell does not impact the contents of
the cell. Once the read is complete, WL2 is de-asserted and the read cycle is complete.
10.3 Volatile Memory Technology • 345
Fig. 10.13
SRAM operation during a read cycle – reading “0101” from address “10”
Fig. 10.14
DRAM storage element (1T 1C)
There are a variety of considerations that must be accounted for when using DRAM. First, the
charge in the capacitor will slowly dissipate over time due to the capacitors being non-ideal. If left
unchecked, eventually the data held in the capacitor will be lost. In order to overcome this issue,
DRAM has a dedicated circuit to refresh the contents of the storage cell. A refresh cycle involves
periodically reading the value stored on the capacitor and then writing the same value back again at
full signal strength. This behavior also means that that DRAM is volatile because when the power is
removed and the refresh cycle cannot be performed, the stored data is lost. DRAM is also considered
read/write memory because the storage cells can be easily read from or written to during normal
operation.
Another consideration when using DRAM is that the voltage of the word line must be larger than VCC
in order to turn on the access transistor. In order to turn on an NMOS transistor, the gate terminal must be
larger than the source terminal by at least a threshold voltage (VT). In traditional CMOS circuit design, the
source terminal is typically connected to ground (0 v). This means the transistor can be easily turned on
by driving the gate with a logic 1 (i.e., VCC) since this creates a VGS voltage much larger than VT. This is
not always the case in DRAM. In DRAM, the source terminal is not connected to ground, but rather to the
storage capacitor. In the worst-case situation, the capacitor could be storing a logic 1 (i.e., VCC). This
means that in order for the word line to be able to turn on the access transistor, it must be equal to or
larger than (VCC + VT). This is an issue because the highest voltage that the DRAM device has access to
is VCC. In DRAM, a charge pump is used to create a voltage larger than VCC + VT that is driven on the
word lines. Once this voltage is used, the charge is lost so the line must be pumped up again before its
next use. The process of “pumping up” takes time that must be considered when calculating the
maximum speed of DRAM. Figure 10.15 shows a graphical depiction of this consideration.
Fig. 10.15
DRAM charge pumping of word lines
10.3 Volatile Memory Technology • 347
Another consideration when using DRAM is how the charge in the capacitor develops into an actual
voltage on the digital line when the access transistor is closed. Consider the simple 4 4 array of DRAM
cells shown in Fig. 10.16. In this topology, the DRAM cells are accessed using the same approach as in
the SRAM array from Fig. 10.11.
Fig. 10.16
Simple 4 4 DRAM array topology
One of the limitations of this simple configuration is that the charge stored in the capacitors cannot
develop a full voltage level across the digit line when the access transistor is closed. This is because the
digit line itself has capacitance that impacts how much voltage will be developed. In practice, the
capacitance of the digit line (CDL) is much larger than the capacitance of the storage cell (CS) due to
having significantly more area and being connected to numerous other storage cells. This becomes an
issue because when the storage capacitor is connected to the digit line, the resulting voltage on the digit
line (VDL) is much less than the original voltage on the storage cell (VS). This behavior is known as
charge sharing because when the access transistor is closed, the charge on both capacitors is
distributed across both devices and results in a final voltage that depends on the initial charge in the
system and the values of the two capacitors. Example 10.1 shows an example of how to calculate the
final digit line voltage when the storage cell is connected.
348 • Chapter 10: Memory
Example 10.1
Calculating the final digit line voltage in a DRAM based on charge sharing
The issue with the charge sharing behavior of a DRAM cell is that the final voltage on the word line is
not large enough to be detected by a standard logic gate or latch. In order to overcome this issue, modern
DRAM arrays use complementary storage cells and sense amplifiers. The complementary cells store
the original data and its complement. Two digit lines (DL and DLn) are used to read the contents of the
storage cells. DL and DLn are initially pre-charged to exactly VCC/2. When the access transistors are
closed, the storage cells will share their charge with the digit lines and move them slightly away from
VCC/2 in different directions. This allows twice the voltage difference to be developed during a read.
10.3 Volatile Memory Technology • 349
A sense amplifier is then used to boost this small voltage difference into a full logic level that can be read
by a standard logic gate or latch. Figure 10.17 shows the modern DRAM array topology based on
complementary storage cells.
Fig. 10.17
Modern DRAM array topology based on complementary storage cells
The sense amplifier is designed to boost small voltage deviations from VCC/2 on DL and DLn to full
logic levels. The sense amplifier sits in-between DL and DLn and has two complementary networks, the
N-sense amplifier and the P-sense amplifier. The N-sense amplifier is used to pull a signal that is below
VCC/2 (either DL or DLn) down to GND. A control signal (N-Latch or NLATn) is used to turn on this
network. The P-sense amplifier is used to pull a signal that is above VCC/2 (either DL or DLn) up to VCC. A
control signal (Active Pull-Up or ACT) is used to turn on this network. The two networks are activated in a
sequence with the N-sense network activating first. Figure 10.18 shows an overview of the operation of a
DRAM sense amplifier.
350 • Chapter 10: Memory
Fig. 10.18
DRAM sense amplifier
Let’s now put everything together and look at the operation of a DRAM system during a read
operation. Figure 10.19 shows a simplified timing diagram of a DRAM read cycle. This diagram shows
the critical signals and their values when reading a logic 1. Notice that there is a sequence of steps that
must be accomplished before the information in the storage cells can be retrieved.
10.3 Volatile Memory Technology • 351
Fig. 10.19
DRAM operation during a read cycle – reading a 1 from a storage cell
A DRAM write operation is accomplished by opening the access transistors to the complementary
storage cells using WL, disabling the pre-charge drivers and then writing full logic level signals to the
storage cells using the Data_In line driver.
CONCEPT CHECK
Example 10.2
Behavioral models of a 4 4 asynchronous read only memory in Verilog
10.4 Modeling Memory with Verilog • 353
A synchronous ROM can be created in a similar manner as in the asynchronous approach. The
only difference is that in a synchronous ROM, a clock edge is used to trigger the procedural block
that updates data_out. A sensitivity list is used that contains the clock to trigger the assignment. Example
10.3 shows two Verilog models for a synchronous ROM. Notice that prior to the first clock edge, the
simulator does not know what to assign to data_out so it lists the value as unknown (X).
Example 10.3
Behavioral models of a 4 4 synchronous read only memory in Verilog
sensitivity list containing every input to the system. Example 10.4 shows an asynchronous R/W 4 4
memory system and functional simulation results. In the simulation, each address is initially read from to
verify that it does not contain data. The data_out port produces unknown (X) for the initial set of read
operations. Each address in the array is then written to. Finally, the array is read from verifying that the
data that was written can be successfully retrieved.
Example 10.4
Behavioral model of a 4 4 asynchronous read/write memory in Verilog
A synchronous read/write memory is made in a similar manner with the exception that a clock is
used to trigger the procedural block managing the signal assignments. In this case, the WE signal acts
as a synchronous control signal indicating whether assignments are read from or written to the RW array.
Example 10.5 shows the Verilog model for a synchronous read/write memory and the simulation
waveform showing both read and write cycles.
10.4 Modeling Memory with Verilog • 355
Example 10.5
Behavioral model of a 4 4 synchronous read/write memory in Verilog
CONCEPT CHECK
CC10.4 Explain the advantage of modeling memory in Verilog without going into the details of the
storage cell operation.
(A) It allows the details of the storage cell to be abstracted from the functional
operation of the memory system.
(B) It is too difficult to model the analog behavior of the storage cell.
(C) There are too many cells to model so the simulation would take too long.
(D) It lets both ROM and R/W memory to be modeled in a similar manner.
356 • Chapter 10: Memory
Summary
v The term memory refers to large arrays of v The basic architecture of a ROM consists of
digital storage. The technology used in mem- intersecting bit lines (vertical) and word lines
ory is typically optimized for storage density (horizontal) that contain storage cells at their
at the expense of control capability. This is crossing points. The data is read out of the
different from a D-flip-flop, which is optimized ROM array using the bit lines. Each bit line
for complete control at the bit level. contains a pull-up resistor to initially store a
v A memory device always contains an logic 1 at each location. If a logic 0 is desired
address bus input. The number of bits in the at a certain location, a pull-down transistor is
address bus dictates how many storage placed on a particular bit line with its gate
locations can be accessed. An n-bit address connected to the appropriate word line.
bus can access 2n (or M) storage locations. When the storage cell is addressed, the
v The width of each storage location (N) allows word line will assert and turn on the pull-
the density of the memory array to be down transistor producing a logic 0 on the
increased by reading and writing vectors of output.
data instead of individual bits. v There are a variety of technologies to imple-
v A memory map is a graphical depiction of a ment the pull-down transistor in a ROM. Dif-
memory array. A memory map is useful to ferent ROM architectures include MROMs,
give an overview of the capacity of the array PROMs, EPROMs, and EEPROMs. These
and how different address ranges of the array memory types are non-volatile.
are used. v A R/W memory requires a storage cell that
v A read is an operation in which data is can be both read from and written to during
retrieved from memory. A write is an opera- normal operation. A DRAM (dynamic RAM)
tion in which data is stored to memory. cell is a storage element that uses a capaci-
v An asynchronous memory array responds tor to hold charge corresponding to a logic
immediately to its control inputs. A synchro- value. An SRAM (static RAM) cell is a stor-
nous memory array only responds on the age element that uses a cross-coupled
triggering edge of clock. inverter pair to hold the value being stored
v Volatile memory will lose its data when the in the positive feedback loop formed by the
power is removed. Non-volatile memory will inverters. Both DRAM and SRAM and vola-
retain its data when the power is removed. tile and random access.
v Read Only Memory (ROM) is a memory type v The floating-gate transistor enables memory
that cannot be written to during normal oper- that is both non-volatile and R/W. Modern
ation. Read/Write (R/W) memory is a mem- memory systems based on floating-gate
ory type that can be written to during normal transistor technology allow writing to take
operation. Both ROM and R/W memory can place using the existing system power supply
be read from during normal operation. levels. This type of R/W memory is called
v Random Access Memory (RAM) is a memory FLASH. In FLASH memory, the information
type in which any location in memory can be is read out in blocks, thus it is not technically
accessed at any time. In Sequential Access random access.
Memory the data can only be retrieved in a v Memory can be modeled in Verilog using an
linear sequence. This means that in sequen- array data type consisting of elements of
tial memory the data cannot be accessed type reg.
arbitrarily.
Exercise Problems
Section 10.1: Memory Architecture 10.1.4 For a 512 k 32-bit memory system, what is
the capacity in bytes?
and Terminology
10.1.5 For a 512 k 32 memory system, how wide
10.1.1 For a 512 k 32 memory system, how many
does the incoming address bus need to be in
unique address locations are there? Give the
order to access every unique address
exact number.
location?
10.1.2 For a 512 k 32 memory system, what is the
10.1.6 Name the type of memory with the following
data width at each address location?
characteristic: when power is removed, the
10.1.3 For a 512 k 32 memory system, what is the data is lost.
capacity in bits?
Exercise Problems • 357
10.1.7 Name the type of memory with the following system that will write a 0 to the cell, then read it
characteristic: when power is removed, the back to verify the 0 was stored and then repeat
memory still holds its information. the write/read cycles for a 1.
10.1.8 Name the type of memory with the following
characteristic: it can only be read from during
normal operation.
10.1.9 Name the type of memory with the following
characteristic: during normal operation, it can
be read and written to.
10.1.10 Name the type of memory with the following
characteristic: data can be accessed from any
address location at any time.
10.1.11 Name the type of memory with the following
characteristic: data can only be accessed in
consecutive order, thus not every location of
memory is available instantaneously.
the access transistor (M1) closes if initially 10.4.3 Design a Verilog model for the 16 8, asyn-
VS ¼ GND (i.e., the cell is storing a 0). In this chronous, read/write memory system shown in
system, CS ¼ 5 pF, CDL ¼ 10 pF, and Fig. 10.24. Create a test bench to simulate
VCC ¼ +3.4 v. Prior to the access transistor your model. Your test bench should first read
closing, the digit line is pre-charged to VCC/2. from all of the address locations to verify they
are uninitialized. Next, your test bench should
Section 10.4: Modeling Memory write unique information to each of the address
locations. Finally, your test bench should read
with Verilog from each address location to verify that the
10.4.1 Design a Verilog model for the 16 8, asyn- information that was written was stored and
chronous, read only memory system shown in can be successfully retrieved.
Fig. 10.22. The system should contain the
information provided in the memory map. Cre-
ate a test bench to simulate your model by
reading from each of the 16 unique addresses
and observing data_out to verify it contains the
information in the memory map.
Fig. 10.24
16 8 asynchronous R/W memory block diagram
Fig. 10.25
16 8 synchronous R/W memory block diagram
Fig. 10.23
16 8 synchronous ROM block diagram
Chapter 11: Programmable Logic
This chapter provides an overview of programmable logic devices (PLDs). The term PLD is used as
a generic description for any circuit that can be programmed to implement digital logic. The technology
and architectures of PLDs have advanced over time. A historical perspective is given on how the first
programmable devices evolved into the programmable technologies that are prevalent today. The goal of
this chapter is to provide a basic understanding of the principles of programmable logic devices.
Learning Outcomes—After completing this chapter, you will be able to:
11.1 Describe the basic architecture and evolution of programmable logic devices.
11.2 Describe the basic architecture of Field Programmable Gate Arrays (FPGAs).
Fig. 11.1
Programmable logic array (PLA) architecture
A more compact schematic for the PLA is drawn by representing all of the inputs into the AND and
OR gates with a single wire. Connections are indicated by inserting X’s at the intersections of wires.
Figue 11.2 shows this simplified PLA schematic implementing two different SOP logic expressions.
Fig. 11.2
Simplified PLA schematic
Fig. 11.3
Programmable array logic (PAL) architecture
Fig. 11.4
Generic array logic (GAL) architecture
In 1983, Altera Inc., was founded as a programmable logic device company. In 1984, Altera
released its first version of a PAL with a unique feature that it could be programmed and erased multiple
times using a programmer and an UV light source similar to an EEPROM.
The term simple programmable logic device (SPLD) was created to describe all of the previous PLD
architectures (i.e., PLA, PAL, GAL, and HAL). Figure 11.5 shows the architecture of the CPLD.
Fig. 11.5
Complex PLD (CPLD) architecture
CONCEPT CHECK
CC11.1 What is the only source of delay mismatch from the inputs to the outputs in a programmable
array?
(A) The AND gates will have different delays due to having different numbers of
inputs.
(B) The OR gates will have different delays due to having different numbers of inputs.
(C) An input may or may not go through an inverter before reaching the AND gates.
(D) None. All paths through the programmable array have identical delay.
Today, FPGAs are the most commonly used programmable logic device with Altera Inc. and Xilinx Inc.
being the two largest manufacturers. Figure 11.6 shows the generic architecture of an FPGA.
Fig. 11.6
Field programmable gate array (FPGA) architecture
the D-Flip-Flop, thus creating a highly efficient topology for finite state machines. A global routing
network is used to provide common signals to the CLB/LE such as clock, reset and enable. This global
routing network can provide these common signals to the entire FPGA or local groups of CLB/LEs.
Figure 11.7 shows the topology of a simple CLB/LE.
Fig. 11.7
Simple FPGA configurable logic block (or logic element)
CLB/LEs have evolved to include numerous other features such as carry in/carry out signals so that
arithmetic operations can be cascaded between multiple blocks in addition to signal feedback and D-flip-
Flop initialization.
Fig. 11.8
2-input LUT implemented with a 4-input multiplexer
Fan-in limitations can be encountered quickly in LUTs as the number of inputs of the combinational
logic circuit being implemented grows. Recall that multiplexers are implemented with an SOP topology in
which each product term in the first level of logic has a number of inputs equal to the number of select
lines plus one. Also recall that the sum term in the second level of logic in the SOP topology has a
number of inputs equal to the total number of inputs to the multiplexer. In the example circuit shown in
Fig. 11.8, each product term in the multiplexer will have three inputs and the sum term will have four
inputs. As an illustration of how quickly fan-in limitations are encountered, consider the implication of
increasing the number of inputs in Fig. 11.8 from two to three. In this new configuration, the number of
inputs in the product terms will increase from three to four and the number of inputs in the sum term will
increase to from four to eight. Eight inputs is often beyond the fan-in specifications of modern devices,
meaning that even a 3-input combinational logic circuit will encounter fan-in issues when implemented
using a LUT topology.
To address this issue, multiplexer functionality in LUTs is typically implemented as a series of
smaller, cascaded multiplexers. Each of the smaller multiplexers progressively choose which row of
the truth table to route to the output of the LUT. This eliminates fan-in issues at the expense of adding
additional levels of logic to the circuit. While cascading multiplexers increases the overall circuit delay,
this approach achieves a highly consistent delay because regardless of the truth table output value, the
number of levels of logic through the multiplexers is always the same. Figure 11.9 shows how the 2-input
truth table from Fig. 11.8 can be implemented using a 2-level cascade of 2-input multiplexers.
11.2 Field Programmable Gate Arrays (FPGAs) • 367
Fig. 11.9
2-input LUT implemented with a 2-level cascade of 2-input multiplexers
If more inputs are needed in the LUT, additional MUX levels are added. Figure 11.10 shows the
architecture for a 3-input LUT implemented with a 3-level cascade of 2-input multiplexers.
368 • Chapter 11: Programmable Logic
Fig. 11.10
3-Input LUT implemented with a 3-level cascade of 2-input multiplexers
Modern FPGAs can have LUTs with up to 6 inputs. If even more inputs are needed in a combina-
tional logic expression, then multiple CLB/LEs are used that form even larger LUTs.
Fig. 11.11
FPGA programmable interconnect
Fig. 11.12
FPGA input/output block (IOB)
CONCEPT CHECK
Summary
v A programmable logic device (PLD) is a v FPGAs contain an array of programmable
generic term for a circuit that can be logic elements that each consist of combina-
configured to implement arbitrary logic tional logic capability and sequential logic
functions. storage. FPGAs also contain a programma-
v There are a variety of PLD architectures that ble interconnect network that provides the
have been used to implement combinational highest level of flexibility in programmable
logic. These include the PLA and PAL. These logic.
devices contain an AND-plane and an v A look-up-table (LUT) is a simple method to
OR-plane. The AND-plane is configured to create a programmable combinational logic
implement the product terms of a SOP circuit. A LUT is simply a multiplexer with the
expression. The OR-plane is configured to inputs to the circuit connected to the select
implement the sum term of a SOP lines of the MUX. The desired outputs of the
expression. truth table are connected to the MUX inputs.
v A GAL increases the complexity of logic As different input codes arrive on the select
arrays by adding sequential logic storage lines of the MUX, they select the
and programmable I/O capability. corresponding logic value to be routed to
v A CPLD significantly increases the density of the system output.
PLDs by connecting an array of PALs
together and surrounding the logic with I/O
drivers.
Exercise Problems
Section 11.1: Programmable Arrays
11.1.1 Name the type of programmable logic
described by the characteristic: this device
adds an output logic macrocell to a traditional
PAL.
11.1.2 Name the type of programmable logic
described by the characteristic: this device
combines multiple PALs on a single chip with
a partitioned interconnect system.
11.1.3 Name the type of programmable logic
described by the characteristic: this device
has a programmable AND-plane and program-
mable OR-plane.
11.1.4 Name the type of programmable logic
described by the characteristic: this device
has a programmable AND-plane and fixed
OR-plane.
11.1.5 Name the type of programmable logic Fig. 11.13
described by the characteristic: this device is Blank PAL Schematic
a PAL or GAL that is programmed during
manufacturing. Section 11.2: Field Programmable Gate
11.1.6 For the following unconfigured PAL schematic Arrays (FPGAs)
in Fig. 11.13, draw in the connection points 11.2.1 Give a general description of a Field Program-
(i.e., the X’s) to implement the two SOP logic mable Gate Array that differentiates it from
expressions shown on the outputs. other programmable logic devices.
372 • Chapter 11: Programmable Logic
12.1 Design a binary adder using both the classical digital design approach and the modern
HDL-based approach.
12.2 Design a binary subtractor using both the classical digital design approach and the modern
HDL-based approach.
12.3 Design a binary multiplier using both the classical digital design approach and the modern
HDL-based approach.
12.4 Design a binary divider using both the classical digital design approach and the modern
HDL-based approach.
12.1 Addition
Binary addition is performed in a similar manner to performing decimal addition by hand. The
addition begins in the least significant position of the number (p ¼ 0). The addition produces the sum
for this position. In the event that this positional sum cannot be represented by a single symbol, then the
higher order symbol is carried to the subsequent position (p ¼ 1). The addition in the next higher
position must include the number that was carried in from the lower positional sum. This process
continues until all of the symbols in the number have been operated on. The final positional sum can
also produce a carry, which needs to be accounted for in a separate system.
Designing a binary adder involves creating a combinational logic circuit to perform the positional
additions. Since a combinational logic circuit can only produce a scalar output, circuitry is needed to
produce the sum and the carry at each position. The binary adder size is pre-determined and fixed prior
to implementing the logic (i.e., an n-bit adder). Both inputs to the adder must adhere to the fixed size,
regardless of their value. Smaller numbers simply contain leading zeros in their higher order positions.
For an n-bit adder, the largest sum that can be produced will require n + 1 bits. To illustrate this, consider
a 4-bit adder. The largest numbers that the adder will operate on are 11112 + 11112. (or 1510 + 1510). The
result of this addition is 111102 (or 3010). Notice that the largest sum produced fits within 5 bits, or n + 1.
When constructing an adder circuit, the sum is always recorded using n-bits with a separate carry out bit.
In our 4-bit example, the sum would be expressed as “1110” with a carry out. The carry out bit can be
used in multiple word additions, used as part of the number when being decoded for a display, or simply
discarded as in the case when using two’s complement numbers.
in order to produce the sum (the XOR gate) and the carry out (the AND gate). These two gates are in
parallel to each other, thus the delay through the half adder is due to only one level of logic.
Example 12.1
Design of a half adder
Example 12.2
Design of a full adder
12.1 Addition • 375
Fig. 12.1
A useful logic equivalency that can be exploited in arithmetic circuits
The ability to implement the carry out logic using the expression Cout ¼ AB + (A B)Cin allows us to
implement a full adder with two half adders and the addition of a single OR gate. Example 12.3 shows
this approach. In this new configuration, the sum is produced in two levels of logic while the carry out is
produced in three levels of logic.
376 • Chapter 12: Arithmetic Circuits
Example 12.3
Design of a full adder out of half adders
Example 12.4
Design of a 4-bit ripple carry adder (RCA)
While the ripple carry adder provides a simple architecture based on design re-use, its delay can
become considerable when scaling to larger inputs sizes (e.g., n ¼ 32 or n ¼ 64). A simple analysis of the
timing can be stated such that if the time for a full adder to complete its positional sum is tFA, then the time
for an n-bit ripple carry adder to complete its computation is tRCA ¼ ntFA.
If we examine the RCA in more detail, we can break down the delay in terms of the levels of logic
necessary for the computation. Example 12.5 shows the timing analysis of the 4-bit RCA. This analysis
determines the number of logic levels in the adder. The actual gate delays can then be plugged in to find
the final delay. The inputs to the adder are A, B and Cin and are always assumed to update at the same
time. The first full adder requires two levels of logic to produce its sum and three levels to produce its
carry out. Since the timing of a circuit is always stated as its worst case delay, we say that the first full
adder takes three levels of logic. When the carry (C1) ripples to the next full adder (FA1), it must
propagate through two additional levels of logic in order to produce C2. Notice that the first half adder
in FA1 only depends on A1 and B1, thus it is able to perform this computation immediately. This half adder
can be considered as first level logic. More importantly, it means that when the carry in arrives (C1),
only two additional levels of logic are needed, not three. The levels of logic for the RCA can be expressed
as 3 + 2(n 1). If each level of logic has a delay of tgate, then a more accurate expression for the RCA
delay is tRCA ¼ (3 + 2(n 1))tgate.
378 • Chapter 12: Arithmetic Circuits
Example 12.5
Timing analysis of a 4-bit ripple carry adder
Example 12.6
Design of a 4-bit carry look ahead adder (CLA) – overview
For the CLA architecture to be effective, the look ahead circuitry needs to be dependent only on the
system inputs A, B, and Cin (i.e., C0). A secondary characteristic of the CLA is that it should exploit as
much design re-use as possible. In order to examine the design re-use aspects of a multi-bit adder, the
concepts of carry generation (g) and propagation (p) are used. A full adder is said to generate a carry if
its inputs A and B result in Cout ¼ 1 when Cin ¼ 0. A full adder is said to propagate a carry if its inputs A
and B result in Cout ¼ 1 when Cin ¼ 1. These simple statements can be used to derive logic expressions
for each stage of the adder that can take advantage of existing logic terms from prior stages. Example
12.7 shows the derivation of these terms and how algebraic substitutions can be exploited to create look
ahead circuitry for each full adder that is only dependent on the system inputs. In these derivations, the
variable i is used to represent position since p is used to represent the propagate term.
380 • Chapter 12: Arithmetic Circuits
Example 12.7
Design of a 4-bit carry look ahead adder (CLA) – algebraic formation
Example 12.8 shows a timing analysis of the 4-bit carry look ahead adder. Notice that the full adders
are modified to add the logic for the generate and propagate bits in addition to removing the unnecessary
gates associated with creating the carry out.
12.1 Addition • 381
Example 12.8
Timing analysis of a 4-bit carry look ahead adder
The 4-bit CLA can produce the sum in four levels of logic as long as fan-in specifications are met. As
the CLA width increases, the look ahead circuitry will become fan-in limited and additional stages will be
required to address the fan-in. Regardless, the CLA has considerably less delay than a RCA as the width
of the adder is increased.
Example 12.9
Structural model of a full adder using two half adders in Verilog
Example 12.10 shows the structural model of a 4-bit ripple carry adder in Verilog. The RCA is
created by instantiating four full adders. Notice that a logic 1’b0 can be directly inserted into the port map
of the first full adder to model the behavior of C0 ¼ 0.
12.1 Addition • 383
Example 12.10
Structural model of a 4-bit ripple carry adder in Verilog
When creating arithmetic circuitry, testing under all input conditions is necessary to verify function-
ality. Testing under each and every input condition can require a large number of input conditions. To test
an n-bit adder under each and every numeric input condition will take (2n)2 test vectors. For our simple
4-bit adder example, this equates to 256 input patterns. The large number of input patterns precludes the
use of manual signal assignments in the test bench to stimulate the circuit. One approach to generating
the input test patterns is to use nested for loops. Example 12.11 shows a test bench that uses two nested
for loops to generate the 256 unique input conditions for the 4-bit ripple carry adder. Note that the loop
variables i and j are declared as type integer and then automatically incremented within the for loops.
Within the loops, the loop variables i and j are assigned to the DUT inputs A_TB and B_TB. The
truncation to 4-bits is automatically handled in Verilog. The simulation waveform illustrates how the
ripple carry adder has a noticeable delay before the output sum is produced. During the time the carry is
rippling through the adder chain, glitches can appear on each of the sum bits in addition to the carry out
signal. The values in this waveform are displayed as unsigned decimal symbols to make the results
easier to interpret.
384 • Chapter 12: Arithmetic Circuits
Example 12.11
Test bench for a 4-bit ripple carry adder using nested for loops in Verilog
Example 12.12
Structural model of a 4-bit carry look ahead adder in Verilog
Example 12.13 shows the simulation waveform for the 4-bit carry look ahead adder. The outputs still
have intermediate transitions while the combinational logic is computing the results; however, the overall
delay of the adder is bound to 4*tgate.
Example 12.13
4-bit carry look ahead adder – simulation waveform
386 • Chapter 12: Arithmetic Circuits
Example 12.14
Behavioral model of a 4-bit adder in Verilog
CONCEPT CHECK
CC12.1 Does a binary adder behave differently when it’s operating on unsigned vs. two’s comple-
ment numbers? Why or why not?
(A) Yes. The adder needs to keep track of the sign bit, thus extra circuitry is needed.
(B) No. The binary addition is identical. It is up to the designer to handle how the two’s
complement codes are interpreted and whether two’s complement overflow
occurred using a separate system.
12.2 Subtraction
Binary subtraction can be accomplished by building a dedicated circuit using a similar design
approach as just described for adders. A more effective approach is to take advantage of two’s
complement representation in order to re-use existing adder circuitry. Recall that taking the two’s
complement of a number will produce an equivalent magnitude number, but with the opposite sign
(i.e., positive to negative or negative to positive). This means that all that is required to create a subtractor
from an adder is to first take the two’s complement of the subtrahend input. Since the steps to take the
two’s complement of a number involve complementing each of the bits in the number and then adding
12.2 Subtraction • 387
1, the logic required is relatively simple. Example 12.15 shows a 4-bit subtractor using full adders. The
subtrahend B is inverted prior to entering the full adders. Also, the carry in bit C0 is set to 1. This handles
the “adding 1” step of the two’s complement. All of the carries in the circuit are now treated as borrows
and the sum is now treated as the difference.
Example 12.15
Design of a 4-bit subtractor using full adders
A programmable adder/subtractor can be created with the use of a programmable inverter and a
control signal. The control signal will selectively invert B and also change the C0 bit between a 0 (for
adding) and a 1 (for subtracting). Example 12.16 shows how an XOR gate can be used to create a
programmable inverter for use in a programmable adder/subtractor circuit.
Example 12.16
Creating a programmable inverter using an XOR gate
388 • Chapter 12: Arithmetic Circuits
We can now define a control signal called (ADDn/SUB) that will control whether the circuit performs
addition or subtraction. Example 12.17 shows the architecture of a 4-bit programmable adder/subtractor.
It should be noted that this programmability adds another level of logic to the circuit, thus increasing its
delay. The programmable architecture in Example 12.17 is shown for a ripple carry adder; however, this
approach works equally well for a carry look ahead adder architecture.
Example 12.17
Design of a 4-bit programmable adder/subtractor
When using two’s complement representation in arithmetic, care must be taken to monitor for two’s
complement overflow. Recall that when using two’s complement representation, the number of bits of the
numbers is fixed (e.g., 4-bits) and if a carry/borrow out is generated, it is ignored. This means that the
Cout bit does not indicate whether two’s complement overflow occurred. Instead, we must construct
additional circuitry to monitor the arithmetic operations for overflow. Recall from Chap. 2 that two’s
complement overflow occurs in any of these situations:
The construction of circuitry for these conditions is straightforward since the sign bit of all numbers
involved in the operation indicates whether the number is positive or negative. The sign bits of the input
arguments and the output are fed into combinational logic circuitry that will assert for any of the above
conditions. These signals are then logically combined to create two’s complement overflow signal.
12.3 Multiplication • 389
CONCEPT CHECK
CC12.2 What modifications can be made to the programmable adder/subtractor architecture so that
it can be used to take the 2’s complement of a number?
(A) Remove the input A.
(B) Add an additional control signal that will cause the circuit to ignore A and just
perform a complement on B and then add 1.
(C) Add an additional 1 to the original number using an OR gate on Cin.
(D) Set A to 0, put the number to be manipulated on B, and put the system into
subtraction mode. The system will then complement the bits on B and then add
1, thus performing two’s complement negation.
12.3 Multiplication
12.3.1 Unsigned Multiplication
Binary multiplication is performed in a similar manner to performing decimal multiplication by hand.
Recall the process for long multiplication. First, the two numbers are placed vertically over one another
with their least significant digits aligned. The upper number is called the multiplicand and the lower
number is called the multiplier. Next, we multiply each individual digit within multiplier with the entire
multiplicand, starting with the least position. The result of this interim multiplication is called the partial
product. The partial product is recorded with its least significant digit aligned with the corresponding
position of the multiplier digit. Finally, all partial products are summed to create the final product of the
multiplication. This process is often called the shift and add approach. Example 12.18 shows the process
for performing long multiplication on decimal numbers highlighting the individual steps.
Example 12.18
Performing long multiplication on decimal numbers
390 • Chapter 12: Arithmetic Circuits
Binary multiplication follows this same process. Example 12.19 shows the process for performing
long multiplication on binary numbers. Note that the inputs represent the largest unsigned numbers
possible using 4-bits, thus producing the largest possible product. The largest product will require 8-bits
to be represented. This means that for any multiplication of n-bit inputs, the product will require 2n bits for
the result.
Example 12.19
Performing long multiplication on binary numbers
The first step in designing a binary multiplier is to create circuitry that can compute the product on
individual bits. Example 12.20 shows the design of a single-bit multiplier.
Example 12.20
Design of a single-bit multiplier
We can create all of the partial products in one level of logic by placing an AND gate between each
bit pairing in the two input numbers. This will require n2 AND gates. The next step involves creating
adders that can perform the sum of the columns of bits within the partial products. This step is not as
straightforward. Notice that in our 4-bit example in Example 12.19 that the number of input bits in the
column addition can reach up to 6 (in position 3). It would be desirable to re-use the full adders previously
12.3 Multiplication • 391
created; however, the existing full adders could only accommodate 3 inputs (A, B, Cin). We can take
advantage of the associative property of addition to form the final sum incrementally. Example 12.21
shows the architecture of this multiplier. This approach implements a shift and add process to compute
the product and is known as a combinational multiplier because it is implemented using only combina-
tional logic. Note that this multiplier only handles unsigned numbers.
Example 12.21
Design of a 4-bit unsigned multiplier
This multiplier can have a significant delay, which is caused by the cascaded full adders. Example
12.22 shows the timing analysis of the combinational multiplier highlighting the worst case path through
the circuit.
392 • Chapter 12: Arithmetic Circuits
Example 12.22
Timing analysis of a 4-bit unsigned multiplier
Example 12.23
Multiplying an unsigned binary number by two using a logical shift left
12.3 Multiplication • 393
This process does not work properly in binary due to the way that negative numbers are represented
with two’s complement. Example 12.24 illustrates how an unsigned multiplier incorrectly handles signed
numbers.
Example 12.24
Illustrating how an unsigned multiplier incorrectly handles signed numbers
Instead of building a dedicated multiplier for signed numbers, we can add functionality to the
unsigned multiplier previously presented to handle negative numbers. The process involves first
identifying any negative numbers. If a negative number is present, the two’s complement is taken on it
to produce its equivalent magnitude, positive representation. The multiplication is then performed on the
positive values. The final step is to apply the correct sign to the product. If the product should be negative
due to one of the inputs being negative, the sign is applied by taking the two’s complement on the final
result. This creates a number that is now in 2n two’s complement format. Example 12.25 shows an
illustration of the process to correctly handle signed numbers using an unsigned multiplier.
394 • Chapter 12: Arithmetic Circuits
Example 12.25
Process to correctly handle signed numbers using an unsigned multiplier
CONCEPT CHECK
CC12.3 Will the AND gates used to compute the partial products in a binary multiplier ever experi-
ence an issue with fan-in as the size of the multiplier increases?
(A) Yes. When the number of bits of the multiplier arguments exceed the fan-in
specification of the AND gates used for the partial products, a fan-in issue has
occurred.
(B) No. The number of inputs of the AND gates performing the partial products will
always be two, regardless of the size of the input arguments to the multiplier.
12.4 Division • 395
12.4 Division
12.4.1 Unsigned Division
There are a variety of methods to perform division, each with trade-offs between area, delay, and
accuracy. To understand the general approach to building a divider circuit, let’s focus on how a simple
iterative divider can be built. Basic division yields a quotient and a remainder. The process begins by
checking whether the divisor goes into the highest position digit in the dividend. The number of times this
dividend digit can be divided is recorded as the highest position value of the quotient. Note that when
performing division by hand, we typically skip over the condition when the result of these initial operations
are zero, but when breaking down the process into steps that can be built with logic circuits, each step
needs to be highlighted. The first quotient digit is then multiplied with the divisor and recorded below the
original dividend. The next lower position digit of the dividend is brought down and joined with the product
from the prior multiplication. This forms a new number to be divided by the divisor to create the next
quotient value. This process is repeated until each of the quotient digits have been created. Any value
that remains after the last subtraction is recorded as the remainder. Example 12.26 shows the long
division process on decimal numbers highlight each incremental step.
Example 12.26
Performing long division on decimal numbers
Long division in binary follows this same process. Example 12.27 shows the long division process
on two 4-bit, unsigned numbers. This division results in a 4-bit quotient and a 4-bit remainder.
396 • Chapter 12: Arithmetic Circuits
Example 12.27
Performing long multiplication on binary numbers
When building a divider circuit using combinational logic, we can accomplish the computation using
a series of iterative subtractors. Performing division is equivalent to subtracting the divisor from the
interim dividend. If the subtraction is positive, then the divisor went into the dividend and the quotient is a
1. If the subtraction yields a negative number, then the divisor did not go into the interim dividend and the
quotient is 0. We can use the borrow out of a subtraction chain to provide the quotient. This has the
advantage that the difference has already been calculated for the next subtraction. A multiplexer is used
to select whether the difference is used in the next subtraction (Q ¼ 0), or if the interim divisor is simply
brought down (Q ¼ 1). This inherently provides the functionality of the multiplication step in long division.
Example 12.28 shows the architecture of a 4-bit, unsigned divider based on the iterative subtraction
approach. Notice that when the borrow out of the 4-bit subtractor chain is a 0, it indicates that the
subtraction yielded a positive number. This means that the divisor went into the interim dividend once. In
this case, the quotient for this position is a 1. An inverter is required to produce the correct polarity of the
quotient. The borrow out is also fed into the multiplexer stage as the select line to pass the difference to
the next stage of subtractors. If the borrow out of the 4-bit subtractor chain is a 1, it indicates that the
subtraction yielded a negative number. In this case, the quotient is a 0. This also means that the
difference calculated is garbage and should not be used. The multiplexer stage instead selects the
interim dividend as the input to the next stage of subtractors.
12.4 Division • 397
Example 12.28
Design of a 4-bit unsigned divider using a series of iterative subtractors
To illustrate how this architecture works, Example 12.29 walks through each step in the process
where 11112 (1510) is divided by 01112 (710). In this example, the calculations propagate through the logic
stages from top to bottom in the diagram.
398 • Chapter 12: Arithmetic Circuits
Example 12.29
Dividing 11112 (1510) by 01112 (710) using the iterative subtraction architecture
Example 12.30
Dividing an unsigned binary numbers by two using a logical shift right
• The quotient will be negative if the input signs are different (i.e., pos/neg or neg/pos).
• The remainder has the same sign as the dividend.
CONCEPT CHECK
CC12.4 Could a shift register help reduce the complexity of a combinational divider circuit? How?
(A) Yes. Instead of having redundant circuits holding the different shifted versions of
the divisor, a shift register could be used to hold and shift the divisor after each
subtraction.
(B) No. A state machine would then be needed to control the divisor shifting, which
would make the system even more complex.
Summary
v Binary arithmetic is accomplished using v A ripple carry adder performs addition by
combinational logic circuitry. These circuits reusing lower level components that each
tend to be the largest circuits in a system performs a small part of the computation. A
and have the longest delay. Arithmetic full adder is made from two half adders and a
circuits are often broken up into interim ripple carry adder is made from a chain of full
calculations in order to reduce the overall adders. This approach simplifies the design
delay of the computation. of the adder but leads to long delay times
since the carry from each sum must ripple
400 • Chapter 12: Arithmetic Circuits
to the next higher position’s addition before it accomplished by hand using the shift and
can complete. add approach. The partial products of the
v A carry look ahead adder attempts to elimi- multiplication can be performed using
nate the linear dependence of delay on the 2-input AND gates. The sum of the partial
number of bits that exists in a ripple carry products can have more inputs than the typi-
adder. The carry look ahead adder contains cal ripple carry adder can accommodate. To
dedicated circuitry that calculates the carry handle this, the additions are performed two
bits for each position of the addition. This bits at a time using a series of adders.
leads to a more constant delay as the width v Division can be accomplished using an itera-
of the adder increases. tive subtractor architecture.
v A binary multiplier can be created in a
similar manner to the way multiplication is
Exercise Problems
Section 12.1 – Addition 12.1.5 Design a Verilog model for an 8-bit Ripple
Carry Adder (RCA) using a structural design
12.1.1 Give the total delay of the full adder shown in
approach. This involves creating a half adder
Fig. 12.2 if all gates have a delay of 1 ns.
(half_adder.v), full adder (full_adder.v), and
then finally a top-level adder (rca.v) by
instantiating eight full adder sub-systems.
Model the logic operations using gate level
primitives. Give each gate primitive a delay of
1 ns. The general topology and module defini-
tion for the design are shown in Fig. 12.4. Cre-
ate a test bench to exhaustively verify your
design under all input conditions. The test
bench should drive in different values every
Fig. 12.2 30 ns in order to give sufficient time for the
Full Adder Timing Exercise results to ripple through the adder.
Fig. 12.4
4-Bit RCA Module Definition
Fig. 12.3
4-Bit RCA Timing Exercise
Fig. 12.5
4-Bit CLA Timing Exercise
Exercise Problems • 401
12.1.8 Design a Verilog model for an 8-bit Carry Look port called “Sum_Diff”. The model should
Ahead Adder (cla.v). The model should instan- assert the output “Cout_Bout” when an addi-
tiate eight instances of a modified full adder tion creates a carry or when a subtraction
(mod_full_adder.v), which is implemented creates a borrow. The circuit will also assert
with gate-level primitives. The carry look the output Vout when either operation results in
ahead logic should be implemented using con- two’s complement overflow. The port definition
tinuous assignment with logical operators and block diagram for the system is shown in
within the cla.v module. All logic operations Fig. 12.8. Create a test bench to exhaustively
should have 1 ns of delay. The topology and verify this design under all input conditions.
port definition for the design are shown in
Fig. 12.6. Create a test bench to exhaustively
verify this design under all input conditions.
The test bench should drive in different values
every 30 ns in order to give sufficient time for
the signals to propagate through the adder.
Fig. 12.8
Programmable Adder/Subtractor Module
Definition
Fig. 12.7
Programmable Adder/Subtractor Block Diagram Fig. 12.9
4-Bit Unsigned Multiplier Block Diagram
12.2.2 Will the programmable adder/subtractor archi-
tecture shown in Fig. 12.7 work for negative
12.3.2 For the 4-bit unsigned multiplier shown in
numbers encoded using signed magnitude or
Fig. 12.9, how many levels of logic does it
1’s complement?
take to compute all of the partial products?
12.2.3 When calculating the delay of the programma-
12.3.3 For the 4-bit unsigned multiplier shown in
ble adder/subtractor architecture shown in
Fig. 12.9, how many AND gates are needed
Fig. 12.7 does the delay of the XOR gate that
to compute the partial products?
acts as the programmable inverter need to be
considered? 12.3.4 For the 4-bit unsigned multiplier shown in
Fig. 12.9, how many total AND gates are
12.2.4 Design a Verilog model for an 8-bit, program-
used if the additions are implemented using
mable adder/subtractor. The design will have
full adders made of half adders?
an input called “ADDn_SUB” that will control
whether the system behaves as an adder (0) or 12.3.5 Based on the architecture of a unsigned multi-
as a subtractor (1). The design should operate plier in Fig. 12.9, how many AND gates are
on two’s complement signed numbers. The needed to compute the partial products if the
result of the operation(s) will appear on the inputs are increased to 8-bits?
402 • Chapter 12: Arithmetic Circuits
12.3.6 For an 8-bit multiplier, how many bits are 12.3.12 Design a Verilog model for an 8-bit signed
needed to represent the product? multiplier using whatever modeling approach
12.3.7 For an 8-bit unsigned multiplier, what is the you wish. Create a test bench to exhaustively
largest value that the product can ever take verify this design under all input conditions.
on? Give your answer in decimal. The port definition for this multiplier is given in
Fig. 12.11.
12.3.8 For an 8-bit signed multiplier, what is the larg-
est value that the product can ever take on?
Give your answer in decimal.
12.3.9 For an 8-bit signed multiplier, what is the
smallest value that the product can ever take
on? Give your answer in decimal. Fig. 12.11
12.3.10 What is the maximum number of times that a 8-Bit Signed Multiplier Module Definition
4-bit unsigned multiplicand can be multiplied
by two using the logical shift left approach
before the product is too large to be Section 12.4 – Division
represented by an 8-bit-product? Hint: The
12.4.1 For a 4-bit divider, how many bits are needed
maximum number of times this operation can
for the quotient?
be performed corresponds to when the multi-
plicand starts at its lowest possible non-zero 12.4.2 For a 4-bit divider, how many bits are needed
value (i.e., 1). for the remainder?
12.3.11 Design a Verilog model for an 8-bit unsigned 12.4.2 Explain the basic concept of the iterative-
multiplier using whatever modeling approach subtractor approach to division.
you wish. Create a test bench to exhaustively 12.4.4 For the 4-bit divider shown in Example 12.28,
verify this design under all input conditions. estimate the total delay assuming all gates
The port definition for this multiplier is given in have a delay of 1 ns.
Fig. 12.10.
Fig. 12.10
8-Bit Unsigned Multiplier Module Definition
Chapter 13: Computer System Design
One of the most common digital systems in use today is the computer. A computer accomplishes
tasks through an architecture that uses both hardware and software. The hardware in a computer
consists of many of the elements that we have covered so far. These include registers, arithmetic and
logic circuits, finite state machines, and memory. What makes a computer so useful is that the hardware
is designed to accomplish a predetermined set of instructions. These instructions are relatively simple,
such as moving data between memory and a register or performing arithmetic on two numbers. The
instructions are comprised of binary codes that are stored in a memory device and represent the
sequence of operations that the hardware will perform to accomplish a task. This sequence of
instructions is called a computer program. What makes this architecture so useful is that the preexisting
hardware can be programmed to perform an almost unlimited number of tasks by simply defining the
sequence of instructions to be executed. The process of designing the sequence of instructions, or
program, is called software development or software engineering.
The idea of a general purpose computing machine dates back to the 19th century. The first
computing machines were implemented with mechanical systems and were typically analog in nature.
As technology advanced, computer hardware evolved from electromechanical switches to vacuum
tubes and ultimately to integrated circuits. These newer technologies enabled switching circuits and
provided the capability to build binary computers. Today’s computers are built exclusively with semicon-
ductor materials and integrated circuit technology. The term microcomputer is used to describe a
computer that has its processing hardware implemented with integrated circuitry. Nearly all modern
computers are binary. Binary computers are designed to operate on a fixed set of bits. For example, an
8-bit computer would perform operations on 8-bits at a time. This means it moves data between registers
and memory and performs arithmetic and logic operations in groups of 8-bits.
This chapter will cover the basics of a simple computer system and present the design of an 8-bit
system to illustrate the details of instruction execution. The goal of this chapter is to provide an
understanding of the basic principles of computer systems.
Fig. 13.1
Hardware components of a computer system
• Instruction Register (IR) – The instruction register holds the current binary code of the
instruction being executed. This code is read from program memory as the first part of
instruction execution. The IR is used by the control unit to decide which states in its FSM to
traverse in order to execute the instruction.
• Memory Address Register (MAR) – The memory address register is used to hold the current
address being used to access memory. The MAR can be loaded with addresses in order to
fetch instructions from program memory or with addresses to access data memory and/or I/O
ports.
• Program Counter (PC) – The program counter holds the address of the current instruction
being executed in program memory. The program counter will increment sequentially through
the program memory reading instructions until a dedicated instruction is used to set it to a new
location.
• General Purpose Registers – These registers are available for temporary storage by the
program. Instructions exist to move information from memory into these registers and to move
information from these registers into memory. Instructions also exist to perform arithmetic and
logic operations on the information held in these registers.
• Condition Code Register (CCR) – The condition code register holds status flags that provide
information about the arithmetic and logic operations performed in the CPU. The most common
flags are negative (N), zero (Z), two’s complement overflow (V), and carry (C). This register can
also contain flags that indicate the status of the computer, such as if an interrupt has occurred
or if the computer has been put into a low-power mode.
Figure 13.2 shows the typical organization of a CPU. The registers and ALU are grouped into the
data path. In this example, the computer system has two general purpose registers called A and B. This
CPU organization will be used throughout this chapter to illustrate the detailed execution of instructions.
Fig. 13.2
Typical CPU organization
Fig. 13.3
Computer hardware in a memory mapped configuration
To help visualize how the memory addresses are assigned, a memory map is used. This is a
graphical depiction of the memory system. In the memory map, the ranges of addresses are provided for
each of the main subsections of memory. This gives the programmer a quick overview of the available
resources in the computer system. Example 13.1 shows a representative memory map for a computer
system with an address bus with a width of 8-bits. This address bus can provide 256 unique locations.
For this example, the memory system is also 8-bits wide, thus the entire memory system is 256 8 in
size. In this example 128 bytes are allocated for program memory; 96 bytes are allocated for data
memory; 16 bytes are allocated for output ports; and 16 bytes are allocated for input ports.
408 • Chapter 13: Computer System Design
CONCEPT CHECK
Example 13.1
Memory map for a 256 8 memory system
given task. This architectural approach is called a reduced instruction set computer (RISC). The
alternative to this approach is to make an instruction set with a large number of dedicated instructions
that can accomplish a given task in fewer CPU operations. The drawback of this approach is that the
physical size of the CPU must be larger in order to accommodate the various instructions. This
architectural approach is called a complex instruction set computer (CISC).
Fig. 13.4
Anatomy of a computer instruction
immediate addressing, the operand would be the constant. When the CPU reads the operand, it simply
inserts the contents into the CPU register and the instruction is complete.
Example 13.2
Execution of an instruction to “Load Register A Using Immediate Addressing”
Now let’s look at a load instruction using direct addressing. In direct addressing, the operand of the
instruction is the address of where the data to be loaded resides. As an example, let’s look at an
instruction to load the general purpose register A. Let’s say that the opcode of the instruction is x00 8700 ,
has a mnemonic LDA_DIR, and is inserted into program memory starting at x00 0800 . The value to be
loaded into A resides at address x00 8000 , which has already been initialized with x00 AA00 before this
instruction. Example 13.3 shows the steps involved in executing the LDA_DIR instruction.
412 • Chapter 13: Computer System Design
Example 13.3
Execution of an instruction to “Load Register A Using Direct Addressing”
A store is an instruction that moves information from a CPU register into memory. The operand of a
store instruction indicates the address of where the contents of the CPU register will be written. As an
example, let’s look at an instruction to store the general purpose register A into memory address x00 E000 .
Let’s say that the opcode of the instruction is x00 9600 , has a mnemonic STA_DIR, and is inserted into
program memory starting at x00 0400 . The initial value of A is x00 CC00 before the instruction is executed.
Example 13.4 shows the steps involved in executing the STA_DIR instruction.
13.2 Computer Software • 413
Example 13.4
Execution of an instruction to “Store Register A Using Direct Addressing”
Example 13.5
Execution of an instruction to “Add Registers A and B”
13.2.3.3 Branches
In the previous examples the program counter was always incremented to point to the address of
the next instruction in program memory. This behavior only supports a linear execution of instructions. To
provide the ability to specifically set the value of the program counter, instructions called branches are
used. There are two types of branches: unconditional and conditional. In an unconditional branch, the
program counter is always loaded with the value provided in the operand. As an example, let’s look at an
instruction to branch always to a specific address. This allows the program to perform loops. Let’s say
that the opcode of the instruction is x00 2000 , has a mnemonic BRA, and is inserted into program memory
starting at x00 0600 . Example 13.6 shows the steps involved in executing the BRA instruction.
13.2 Computer Software • 415
Example 13.6
Execution of an instruction to “Branch Always”
In a conditional branch, the program counter is only updated if a particular condition is true. The
conditions come from the status flags in the condition code register (NZVC). This allows a program to
selectively execute instructions based on the result of a prior operation. Let’s look at an example
instruction that will branch only if the Z flag is asserted. This instruction is called a branch if equal to
zero. Let’s say that the opcode of the instruction is x00 2300 , has a mnemonic BEQ, and is inserted into
program memory starting at x00 0500 . Example 13.7 shows the steps involved in executing the BEQ
instruction.
416 • Chapter 13: Computer System Design
Example 13.7
Execution of an instruction to “Branch if Equal to Zero”
Conditional branches allow computer programs to make decisions about which instructions to
execute based on the results of previous instructions. This gives computers the ability to react to input
signals or take action based on the results of arithmetic or logic operations. Computer instruction sets
typically contain conditional branches based on the NZVC flags in the condition code registers. The
following instructions are based on the values of the NZVC flags.
CONCEPT CHECK
CC13.2 Software development consists of choosing which instructions, and in what order, will
be executed to accomplish a certain task. The group of instructions is called the
program and is inserted into program memory. Which of the following might a software
developer care about?
(A) Minimizing the number of instructions that need to be executed to accom-
plish the task in order to increase the computation rate.
(B) Minimizing the number of registers used in the CPU to save power.
(C) Minimizing the overall size of the program to reduce the amount of program
memory needed.
(D) Both A and C.
Example 13.8
Top level block diagram for the 8-Bit computer system
We will use the memory map shown in Example 13.1 for our example computer system. This
mapping provides 128 bytes of program memory, 96 bytes of data memory, 16x output ports, and 16x
input ports. To simplify the operation of this example computer, the address bus is limited to 8-bits. This
only provides 256 locations of memory access, but allows an entire address to be loaded into the CPU as
a single operand of an instruction.
Example 13.9
Instruction set for the 8-Bit computer system
Example 13.10
Memory system block diagram for the 8-Bit computer system
Now the program memory can be declared as an array type with initial values to define the program.
The following Verilog shows how to declare the program memory and an example program to perform a
load, store, and a branch always. This program will continually write x00 AA” to port_out_00.
reg[7:0] ROM[0:127];
initial
begin
ROM[0] ¼ LDA_IMM;
ROM[1] ¼ 8’hAA;
ROM[2] ¼ STA_DIR;
ROM[3] ¼ 8’hE0;
ROM[4] ¼ BRA;
ROM[5] ¼ 8’h00;
end
The address mapping for the program memory is handled in two ways. First, notice that the array
type defined above uses indices from 0 to 127. This provides the appropriate addresses for each location
in the memory. The second step is to create an internal enable line that will only allow assignments from
ROM to data_out when a valid address is entered. Consider the following Verilog to create an internal
enable (EN) that will only be asserted when the address falls within the valid program memory range of
0 to 127.
always @ (address)
begin
if ( (address >¼ 0) && (address <¼ 127) )
EN ¼ 1’b1;
else
EN ¼ 1’b0;
end
If this enable signal is not created, the simulation and synthesis will fail because data_out
assignments will be attempted for addresses outside of the defined range of the ROM array. This enable
line can now be used in the behavioral model for the ROM as follows:
always @ (posedge clock)
begin
if (EN)
data_out ¼ ROM[address];
end
422 • Chapter 13: Computer System Design
reg[7:0] RW[128:223];
The following is the Verilog to model the local enable and signal assignments for the R/W memory:
always @ (address)
begin
if ( (address >¼ 128) && (address <¼ 223) )
EN ¼ 1’b1;
else
EN ¼ 1’b0;
end
:
“the rest of the output port models go here. . .”
:
13.3 Computer Implementation – An 8-Bit Computer Example • 423
begin: MUX1
end
a bus system in order to facilitate data movement between the registers and memory. The bus system is
implemented with two multiplexers that are controlled by the control unit. The control unit contains the
finite state machine that generates all control signals for the data path as it performs the fetch-decode-
execute steps of each instruction. Example 13.11 shows the block diagram of the CPU in our 8-bit
microcomputer example.
Example 13.11
CPU block diagram for the 8-Bit computer system
connected directly to the to_memory port of the CPU to allow registers to write data to the memory
system. Bus2 can be driven by the from_memory port of the CPU to allow the memory system to provide
data for the CPU registers. The two multiplexers handle all signal routing and have their select lines
(Bus1_Sel and Bus2_Sel) driven by the control unit. The following Verilog shows how the multiplexers
are implemented. Again, a multiplexer is combinational logic so all inputs must be listed in the sensitivity
list of its procedural block and blocking assignments are used. Two additional signal assignments are
also required to connect the MAR to the address port and to connect Bus1 to the to_memory port.
always @ (Bus1_Sel, PC, A, B)
begin: MUX_BUS1
case (Bus1_Sel)
2’b00 : Bus1 ¼ PC;
2’b01 : Bus1 ¼ A;
2’b10 : Bus1 ¼ B;
default : Bus1 ¼ 8’hXX;
endcase
end
Next, let’s look at implementing the registers in the data path. Each register is implemented using a
dedicated procedural block that is sensitive to clock and reset. This models the behavior of synchronous
latches, or registers. Each register has a synchronous enable line that dictates when the register is
updated. The register output is only updated when the enable line is asserted and a rising edge of the
clock is detected. The following Verilog shows how to model the instruction register (IR). Notice that the
signal IR is only updated if IR_Load is asserted and there is a rising edge of the clock. In this case, IR is
loaded with the value that resides on Bus2.
always @ (posedge clock or negedge reset)
begin: INSTRUCTION_REGISTER
if (!reset)
IR <¼ 8’h00;
else
if (IR_Load)
IR <¼ Bus2;
end
A nearly identical block is used to model the memory address register. A unique signal is declared
called MAR in order to make the Verilog more readable. MAR is always assigned to address in this
system.
always @ (posedge clock or negedge reset)
begin: MEMORY_ADDRESS_REGISTER
if (!reset)
MAR <¼ 8’h00;
else
if (MAR_Load)
MAR <¼ Bus2;
end
426 • Chapter 13: Computer System Design
Now let’s look at the program counter block. This register contains additional functionality beyond
simply latching in the value of Bus2. The program counter also has an increment feature that will take
place synchronously when the signal PC_Inc coming from the control unit is asserted. This is handled
using an additional nested if-else clause under the portion of the block handling the rising edge of clock
condition.
always @ (posedge clock or negedge reset)
begin: PROGRAM_COUNTER
if (!reset)
PC <¼ 8’h00;
else
if (PC_Load)
PC <¼ Bus2;
else if (PC_Inc)
PC <¼ MAR + 1;
end
The two general purpose registers A and B are modeled using individual procedural blocks as
follows:
always @ (posedge clock or negedge reset)
begin: A_REGISTER
if (!reset)
A <¼ 8’h00;
else
if (A_Load)
A <¼ Bus2;
end
The condition code register latches in the status flags from the ALU (NZVC) when the CCR_Load
line is asserted. This behavior is modeled using a similar approach as follows:
always @ (posedge clock or negedge reset)
begin: CONDITION_CODE_REGISTER
if (!reset)
CCR_Result <¼ 8’h00;
else
if (CCR_Load)
CCR_Result <¼ NZVC;
end
numbers. The Z flag can be driven using an if-else condition that checks whether the result was x00 0000 .
The V flag is updated based on the type of the operation. For the addition operation, the V flag will be
asserted if a POS + POS ¼ NEG or a NEG + NEG ¼ POS. These conditions can be checked by looking
at the sign bits of the inputs and the sign bit of the result. Finally, the C flag can be computed as the 8th bit
in the addition of A + B.
end
:
//-- other ALU operations go here...
:
default : begin
Result ¼ 8’hXX;
NZVC ¼ 4’hX;
end
endcase
end
following Verilog code shows how the user-defined state names are created for nine basic instructions
(LDA_IMM, LDA_DIR, STA_DIR, LDB_IMM, LDB_DIR, STB_DIR, ADD_AB, BRA and BEQ). Eight bit
state variables are created for current_state and next_state to accommodate future state codes. The
state codes are assigned in binary using integer format to allow additional states to be easily added.
Within the control unit module, the state memory is implemented as a separate procedural block that
will update the current state with the next state on each rising edge of the clock. The reset state will be the
first fetch state in the FSM (i.e., S_FETCH_0). The following Verilog shows how the state memory in the
control unit can be modeled. Note that this block models sequential logic so non-blocking assignments
are used.
13.3 Computer Implementation – An 8-Bit Computer Example • 429
The next state logic is also implemented as a separate procedural block. The next state logic depends
on the current state, instruction register (IR), and the condition code register (CCR_Result). The following
Verilog gives a portion of the next state logic process showing how the state transitions can be modeled.
always @ (current_state, IR, CCR_Result)
begin: NEXT_STATE_LOGIC
case (current_state)
S_FETCH_0 : next_state ¼ S_FETCH_1; //-- Path for FETCH instruction
S_FETCH_1 : next_state ¼ S_FETCH_2;
S_FETCH_2 : next_state ¼ S_DECODE_3;
:
Next state logic for other states goes here. . .
:
endcase
end
Finally, the output logic is modeled as a third, separate procedural block. It is useful to explicitly state
the outputs of the control unit for each state in the machine to allow easy debugging and avoid
synthesizing latches. Our example computer system has Moore type outputs so the process only
depends on the current state. The following Verilog shows a portion of the output logic process.
always @ (current_state)
begin: OUTPUT_LOGIC
case (current_state)
S_FETCH_1 : begin //-- Increment PC, Opcode will be available next state
IR_Load ¼ 0;
MAR_Load ¼ 0;
PC_Load ¼ 0;
PC_Inc ¼ 1;
A_Load ¼ 0;
B_Load ¼ 0;
ALU_Sel ¼ 3’b000;
CCR_Load ¼ 0;
Bus1_Sel ¼ 2’b00; //-- "00"¼PC, "01"¼A, "10"¼B
Bus2_Sel ¼ 2’b00; //-- "00"¼ALU, "01"¼Bus1, "10"¼from_memory
write ¼ 0;
end;
:
Output logic for other states goes here. . .
:
endcase
end
Example 13.12
State diagram for LDA_IMM
432 • Chapter 13: Computer System Design
Example 13.13 shows the simulation waveform for executing LDA_IMM. In this example, register A
is loaded with the operand of the instruction, which holds the value x00 AA00 .
Example 13.13
Simulation waveform for LDA_IMM
Example 13.14
State diagram for LDA_DIR
Example 13.15 shows the simulation waveform for executing LDA_DIR. In this example, register A
is loaded with the contents located at address x00 8000 , which has already been initialized to x00 AA00 .
434 • Chapter 13: Computer System Design
Example 13.15
Simulation waveform for LDA_DIR
Example 13.16
State diagram for STA_DIR
Example 13.17 shows the simulation waveform for executing STA_DIR. In this example, register A
already contains the value x00 CC00 and will be stored to address x00 E000 . The address x00 E000 is an output
port (port_out_00) in our example computer system.
436 • Chapter 13: Computer System Design
Example 13.17
Simulation waveform for STA_DIR
Example 13.18
State diagram for ADD_AB
Example 13.19 shows the simulation waveform for executing ADD_AB. In this example, two load
immediate instructions were used to initialize the general purpose registers to A ¼ x00 FF00 and B ¼ x00 0100
prior to the addition. The addition of these values will result in a sum of x00 0000 and assert the carry (C) and
zero (Z) flags in the condition code register.
438 • Chapter 13: Computer System Design
Example 13.19
Simulation waveform for ADD_AB
Example 13.20
State diagram for BRA
440 • Chapter 13: Computer System Design
Example 13.21 shows the simulation waveform for executing BRA. In this example, PC is set back
to address x00 0000 .
Example 13.21
Simulation waveform for BRA
Example 13.22
State diagram for BEQ
Example 13.23 shows the simulation waveform for executing BEQ when the branch is taken. Prior to
this instruction, an addition was performed on x00 FF00 and x00 0100 . This resulted in a sum of x00 0000 , which
asserted the Z and C flags in the condition code register. Since Z ¼ 1 when BEQ is executed, the branch
is taken.
442 • Chapter 13: Computer System Design
Example 13.23
Simulation waveform for BEQ when taking the branch (Z ¼ 1)
Example 13.24 shows the simulation waveform for executing BEQ when the branch is not taken.
Prior to this instruction, an addition was performed on x00 FE00 and x00 0100 . This resulted in a sum of x00 FF00,
which did not assert the Z flag. Since Z ¼ 0 when BEQ is executed, the branch is not taken. When not
taking the branch, PC must be incremented again in order to bypass the operand and point to the next
location in program memory.
13.3 Computer Implementation – An 8-Bit Computer Example • 443
Example 13.24
Simulation waveform for BEQ when the branch is not taken (Z ¼ 0)
444 • Chapter 13: Computer System Design
CONCEPT CHECK
CC13.3 The 8-bit microcomputer example presented in this section is a very simple architec-
ture used to illustrate the basic concepts of a computer. If we wanted to keep this
computer an 8-bit system but increase the depth of the memory, it would require
adding more address lines to the address bus. What changes to the computer system
would need to be made to accommodate the wider address bus?
(A) The width of the program counter would need to be increased to support the
wider address bus.
(B) The size of the memory address register would need to be increased to
support the wider address bus.
(C) Instructions that use direct addressing would need additional bytes of
operand to pass the wider address into the CPU 8-bits at a time.
(D) All of the above.
Fig. 13.5
Von Neumann vs. Harvard Architecture
CONCEPT CHECK
CC13.4 Does a computer with a Harvard architecture require two control unit state machines?
(A) Yes. It has two bus systems that need to be managed separately so two finite
state machines are required.
(B) No. A single state machine is still used to fetch, decode, and execute the
instruction. The only difference is that if data is required for the execute
stage, it can be retrieved from data memory at the same time the state
machine fetches the opcode of the next instruction from program memory.
446 • Chapter 13: Computer System Design
Summary
v A computer is a collection of hardware v A computer also contains data memory to
components that are constructed to perform hold temporary variables during run time.
a specific set of instructions to process and v A computer also contains input and output
store data. The main hardware components ports to interface with the outside world.
of a computer are the central processing unit v A memory mapped system is one in which
(CPU), program memory, data memory, and the program memory, data memory, and I/O
input/output ports. ports are all assigned a unique address. This
v The CPU consists of registers for fast storage, allows the CPU to simply process information
an arithmetic logic unit (ALU) for data manip- as data and addresses and allows the pro-
ulation, and a control state machine that gram to handle where the information is
directs all activity to execute an instruction. being sent to. A memory map is a graphical
v A CPU is typically organized into a data path representation of what address ranges vari-
and a control unit. The data path contains all ous components are mapped to.
circuitry used to store and process information. v There are three primary classes of
The data path includes the registers and the instructions. These are loads and stores,
ALU. The control unit is a large state machine data manipulations, and branches.
that sends control signals to the data path in v Load instructions move information from
order to facilitate instruction execution. memory into a CPU register. A load instruc-
v The control unit continuously performs a tion takes multiple read cycles. Store
fetch-decode-execute cycle in order to com- instructions move information from a CPU
plete instructions. register into memory. A store instruction
v The instructions that a computer is designed takes multiple read cycles and at least one
to execute is called its instruction set. write cycle.
v Instructions are inserted into program mem- v Data manipulation instructions operate on
ory in a sequence that when executed will information being held in CPU registers.
accomplish a particular task. This sequence Data manipulation instructions often use
of instructions is called a computer program. inherent addressing.
v An instruction consists of an opcode and a v Branch instructions alter the flow of instruc-
potential operand. The opcode is the unique tion execution. Unconditional branches
binary code that tells the control state always change the location in memory of
machine which instruction is being executed. where the CPU is executing instructions.
An operand is additional information that may Conditional branches only change the loca-
be needed for the instruction. tion of instruction execution if a status flag is
v An addressing mode refers to the way that asserted.
the operand is treated. In immediate v Status flags are held in the condition code
addressing the operand is the actual data to register and are updated by certain
be used. In direct addressing the operand is instructions. The most commonly used flags
the address of where the data is to be are the negative flag (N), zero flag (Z), two’s
retrieved or stored. In inherent addressing complement overflow flag (V), and carry
all of the information needed to complete flag (C).
the instruction is contained within the opcode
so no operand is needed.
Exercise Problems
Section 13.1: Computer Hardware 13.1.4 What computer hardware sub-system contains
the state machine that orchestrates the fetch-
13.1.1 What computer hardware sub-system holds
decode-execute process?
the temporary variables used by the program?
13.1.5 What computer hardware sub-system contains
13.1.2 What computer hardware sub-system contains
the circuitry that performs mathematical and
fast storage for holding and/or manipulating
logic operations?
data and addresses?
13.1.6 What computer hardware sub-system holds
13.1.3 What computer hardware sub-system allows
the instructions being executed?
the computer to interface to the outside world?
Exercise Problems • 447
EXAMPLE 4.15 CREATING A CANONICAL SUM OF PRODUCTS LOGIC CIRCUIT USING MINTERMS ........................ ........................ 104
EXAMPLE 4.16 CREATING A MINTERM LIST FROM A TRUTH TABLE ............................................ ........................................... 105
EXAMPLE 4.17 CREATING EQUIVALENT FUNCTIONAL REPRESENTATIONS FROM A MINTERM LIST ........................ ....................... 106
EXAMPLE 4.18 CREATING A PRODUCT OF SUMS LOGIC CIRCUIT USING MAXTERMS ................................ ................................ 108
EXAMPLE 4.19 CREATING A MAXTERM LIST FROM A TRUTH TABLE ........................................... ........................................... 109
EXAMPLE 4.20 CREATING EQUIVALENT FUNCTIONAL REPRESENTATIONS FROM A MAXTERM LIST ................................................ 110
EXAMPLE 4.21 CREATING EQUIVALENT FORMS TO REPRESENT LOGIC FUNCTIONALITY ............................................................. 111
EXAMPLE 4.22 MINIMIZING A LOGIC EXPRESSION ALGEBRAICALLY ........................................................................................ 113
EXAMPLE 4.23 USING A K-MAP TO FIND A MINIMIZED SUM OF PRODUCTS EXPRESSION (2-INPUT) ............................................ 118
EXAMPLE 4.24 USING A K-MAP TO FIND A MINIMIZED SUM OF PRODUCTS EXPRESSION (3-INPUT) ............................................ 119
EXAMPLE 4.25 USING A K-MAP TO FIND A MINIMIZED SUM OF PRODUCTS EXPRESSION (4-INPUT) ..................... ..................... 120
EXAMPLE 4.26 USING A K-MAP TO FIND A MINIMIZED PRODUCT OF SUMS EXPRESSION (2-INPUT) ..................... ..................... 121
EXAMPLE 4.27 USING A K-MAP TO FIND A MINIMIZED PRODUCT OF SUMS EXPRESSION (3-INPUT) ..................... ..................... 122
EXAMPLE 4.28 USING A K-MAP TO FIND A MINIMIZED PRODUCT OF SUMS EXPRESSION (4-INPUT) ..................... ..................... 123
EXAMPLE 4.29 DERIVING THE MINIMAL SUM FROM A K-MAP ............................................... .............................................. 125
EXAMPLE 4.30 USING DON’T CARES TO PRODUCE A MINIMAL SOP LOGIC EXPRESSION ............................ ............................ 126
EXAMPLE 4.31 ELIMINATING A TIMING HAZARD BY INCLUDING NON-ESSENTIAL PRODUCT TERMS ....................... ....................... 131
EXAMPLE 5.1 DECLARING VERILOG MODULE PORTS .................................................... .................................................... 157
EXAMPLE 5.2 MODELING COMBINATIONAL LOGIC USING CONTINUOUS ASSIGNMENT WITH LOGICAL OPERATORS ............. ............. 165
EXAMPLE 5.3 MODELING COMBINATIONAL LOGIC USING CONTINUOUS ASSIGNMENT WITH CONDITIONAL OPERATORS (1) ....... ....... 166
EXAMPLE 5.4 MODELING COMBINATIONAL LOGIC USING CONTINUOUS ASSIGNMENT WITH CONDITIONAL OPERATORS (2) ....... ....... 167
EXAMPLE 5.5 MODELING DELAY IN CONTINUOUS ASSIGNMENTS ............................................. ............................................. 168
EXAMPLE 5.6 INERTIAL DELAY MODELING WHEN USING CONTINUOUS ASSIGNMENT. ................................ ................................ 169
EXAMPLE 5.7 VERILOG STRUCTURAL DESIGN USING EXPLICIT PORT MAPPING .................................... ................................... 171
EXAMPLE 5.8 VERILOG STRUCTURAL DESIGN USING POSITIONAL PORT MAPPING .................................. ................................. 172
EXAMPLE 5.9 MODELING COMBINATIONAL LOGIC CIRCUITS USING GATE LEVEL PRIMITIVES ........................... ........................... 173
EXAMPLE 5.10 MODELING COMBINATIONAL LOGIC CIRCUITS WITH A USER-DEFINED PRIMITIVE ......................... ........................ 174
EXAMPLE 6.1 2-TO-4 ONE-HOT DECODER – LOGIC DYNTHESIS BY HAND ....................................... ...................................... 182
EXAMPLE 6.2 3-TO-8 ONE-HOT DECODER – VERILOG MODELING USING LOGICAL OPERATORS ........................ ........................ 183
EXAMPLE 6.3 3-TO-8 ONE-HOT DECODER – VERILOG MODELING USING CONDITIONAL OPERATORS ..................... ..................... 184
EXAMPLE 6.4 7-SEGMENT DISPLAY DECODER – TRUTH TABLE .............................................. .............................................. 185
EXAMPLE 6.5 7-SEGMENT DISPLAY DECODER – LOGIC SYNTHESIS BY HAND .................................... .................................... 186
EXAMPLE 6.6 7-SEGMENT DISPLAY DECODER – VERILOG MODELING USING LOGICAL OPERATORS ...................... ...................... 187
EXAMPLE 6.7 7-SEGMENT DISPLAY DECODER – VERILOG MODELING USING CONDITIONAL OPERATORS ................... .................. 187
EXAMPLE 6.8 4-TO-2 BINARY ENCODER – LOGIC SYNTHESIS BY HAND ....................................... ........................................ 189
EXAMPLE 6.9 4-TO-2 BINARY ENCODER – VERILOG MODELING USING LOGICAL AND CONDITIONAL OPERATORS ............. ............ 190
EXAMPLE 6.10 2-TO-1 MULTIPLEXER – LOGIC SYNTHESIS BY HAND .......................................... .......................................... 191
EXAMPLE 6.11 4-TO-1 MULTIPLEXER – VERILOG MODELING USING LOGICAL AND CONDITIONAL OPERATORS ............... .............. 192
EXAMPLE 6.12 1-TO-2 DEMULTIPLEXER – LOGIC SYNTHESIS BY HAND ........................................ ........................................ 193
EXAMPLE 6.13 1-TO-4 DEMULTIPLEXER – VERILOG MODELING USING LOGICAL AND CONDITIONAL OPERATORS ............. ............ 194
EXAMPLE 7.1 PUSH-BUTTON WINDOW CONTROLLER – WORD DESCRIPTION ..................................... ..................................... 223
EXAMPLE 7.2 PUSH-BUTTON WINDOW CONTROLLER – STATE DIAGRAM ........................................ ........................................ 224
EXAMPLE 7.3 PUSH-BUTTON WINDOW CONTROLLER – STATE TRANSITION TABLE .................................. ................................. 225
EXAMPLE 7.4 SOLVING FOR THE NUMBER OF BITS NEEDED FOR BINARY STATE ENCODING ........................... .......................... 227
EXAMPLE 7.5 PUSH-BUTTON WINDOW CONTROLLER – STATE ENCODING ....................................... ....................................... 229
EXAMPLE 7.6 PUSH-BUTTON WINDOW CONTROLLER – NEXT STATE LOGIC ...................................... ..................................... 230
EXAMPLE 7.7 PUSH-BUTTON WINDOW CONTROLLER – OUTPUT LOGIC ......................................... ........................................ 231
EXAMPLE 7.8 PUSH-BUTTON WINDOW CONTROLLER – LOGIC DIAGRAM ........................................ ....................................... 232
EXAMPLE 7.9 SERIAL BIT SEQUENCE DETECTOR (PART 1) ................................................ ................................................ 234
EXAMPLE 7.10 SERIAL BIT SEQUENCE DETECTOR (PART 2) ............................................... ............................................... 235
EXAMPLE 7.11 SERIAL BIT SEQUENCE DETECTOR (PART 3) ............................................... ............................................... 236
EXAMPLE 7.12 VENDING MACHINE CONTROLLER (PART 1) ................................................ ............................................... 237
EXAMPLE 7.13 VENDING MACHINE CONTROLLER (PART 2) ................................................ ............................................... 238
EXAMPLE 7.14 VENDING MACHINE CONTROLLER (PART 3) ................................................ ............................................... 239
EXAMPLE 7.15 2-BIT BINARY UP COUNTER (PART 1) .................................................... ................................................... 241
Appendix A: List of Worked Examples • 451
EXAMPLE 9.25 REGISTERS AS AGENTS ON A DATA BUS – SYSTEM TOPOLOGY ................................... .................................. 324
EXAMPLE 9.26 REGISTERS AS AGENTS ON A DATA BUS – RTL MODEL IN VERILOG .............................. .............................. 324
EXAMPLE 9.27 REGISTERS AS AGENTS ON A DATA BUS – SIMULATION WAVEFORM ................................ ............................... 325
EXAMPLE 9.28 RTL MODEL OF A 4-STAGE, 8-BIT SHIFT REGISTER IN VERILOG ................................. ................................. 326
EXAMPLE 10.1 CALCULATING THE FINAL DIGIT LINE VOLTAGE IN A DRAM BASED ON CHARGE SHARING ................. ................ 348
EXAMPLE 10.2 BEHAVIORAL MODELS OF A 4 4 ASYNCHRONOUS READ ONLY MEMORY IN VERILOG ................... .................. 352
EXAMPLE 10.3 BEHAVIORAL MODELS OF A 4 4 SYNCHRONOUS READ ONLY MEMORY IN VERILOG .................... ................... 353
EXAMPLE 10.4 BEHAVIORAL MODEL OF A 4 4 ASYNCHRONOUS READ/WRITE MEMORY IN VERILOG ................... .................. 354
EXAMPLE 10.5 BEHAVIORAL MODEL OF A 4 4 SYNCHRONOUS READ/WRITE MEMORY IN VERILOG .................... ................... 355
EXAMPLE 12.1 DESIGN OF A HALF ADDER ........................................................... ........................................................... 374
EXAMPLE 12.2 DESIGN OF A FULL ADDER ........................................................... ........................................................... 374
EXAMPLE 12.3 DESIGN OF A FULL ADDER OUT OF HALF ADDERS ............................................ ........................................... 376
EXAMPLE 12.4 DESIGN OF A 4-BIT RIPPLE CARRY ADDER (RCA) ........................................... .......................................... 377
EXAMPLE 12.5 TIMING ANALYSIS OF A 4-BIT RIPPLE CARRY ADDER .......................................... .......................................... 378
EXAMPLE 12.6 DESIGN OF A 4-BIT CARRY LOOK AHEAD ADDER (CLA) – OVERVIEW .............................. ............................. 379
EXAMPLE 12.7 DESIGN OF A 4-BIT CARRY LOOK AHEAD ADDER (CLA) – ALGEBRAIC FORMATION ..................... ..................... 380
EXAMPLE 12.8 TIMING ANALYSIS OF A 4-BIT CARRY LOOK AHEAD ADDER ...................................... ...................................... 381
EXAMPLE 12.9 STRUCTURAL MODEL OF A FULL ADDER USING TWO HALF ADDERS IN VERILOG ........................ ....................... 382
EXAMPLE 12.10 STRUCTURAL MODEL OF A 4-BIT RIPPLE CARRY ADDER IN VERILOG .............................. .............................. 383
EXAMPLE 12.11 TEST BENCH FOR A 4-BIT RIPPLE CARRY ADDER USING NESTED FOR LOOPS IN VERILOG ................ ............... 384
EXAMPLE 12.12 STRUCTURAL MODEL OF A 4-BIT CARRY LOOK AHEAD ADDER IN VERILOG .......................... ......................... 385
EXAMPLE 12.13 4-BIT CARRY LOOK AHEAD ADDER – SIMULATION WAVEFORM .................................. ................................. 385
EXAMPLE 12.14 BEHAVIORAL MODEL OF A 4-BIT ADDER IN VERILOG ......................................... ........................................ 386
EXAMPLE 12.15 DESIGN OF A 4-BIT SUBTRACTOR USING FULL ADDERS ....................................... ...................................... 387
EXAMPLE 12.16 CREATING A PROGRAMMABLE INVERTER USING AN XOR GATE ................................. ................................. 387
EXAMPLE 12.17 DESIGN OF A 4-BIT PROGRAMMABLE ADDER/SUBTRACTOR ..................................... .................................... 388
EXAMPLE 12.18 PERFORMING LONG MULTIPLICATION ON DECIMAL NUMBERS .................................... ................................... 389
EXAMPLE 12.19 PERFORMING LONG MULTIPLICATION ON BINARY NUMBERS ..................................... .................................... 390
EXAMPLE 12.20 DESIGN OF A SINGLE-BIT MULTIPLIER ................................................... ................................................... 390
EXAMPLE 12.21 DESIGN OF A 4-BIT UNSIGNED MULTIPLIER ............................................... ............................................... 391
EXAMPLE 12.22 TIMING ANALYSIS OF A 4-BIT UNSIGNED MULTIPLIER ......................................... ......................................... 392
EXAMPLE 12.23 MULTIPLYING AN UNSIGNED BINARY NUMBER BY TWO USING A LOGICAL SHIFT LEFT .................... ................... 392
EXAMPLE 12.24 ILLUSTRATING HOW AN UNSIGNED MULTIPLIER INCORRECTLY HANDLES SIGNED NUMBERS ................ ................ 393
EXAMPLE 12.25 PROCESS TO CORRECTLY HANDLE SIGNED NUMBERS USING AN UNSIGNED MULTIPLIER .................. ................. 394
EXAMPLE 12.26 PERFORMING LONG DIVISION ON DECIMAL NUMBERS ......................................... ........................................ 395
EXAMPLE 12.27 PERFORMING LONG MULTIPLICATION ON BINARY NUMBERS ..................................... .................................... 396
EXAMPLE 12.28 DESIGN OF A 4-BIT UNSIGNED DIVIDER USING A SERIES OF ITERATIVE SUBTRACTORS .................. .................. 397
EXAMPLE 12.29 DIVIDING 11112 (1510) BY 01112 (710) USING THE ITERATIVE SUBTRACTION ARCHITECTURE ............ ............ 398
EXAMPLE 12.30 DIVIDING AN UNSIGNED BINARY NUMBERS BY TWO USING A LOGICAL SHIFT RIGHT ..................... .................... 399
EXAMPLE 13.1 MEMORY MAP FOR A 256 8 MEMORY SYSTEM ........................................... ........................................... 408
EXAMPLE 13.2 EXECUTION OF AN INSTRUCTION TO “LOAD REGISTER A USING IMMEDIATE ADDRESSING” ................................... 411
EXAMPLE 13.3 EXECUTION OF AN INSTRUCTION TO “LOAD REGISTER A USING DIRECT ADDRESSING” ................... ................... 412
EXAMPLE 13.4 EXECUTION OF AN INSTRUCTION TO “STORE REGISTER A USING DIRECT ADDRESSING” .................. .................. 413
EXAMPLE 13.5 EXECUTION OF AN INSTRUCTION TO “ADD REGISTERS A AND B” ................................. ................................. 414
EXAMPLE 13.6 EXECUTION OF AN INSTRUCTION TO “BRANCH ALWAYS” ........................................ ....................................... 415
EXAMPLE 13.7 EXECUTION OF AN INSTRUCTION TO “BRANCH IF EQUAL TO ZERO” ................................ ................................ 416
EXAMPLE 13.8 TOP LEVEL BLOCK DIAGRAM FOR THE 8-BIT COMPUTER SYSTEM ................................. ................................. 418
EXAMPLE 13.9 INSTRUCTION SET FOR THE 8-BIT COMPUTER SYSTEM ......................................... ........................................ 419
EXAMPLE 13.10 MEMORY SYSTEM BLOCK DIAGRAM FOR THE 8-BIT COMPUTER SYSTEM ............................ ........................... 420
EXAMPLE 13.11 CPU BLOCK DIAGRAM FOR THE 8-BIT COMPUTER SYSTEM .................................... .................................... 424
EXAMPLE 13.12 STATE DIAGRAM FOR LDA_IMM ..................................................... ..................................................... 431
EXAMPLE 13.13 SIMULATION WAVEFORM FOR LDA_IMM ................................................ ................................................ 432
EXAMPLE 13.14 STATE DIAGRAM FOR LDA_DIR ...................................................... ..................................................... 433
EXAMPLE 13.15 SIMULATION WAVEFORM FOR LDA_DIR ................................................ ................................................ 434
EXAMPLE 13.16 STATE DIAGRAM FOR STA_DIR ...................................................... ..................................................... 435
Appendix A: List of Worked Examples • 453