Computer Engineering - Hardware Design
Computer Engineering - Hardware Design
https://archive.org/details/computerengineerOOOOmano
COMPUTER
ENGINEERING:
Hardware Design
M. Morris Mano
Professor of Engineering
California State University, Los Angeles
PRENTICE
HALL
Englewood Cliffs, New Jersey 07632
t
Library of Congress Cataloging-in-Publication Data
Mano, M. Morris
Computer engineering.
ISBN
Preface, ix
2 digital
CIRCUITS a
2- 1 Binary Logic and Gates 28
2-2 Boolean Algebra 32
2-3 Standard Forms 38
IV Contents
3 COMBINATIONAL
SYSTEMS 79
3-1 Introduction 79
3-2 Analysis Procedure 80
3-3 Design Procedure 83
3-4 Arithmetic Circuits 88
3-5 Decoders 96
3-6 Encoders 100
3-7 Multiplexers 103
3- 8 Standard Graphic Symbols 108
References 115
Problems 116
SEQUENTIAL
LOGIC 120
4- 1 Introduction 120
4-2 Latches 122
4-3 Flip-Flops 126
4-4 Analysis Procedure 133
4-5 Design with D Flip-Flops 138
4-6 Design with JK Flip-Flops 144
References 148
Problems 148
5 REGISTERS
AND COUNTERS m
5-1 Introduction 152
5-2 Registers 153
5-3 Shift Registers 156
5-4 Shift Register with Parallel Load 160
5-5 Ripple Counter 165
5-6 Synchronous Binary Counters 170
Contents V
6 MEMORY
AND PROGRAMMABLE
LOGIC i86
6- 1 Introduction 186
6-2 Random-Access Memory (RAM) 187
6-3 Memory Decoding 193
6-4 Error Detection and Correction 199
6-5 Read-Only Memory (ROM) 202
6-6 Programmable Logic Device (PLD) 207
6-7 Programmable Logic Array (PLA) 209
6- 8 Programmable Array Logic (PAL) 213
References 216
Problems 217
7 REGISTER TRANSFER
AND COMPUTER OPERATIONS 220
7- 1 Introduction 220
7-2 Register Transfer 222
7-3 Microoperations 225
7-4 Bus Transfer 232
7-5 Processor Unit 238
7-6 Arithmetic Logic Unit (ALU) 240
7-7 Shifter Unit 246
7- 8 Control Word 248
References 252
Problems 252
S CONTROL
LOGIC DESIGN 257
8- 1 Introduction 257
8-2 Microprogrammed Control 258
8-3 Control of Processor Unit 260
8-4 Microprogram Examples 266
8-5 Design Example: Binary Multiplier 270
8-6 Hardwired Control for Multiplier 274
VI Contents
9 COMPUTER INSTRUCTIONS
AND ADDRESSING MODES 2*
9-1 Introduction 296
9-2 Address Field 297
9-3 Addressing Modes 300
9-4 Stack Organization 306
9-5 Data Transfer Instructions 311
9-6 Data Manipulation Instructions 313
9-7 Floating-Point Operations 317
9-8 Program Control Instructions 321
9-9 Program Interrupt 326
References 329
Problems 330
tO DESIGN
OF A CENTRAL
PROCESSING UNIT (CPU) 333
// INPUT-OUTPUT
AND COMMUNICATION 37,
11-1 Introduction 378
11-2 Input-Output Interface 379
Contents VII
t2 MEMORY
MANAGEMENT 409
12- 1 Memory Hierarchy 409
12-2 Pipeline Processing 411
12-3 Associative Memory 415
12-4 Cache Memory 418
12-5 Virtual Memory Management 422
References 425
Problems 425
INDEX 427
'
PREFACE
Computer and Electrical Engineering programs include one or more courses that
provide an understanding of the hardware design of digital systems and digital
computers. Computer Science curricula introduce similar courses that deal with
basic digital systems and computer organization. This book covers all aspects of
computer hardware engineering from basic digital circuits to the structure of a
complete computer system. It introduces the principles of computer hardware and
provides the concepts needed to analyze and design digital systems.
The material covered in the book can be divided into three parts. The first four
chapters deal with digital circuits from the gate and flip-flop level and present the
analysis and design of combinational and sequential circuits. The next four chapters
introduce digital design from the register transfer level. The various components
of a computer processor unit are detailed and the design of control logic is described
using the hardwire and microprogram methods. The last four chapters focus on
the hardware components of the digital computer. A central processing unit (CPU)
is designed using a microprogrammed control. Input and output procedures are
presented together with the hardware associated with virtual memory management.
The book covers the material recommended by the IEEE Computer Society
Model Program in Computer Science and Engineering subject area 6 (logic design)
and subject area 7 (digital systems design). It also conforms with most of the subjects
listed in course CS4, introduction to computer organization, in the ACM Curric¬
ulum Recommendations for the Undergraduate Program in Computer Science.
Often used digital components are available commercially in integrated circuits
and are classified as MSI (medium scale integration) circuits. Standard graphic
symbols have been developed for these components so that the user can recognize
IX
each function from the unique graphic symbol assigned to it. This standard, known
as ANSI/IEEE Std. 91-1984, has been adopted by industry, government, and
professional organizations. The best time to learn the standard symbols is when
learning about digital systems. They are introduced throughout the book at the
same time that the operation of the corresponding components are explained.
The sequence in which the material is presented provides an orderly and logical
transition from the basic ideas of representing binary information to the concepts
of complex computer operations. Chapter 1 presents various binary systems suitable
for representing information in digital components. The binary number system is
explained and binary codes are illustrated to show the representation of decimal
and alphanumeric information. Chapter 2 introduces Boolean algebra and the map
simplification of Boolean functions. The characteristics of digital logic gates are
presented together with various possible implementations of digital logic circuits.
Chapter 3 provides procedures for the analysis and design of combinational
circuits. Often used digital components such as adders, decoders, and multiplexers
are analyzed and their internal construction explained. The standard graphic sym¬
bols are introduced in this chapter. However, the standard graphic symbols for
components covered in subsequent chapters are shown later. Chapter 4 presents
various types of flip-flops and outlines formal procedures for the analysis and design
of sequential circuits.
Chapter 5 presents various sequential digital components such as registers, shift
registers, and counters. These digital components are the basic building blocks
from which digital computers and other digital systems are constructed. Chapter
6 deals with the memory unit and programmable logic devices such as PROM,
PLA, and PAL. These components are very useful in the design and construction
of complex digital circuits.
Chapter 7 introduces the register transfer method of describing digital systems.
Symbols are defined for arithmetic, logic, and shift microoperations. An arithmetic
logic unit is designed and a typical processor unit is developed. Chapter 8 presents
methods of control logic design. Examples are given to show how the design
algorithm is developed from which we proceed to show the procedure for obtaining
the control subsystem. The chapter concludes with the design of a simple computer
with a hardwired control unit.
Chapter 9 enumerates the most common instructions found in a typical computer
together with explanations of their function. Various instruction formats are illus¬
trated and typical addressing modes are presented in preparation for the design
undertaken in the next chapter.
Chapter 10 is devoted to the design of a central processing unit (CPU). The
registers of the system are defined and the computer instruction formats are spec¬
ified. A microprogrammed control unit is developed together with the micro¬
instruction formats. Some examples of microprogram routines for typical instruc¬
tions with different addressing modes are presented. The chapter provides enough
information for the hardware and firmware construction of the CPU.
Chapter 11 discusses the requirements of an interface between the processor
and input or output devices. Various modes of transfer are explained including
synchronous and asynchronous serial transfer, direct memory access, and priority
interrupt. Chapter 12 introduces the concept of memory hierarchy, composed of
Preface XI
M. Morris Mano
/
BINARY
NUMBERS
AND CODES
Digital computers occupy a prominent place in modern society. They have con¬
tributed to many scientific, industrial, and commercial developments that would
have been unattainable otherwise. Computers are used in home entertainment,
medical treatment, weather prediction, space exploration, air traffic control, sci¬
entific calculations, business data processing, and numerous other fields of en¬
deavor. The most striking property of the digital computer is its generality. It can
follow a sequence of instruction, called a program, that operates on given data.
The user can specify and change the program or the data according to specific
needs. As a result of this flexibility, general purpose digital computers can perform
a variety of information processing tasks that range over a wide spectrum of ap¬
plications.
The general purpose digital computer is the best-known example of a digital
system. Characteristic of a digital system is its manipulation of discrete elements of
information. Discrete information is contained in any set that is restricted to a
finite number of elements. Examples of discrete quantities are the 10 decimal digits,
the 26 letters of the alphabet, the 52 playing cards, and the 64 squares of a chess¬
board. Early digital computers were used mostly for numeric computations. In this
case the discrete elements used are the digits. From this application, the term digital
computer has emerged.
Discrete elements of information are represented in a digital system by physical
quantities called signals. Electrical signals such as voltages and currents are the
most common. The signals in all present-day electronic digital systems have only
two discrete values and are said to be binary. The digital system designer is restricted
1
2 Chapter 1 Binary Numbers and Codes
to the use of binary signals because of the low reliability encountered in many¬
valued electronic circuits. In other words, a circuit with ten states, using one discrete
voltage value for each state, can be designed, but it would possess a very low
reliability of operation. In contrast, a transistor circuit that is either on or off has
two possible signal values and can be constructed with extreme reliability. Because
of this physical restriction of electronic components, and because human logic tends
to be binary (true or false, yes or no), digital systems that are constrained to take
discrete values are further constrained to take binary values.
Digital computers use the binary number system that has two digits: 0 and 1.
A binary digit is called a bit. Information is represented in digital computers in
groups of bits. By using various coding techniques, groups of bits can be made to
represent not only binary numbers but also any other group of discrete symbols.
By judicious use of binary arrangements to form binary codes, the group of bits
are used to develop complete sets of instructions for performing computations on
'^rious types of data.
Discrete quantities of information emerge either from the nature of the process
or may be purposely quantized from a continuous process. For example, a payroll
schedule is an inherently discrete process that contains employee names, social
security numbers, weekly salaries, income taxes, and so on. An employee’s pay-
check is processed using discrete data values such as letters of the alphabet (name),
digits (salary), and special symbols like $. On the other hand, a research scientist
may observe a process that continuously varies with time but record only specific
quantities in tabular form. The scientist is thus quantizing the continuous data,
making each number in the table a discrete quantity of information.
To simulate a process in a digital computer, the quantities must be quantized.
When the variables of the process are presented by continuous real-time signals,
the signals are quantized by an analog-to-digital conversion device. A system whose
behavior may be described with mathematical equations is simulated in a digital
computer by means of numerical analysis methods that formulate the mathematical
equations with a series of discrete numerical quantities. When the problem to be
processed is inherently discrete, as in commercial or business applications, the
digital computer manipulates the variables in their original form.
A block diagram of the digital computer is shown in Figure 1-1. The memory
unit stores programs as well as input, output, and intermediate data. The processor
unit performs arithmetic and other data-processing operations as specified by the
program. The control unit supervises the flow of information between the various
units. A processor, when combined with the control unit, forms a component
referred to as a central processing unit or CPU. A CPU enclosed in a small integrated
circuit package is called a microprocessor.
The program and data prepared by the user are transferred into the memory
unit by means of an input device such as a keyboard. An output device, such as a
printer, receives the results of the computations, and the printed results are pre¬
sented to the user. A digital computer can accommodate many different input and
output devices. These devices are special digital systems driven by electromechan¬
ical parts and controlled by electronic digital circuits.
The control unit in the CPU retrieves the instructions, one by one, from the
program stored in the memory unit. For each instruction, the control unit informs
Section 1-2 Number Systems 3
FIGURE 1-1
Block Diagram of a Digital Computer
the processor to execute the operation specified by the instruction. Both program
and data are stored in memory. The control unit supervises the program instruc¬
tions, and the processor unit manipulates the data as specified by the program. A
digital computer is a powerful instrument. It can perform arithmetic computations
as well as logical operations and can be programmed to make decisions based on
internal and external conditions.
A digital computer is an interconnection of digital modules. To understand the
operation of each digital module, it is necessary to have a basic knowledge of digital
systems and their general behavior. The first half of the book deals with digital
systems in general to provide the background necessary for their design and analysis.
The second half of the book discusses the various components of the digital com¬
puter, their operation, and design. The operational characteristics of the memory
unit are explained in Chapter 6. The organization and design of the processor unit
are discussed in Chapter 7. Methods for designing the control unit are introduced
in Chapter 8. Some typical instructions employed in digital computers are presented
in Chapter 9. The organization and design of a typical central processing unit is
presented in Chapter 10. The various ways that a CPU can communicate with input
and output devices is discussed in Chapter 11. Memory management concepts are
introduced in Chapter 12.
It has been mentioned that a digital computer manipulates discrete elements of
information and that all information in the computer is represented in binary form.
Operands used for calculations may be expressed in the binary number system, or
in the decimal system, by means of a binary code. The letters of the alphabet are
also converted into a binary code. The purpose of this chapter is to introduce the
binary number system and the various binary codes as a frame of reference for
further study in the succeeding chapters.
is interpreted to represent 7 hundreds plus 2 tens plus 4 units plus 5 tenths. The
hundreds, tens, units, and tenths are powers of 10 implied by the position of the
digits. The value of the number is computed as follows:
724.5 - 7 x 102 + 2 x 101 + 4 x 10° + 5 x 10-1
The convention is to write only the digits and deduce the corresponding powers
of 10 from their positions. In general, a decimal number with a decimal point is
represented by a string of coefficients:
When the number is expressed in positional notation, only the coefficients and the
radix point are written down:
AnAn- i . . . A(A() . A_iT_2 • • •
Binary Numbers
The binary number system is a base 2 system with two digits: 0 and 1. A binary
number is expressed with a string of l’s and 0’s and a possible binary point such
as 11010.11. The decimal equivalent of a binary number can be found by expanding
it to a power series with a base of 2. For example
TABLE 1-1
Powers of Two
n 2n n 2" n 2n
0 1 8 256 16 65,536
1 2 9 512 17 131,072
2 4 10 1,024 18 262,144
3 8 11 2,048 19 524,288
4 16 12 4,096 20 1,048,576
5 32 13 8,192 21 2,097,152
6 64 14 16,384 22 4,194,304
7 128 15 32,768 23 8,388,608
As noted earlier, the digits in a binary number are called bits. When a bit is equal
to 0, it does not contribute to the sum during the conversion. Therefore, the
conversion to decimal can be obtained by adding the numbers with powers of two
corresponding to the bits that are equal to 1. For example
The first 21 numbers obtained from 2 to the power of n are listed in Table 1-1. In
computer work, 210 is referred to as K (Kilo), 220 as M (Mega), and 230 as G (Giga).
Thus 4K = 4096 and 16M = 224 - 16,777,216.
The conversion of a decimal number to binary can be easily achieved by a method
that successively subtracts powers of two from the decimal number. To convert the
decimal number N to binary, first find the greatest number from Table 1-1 that
can be subtracted from N and produce a positive difference. Let the difference be
designated by Nv Find another number from Table 1-1 that can be subtracted from
and produce a positive difference N2. Continue this procedure until the differ¬
ence is zero. In this way, the decimal number is converted to its powers-of-two
components. The equivalent binary number is obtained from the power series that
forms the sum of the components. This method is demonstrated below, by the
conversion of decimal 625 to binary.
(625)10 - 29 + 26 + 25 + 24 + 2° (1001110001)2
Note that all the subtractions can be done quickly using a calculator.
The first 16 numbers in the decimal, binary, octal, and hexadecimal number
systems are listed in Table 1-2. Note that the sequence of binary numbers follows
a prescribed pattern: the first significant bit alternates between 0 and 1, the second
significant bit alternates between two 0’s and two l’s, the third significant bit
alternates between four 0’s and four l’s, and the fourth alternates between eight
0’s and eight l’s.
As previously mentioned, all computers and digital systems use the binary rep¬
resentation. The octal and hexadecimal systems are useful for representing binary
quantities indirectly because they possess the property that their bases are powers
of two. Since 23 = 8 and 24 = 16, each octal digit corresponds to three binary
digits and each hexadecimal digit corresponds to four binary digits. The conversion
from binary to octal is easily accomplished by partitioning the binary number into
groups of three digits each, starting from the binary point and proceeding to the
left and to the right. The corresponding octal digit is then assigned to each group.
The following example illustrates the procedure:
TABLE 1-2
Numbers with Different Bases
00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 mi 17 F
Section 1-3 Arithmetic Operations 7
(010 110 001 101 Oil. Ill 100 000 110)2 = (26153.7406)8
The corresponding octal digit for each group of three bits is obtained from the first
eight entries in Table 1-2. Note that 0’s can be freely added to the left or right to
make the total number of bits a multiple of three.
Conversion from binary to hexadecimal is similar, except that the binary number
is divided into groups of four digits. The previous binary number is converted to
hexadecimal as follows:
The corresponding hexadecimal digit for each group of four bits is listed in Table
1-2.
Conversion from octal or hexadecimal to binary is done by a procedure reverse
to that above. Each octal digit is converted to a three-digit binary equivalent.
Similarly, each hexadecimal digit is converted to its four-digit binary equivalent.
This is illustrated in the following examples:
Most computer manuals use either octal or hexadecimal numbers to specify the
binary quantities in the machine. A group of 15 bits, for example, can be repre¬
sented in the octal system with only five digits in the range of 0 to 77777. A group
of 16 bits can be represented in hexadecimal with four digits in the range from 0
to FFFF. The choice between octal or hexadecimal representation of binary num¬
bers is arbitrary and is determined from the particular computer manual. During
communication between people (about binary quantities in the computer) the octal
or hexadecimal equivalent representation is more convenient because the numbers
can be expressed more compactly with a third or fourth of the number of digits.
When communicating with the computer, through console switches or by means
of a machine language program, the conversion from octal or hexadecimal to binary
(and vice versa) is done easily by the grouping of bits method.
The sum of two binary numbers is calculated following the same rules as for decimal
numbers, except that the digit of the sum in any significant position can be only 1
or 0. Any carry obtained in a given column is used by the digits in the column one
significant position higher. The rules for subtraction are the same as in decimal,
except that a borrow from a given column adds two to the minuend digit. (A borrow
in the decimal system adds 10 to a minuend digit.) Multiplication is very simple.
The multiplier digits are always 1 or 0. Therefore, the partial products are equal
either to the multiplicand or to 0.
Arithmetic operations with octal, hexadecimal, or any other base r system will
normally require the formulation of tables from which one obtains sums and prod¬
ucts of two digits in base r. An easier alternative for adding two numbers in base
r is to convert each pair of digits in a column to decimal, add the digits in decimal,
and then convert the result to the corresponding sum and carry in the base r system.
Since addition is done in decimal, we can rely on our memories for obtaining the
entries from the familiar decimal addition table. The sequence of steps for adding
the two hexadecimal numbers 59F and E46 is shown in Example 1-1.
1
5 9 F 5 9 15
E 4 6 14 4 6
1 3 E 5 19 16 + 3 14 21 = 16 + 5
The equivalent decimal columns show the mental reasoning that must be carried
out in order to produce the hexadecimal sum. Instead of adding F + 6 in hexa¬
decimal, we add the equivalent decimals 15 + 6 = 21. We then convert back to
hexadecimal by noting that 21 = 16 + 5. This gives a sum digit of 5 and a carry
to the next higher order column digits. The other two columns are added in a
similar fashion.
The multiplication of two base r numbers can be accomplished by doing all the
arithmetic operations in decimal and converting intermediate results one at a time.
This is illustrated in the multiplication of two octal numbers as shown in Example
1-2.
7 6 2 5 x2 10 =- 8 ■+ :2 12
4 5 5 x 6 +1 31 == 24 + 7 37
4672 5x7 + 3 38 =- 32 + 6 46
3 7 1 0 4 x2 8 = = 8 ■+ i 0 10
4 3 7 7 2 4x6+1 25 =- 24 + 1 31
4x7 + 3 31 -= 24 + 7 37
Section 1-3 Arithmetic Operations 9
The computations on the right show the mental calculations for each pair of octal
digits. The octal digits 0 through 7 have the same value as their corresponding
decimal digits. The multiplication of two octal digits plus a carry, if present, is
done in decimal and the result then converted back to octal. The left digit of the
two-digit octal result gives the carry that must be added to the next product. For
example, (5 x 2)8 = (12)8. The left digit, 1, is the carry to be added to the product
(5 x 6)8, and the least significant digit, 2, is the corresponding digit of the octal
partial product. ■
Note that the first remainder gives the least significant digit of the converted
number, and that the quotients are divided by r until the result is 0. We also can
use this procedure to convert decimal numbers to binary. In this case, the base of
the converted number is 2 and therefore, all the divisions must be done by 2.
Of course, the decimal number could be converted by the sum of powers of two.
(41)10 = 32 + 8 + 1 - (101001)2
Note that the first integer produces the first and most significant bit of the fraction.
In this example, there are a finite number of digits in the converted number. The
process of multiplying fractions by r does not necessarily end with zero so we must
decide on how many digits of the fraction to use from the conversion. Also re¬
member that the multiplying number is equal to r. Therefore, to convert a decimal
fraction to octal, we must multiply the fractions by 8.
The answer to five significant figures is obtained from the integer digits: (0.513) 10
- (0.40651)8 ■
The conversion of decimal numbers with both integer and fractional parts is
done by converting each part separately and then combining the two answers.
Using the results of Examples 1-3 and 1-6 we obtain
(153.513)10 = (231.40651)8
Section 1-4 Complements 11
1-4 COMPLEMENTS
Complements are used in digital computers for simplifying the subtraction operation
and for logical manipulation. There are two types of complements for each base r
system: 1. the radix complement and 2. the diminished radix complement. The
first is referred to as the f s complement and the second as the (r - l)’s complement.
When the value of the base r is substituted in the name, the two types are referred
to as the 2’s and l’s complements for binary numbers and the 10’s and 9’s com¬
plements for decimal numbers.
Radix Complement
The r s complement of an n-digit number N in base r is defined as rn — N for
jV ^ 0 and 0 for N = 0. Comparing with the (r - l)’s complement we note that
the r’s complement is obtained by adding 1 to the (r — l)’s complement since
rn — N = \{rn — 1) — N] + 1. Thus, the 10’s complement of the decimal 2389
is 7610 + 1 = 7611 and is obtained by adding 1 to the 9’s complement value. The
2’s complement of binary 101100 is 010011 + 1 = 010100 and is obtained by adding
1 to the l’s complement value.
12 Chapter 1 Binary Numbers and Codes
1. Add the minuend M to the r’s complement of the subtrahend N. This performs
M + (r" - N) = M - N + r".
2. If M > N, the sum will produce an end carry, r", which is discarded; what
is left is the result M — N.
3. If M < N, the sum does not produce an end carry and is equal to r" —
(N - M) which is the r’s complement of (N — M). To obtain the answer in
a familiar form, take the r’s complement of the sum and place a negative sign
in front.
M = 72532
10’s complement of N = + 96750
Sum = 169282
Discard end carry 105 = -100000
Answer = 69282
Section 1-4 Complements 13
Note that M has 5 digits and N has only 4 digits. Both numbers must have the
same number of digits; so we write N as 03250. Taking the 10’s complement of N
produces a 9 in the most significant position. The occurrence of the end carry
signifies that M > N and the result is positive.
M = 03250
10’s complement of N = + 27468
Sum = 30718
Note that since 3250 < 72532, the result is negative. Since we are dealing with
unsigned numbers, there is no way to get an unsigned result for this case. When
working with paper and pencil, we recognize that the answer must be changed to
a signed negative number. When subtracting with complements, the negative an¬
swer is recognized by the absence of the end carry and the complemented result.
Subtraction with complements is done with binary numbers in a similar manner
using the same procedure outlined above.
Example 1-9 Given the two binary numbers X = 1010100 and Y = 1000011, perform the
subtraction X — Y and Y — X using 2’s complements.
X = 1010100
2’s complement of Y = + 0111101
Sum = 10010001
Discard end carry 27 = -10000000
Answer: X — Y = 0010001
Y = 1000011
2’s complement of X = + 0101100
Sum = 1101111
There is no end carry
X = 1010100
l’s complement of Y = + 0111100
Sum = r-10010000
End-around carry -- + 1
Answer: X — Y — 0010001
B. Y - X = Oil - 1010100
Y = 1000011
l’s complement of X = + 0101011
Sum = 1101110
There is no end carry
Note that the negative result is obtained by taking the l’s complement of the sum
since this is the type of complement used. The procedure with end-around carry
is also applicable for subtracting unsigned decimal numbers with 9’s complement.
TABLE 1-3
Signed Binary Numbers
positive numbers in all three representations are identical and have 0 in the leftmost
position. The signed-2’s complement system has only one representation for 0 and
is always positive. The other two systems have a positive 0 and a negative 0, which
is something not encountered in ordinary arithmetic. Note that all negative numbers
have a 1 in the leftmost bit position; this is the way we distinguish them from
positive numbers. With four bits we can represent 16 binary numbers. In the signed-
magnitude and the l’s complement representations, there are eight positive num¬
bers and eight negative numbers, including two zeros. In the 2’s complement
representation, there are eight positive numbers including one zero, and eight
negative numbers.
The signed-magnitude system is used in ordinary arithmetic but is awkward when
employed in computer arithmetic. Therefore, the signed-complement is normally
used. The l’s complement imposes difficulties because of its two representations
of 0 and is seldom used for arithmetic operations except in some older computers.
The l’s complement is useful as a logical operation since the change of 1 to 0 or
0 to 1 is equivalent to a logical complement operation, as will be shown in the next
chapter. The following discussion of signed binary arithmetic deals exclusively with
the signed-2’s complement representation of negative numbers. The same proce¬
dures can be applied to the signed-l’s complement system by including the end-
around carry as done with unsigned numbers.
Arithmetic Addition
The addition of two numbers in the signed-magnitude system follows the rules of
ordinary arithmetic: If the signs are the same, we add the two magnitudes and give
the sum the common sign. If the signs are different, we subtract the smaller mag¬
nitude from the larger and give the result the sign of the larger magnitude. For
example, ( + 25) + (-37) = — (37 — 25) = —12 and is done by subtracting the
smaller magnitude 25 from the larger magnitude 37 and using the sign of 37 for
the sign of the result. This is a process that requires the comparison of the signs
and the magnitudes and then performing either addition or subtraction. The same
procedure applies to binary numbers in sign and magnitude representation. In
contrast, the rule for adding numbers in the signed-complement system does not
require a comparison or subtraction, but only addition. The procedure is very
simple and can be stated as follows for binary numbers. (Decimal numbers are
considered in the next section.)
The addition of two signed binary numbers with negative numbers represented in
signed-2’s complement form is obtained from the addition of the two numbers including
their sign bits. A carry out of the sign bit position is discarded.
Numerical examples for addition are shown below. Note that negative numbers
must be initially in 2’s complement and that the sum obtained after the addition
if negative, is in 2’s complement form.
In each of the four cases, the operation performed is addition, including the sign
bits. Any carry out of the sign bit position is discarded, and negative results are
automatically in 2’s complement form.
In order to obtain a correct answer, we must ensure that the result has sufficient
number of bits to accommodate the sum. If we start with two n-bit numbers and
the sum occupies n + 1 bits, we say that an overflow occurs. When one performs
the addition with paper and pencil, an overflow is not a problem since we are not
limited by the width of the page. We just add another 0 to a positive number and
another 1 to a negative number, in the most significant position, to extend them
to n + 1 bits and then perform the addition. Overflow is a problem in computers
because the number of bits that hold a number is finite, and a result that exceeds
the finite value by 1 cannot be accommodated. Computer overflow is discussed in
Section 7-3.
The complement form of representing negative numbers is unfamiliar to people
used to the signed-magnitude system. To determine the value of a negative number
when in signed-2’s complement, it is necessary to convert it to a positive number
to place it in a more familiar form. For example, the signed binary number 11111001
is negative because the leftmost bit is 1. Its 2’s complement is 00000111 which is
the binary equivalent of +7. We therefore recognize the original number to be
equal to -7.
Arithmetic Subtraction
Subtraction of two signed binary numbers when negative numbers are in 2’s com¬
plement form is very simple and can be stated as follows:
Take the 2’s complement of the subtrahend (including the sign bit) and add it to the
minuend (including the sign bit). A carry out of the sign bit position is discarded.
This procedure stems from the fact that a subtraction operation can be changed
to an addition operation if the sign of the subtrahend is changed. This is demon¬
strated by the following relationship:
The binary number system is the most natural system for a computer, but people
are accustomed to the decimal system. One way to resolve this difference is to
convert the decimal numbers to binary, perform all arithmetic calculations in binary
and then convert the binary results back to decimal. This method requires that we
store the decimal numbers in the computer in a way that they can be converted to
binary. Since the computer can accept only binary values, we must represent the
decimal digits by a code that contains l’s and 0’s. It is also possible to perform the
arithmetic operations directly with decimal numbers when they are stored in the
computer in coded form.
A binary code is a group of n bits that assume up to 2n distinct combinations of
l’s and 0’s, with each combination representing one element of the set that is being
coded. A set of four elements can be coded with two bits with each element assigned
one of the following bit combinations: 00, 01, 10, 11. A set of eight elements
requires a 3-bit code and a set of 16 elements requires a 4-bit code. The bit
combination of an n-bit code is determined from the count in binary from 0 to
2n - 1. Each element must be assigned a unique binary bit combination and no
two elements can have the same value; otherwise, the code assignment will be
ambiguous.
A binary code will have some unassigned bit combinations if the number of
elements in the set is not a power of 2. The 10 decimal digits form such a set. A
binary code that distinguishes among 10 elements must contain at least four bits,
but six out of the 16 possible combinations will remain unassigned. Numerous
different binary codes can be obtained by arranging four bits in 10 distinct com¬
binations. The code most commonly used for the decimal digits is the straight
binary assignment as listed in Table 1-4. This is called binary coded decimal and
is commonly referred to as BCD. Other decimal codes are possible and a few of
them are presented later in this section.
Table 1-4 gives the 4-bit code for one decimal digit. A number with n decimal
digits will require 4n bits in BCD. Decimal 396 is represented in BCD with 12 bits
TABLE 1-4
Binary Coded Decimal
(BCD)
Decimal BCD
symbol digit
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
Section 1-6 Decimal Codes 19
as 0011 1001 0110, with each group of 4 bits representing one decimal digit. A
decimal number in BCD is the same as its equivalent binary number only when
the number is between 0 and 9. A BCD number greater than 9 looks different
from its equivalent binary number even though both contain l’s and 0’s. Moreover,
the binary combinations 1010 through 1111 are not used and have no meaning in
the BCD code. Consider decimal 185 and its corresponding value in BCD and
binary.
BCD Addition
Consider the addition of two decimal digits in BCD, together with a possible carry
from a previous less significant pair of digits. Since each digit does not exceed 9,
the sum cannot be greater than 9 + 9 + 1 = 19, the 1 being a carry. Suppose we
add the BCD digits as if they were binary numbers. The binary sum will produce
a result in the range from 0 to 19. In binary, this will be from 0000 to 10011 but
in BCD it should be from 0000 to 1 1001; the first 1 being a carry and the next
four bits being the BCD digit sum. When the binary sum is equal to or less than
1001 (without a carry), the corresponding BCD digit is correct. But when the binary
sum is greater or equal to 1010, the result is an invalid BCD digit. The addition
of binary 6, (0110)2, to the sum converts it to the correct digit and also produces
a carry as required. This is because the difference between a carry in the 24th
position of the binary sum and a decimal carry differ by 16 — 10 = 6. Consider
the following three BCD additions:
In each case, the two BCD digits are added as if they were two binary numbers.
If the binary sum is greater or equal to 1010, we add 0110 to obtain the correct
BCD digit sum and a carry. In the first example, the sum is equal to 9 and is the
correct BCD digit sum. In the second example, the binary sum produces an invalid
BCD digit. The addition of 0110 produces the correct BCD digit sum 0010 (2) and
20 Chapter 1 Binary Numbers and Codes
a carry. In the third example, the binary sum produces a carry. This condition
occurs when the sum is greater than or equal to 16. Even though the other four
bits are less than 1001, the binary sum requires a correction because of the carry.
Adding 0110, we obtain the required BCD digit sum 0111 (7) and a BCD carry.
The addition of two n-digit unsigned BCD numbers follows the same procedure.
ider the addition of 184 + 576 - 760 in BCD.
BCD carry 1 1
0001 1000 0100 184
+ 0101 0111 0110 + 576
Binary sum 0111 10000 1010
Add 6 0110 0110
BDC sum 0111 0110 0000 760
The first, least significant pair of BCD digits produce a BCD digit sum of 0000
and a carry for the next pair of digits. The second pair of BCD digits plus a previous
carry produce a digit sum of 0110 and a carry for the next pair of digits. The third
pair of digits plus a carry produce a binary sum of 0111 and does not require a
correction.
Decimal Arithmetic
The representation of signed decimal numbers in BCD is similar to the represen¬
tation of signed numbers in binary. We can either use the familiar signed-magnitude
system or the signed-complement system. The sign of a decimal number is usually
represented with four bits to conform with the 4-bit code of the decimal digits. It
is customary to designate a plus with four 0’s and a minus with the BCD equivalent
of 9 which is 1001.
The signed-magnitude system is difficult to use with computers. The signed-
complement system can be either the 9’s or the 10’s complement, but the 10’s
complement is the one most often used. To obtain the 10’s complement of a BCD
number, we take the 9’s complement and add one to the least significant digit. The
9’s complement is calculated by subtracting each digit from 9.
The procedures developed for the signed-2’s complement system in the previous
section also apply to the signed-lO’s complement system for decimal numbers.
Addition is done by adding all digits, including the sign digit, and discarding the
end carry. Obviously, this assumes that all negative numbers are in 10’s complement
form. Consider the addition ( + 375) + ( — 240) = +135 done in the signed-com¬
plement system.
0 375
+ 9 760
0 135
The 9 in the leftmost position of the second number represents a minus, and 9760
is the 10’s complement of 0240. The two numbers are added and the end carry is
discarded to obtain +135. Of course, the decimal numbers inside the computer
must be in BCD including the sign digits. The addition is done with BCD digits
as described previously.
Section 1-6 Decimal Codes 21
TABLE 1-5
Four Different Binary Codes for the Decimal Digits
Decimal BCD
digit 8421 2421 Excess-3 84-2-1
The 2421 and the excess-3 codes are examples of self-complementing codes. Such
codes have the property that the 9’s complement of a decimal number is obtained
directly by changing Ts to 0’s and 0’s to l’s in the code. For example, decimal 395
is represented in the excess-3 code as 0110 1100 1000. The 9’s complement (604)
is represented as 1001 0011 0111 which is simply obtained by complementing each
bit of the code (as with the l’s complement of binary numbers).
The excess-3 code has been used in some older computers because of its self¬
complementing property. It is an unweighted code where each coded combination
is obtained from the corresponding binary value plus 3. Note that the BCD code
is not self-complementing.
The 84-2-1 code is an example of assigning both positive and negative weights
to a decimal code. In this case, the bit combination 0110 is interpreted as a decimal
2 and is calculated from 8x0 + 4x1 + ( — 2) x 1 + ( —l)x0 = 2.
It is important to understand the difference between conversion of a decimal
number to binary and the binary coding of a decimal number. In each case the
final result is a string of bits. The bits obtained from conversion are binary digits.
The bits obtained from coding are combinations of l’s and 0’s arranged according
to the rules of the code used. Therefore, it is extremely important to realize that
a string of bits in a computer sometimes represents a binary number and at other
times string of bits represents other information as specified by a given binary code.
Many applications of digital computers require the handling of data not only of
numbers, but also of letters. For instance, an insurance company with thousands
of policy holders will use a computer to process its files. To represent the names
and other pertinent information, it is necessary to formulate a binary code for the
letters of the alphabet. In addition, the same binary code must represent numerals
and special characters like $. An alphanumeric character set is a set of elements
that include the 10 decimal digits, the 26 letters of the alphabet, and a number of
special characters. Such a set contains between 36 and 64 elements if only capital
letters are included, or between 64 and 128 elements if both upper- and lowercase
letters are included. In the first case we need a binary code of six bits, and in the
second we need a binary code of seven bits.
Binary codes play an important role in digital computers. The codes must be in
binary because computers can only hold l’s and 0’s. It must be realized that binary
codes merely change the symbols, not the meaning of the elements of information
that they represent. If we inspect the bits of a computer at random, we will find
that most of the time they represent some type of coded information rather than
binary numbers.
TABLE 1-6
American Standard Code for Information Interchange (ASCII)
b7b6b5
Control characters:
represented in ASCII as 1000001 (column 100, row 0001). The ASCII code contains
94 graphic characters that can be printed and 34 non-printing characters used for
various control functions. The graphic characters consist of the 26 uppercase letters
A through Z, the 26 lowercase letters, the 10 numerals 0 through 9, and 32 special
printable characters such as %, *, and $.
The 34 control characters are designated in the ASCII table with abbreviated
names. They are listed again below the table with their full functional names. The
control characters are used for routing data and arranging the printed text into a
24 Chapter 1 Binary Numbers and Codes
prescribed format. There are three types of control characters: format effectors,
information separators, and communication control characters. Format effectors
are characters that control the layout of printing. They include the familiar type¬
writer controls such as backspace (BS), horizontal tabulation (HT), and carriage
return (CR). Information separators are used to separate the data into divisions
like paragraphs and pages. They include characters like record separator (RS), and
file separator (FS). The communication control characters are useful during the
transmission of text between remote terminals. Examples of communication control
characters are STX (start of text) and ETX (end of text), which are used to frame
a text message when transmitted through telephone wires.
Parity Bit
ASCII is a 7-bit code, but most computers manipulate an 8-bit quantity as a single
unit called byte. Therefore, ASCII characters most often are stored one per byte,
with the most significant bit set to 0. The extra bit is sometimes used for specific
purposes, depending on the application. For example, some printers recognize an
additional 128 ASCII, 8-bit characters with the most significant bit set to 1. These
characters enable the printer to produce additional symbols such as the Greek
alphabet or italic type font.
When used for data communication, an eighth bit is sometimes used to indicate
the parity of the character. A parity bit is an extra bit included to make the total
number of l’s either even or odd. Consider the following two characters and their
even and odd parity.
In each case we use the extra bit in the leftmost position of the code to produce
an even number of l’s in the character for even parity or an odd number of l’s in
the character for odd parity. In general one parity or the other is adopted, with
even parity being more common.
The parity bit is helpful in detecting errors during the transmission of information
from one location to another. This is handled as follows: An even parity bit is
generated in the sending end for each character; the 8-bit characters that include
parity bits are transmitted to their destination; the parity of each character is then
checked at the receiving end; if the parity of the received character is not even, it
means that at least one bit has changed value during the transmission. This method
detects one, three or any odd number of errors in each character transmitted. An
even number of errors is undetected. Additional error detection codes may be
needed to take care of an even number of errors.
What is done after an error is detected depends on the particular application.
One possibility is to request retransmission of the message on the assumption that
the error was random and will not occur again. Thus, if the receiver detects a parity
error, it sends back an NAK (negative acknowledge) control character consisting
of an even-parity eight bits 10010101 (Table 1-6). If no error is detected, the receiver
Section 1-7 Alphanumeric Codes 25
sends back an ACK (acknowledge) control character 00000110. The sending end
will respond to an NAK by transmitting the message again until the correct parity
is received. If, after a number of attempts, the transmission is still in error, a
message can be sent to the operator to check for malfunctions in the transmission
path.
REFERENCES
PROBLEMS
1-1 List the binary, octal, and hexadecimal numbers from 16 to 31.
1-2 What is the exact number of bits in a system that contains (a) 32K bits; (b) 50K bits;
(c) 32M bits?
1 -3 What is the largest binary number that can be obtained with 16 bits? What is its decimal
equivalent?
1-4 Give the binary value of a 24-bit number with the hexademical equivalent of F3A7C2.
What is the octal equivalent of the binary number?
1-5 Convert the following binary numbers to decimal: 101110, 1110101.11, and 110110100.
1-6 Convert the following decimal numbers to binary: 1231, 673, 104, and 1998.
1-7 Convert the following numbers with the indicated bases to decimal: (12121)3, (4310)5,
and (198)12.
1-8 Convert the following numbers from the given base to the other three bases listed in
the table.
1-9 Add and multiply the following numbers without converting to decimal.
(a) (367)8 and (715)8 (b) (15F)16 and (A7)16 (c) (110110)2 and (110101)2
1-10 Convert the following decimal numbers to the indicated bases using the methods of
Examples 1-3 and 1-6.
(a) 7562.45 to octal (b) 1938.257 to hexadecimal (c) 175.175 to binary.
1-15 Perform the subtraction with the following unsigned decimal numbers by taking the
10’s complement of the subtrahend.
(a) 5250 - 1321 (b) 1753 - 8640 (c) 20 - 100 (d) 1200 - 250
1-16 Perform the subtraction with the following unsigned binary numbers by taking the 2’s
complement of the subtrahend.
(a) 11010 - 10000 (c) 100 - 110000
(b) 11010 - 1101 (d) 1010100 - 1010100
1-17 Perform the arithmetic operations ( + 42) + (-13) and (-42) - (-13) in binary
using signed-2’s complement representation for negative numbers.
1-18 The binary numbers listed below have a sign in the leftmost position and, if negative,
are in 2’s complement form. Perform the arithmetic operations indicated and verify
the answers.
(a) 101011 + 111000 (c) 111001 - 001010
(b) 001110 + 110010 (d) 101011 - 100110
1-19 Represent the following decimal numbers in BCD: 13597 (unsigned), + 9328, -0120
(in 10’s complement).
1-20 Represent the unsigned decimal numbers 831 and 793 in BCD and then show the steps
necessary to form their sum.
1-21 Convert the following decimal numbers into signed-lO’s complement form: -0950,
and -9028, then perform the following four additions with negative numbers in com¬
plement form.
(a) ( + 950) + ( + 9028) (c) (-950) + ( + 9028)
(b) ( + 950) + (-9028) (d) (-950) + (-9028)
1-22 Formulate a weighted binary code for the decimal digits using weights of 7, 4, 2, 1.
1-23 Represent the decimal number 8620 in (a) BCD, (b) excess-3 code (c) 2421 code,
and (d) as a binary number.
1-24 Represent the decimal 3864 in the 2421 code of Table 1-5. Show that the code is self¬
complementing by taking the 9’s complement.
1-25 Assign a binary code in some orderly manner to the 52 playing cards. Use the minimum
number of bits.
1-26 Write your full name in ASCII using an eight bit code with the leftmost bit always 0.
Include a space between names and a period after a middle initial.
1-27 Decode the following ASCII code: 1001010 1101111 1101000 1101110 0100000 1000100
1101111 1100101.
1-28 Show the bit configuration that represents the decimal number 295 (a) in binary,
(b) in BCD, (c) in ASCII.
1-29 List the ten BCD digits with an even parity in the leftmost position. (Total of five bits
per digit.) Repeat with an odd parity bit.
1-30 What bit must be complemented to change an ASCII letter from capital to lowercase,
and vice versa?
1-31 How many printing characters are there in ASCII? How many of them are not letters
or numerals?
DIGITAL
CIRCUITS
Binary Logic
Binary logic deals with variables that take on two discrete values and with operations
that assume logical meaning. The two values the variables take may be called by
different names, but for our purpose it is convenient to think in terms of binary
28
Section 2-1 Binary Logic and Gates 29
values and assign 1 and 0 to each variable. The variables are designated by letters
of the alphabet such as A, B, C, X, Y, Z. There are three logical operations
associated with the binary variables called AND, OR, and NOT.
1. AND. This operation is represented by a dot or by the absence of an operator.
For example, X • Y - Z or XY - Z is read “A AND Y is equal to Z.” The
logical operation AND is interpreted to mean that Z = 1 if and only if X -
1 and Y — 1; otherwise Z = 0. (Remember that X, y, and Z are binary
variables and can be equal to 1 or 0 and nothing else.)
2. OR. This operation is represented by a plus symbol. For example X + Y —
Z is read “X OR Y is equal to Z”, meaning that Z = 1 if AT = 1 or 7 = 1
or if both X — 1 and Y = 1. Only if AT = 0 and Y - 0, is Z = 0.
3. NOT. This operation is represented by a bar over the variable. For example,
X - Z is read “A NOT is equal to Z”, meaning that Z is what A is not. In
other words, if X — 1, then Z = 0; but if X - 0, then Z = 1. The NOT
operation is also referred to as the complement operation, since it changes a
1 to 0 and a 0 to 1.
Binary logic resembles binary arithmetic, and the operations AND and OR have
similarities to multiplication and addition, respectively. In fact, the symbols used
for AND and OR are the same as those used for multiplication and addition.
However, binary logic should not be confused with binary arithmetic. One should
realize that an arithmetic variable designates a number that may consist of many
digits. A logic variable is always either a 1 or a 0. The possible binary values for
the logical OR operation are as follows:
0 + 0-0
0+1-1
1+0-1
1 + 1-1
These resemble binary addition except for the last operation. In binary logic we
have 1 + 1-1 (read “one OR one is equal to one”), but in binary arithmetic
we have 1 + 1-10 (read “one plus one is equal to two”). To avoid ambiguity,
the symbol V is sometimes used for the OR operation instead of the + symbol.
But as long as arithmetic and logic operations are not mixed, each can use the +
symbol with its own independent meaning.
The binary values for the AND operation are
0-0-0
0 1-0
-
1 0-0
-
1 1-1
-
This is identical to binary multiplication provided we use only a single bit. Logical
AND is sometimes referred to as logical multiplication and logical OR as logical
addition.
30 Chapter 2 Digital Circuits
TABLE 2-1
Truth Tables for the Three Logical Operations
AND OR NOT
X y XV X Y x + y X X
0 0 0 0 0 0 0 1
0 i 0 0 1 1 1 0
1 0 0 1 0 1
1 1 1 1 1 1
For each combination of the values of binary variables such as X and Y, there
is a value of Z specified by the definition of the logical operation. These definitions
may be listed in a compact form in a truth table. A truth table is a table of
combinations of the binary variables showing the relationship between the values
that the variables take and the result of the operation. The truth tables for the
operations AND, OR, and NOT are shown in Table 2-1. The tables list all possible
values for the variables and the results of the operation. These tables clearly
demonstrate the definition of the three operations.
Logic Gates
Logic gates are electronic circuits which operate on one or more input signals to
produce an output signal. Electrical signals such as voltages or currents exist throughout
a digital system in either of two recognizable values. Voltage operated circuits
respond to two separate voltage levels which represent a binary variable equal to
logic-1 or logic-0. For example, a particular digital system may define logic-0 as a
signal equal to 0 volts, and logic-1 as a signal equal to 4 volts. In practice, each
voltage level has an acceptable range as shown in Figure 2-1. The input terminals
of digital circuits accept binary signals within the allowable range and respond at
the output terminals with binary signals that fall within the specified range. The
intermediate region between the allowed regions is crossed only during state tran¬
sition. Any desired information for computing or control can be operated upon by
passing binary signals through various combinations of logic gates with each signal
representing a particular binary variable.
The graphic symbols used to designate the three types of gates are shown in
FIGURE 2-1
Example of Binary Signals
Section 2-1 Binary Logic and Gates 31
Z = X • Y
(AND) X •
(OR) X +
(NOT) X
FIGURE 2-2
Digital Logic Gates
Figure 2-2(a). The gates are blocks of hardware that produce the equivalent of
logic-1 and logic-0 output signals if input logic requirements are satisfied. The input
signals X and Y may exist in the AND and OR gates in one of four possible states:
00, 01, 10, or 11. These input signals are shown in Figure 2-2(b) together with the
corresponding output signal for each gate. The timing diagrams illustrate the re¬
sponse of each gate to the four possible input signal combinations. The horizontal
axis of the timing diagram represents time and the vertical axis shows the signal
as it changes between the two possible voltage levels. The low level represents
logic-0 and the high level represents logic-1. The AND gate responds with a logic-
1 output signal when both input signals are logic-1. The OR gate responds with
logic-1 output signal if any input signal is logic-1. The NOT gate is commonly
referred to as an inverter. The reason for this name is apparent from the signal
response in the timing diagram where it is shown that the output signal inverts the
logic sense of the input signal.
AND and OR gates may have more than two inputs. An AND gate with three
inputs and an OR gate with four inputs are shown in Figure 2-3. The three-input
A
B •F = ABC F=A+B+C + D
C
FIGURE 2-3
Gates with Multiple Inputs
32 Chapter 2 Digital Circuits
AND gate responds with a logic-1 output if all three inputs are logic-1. The output
produces a logic-0 if any input is logic-0. The four-input OR gate responds with a
logic-1 if any input is logic-1; its output becomes a logic-0 only when all inputs are
logic-0.
F = X + YZ
FIGURE 2-4
Logic Circuit Diagram for F = X + YZ
Section 2-2 Boolean Algebra 33
variety of ways. The particular expression used to designate the function will also
dictate the interconnection of gates in the logic circuit diagram. By manipulating
a Boolean expression according to Boolean algebra rules, it is sometimes possible
to obtain a simpler expression for the same function and thus reduce the number
of gates in the circuit. To see how this is done, it is necessary first to study the
basic rules of the algebra.
AB + C + 1 = 1
Note that equation 9 states that double complementation restores the variable to
its original value. Thus if A = 0 then A = 1 and A = 0 = A.
The commutative laws state that the order in which the variables are written
will not affect the result when using the OR and AND operations. The associative
laws state that the result of forming an operation among three variables is inde-
TABLE 2-3
Basic Identities of Boolean Algebra
1. A + 0 = A 2. A • 1 = A
o
o
*
3. A + 1 = 1
II
5. A + A = A 6. A • A = A
7. A + A = 1 8. A • A = 0
9. X = X
10. A + Y = y + A 11. Ay = TA Commutative
12. X + (Y + Z) = (X + Y) + Z 13. X(YZ) = (XY)Z Associative
14. A(T + Z) = AT + AZ 15. A + yz = (A + Y)(A + Z) Distributive
16. A + Y = A • Y 17. a• y = a + y DeMorgan
34 Chapter 2 Digital Circuits
pendent of the order that is taken and therefore, the parentheses can be removed
altogether.
X+(Y+Z) = (X+Y) + Z = X+ Y+ Z
X(YZ) - (XY)Z = XYZ
These two laws and the first distributive law are well known from ordinary algebra
so they should not impose any difficulty. The second distributive law given by
identity 15 is the dual of the ordinary distributive law and is very useful in manip¬
ulating Boolean functions.
X + YZ = (X -h Y) (X + Z)
This equation can be used for other combination of variables. Consider the expres¬
sion (A + B) (A + CD). Letting X = A, Y = B, and Z = CD, and applying
the second distributive law we obtain
(A + B) (A + CD) = A + BCD
The last two identities in Table 2-3 are referred to as DeMorgan’s theorem.
(ITT) = X • Y and (IT) = X + Y
This is a very important theorem and is used to obtain the complement of an
expression. DeMorgan’s theorem can be verified by means of truth tables that
assign all the possible binary values to X and Y. Table 2-4 shows two truth tables
that verify the first part of DeMorgan’s theorem. In A, we evaluate (X + Y) for
all possible values of X and Y. This is done by first evaluating X + Y and then
taking its complement. In B, we evaluate X and Y and then AND them together.
The result is the same for the four binary combinations of X and Y which verifies
the identity of the equation.
Note the order in which the operations are performed when evaluating an expres¬
sion. The complement over a single variable is evaluated, then the AND operation,
and then the OR operation, just as we do in ordinary algebra with multiplication
and addition. A complement over an expression such as (X + Y) is considered as
specifying NOT ( X + Y) so the value within the parentheses is evaluated first
and then the complement of the result is taken. It is customary to exclude the
parentheses when complementing an expression since a bar is drawn over the entire
expression. Thus (.X + Y) is expressed as X + Y when designating the complement
of (X + Y).
TABLE 2-4
Truth Tables to Verify DeMorgan’s Theorem
a. x y x + y (X + y) b. x v x y x y
0 0 0 1 0 0 1 1 1
011 0 01100
10 1 0 10 0 10
111 0 11000
Section 2-2 Boolean Algebra 35
X{ + X2 + X3 + . . . + Xn =X1X2X3 . . . Xn
XxX2X3 . • • Xn = X1 + X2 + X3 + . . . + Xn
The logic operation changes from OR to AND or from AND to OR. In addition,
the complement is removed from the entire expression and placed instead over
each variable. For example,
Algebraic Manipulation
Boolean algebra is a useful tool for simplifying digital circuits. Consider for example
the following Boolean function:
F = XYZ + XYZ + XZ
The implementation of this function with logic gates is shown in Figure 2-5(a).
Input variables X and Z are complemented with inverters to obtain X and Z. The
three terms in the expression are implemented with three AND gates. The OR
gate forms the logical sum of the three terms. Now consider the possible simpli¬
fication of the function by applying some of the identities listed in Table 2-3.
F = XYZ + XYZ + XZ
= XY(Z -h Z) + XZ by identity 14
= XY • 1 + XZ by identity 7
= XY + XZ by identity 2
(b) F= XY + XZ
FIGURE 2-5
Implementation of Boolean Function with Gates
36 Chapter 2 Digital Circuits
The function is reduced to only two terms and can be implemented with gates as
TABLE 2-5 shown in Figure 2-5(b). It is obvious that the circuit in (b) is simpler than the one
Truth Table for
Boolean Function in (a); yet both implement the same function. It is possible to use a truth table to
verify that the two expressions are equivalent, as shown in Table 2-5. The function
X Y z F
as expressed in Figure 2-5(a) is equal to 1 when XYZ = Oil, or when XYZ =
0 0 0 0 010, or when XZ = 11. This produces four l’s for F in the table. The function as
0 0 1 0 expressed in Figure 2-5(b) is equal to 1 when XY = 01, or when XZ = 11. This
0 1 0 1 produces the four l’s in the table. Since both expressions produce the same truth
0 1 1 1 table, they are said to be equivalent. Therefore, the two circuits have the same
1 0 0 0 output for all possible input binary combinations of the three variables. Each
1 0 1 1 implements the same function but the one with fewer gates is preferable because
1 1 0 0
it requires fewer components.
1 1 1 1
When a Boolean expression is implemented with logic gates, each term requires
a gate and each variable within the term designates an input to the gate. We define
a literal as a single variable within a term that may or may not be complemented.
The function of Figure 2-5(a) has three terms and eight literals; the one in Figure
2-5(b) has two terms and four literals. By reducing the number of terms, the number
of literals, or both, in a Boolean expression, it is sometimes possible to obtain a
simpler circuit. The manipulation of Boolean algebra consists primarily of reducing
an expression for the purpose of obtaining a simpler circuit. Unfortunately, there
are no specific rules that guarantee a good result. The only method available is a
cut-and-try procedure employing the basic relations and other manipulations that
become familiar with use. The following examples illustrate a few of the possibil¬
ities.
a. X + XY = X(l + Y) = X
b. XY + XY = X(Y Y) = X
+
c. X + XY = (X Y X) (X + Y) = X + Y
Note that the intermediate step X = X-1 has been omitted when X is factored out
in the first equation. The relationship 1 + Y = 1 is useful for eliminating redundant
terms, as is done with the term XY in the first equation. The relation Y + Y =
1 is useful for combining two terms, as is done in the second equation. The two
terms to be combined must contain the same variable, but the variable must be
complemented in one term and not complemented in the other. The third equation
is simplified by means of the second distribution law (identity 15 in Table 2-3).
The following are three more examples of Boolean expression simplification.
d. X (X Y Y) = X Y XY = X(1 Y Y) = X
e. (X Y Y)(X YY)=XyYY = X
f• X (X Y Y) = XX Y XY = XY
Note that the intermediate steps XX = X = X • 1 has been omitted during the
manipulation of equation d. The expression in e is simplified by means of the
second distributive law. Here again we omit the intermediate step YY = 0 and
X + 0 = X.
The last three equations are the dual of the first three equations. Remember
that the dual of an expression is obtained by changing AND to OR and OR to
AND throughout (and l’s to 0’s and 0’s to l’s if they appear in the expression).
Section 2-2 Boolean Algebra 37
The duality principle of Boolean algebra states that a Boolean equation remains
valid if we take the dual of the expressions on both sides of the equal sign. There¬
fore, equations d, e, and f can be verified by taking the dual of equations a, b,
and c, respectively.
The consensus theorem, shown below, is sometimes useful when simplifying
Boolean expressions.
XY Y XZ Y YZ = XY Y XZ
It shows that the third term YZ is redundant and can be eliminated. Note that Y
and Z are also associated with X and X in the first two terms. The proof of the
equation is obtained by first ANDing YZ with (X + A) = 1.
XY + XZ + YZ = XY Y XZ Y YZ(X Y X)
= XY + XZ Y XYZ Y XYZ
= XY + XYZ Y XZ Y XYZ
= XY( 1 + Z) + XZ( 1 + Y)
= XY + XZ
(A Y B) (A Y C) = AA + AC Y AB + BC
— AC Y AB + BC
= AC Y AB
Complement of a Function
The complement of a function, F, is obtained from an interchange of l’s to 0’s and
0’s to l’s in the values of F in the truth table. The complement of a function can
be derived algebraically by applying DeMorgan’s theorem. Remember that the
generalized form of this theorem states that the complement of an expression is
obtained by interchanging AND and OR operations and complementing each var¬
iable.
Example 2-1 Find the complement of the following two functions: Fx = XYZ + XYZ and F2
= X(YZ + YZ).
Applying DeMorgan’s theorem as many times as necessary the complements
are obtained as follows:
= (X + Y Y Z) (X Y Y + Z)
38 Chapter 2 Digital Circuits
= X+ (YZ ■ YZ)
= X + (Y + Z) (7 + Z) ■
A simpler method for deriving the complement of a function is to take the dual
of the function and complement each literal. This method follows from the gen¬
eralized DeMorgan’s theorem. Remember that the dual of an expression is obtained
by interchanging AND and OR operations and l’s and 0’s.
Example 2-2 Find the complement of the functions in Example 2-1 by taking their dual and
complementing each literal
F1 = XYZ + XYZ
The dual of Fx (X + Y + Z) (X + Y + Z)
F2 = X(YZ + YZ)
The dual of F2 X + (Y + Z) (Y + Z)
TABLE 2-6
Minterms and Maxterms for Three Variables
Minterms Maxterms
Product
X Y z Term Symbol Sum Term Symbol
0 0 0 XYZ m0 X + Y + Z M0
0 0 1 XYZ m, X + Y + Z Mx
0 1 0 XYZ m2 X + Y + z m2
0 1 1 XYZ m3 X + Y + z m3
1 0 0 XYZ m4 X + Y + z m4
1 0 1 XYZ m5 X + Y + z m5
1 1 0 XYZ m6 X + Y + z m6
1 1 1 XYZ m7 X + Y + z m7
exactly one combination of the binary variables in a truth table. There are 2n
distinct minterms for n variables. The four minterms for the two variables X and
Y are XY, XY, XY, and XY. The eight minterms for the three variables X, Y,
and Z are listed in Table 2-6. The binary numbers from 000 to 111 are listed under
the variables. Each minterm is obtained from the product term of exactly three
variables with each variable being complemented if the corresponding bit of the
binary number is 0 and uncomplemented if it is 1. A symbol for each minterm is
also shown in the table and is of the form ray, where the subscript j denotes the
decimal equivalent of the binary number of the mintern. The list of minterms for
any given n variables can be formed in a similar manner from a list of the binary
numbers from 0 through 2n - 1.
A sum term that contains all the variables in complemented or uncomplemented
form is called a maxterm. Again, it is possible to formulate 2n maxterms with n
variables. The eight maxterms for three variables are listed in Table 2-6. Each
maxterm is obtained from the logical sum of the three variables with each variable
being complemented if the corresponding bit is 1 and uncomplemented if 0. The
symbol for a maxterm is Mp where j denotes the binary number of the maxterm.
Note that a minterm and maxterm with the same subscript number are the com¬
plements of each other, that is My = ray. For example, for j = 3, we have
m3 = XYZ = X+ Y+ Z = M3
A Boolean function can be expressed algebraically from a given truth table by
forming the logical sum of all the minterms which produce a 1 in the function.
Consider the Boolean function F in Table 2-7(a). The function is equal to 1 for
each of the following binary combinations of the variables X, Y and Z: 000, 010,
101, and 111. These combinations correspond to minterms 0, 2, 5, and 7. The
function Fean be expressed algebraically as the logical sum of these four minterms.
F(X, Y, Z) = 2m(0, 2, 5, 7)
40 Chapter 2 Digital Circuits
TABLE 2-7
Boolean Functions of Three Variables
(a) X Y z F F (b) X Y z E
0 0 0 1 0 0 0 0 1
&*) IL..JX2 0 0 1 0 1 0 0 1 1
0 1 0 1 0 0 1 0 1
0 1 1 0 1 0 1 1 0
1 0 0 0 1 1 0 0 1
1 0 1 1 0 1 0 1 1
1 1 0 0 1 1 1 0 0
1 1 1 1 0 1 1 1 0
The symbol X stands for the logical sum (Boolean OR) of the minterms. The
numbers following it are the minterms of the function. The letters in parentheses
following F form a list of the variables in the order taken when the minterms are
converted to product terms.
Now consider the complement of a Boolean function. The binary values of F in
Table 2-7(a) are obtained by changing l’s to 0’s and 0’s to l’s in the values of F.
Taking the logical sum of the minterms of F we obtain
F(X, Y, Z) = 2m( 1, 3, 4, 6)
Note that the minterm numbers for F are the ones missing from the list of the
minterms of F. We now take the complement of F to obtain F.
F — ni] + m3 + m4 + m6 - rill • m3 • m4 • m6
= Ml • M3 • M4 • Me (Since m] - M;)
- (x + y + z) (x + y + z) (x + y + z) (x + 7 + z)
This shows the procedure for expressing a Boolean function in product of maxterms.
The abbreviated form for the product of maxterms form is
F(X, y, Z) = UM(1, 3, 4, 6)
The symbol II denotes the logical product (Boolean AND) of the maxterms listed
in parentheses. Note that the decimal numbers included in the product of maxterms
will always be the same as the minterm list of the complemented function (1, 3,
4, 6 in the above example). Maxterms are seldom used when dealing with Boolean
functions as we can always replace them with the minterm list of F. The following
is a summary of the most important properties of minterms:
1. There are 2n minterms for n Boolean variables. They can be evaluated from
the binary numbers from 0 to 2n — 1.
2. Any Boolean function can be expressed as a logical sum of minterms.
Section 2-3 Standard Forms 41
E = Y + AZ
The expression is not in sum of minterms because each term does not contain all
three variables A, T, and Z. The truth table for this function is listed in Table
2-7(b). From the truth table we obtain the minterms of the function.
E(X, y, Z) - Xm{0, 1, 2, 4, 5)
The minterms for the complement of E are
E(X, y, Z) = 2m(3, 6, 7)
Note that the total number of minterms in E and E is equal to eight since the
function has three variables and three variables can produce a total of eight min¬
terms. With four variables, there will be a total of 16 minterms, and for two
variables, there will be four minterms. An example of a function that includes all
the minterms is
G(A, Y) = £m(0, 1, 2, 3) = 1
Since G is a function of two variables and contains all four minterms, it will always
equal to logic-1.
Sum of Products
The sum of minterms form is a standard algebraic expression that is obtained
directly from a truth table. The expression so obtained contains the maximum
number of product terms and the maximum number of literals in each term. This
is because, by definition, each minterm must include all the variables of the function
complemented or uncomplemented. Once the sum of minterms is obtained from
the truth table, the next step is to try to simplify the expression to see if it is possible
to reduce the number of product terms and the number of literals in the terms.
The result is a simplified expression in sum of products. The sum of products is
an alternate standard form of expression that contains product terms with one, two
or any number of literals. An example of a Boolean function expressed in sum of
products is
F = Y + XYZ + XY
The expression has three product terms. The first term has one literal, the second
has three literals, and the third has two literals.
The logic diagram of a sum of products expression consists of a group of AND
gates followed by a single OR gate. This configuration pattern is shown in Figure
Chapter 2 Digital Circuits
FIGURE 2-6
Sum of Products Implementation
2-6. Each product term requires an AND gate except for a term with a single
literal. The logical sum is formed with an OR gate that receives its inputs from the
outputs of the AND gates or the single variable. It is assumed that the input
variables are directly available in their complement, so inverters are not included
in the diagram. The AND gates followed by the OR gate forms a circuit config¬
uration referred to as a two-level implementation.
If an expression is not in sum of products form, it can be converted to the
standard form by means of the distributive laws. Consider the expression
F = AB + C(D + E)
This is not in sum of products form because the term (D + E) is part of a product
but is not a single variable. The expression can be converted to a sum of products
by removing the parentheses.
F = AB + C(D + E) = AB + CD + CE
The implementation of this function is shown in Figure 2-7. The function is im¬
plemented in a nonstandard form in (a). This requires two AND gates and two
OR gates. There are three levels of gating in this circuit. The expression is imple¬
mented in sum of products form in (b). This circuit requires three AND gates and
an OR gate and uses two levels of gating. In general, a two-level implementation
is preferred because it produces the least amount of delay time through the gates
when the signal propagates from the inputs to the output.
FIGURE 2-7
Three- and Two-Level Implementation
Section 2-4 Map Simplification 43
FIGURE 2-8
Product of Sums Implementation
Product of Sums
Another standard form of expressing Boolean functions algebraically is the product
of sums. It is obtained by forming the logical product of sum terms. Each logical
sum term may have any number of literals. An example of a function expressed
in product of sums is
F = X(Y + Z)(X + Y + Z)
This expression has three sum terms of one, two, and three literals. The sum terms
perform an OR operation and the product is an AND operation.
The gate structure of the product of sums expression consists of a group of OR
gates for the sum terms (except for a single literal term) followed by an AND gate.
This is shown in Figure 2-8. This standard type of expression results in a two-level
gating structure.
The simplified expressions produced by the map are always in one of the two
standard forms: either in sum of products or in product of sums. It will be assumed
that the simplest algebraic expression is one with a minimum number of terms and
with the fewest possible number of literals in each term. This produces a circuit
logic diagram with a minimum number of gates and the minimum number of inputs
to the gates. We will see subsequently that the simplest expression is not necessarily
unique. It is sometimes possible to find two or more expressions that satisfy the
simplification criteria. In that case, either solution would be satisfactory. This
section covers only the sum of products simplification. In the next section we will
show how to obtain the product of sums simplification.
Two-Variable Map
There are four minterms for a Boolean function with two variables. Hence, the
two-variable map consists of four squares, one for each minterm, as shown in
Figure 2-9. The map is redrawn in (b) to show the relationship between the squares
and the two variables X and Y. The 0 and 1 marked on the left side and the top
of the map designate the values of the variables. Variable X appears complemented
in row 0 and uncomplemented in row 1. Similarly, Y appears complemented in
column 0 and uncomplemented in column 1.
A function of two variables can be represented in a map by marking the squares
that correspond to the minterms of the function. As an example, the function XY
is shown in Figure 2-10(a). Since XY is equal to minterm m3, a 1 is placed inside
the square that belongs to ra3. Figure 2-10 (b) shows the map for the logical sum
of three minterms.
mx + m2 + m3 = XY + XY + XY = V + Y
\y o i
m0 XY X Y
m2 m3 XY XY
(a) (b)
FIGURE 2-9
Two-Variable Map
V0 1
\Y 0 1
1 1 1
(a) XY (b) X + Y
FIGURE 2-10
Representation of Functions in the Map
Section 2-4 Map Simplification 45
XY + XY + XY =XY + X(Y + Y) = {X + X) (Y + X) = X + Y
The exact procedure for combining squares in the map will be clarified in the
examples that follow.
Three-Variable Map
There are eight minterms for three binary variables. Therefore, a three-variable
map consists of eight squares as shown in Figure 2-11. The map drawn in part (b)
is marked with binary numbers in each row and each column to show the binary
values of the minterms. Note that the numbers along the columns do not follow
the binary count sequence. The characteristic of the listed sequence is that only
one bit changes in value from one adjacent column to the next.
A minterm square can be located in the map in two ways. We can memorize
the numbers listed in Figure 2-11 (a) for each minterm location, or we can refer
to the binary numbers along the rows and columns. For example, the square
assigned to m5 corresponds to row 1 and column 01. When these two numbers are
concatenated, they give the binary number 101, whose decimal equivalent is 5.
Another way of looking at square m5 — XYZ is to consider it to be in the row
marked X and the column belonging to YZ (column 01). Note that there are four
squares where each variable is equal to 1 and four squares where each is equal to
0. The variable appears uncomplemented in the four squares where it is equal to
1 and complemented in the four squares where it is equal to 0. For convenience,
we write the variable name with the letter symbol along the four squares where it
is uncomplemented.
To understand the usefulness of the map for simplifying Boolean functions, we
must recognize the basic property possessed by adjacent squares. Any two adjacent
squares placed horizontally or vertically (but not diagonally) correspond to min¬
terms which differ in only a single variable. The single variable appears uncom¬
plemented in one square and complemented in the other. For example, m5 and m1
lie in two adjacent squares. Variable Y is complemented in m5 and uncomplemented
00 01 11 10
X
m0 mi m3 m2 0 XYZ XYZ xyz x vz
v-
z
(a) (b)
FIGURE 2-11
Three-Variable Map
46 Chapter 2 Digital Circuits
in ra7, while the other two variables are the same in both squares. The logical sum
of two adjacent minterms can be simplified into a single product term of two
variables.
F(X, Y, Z) = Xm(2, 3, 4, 5)
First, a 1 is marked in each minterm that represents the function. This is shown
in Figure 2-12 where the squares for minterms 010, Oil, 100, and 101 are marked
with l’s. The next step is to find possible adjacent squares. These are indicated in
the map by two rectangles, each enclosing two l’s. The upper right rectangle
represents the area enclosed by XY. This is determined by observing that the two-
square area is in row 0, corresponding to X, and the last two columns, corresponding
to Y. Similarly, the lower left rectangle represents the product term XY. (The
second row represents X and the two left columns represent Y.) The logical sum
of these two product terms gives the simplified expression.
F = XY + XY m
There are cases where two squares in the map are considered to be adjacent
even though they do not touch each other. In Figure 2-11, m0 is adjacent to m2
and m4 is adjacent to m6 because the minterms differ by one variable. This can be
readily verified algebraically.
z
FIGURE 2-12
Map for Example 2-3g F(X, Y^Z)
= lm(2, 3, 4, 5) = XY + XY
Section 2-4 Map Simplification 47
= XZ(Y + Y) + XZ(Y + Y)
= XZ + XZ = Z(X + X) = z
The number of adjacent squares that may be combined must always represent
a number that is a power of two such as 1, 2, 4, and 8. As a larger number of
adjacent squares are combined, we obtain a product term with fewer literals.
F\(X, 7, Z) = Sm(3, 4, 6, 7)
F2(X, 7, Z) = Xm(0, 2, 4, 5, 6)
The map for Fv is shown in Figure 2-13(a). There are four squares marked with
l’s, one for each minterm of the function. Two adjacent squares are combined in
the third column to give a two-literal term YZ. The remaining two squares with
l’s are also adjacent by the new definition and are shown in the diagram with their
values enclosed in half rectangles. These two squares when combined, give the
two-literal term XZ. The simplified function becomes
F1 = YZ + XZ
YZ
00 01
,-A-
11
Y
10
z
(a) F,[X, Y, Z) = Lm{3, 4^6, 7) (b) F2(X, Y, Z) = 2m(0, 2, 4, 5, 6)
= YZ + XZ = Z + XY
FIGURE 2-13
Maps for Example 2-4
48 Chapter 2 Digital Circuits
FIGURE 2-14
F(X, Y, Z) = 2m(J,3, 4, 5, 6)
= XZ + XZ + XY
= XZ + XZ + YZ
The map for F2 is shown in Fig. 2-13(b). First we combine the four adjacent squares
in the first and last columns to give the single literal term Z. The remaining single
square representing minterm 5 is combined with an adjacent square that is already
being used once. This is not only permissible but rather desirable since the two
adjacent squares give the two-literal term XY while the single square represents
the three-literal minterm XYZ. The simplified function is
F2 = Z + XY ■
There are occasions when there are two alternate ways of combining squares to
produce equally simplified expressions. An example of this is demonstrated in the
map of Figure 2-14. Minterms 1 and 3 are combined to give the term XZ and
minterms 4 and 6 produce the term XZ. However, there are two ways that the
square of minterm 5 can be combined with another adjacent square to produce a
third two-literal term. Combining it with minterm 4 gives the term XY. We could
choose instead to combine it with minterm 1 to give the term YZ. Each of the two
possible simplified expressions listed in Figure 2-14 has three terms of two literals
each; so there are two possible simplified solutions for this function.
If a function is not expressed as a sum of minterms, we can use the map to
obtain the minterms of the function and then simplify the function. It is necessary
to have the algebraic expression in sum of products, from which each product term
is plotted in the map. The minterms of the function are then read directly from
the map. Consider the following Boolean function.
F = XZ + XY + XYZ + yz
Three product terms in the expression have two literals and are represented in a
three-variable map by two squares each. The two squares corresponding to the
first term, XZ, are found in Figure 2-15 from the coincidence of X (first row) and
Z (two middle columns) to give squares 001 and Oil. Note that when marking Fs
in the squares, it is possible to find a 1 already placed there from a preceding term.
This happens with the second term XY which has l’s in squares Oil and 010, but
square Oil is common with the first term XZ so only one 1 is marked in it.
Continuing in this fashion we find that the function has five minterms as indicated
by the five Fs in the map of Figure 2-15. The minterms are read directly from the
Section 2-4 Map Simplification 49
"V
FIGURE 2-15
F(X, Y, Z) = Xm( 1, 2, 3, 5, 7) =
Z + XY
map to be 1, 2, 3, 5, and 7. The function as originally given has too many product
terms. It can be simplified to only two terms.
F = Z + XY
Four-Variable Map
There are 16 minterms for four binary variables and therefore, a four-variable map
consists of 16 squares as shown in Figure 2-16. The minterm assignment in each
square is indicated in part (a) of the diagram. The map is redrawn in (b) to show
the relationship of the four variables. The rows and columns are numbered in a
special sequence so that only one bit of the binary number changes in value between
any two adjacent squares. The minterms corresponding to each square can be
obtained from the concatenation of the row number with the column number. For
example, the numbers in the third row (11) and the second column (01), when
concatenated, give the binary number 1101, the binary equivalent of 13. Thus, the
square in the third row and second column represents minterm m13. In addition,
each variable is marked in the map to show the eight squares where it appears
m0 m-\ m3 m2
m5 m7 m6
m 12 m-\3 m1 5 m 14
m8 m9 mu
(a) (b)
FIGURE 2-16
Four-Variable Map
50 Chapter 2 Digital Circuits
The minterms of the function are marked with l’s in the map of Figure 2-17. Eight
adjacent squares in the two left columns are combined to form the one literal term
Y. The remaining three l’s cannot be combined togethei to give a simplified term.
They must be combined as two or four adjacent squares. The top two l’s on the
right are combined with the top two l’s on the left to give the term WZ. Note
again that it is permissible to take the same square more than once. We are now
left with a square marked with 1 in the third row and fourth column (minterm
1100). Instead of taking this square alone which will give a term of four literals.
Y
YZ A
oo oi f 7i kT^
wx
00 1 1 1
01 1 1 1
>x
11 1 1 1
w<
10 1 1
~V"
z
FIGURE 2-17
Map for Example 2-5; F = Y + WZ + XZ
Section 2-5 Map Manipulation 51
we combine it with squares already used to form an area of four adjacent squares
in the two middle rows and the two end columns, giving the term XZ. The simplified
expression is the logical sum of the three terms.
F =Y + WZ + XZ m
F = BD + BC + ACD m
FIGURE 2-18
Map for Example 2-6; F = BD + BC
+ ACD
C
CD vV
00 01 11 10
AB
00 1 1
01 11 1 1 11
r > B
1 1 1 1
A<
10
v
v
D
FIGURE 2-19
Prime Implicants AD, BD, and AB
Section 2-5 Map Manipulation 53
C
CD
00 01 11 10
AB
00 1
01 1
>B
11 1 1 1
A <
10 1 1
~Y~
D
(a) Plotting the minterms (b) Essential prime implicants
FIGURE 2-20
Simplification with Prime Implicants
only by the term AD and minterms 12 and 14 can be covered only by the term
BD. But minterms 4, 5, 6, and 7 are covered by two prime implicants so the term
AB is not an essential prime implicant. In fact, once the essential prime implicants
are taken, the third term is not needed in this case because all the minterms are
already covered by the essential prime implicants. The simplified expression for
the function of Figure 2-19 is
F — AD + BD
A second example is shown in Figure 2-20. The function plotted in part (a) has
seven minterms. If we try to combine adjacent squares, we will find that there are
six prime implicants. In order to obtain a minimum number of terms for the
function, we must first determine the prime implicants that are essential. As shown
in part (b) of the figure, the function has four essential prime implicants. Product
term ABCD is essential because it is the only prime implicant that covers minterm
0. Similarly, product terms BCD, ABC, and ABC are essential prime implicants
because they are the only prime implicants that cover minterms 5, 12, and 10,
respectively. Minterm 15 can be covered by two prime implicants. The simplified
expression for the function consists of the logical sum of the four essential prime
implicants and one prime implicant that covers minterm 15.
ACD
F = ABCD + BCD + ABC + ABC + or
lABD
The identification of essential prime implicants in the map augments the pattern
of adjacent squares and shows the alternatives available for simplifying the Boolean
function.
Example 2-7 Simplify the following Boolean function in product of sums form.
F = AB + CD + BD
Taking the dual and complementing each literal gives the complement of F. This
is F in product of sums.
F = (A + B) (C + D) (B + D) ■
The previous example shows the procedure for obtaining the product of sums
simplification when the function is originally expressed in sum of minterms. The
procedure is also valid when the function is originally expressed in product of
maxterms or product of sums. Remember that the maxterm numbers are the same
as the minterm numbers of the complemented function; so 0’s are entered in the
00 01 'll 10
AB
00 1 0 1
1
01 0 1 0 0
11 0 0 0 0
10 1 1 0 1
FIGURE 2-21
Map for Example 2-7y
F = {A + B) (C + D) (B + D)
Section 2-5 Map Manipulation 55
map for the maxterms or for the complement of the function. To enter a function
expressed as a product of sums in the map, we must take the complement of the
function and from it find the squares to be marked by 0’s. For example, the function
F = (A + B + C) (B + D)
can be plotted in the map by first taking its complement
F = ABC + BD
and then marking 0’s in the squares representing the minterms of F. The remaining
squares are marked with l’s. Then, combining the l’s gives the simplified expression
in sum of products form. Combining the 0’s and then complementing gives the
simplified expression in product of sums. Thus, for any function plotted in the map
we can derive the simplified function in either one of the two standard forms.
Y Y
YZ ^_
V* ,->
00 01 11 10 00 01 11 10
wx wx
00 X 1 1 X 00 X 1 1 X
01 0 X 1 0 01 0 X 1 0
>x >x
11 0 0 1 0 11 0 0 1 0
w< w<
10 0 0 1 0 10 0 0 1 0
~V" -v
z
(a) F - YZ + WX (b) F = YZ + WZ
FIGURE 2-22
Example with Don’t Care Conditions
or 1. The map simplification is shown in Figure 2-22. The minterms of Fare marked
by l’s, those of d are marked by crosses, and the remaining squares are filled with
0’s. To get the simplified function in sum of products, we must include all the five
l’s in the map, but we may or may not include any of the crosses, depending on
the way the function is simplified. The term YZ covers the four minterms in the
third column. The remaining minterm in square 0001 can be combined with square
0011 to give a three-literal term. However, by including one or two adjacent crosses
we can combine four adjacent squares to give a two-literal term. In part (a) of the
diagram, don’t care minterms 0 and 2 are included with the l’s which results in
the simplified function
F = YZ + WX
In part (b), don’t care minterm 5 is included with the l’s and the simplified function
now is
F = YZ + WZ
The two expressions listed above represent two functions which are algebraically
unequal. Both cover the specified minterms of the function but each covers different
don’t care minterms. As far as the incompletely specified function is concerned,
both expressions are acceptable. The only difference is in the value of F for the
unspecified minterms.
It is also possible to obtain a simplified product of sums expression for the
function of Figure 2-22. In this case, the way to combine the 0’s is to include don’t
care minterms 0 and 2 with the 0’s to give a simplified complemented function
F = Z + WY
Taking the complement of F gives the simplified expression in product of sums
form.
F = Z(W + Y)
The above examples show that the don’t care minterms in the map are initially
Section 2-5 Map Manipulation 57
Five-Variable Map
Maps for more than four variables are not as simple to use. A five-variable map
needs 32 squares and a six-variable map needs 64 squares. When the number of
variables becomes large, the number of squares becomes excessively large and the
geometry for combining adjacent squares becomes more involved.
The five-variable map is shown in Figure 2-23. It consists of two four-variable
maps with variables A, B, C, D, and E. Variable A distinguishes between the two
maps as indicated on top of the diagram. The left-hand four-variable map represents
the 16 squares where A = 0, and the other four-variable map represents the squares
where A = 1. Minterms 0 through 15 belong with A = 0 and minterms 16 through
31 with A = 1. Each four-variable map retains the previously defined adjacency
when taken separately. In addition, each square in the A = 0 map is adjacent to
the corresponding square in the A — 1 map. For example, minterm 4 is adjacent
to minterm 20 and minterm 15 to 31. The best way to visualize this new rule for
adjacent squares is to consider the two half maps as being one on top of the other.
Any two squares that fall one over the other are considered adjacent.
From inspection, and taking into account the new definition of adjacent squares,
it is possible to show that any 2k adjacent squares, for k = 0, 1, 2, 3, 4, in the
five-variable map represents a product term of 5 — k literals. For example, four
adjacent squares combine an area in the five-variable map that represents a product
term of 5 — 2 = 3 literals.
Following the procedure used for the five-variable map, it is possible to construct
a six-variable map with four four-variable maps to obtain the required 64 squares.
Maps with six or more variables need too many squares and are impractical to use.
The alternative is to employ computer programs specifically written to facilitate
the simplification of Boolean functions with a large number of variables.
A = 0 A = 1
D D
DE f_
DE r->
00 01 11 10 00 01 11 10
BC BC
00 0 1 3 2 00 16 17 19 18
01 4 5 7 6 01 20 21 23 22
>c > C
1 1 12 13 15 14 1 1 28 29 31 30
J
B< B <
10 8 9 1 1 10 10 24 25 27 26
~Y~
E E
FIGURE 2-23
Five-Variable Map
58 Chapter 2 Digital Circuits
A = 0 A = 1
D D
DE DE
00 01 11 10 00 01 l7 10
BC BC
00 1 1 00
01 1 1 01 1 1
r >c >C
1 1 1 11 1 1
B< B<
10 1 10 1
"Y"
E E
FIGURE 2-24
Map for Example 2-8; F = ABE + BDE + ACE
The five-variable map for this function is shown in Figure 2-24. There are six
minterms from 0 to 15 that belong to the part of the map with A — 0. The other
five minterms belong with A — 1. Four adjacent squares in the A — 0 map are
combined to give the three literal term ABE. Note that it is necessary to include
A with the term because all the squares are associated with A — 0. The two squares
in column 01 and the last two rows are common to both parts of the map. Therefore,
they constitute four adjacent squares and give the three-literal term BDE. Variable
A is not included here because the adjacent squares belong to both A — 0 and A
— 1. The term ACE is obtained from the four adjacent squares that are entirely
within the A = 1 map. The simplified function is the logical sum of the three terms.
Graphic symbols
Distinctive Rectangular Algebraic Truth
Name shape shape equation table
X Y F
X 0 0 0
AND F = XY 0 1 0
y 1 0 0
1 1 1
X F
Inverter X 0 1
1 0
X F
Buffer 0 0
1 1
X Y F
X 0 0 1
NAND F F - X • Y 0 1 1
Y
1 0 1
1 1 0
X Y F
0 0 1
F F = X + Y 0 1 0
1 0 0
1 1 0
Exclusive-OR X Y F
(XOR)
X F = XY + XY 0 0 0
Y 0 1 1
= X © Y
1 0 1
1 1 0
Exclusive-NOR X Y F
(XNOR)
F = XY + XY 0 0 1
0 1. 0
= X © /
1 0 0
1 1 1
FIGURE 2-25
Digital Logic Gates
60 Chapter 2 Digital Circuits
output binary variable F. Two graphic symbols are drawn for each gate. The
rectangular shape symbols are recommended by the Institute of Electrical and
Electronics Engineers (IEEE) Standard Graphic Symbols for Logic Functions (IEEE
Standard 91-1984). The distinctive shape symbols have been used in the past and
are considered as alternative to the standard. The rectangular shape symbols are
more convenient when used with computer graphics. In this book we will retain
the distinctive shape symbols because of their extensive use in the technical liter¬
ature.
The AND, OR, and inverter gates were defined previously. The inverter circuit
inverts the logic sense of a binary signal to produce the complement operation.
The small circle in the output of the graphic symbol of an inverter designates the
logic complement. The triangle symbol by itself designates a buffer circuit. A buffer
does not produce any particular logic operation, since the binary value of the output
is equal to the binary value of the input. This circuit is used merely for power
amplification of the electrical signal.
The NAND gate is the complement of the AND operation. Its name is an
abbreviation of Not AND. The graphic symbol consists of an AND symbol followed
by a small circle. The NOR gate (an abbreviation of Not OR) is the complement
of the OR operation and is symbolized by an OR graphic symbol followed by a
small circle. The NAND and NOR gates are extensively used as standard logic
gates and are in fact far more popular than the AND and OR gates. This is because
NAND and NOR gates are easily constructed with electronics circuits and because
Boolean functions can be easily implemented with them.
The exclusive-OR (XOR) gate is similar to the OR gate but excludes the com¬
bination of both X and Y being equal to 1. The graphic symbol of the XOR gate
is similar to the OR gate except for the additional curved line on the input side.
The exclusive-NOR is the complement of the exclusive-OR, as indicated by the
small circle on the output side of the graphic symbol. The exclusive-OR has the
special symbol © to designate its operation.
In the rest of this section we will investigate the implementation of digital circuits
with NAND and NOR gates. The XOR gate is discussed in the next section.
NAND Gate
The NAND gate is said to be a universal gate because any digital system can be
implemented with it. To show that any Boolean function can be implemented with
NAND gates, we need only to show that the logical operations of AND, OR, and
complement can be obtained with NAND gates only. This is shown in Figure
2-26. The complement operation is obtained from a one-input NAND gate which
behaves exactly like an inverter gate. The AND operation requires two NAND
gates. The first produces the NAND operation and the second inverts the logical
sense of the signal. The OR operation is achieved through a NAND gate with
additional inverters in each input.
A convenient way to implement a Boolean function with NAND gates is to
obtain the simplified Boolean function in terms of Boolean operators and then
convert the function to NAND logic. The conversion of an algebraic expression
Section 2-6 NAND and NOR Gates 61
FIGURE 2-26
Logic Operations with NAND Gates
X X.
Y XYZ Y- X + Y + Z = XYZ
Z z-
FIGURE 2-27
Two Graphic Symbols for NAND Gate
from AND, OR, and complement to NAND can be done by simple circuit ma¬
nipulation techniques that change AND-OR diagrams to NAND diagrams.
To facilitate the conversion to NAND logic, it is convenient to define an alternate
graphic symbol for the gate. Two equivalent graphic symbols for the NAND gate
are shown in Figure 2-27. The AND-invert symbol as defined previously, consists
of an AND graphic symbol followed by a small circle. Instead, however, it is possible
to represent a NAND gate by an OR graphic symbol which is preceded by a small
circle in each input. The invert-OR symbol for the NAND gate follows DeMorgan's
theorem and the convention that small circles denote complementation.
The two graphic symbols are useful in the analysis and design of NAND circuits.
When both symbols are mixed in the same diagram, the circuit is said to be in
mixed notation.
Two-Level Implementation
The implementation of Boolean functions with NAND gates requires that the
function be in sum of products form. To see the relationship between a sum of
product expression and its equivalent NAND implementation, consider the logic
diagrams drawn in Figure 2-28. All three diagrams are equivalent and implement
the function
F = AB + CD
The function is implemented in (a) with AND and OR gates. In (b) the AND
gates are replaced by NAND gates and the OR gate is replaced by a NAND gate
with an OR-invert graphic symbol. Remember that a small circle denotes comple¬
mentation and two circles along the same line represent double complementation;
62 Chapter 2 Digital Circuits
(a) (b)
FIGURE 2-28
Three Ways to Implement F AB + CD
so both can be removed. Removing the small circles in the gates of (b) produces
the circuit of (a). Therefore, the two diagrams implement the same function and
are equivalent.
In Figure 2-28(c), the output NAND gate is redrawn with the AND-invert
graphic symbol. When drawing NAND logic diagrams, the circuit shown in either
(b) or (c) is acceptable. The one in (b) is in mixed notation and represents a more
direct relationship with the Boolean expression it implements. The NAND imple¬
mentation in Figure 2-28(c) can be verified algebraically. The function it implements
can be easily converted to a sum of products form by using DeMorgan’s theorem.
F = AB • CD = AB + CD
Example 2-9 Implement the following Boolean function with NAND gates.
F(X, y, Z) = 2m( 1, 2, 3, 4, 5, 7)
The first step is to simplify the function in sum of products form. This is done by
means of the map of Figure 2-29(a) from which the simplified function is obtained.
F = XY + XY +Z
The two-level NAND implementation is shown in Figure 2-29(b) in mixed notation.
Note that input Z must have a one-input NAND gate (inverter) to compensate for
the small circle in the second level gate. An alternate way of drawing the logic
diagram is shown in Figure 2-29(c). Here all the NAND gates are drawn with the
same graphic symbol. The inverter with input Z has been removed but the input
variable is complemented and denoted by Z. ■
The procedure described in the previous example indicates that a Boolean func¬
tion can be implemented with two levels of NAND gates. The procedure for
obtaining the logic diagram from a Boolean function is as follows:
oo 01 rTT 10
X
0
F = XY + XY + Z
x-
(a)
FIGURE 2-29
Solution to Example 2-9
F = A(CD + B) + BC
Although it is possible to remove the parentheses and reduce the expression into
a standard sum of products form, we choose to implement it as a multilevel circuit
for illustration. The AND-OR implementation is shown in Figure 2-30(a). There
are four levels of gating in the circuit. The first level has two AND gates. The
second level has an OR gate followed by an AND gate in the third level and an
OR gate in the fourth level. A logic diagram with a pattern of alternate levels of
AND and OR gates can be easily converted into a NAND circuit by using the
mixed notation. This is shown in Figure 2-30(b). The procedure is to change every
AND gate to an AND-invert graphic symbol and every OR gate to an invert-OR
graphic symbol. The NAND circuit performs the same logic as the AND-OR
diagram as long as there are two small circles along the same line. The small circle
associated with input B causes an extra complementation which must be compen¬
sated for by changing the input literal to B.
The general procedure for converting a multilevel AND-OR diagram into an
all NAND diagram using mixed notation is as follows:
63
F
FIGURE 2-30
Implementing F = A(CD + B) + BC
1. Convert all AND gates to NAND gates with AND-invert graphic symbols.
2. Convert all OR gates to NAND gates with invert-OR graphic symbols.
3. Check all the small circles in the diagram. For every small circle that is not
counteracted by another small circle along the same line, insert an inverter
(one-input NAND gate) or complement the input variable.
FIGURE 2-31
Implementing F = (AB + AB) (C + D)
64
Section 2-6 NAND and NOR Gates 65
The conversion into NAND with mixed notation is presented in part (b) of the
diagram. The two additional small circles associated with inputs C and D cause
these two literals to be complemented to C and D. The small circle in the output
NAND gate complements the output value; so we need to insert an inverter gate
at the output in order to complement the signal again and get the original value.
NOR gate
The NOR operation is the dual of the NAND operation. Therefore, all procedures
and rules for NOR logic are the dual of the corresponding procedures and rules
developed for NAND logic. The NOR gate is another universal gate that can be
used to implement any Boolean function. The implementation of the AND, OR,
and complement operations with NOR gates is shown in Figure 2-32. The com¬
plement operation is obtained from a one-input NOR gate. The OR operation
requires two NOR gates and the AND operation is obtained with a NOR gate that
has inverters in each input.
The two graphic symbols for the mixed notation are shown in Figure 2-33. The
OR-invert symbol defines the NOR operation as an OR followed by a complement.
The invert-AND symbol complements each input and then performs an AND
operation. The two symbols designate the same NOR operation and are logically
identical because of DeMorgan’s theorem.
The two-level implementation with NOR gates requires that the function be
simplified in product of sums form. Remember that the simplified product of sums
expression is obtained from the map by combining the 0’s and complementing. A
product of sums expression is implemented with a first level of OR gates that
produce the sum terms followed by a second level AND gate to produce the product.
FIGURE 2-32
Logic Operations with NOR Gates
x.
Y XYZ = X + Y + Z
z
(a) OR-invert (b) Invert-AND
FIGURE 2-33
Two Graphic Symbols for NOR Gate
66 Chapter 2 Digital Circuits
E--
FIGURE 2-34
Implementing F = (A + B) (C + D) E
with NOR Gates
F = (A + B) (C + D)E
The OR-AND pattern can be easily detected by the removal of the small circles
along the same line. Variable E is complemented to compensate for the third small
circle at the input of the second level gate.
The procedure for converting a multilevel AND-OR diagram to an all NOR
diagram is similar to the one presented for NAND gates. For the NOR case we
must convert each OR gate to an OR-invert symbol and each AND gate to an
invert-AND symbol. Any small circle that is not compensated for by another small
circle along the same line needs an inverter or the complementation of the input
literal.
The transformation of the AND-OR diagram of Figure 2-31(a) into a NOR
diagram is shown in Figure 2-35. The Boolean function for this circuit is:
F = (AB + AB) (C + D)
The equivalent AND-OR diagram can be recognized from the NOR diagram by
removing all the small circles. Removing the small circles at the inputs requires
that we complement the input literals.
FIGURE 2-35
Implementing F = (AB + AB) (C + D) with NOR Gates
Section 2-7 Exclusive-OR-Gate 67
2-7 EXCLUSIVE-OR-GATE
X&Y = XY +XY
It is equal to 1 if only one variable is equal to 1 but not both. The exclusive-NOR,
also known as the equivalence, is the complement of the exclusive-OR and is
expressed by the function
YWY = XY + YY
It is equal to 1 if both X and Y are equal to 1 or if both are equal to 0. The two
functions can be shown to be the complement of each other. This can be done by
means of a truth table or by algebraic manipulation.
YWY = XY + XY = (X + Y) (X + 7) - XY + XY
The following identities apply to the exlusive-OR operation:
A© 0 = A A© 1 = A
A© A = 0 A© A = 1
i©Y=Ify I©y=i©y
Any of these identities can be proven by using a truth table or by replacing the 0
operation by its equivalent Boolean expression. It can also be shown that the
exclusive-OR operation is both commutative and associative.
A © B = B©A
(A © £) © C = A © (£ © C) = A © £ © C
This means that the two inputs to an exclusive-OR gate can be interchanged without
affecting the operation. It also means that we can evaluate a three-variable exclu-
sive-OR operation in any order and for this reason, three or more variables can
be expressed without parentheses. This would imply the possibility of using exclu¬
sive-OR gates with three or more inputs. However, multiple-input exclusive-OR
gates are difficult to fabricate with hardware. In fact even a two-input function is
usually constructed with other types of gates. A two-input exclusive-OR function
is constructed with conventional gates using two inverters, two AND gates, and
an OR gate. Figure 2-36 shows the implementation with four NAND gates. The
mixed notation NAND diagram performs the following operation:
A(A + Y) + Y(X + Y) = XY + XY
F =X © Y
FIGURE 2-36
Exclusive-OR Constructed with NAND Gates
68 Chapter 2 Digital Circuits
Transmission Gate
The exclusive-OR can be constructed by means of a special circuit called trans¬
mission gate. This type of gate is available with CMOS type electronic circuits
(discussed in the next section). The operation of the transmission gate (TG) is
shown in Figure 2-37. X is the input, Y is the output, and the two terminals C and
C are control inputs. The circuit functions as an electronic switch. When C — 1
and C — 0, there is a closed path between X and Y for the signal to pass. When
C = 0 and C — 1, the path disconnects and the circuit behaves like an open switch.
Normally, the control inputs are connected through an inverter as shown in Fig.
2-37(c) so that C and C are the complement of each other.
An exclusive-OR gate can be constructed with two transmission gates and two
inverters as shown in Figure 2-38. Input A controls the paths in the transmission gates
and input B provides the output for Y. When input A is equal to 0, transmission gate
TGI is closed and output Y is equal to input B. When input A is equal to 1, TG2 is
closed and output Y is equal to the complement of input B. This results in the exclusive-
OR truth table as indicated in the table of Figure 2-38.
>Y
(c)
FIGURE 2-37
Transmission Gate (TG)
Section 2-7 Exclusive-OR-Gate 69
A B TGI TG2 Y
0 0 Close Open 0
0 1 Close Open 1
1 0 Open Close 1
1 1 Open Close 0
FIGURE 2-38
Exclusive-OR Constructed with Transmission Gates
Odd Function
The exclusive-OR operation with three or more variables can be converted into
an ordinary Boolean function by replacing the 0 symbol with its equivalent Boolean
expression. In particular, the three-variable case can be converted to a Boolean
expression as follows:
The Boolean expression clearly indicates that the three-variable exclusive-OR func¬
tion is equal to 1 if only one variable is equal to 1 or if all three variables are equal
to 1. Whereas in the two-variable function only one variable need be equal to 1;
with the three or more variables, an odd number variable must be equal to 1. As
a consequence, the multiple-variable exclusive-OR operation is defined as an odd
function.
The Boolean function derived from the three-variable exclusive-OR operation
is expressed as the logical sum of four minterms whose binary numerical values
are 001, 010, 100, and 111. Each of these binary numbers have an odd number of
l’s. The other four minterms not included in the function are 000, 011, 101, and
110, and they have an even number of l’s. In general, an ^-variable exclusive-OR
function is an odd function defined as the logical sum of the 2'7/2 minterms whose
binary numerical values have an odd number of l’s.
The definition of an odd function can be clarified by plotting it in a map. Figure
2-39(a) shows the map for the three-variable exclusive-OR function. The four
minterms of the function are a unit distance apart from each other. The odd function
is identified from the four minterms whose binary values have an odd number of
l’s. The four-variable case is shown in Fig. 2-39(b). The eight minterms marked
with l’s in the map constitute the odd function. Note the characteristic pattern of
the distance between the l’s in the map. It should be mentioned that the minterms
not marked with l’s in the map have an even number of l’s and constitute the
complement of the odd function. An odd function is implemented by means of
two-input exclusive-OR gates as shown in Figure 2-40. The complement of an odd
function is obtained by replacing the output gate with an exclusive-NOR gate.
70 Chapter 2 Digital Circuits
Y C
YZ CD ,-, A
00 01 11 10 00 01 11 10
x AB
o 1 1 00 1 1
X^ 1 1 1 01 1 1
>B
~^r~
Z 11 1 1
(a) X © Y © Z A<
10 1 1
(b) A © B ® C © D
FIGURE 2-39
Maps for Multiple-Variable Exclusive-OR
(a) P = X © / © Z (b) C = X © Y ® Z ® P
FIGURE 2-40
Multiple-Input Exclusive-OR Functions
P = A© Y©Z
The logic diagram for the parity generator is shown in Figure 2-40(a).
Section 2-8 integrated Circuits 71
TABLE 2-8
Even Parity Generator Truth Table
Three Bit
Message Parity Bit
X y z p
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
The three bits in the message together with the parity bit are transmitted to
their destination where they are applied to a parity-checker circuit to check for
possible errors in the transmission. Since the information was transmitted with even
parity, the four bits received must have an even number of l’s. An error occurs if
the four bits received have an odd number of l’s, indicating that at least one bit
has changed in value during transmission. The output of the parity checker, denoted
by C, will be equal to 1 if an error occurs, that is, if the four bits received have
an odd number of l’s. This is, by definition, an odd function and can be implemented
with exclusive-OR gates.
C = X© Y© Z © P
The size of the IC package is very small. For example, four AND gates are
enclosed inside a 14-pin IC package with dimensions of 20 x 8 x 3 millimeters.
An entire microprocessor is enclosed within a 40-pin IC package with dimensions
of 50 x 15 x 4 millimeters.
Levels of Integration
As the technology of ICs has improved, the number of gates that can be put in a
single silicon chip has increased considerably. The differentiation between those
chips that have a few internal gates and those having hundreds or thousands of
gates is made by a customary reference to a package as being either a small, medium,
or large scale integration device.
Small scale integration (SSI) devices contain several independent gates in a single
package. The inputs and outputs of the gates are connected directly to the pins in
the package. The number of gates is usually less than ten and is limited by the
number of pins available in the IC.
Medium scale integration (MSI) devices have a complexity of approximately 10
to 100 gates in a single package. They usually perform specific elementary digital
functions, serving as decoders, adders, and registers. MSI digital functions are
presented in Chapters 3 and 5.
Large scale integration (LSI) devices contain between 100 and a few thousand
gates in a single package. They include digital systems such as processors, memory
chips, and programmable modules. LSI logic systems are introduced in Chapters
6 and 8.
Very large scale integration (VLSI) devices contain thousands of gates within a
single package. Examples are large memory arrays and complex microcomputer
chips. Because of their small size and low cost, VLSI devices have revolutionized
the computer system design technology, giving the designer the capabilities to create
structures that previously were not economical.
TTL is a widespread logic family that has been in operation for some time and is
considered as standard. ECL has an advantage in systems requiring high speed
Section 2-8 Integrated Circuits 73
operation. MOS is suitable for circuits that need high component density, and
CMOS is preferable in systems requiring low power consumption.
The transistor-transistor logic family evolved from a previous technology that
used diodes and transistors for the basic NAND gate. This technology was called
DTL for diode-transistor logic. Later the diodes were replaced by transistors to
improve the circuit operation and the name of the logic family was changed to
TTL. This is the reason for mentioning the world transistor twice.
There are several variations of the TTL family beside the standard TTL, such
as high-speed TTL, low-power TTL, Schottky TTL, low-power Schottky TTL, and
advanced low-power Schottky TTL. The power supply voltage for TTL circuits is
5 volts, and the two logic levels are approximately 0 and 3.5 volts.
The emitter-coupled logic (ECL) family provides the highest speed digital circuits
in integrated form. ECL is used in systems such as supercomputers and signal
processors where high speed is essential. The transistors in ECL gates operate in
a nonsaturated state, a condition that allows the achievement of propagation delays
of 1 to 2 nanoseconds.
The metal-oxide semiconductor (MOS) is a unipolar transistor that depends
upon the flow of only one type of carrier which may be electrons (n-channel) or
holes (p-channel). This is in contrast to the bipolar transistor used in TTL and
ECL gates, where both carriers exist during normal operation. A p-channel MOS
is referred to as PMOS and an n-channel as NMOS. NMOS is the one that is
commonly used in circuits with only one type of MOS transistor. Complementary
MOS (CMOS) technology uses one PMOS and one NMOS transistor connected
in a complementary fashion in all circuits. The most important advantages of MOS
over bipolar transistors are the high packing density of circuits, a simpler processing
technique during fabrication, and a more economical operation because of the low
power consumption.
The characteristics of digital logic families are usually compared by analyzing
the circuit of the basic gate in each family. The most important parameters that
are evaluated and compared are as follows.
Fan-out specifies the number of standard loads that the output of a typical gate
can drive without impairing its normal operation. A standard load is usually defined
as the amount of current needed by an input of another similar gate of the same
family.
Power-dissipation is the power consumed by the gate which must be available
from the power supply.
Propagation delay is the average transition delay time for the signal to propagate
from input to output when the binary signal changes in value. The operating speed
is inversely proportional to the propagation delay.
Noise margin is the minimum external noise voltage that causes an undesirable
change in the circuit output.
1 H 0 H
0 L L
FIGURE 2-41
Signal Assignment and Logic Polarity
assignments of signal level to logic value as shown in Figure 2-41. The higher signal
level is designated by H and the lower signal level by L. Choosing the high level
H to represent logic-1 defines a positive logic system. Choosing the low level L to
represent logic-1 defines a negative logic system. The terms positive and negative
are somewhat misleading since both signals may be positive or both may be neg¬
ative. It is not the actual signal values that determine the type of logic, but rather
the assignment of logic values to the relative amplitudes of the two signal levels.
Integrated circuit data sheets define digital gates not in terms of logic values but
rather in terms of signal values such as H and L. It is up to the user to decide on
a positive or negative logic assignment. Consider for example the TTL gate shown
in Figure 2-42(b). The truth table for this gate as given in a data book is listed in
Figure 2-42(a). This specifies the physical behavior of the gate where H is 3.5 volts
and L is 0 volt. The truth table of Figure 2-42(c) assumes positive logic assignment
with H = 1 and L = 0. This truth table is the same as the one for the AND
operation. The graphic symbol for a positive logic AND gate is shown in Figure
2-42(d).
X Y Z
L L L X- TTL
L H L
H L L Y- gate
H H H
X Y z
0 0 0
0 1 0
1 0 0
1 1 1
X Y z
1 1 1
Z
1 0 1
0 1 1
0 0 0
FIGURE 2-42
Demonstration of Positive and Negative Logic
Problems 75
Now consider the negative logic assignment for the same physical gate with L
= 1 and H = 0. The result is the truth table of Figure 2-42(e). This table represents
the OR operation even though the entries are reversed. The graphic symbol for
the negative logic OR gate is shown in Figure 2-42(f). The small triangles in the
inputs and output designate a polarity indicator. The presence of this polarity
indicator along a terminal signifies that negative logic is assumed for the signal.
Thus, the same physical gate can operate either as a positive logic AND gate or
as a negative logic OR gate.
The conversion from positive logic to negative logic, and vice versa, is essentially
an operation that changes l’s to 0’s and 0’s to l’s in both the inputs and the output
of a gate. Since this operation produces the dual of a function, the change of all
terminals from one polarity to the other results in taking the dual of the function.
The result of this conversion is that all AND operations are converted to OR
operations (or graphic symbols) and vice versa. In addition, one must not forget
to include the polarity indicator triangle in the graphic symbols when negative logic
is assumed. In this book we will not use negative logic gates but assume that all
gates operate with a positive logic assignment.
REFERENCES
1. Boole, G., An Investigation of the Laws of Thought. New York: Dover, 1954.
2. Karnaugh, M., “A Map Method for Synthesis of Combinational Logic Cir¬
cuits,” Transactions of AIEE, Communication and Electronics, 72, Part I (Nov. 1953),
593-99.
3. Mano, M. M., Digital Design. Englewood Cliffs: Prentice-Hall, 1984.
4. Roth, C. H., Fundamentals of Logic Design. 3rd ed. St. Paul: West, 1985.
5. Fletcher, W. I., An Engineering Approach to Digital Design. Englewood Cliffs: Pren¬
tice-Hall, 1980.
6. Ercegovac, M. D., and Lang, T., Digital Systems and Hardware!Firmware Algo¬
rithms. New York: Wiley, 1985.
7. The TTE Data Book for Design Engineers. Dallas: Texas Instruments, 1983.
8. High-Speed CMOS Logic Data Book. Dallas: Texas Instruments, 1984.
9. IEEE Standard Graphic Symbols for Logic Functions. (ANSI/IEEE Std 91-1984.) New
York: The Institute of Electrical and Electronics Engineers.
PROBLEMS
2-1 Demonstrate by means of truth tables the validity of the following identities:
(a) DeMorgan’s theorem for three variables XYZ = X + Y + Z
(b) The second distributive law. X -I- YZ = (X + Y)(X + Z)
(c) XY + YZ Y XZ = XY Y YZ Y XZ
2-2 Prove the identity of each of the following Boolean equations using algebraic manip¬
ulation.
(a) XY + XY + XY = Y_+ Y
(b) XY Y XY + XY Y XY - 1_
(c) A_+ XYJ- XZ + XYZ = X_Y Y + Z
(d) XY Y YZ Y XZ = XY Y XZ
76 Chapter 2 Digital Circuits
F = XY Y XY Y YZ
X Y z E F
0 0 0 1 0
0 0 1 1 0
0 1 0 1 1
0 1 1 0 1
1 0 0 0 0
1 0 1 0 0
1 1 0 0 1
1 1 1 0 1
(a) List the minterms and maxterms of each function.
(b) List the minterms of E and F.
(c) Express E and F in sum of minterms in algebraic form.
(d) Simplify each function to an expression with a minimum number of literals.
2-9 Convert the following expressions into sum of products and product of sums.
(a) (AB + C)(B Y CD)
(b) x + x(x y y)(y + z)
2-10 Draw the logic diagram for the following Boolean expressions.
Problems 77
(a) BC + AB + ACD_
(b) (A + £)(C + £>)X4_+ B + D)
(c) {AB + A B)(CD + CD)
2-11 Simplify the following Boolean functions by means of a three-variable map.
(a) F(X, Y, Z) = 2m(2, 3, 6, 7)
(b) F(X, 7, Z) = 2m(3, 5, 6, 7)
(c) F(/L 5, C) = 2m(0, 2, 3, 4, 6)
(d) F(A, B, C) = 2m(l, 3, 5, 7)
2-12 Simplify the following Boolean expressions using a map.
(a) XY + 7Z + XYZ
(b) AB + BC + ABC
2-13 Simplify the following Boolean functions by means of a four-variable map.
(a) F(A, B, C, D) - Xm{3, 7, 11, 13, 14, 15)
(b) F(W, X, y, Z) = 2m(2, 3, 10, 11, 12, 13, 14, 15)
(c) F{A, £, C, D) = 2m(0, 2, 4, 5, 6, 7, 8, 10, 13, 15)
2-14 Simplify the following Boolean functions using a map.
(a) F(W, X, y, Z) = 2m(l, 4, 5, 6, 12, 14, 15)
(b) F(A, 5, C, D) = 2m(0, 1, 2, 4, 5, 7, 11, 15)
2-15 Simplify the following expressions by means of a four-variable map.
(a) AD + BD + BC + ABD
(b) ZZ + WXYJ- W(XY + XY)_
(c) ABC + BCD + BCD +_ACD + ABC + ABCD
(d) ABC + CD + 5CD + £C
2-16 Find the minterms of the following expressions by first plotting each expression in a
map.
(a) XY + yZ _+ XYZ
(b) yz + WXY + WXZ + WXZ
(c) ABC + BD + ABD
2-17 Find all the prime implicants for the following Boolean functions and determine which
are essential.
(a) F(VF, X, 7, Z) = £m(0, 2, 4, 5, 6, 7, 8, 10, 13, 15)
(b) F(A, B, C, D) = 2m(0, 2, 3, 5, 7, 8, 10, 11, 14, 15)
(c) F(A, 5, C, D) = Xm( 1, 3, 4, 5, 10, 11, 12, 13, 14, 15)
2-18 Simplify the following Boolean functions in product of sums.
(a) F(W, X, 7, Z) = 2m(0, 2, 5, 6, 7, 8, 10)
(b) F(A, B, C, D) = nM(l, 3, 5, 7, 13, 15)
2-19 Simplify the following expressions in (1) sum of products and (2) product of sums.
(a) AC + BD +_ACD ±ABCD_
(b) (A + B + D)(A + B_ + C){A + B_ + D)(B_ + C + D)
(c) (A + B + D){A + D)(A + B + D){A + B + C + D)
2-20 Simplify the following Boolean function F together with the don’t care conditions d.
(a) F{X, 7, Z) = Xm{0, 1, 2, 4, 5) d(X, Y, Z) = 2m(3, 6, 7)
(b) F(A, 5, C, D) = Xm{0, 6, 8. 13, 14) d(A, B, C, D) = Xm{2, 4, 10)
(c) F(/4, B, C, D) = Xm( 1, 3, 5, 7, 9, 15) </(X, B, C, D) = Xm(4, 6, 12, 13)
2-21 Simplify the following Boolean functions by means of a five-variable map.
(a) F(A, B, C,_D,E)_= XmJSY 1, 4^5^16, 17, 21, 25, 29)
(b) + 5CD + CDF + ££>£
78 Chapter 2 Digital Circuits
2-22 Simplify the Boolean function F together with the don’t care conditions d, in (1) sum
of products and (2) product of sums.
(a) F(W, A, Y, Z) = Xm(0, 1, 2, 3, 7, 8, 10)
d(W, X, 7, Z) = Xm(5, 6, 11, 15)
(b) F(A, B, C, D) = Zm(3, 4, 13, 15)
r/(A, £, C, D) = Sm(l, 2, 5, 6, 8, 10, 12, 14)
2-23 Simplify each of the following expressions and implement them with NAND gates,
(a) AB + ABD + ABD + ACD + ABC (b) BD + BCD + ABCD
2-24 Implement the following expression with two-input NAND gates.
(AB + AB)(CD + CD)
2-25 Draw the NAND logic diagram for each of the following expressions using a multiple
level NAND circuit.
(a) W(X + Y + Z) + XYZ (b) (AB + CD)E + BC(A + B)
2-26 Simplify each of the following expressions and implement them with NOR gates.
(a) AB + CD + ACD (b) ABCD + ABCD + ABCD + ABCD
2-27 Repeat problems 2-23 and 2-25 using NOR gates.
2-28 Show that the dual of the exclusive-OR is also its complement.
2-29 Derive the circuits for a three-bit parity generator and four-bit parity checker using
an odd parity bit.
2-30 Implement the following Boolean function:
F = ABCD + ABCD + ABCD + ABCD
with exclusive-OR and AND gates.
2-31 Construct an exclusive-NOR circuit with two inverters and two transmission gates.
2-32 TTL SSI come mostly in 14-pin packages. Two pins are reserved for power and the
other pins are used for input and output terminals. Give the number of gates that can
be enclosed in one package if it contains the following types of gates:
(a) Two-input exclusive-OR gates (d) Five-input NOR gates
(b) Three-input AND gates (e) Eight-input NAND gates
(c) Four-input NAND gates
2-33 Show that a positive logic NAND gate is a negative logic NOR gate and vice versa.
2-34 An integrated circuit logic family has AND gates with fan-out of 5 and buffer gates
with fan-out of 10. Show how the output signal of a single AND gate can be applied
to 50 other gate inputs using buffers.
COMBINATIONAL
SYSTEMS
3-1 INTRODUCTION
Logic circuits for digital systems may be combinational or sequential. A combi¬
national circuit consists of logic gates whose outputs at any time are determined
directly from the values of the present inputs. A combinational circuit performs a
specific information processing operation which can be specified logically by a set
of Boolean expressions. Sequential circuits employ storage elements called flip-
flops in addition to the logic gates. Their outputs are a function of the inputs and
the state of the storage elements. The state of storage elements, in turn, is a function
of previous inputs. As a consequence, the outputs of a sequential circuit depend
not only on the present values of the inputs, but also on past inputs, and the circuit
behavior must be specified by a time sequence of inputs and internal states. Se¬
quential circuits are presented in the next chapter.
A combinational circuit consists of input variables, logic gates, and output var¬
iables. The logic gates accept signals from the inputs and generate signals at the
outputs. This process transforms binary information from a given input data to a
required output data. A block diagram of a combinational circuit is shown in Figure
3-1. The n input variables come from an external source and the m output variables
-►
FIGURE 3-1
Block Diagram of Combinational Circuit
79
80 Chapter 3 Combinational Systems
1. Label all gate outputs that are a function of input variables with arbitrary
symbols. Determine the Boolean functions for each gate.
2. Label the gates that are a function of input variables and previous labeled
gates with different arbitrary symbols. Find the Boolean functions for these
gates.
3. Repeat the process outlined in step 2 until the outputs of the circuit are
obtained in terms of the input variables.
The analysis of the combinational circuit of Figure 3-2 will illustrate this pro¬
cedure. We note that the circuit has four binary input variables A, B, C, and Z),
and two binary output variables Fl and F2. The outputs of the various gates are
labeled with intermediate symbols. The outputs of gates that are a function of input
variables only are T1 and T2. The Boolean functions for these two outputs are
7\ = BC
T2 = AB
Next we consider the outputs of gates that are a function of already defined symbols.
T3 = A F T1 - A + BC
T4 - T2 © D = (AB) © D = ABD + AD + BD
T5 = T2 + D = AB + D
F2 = T5 = AB F D
F1 = T3 F T4 = A + BC F ABD F AD F BD
= A F BC F BD F BD
FIGURE 3-2
Logic Diagram for Analysis Example
82 Chapter 3 Combinational Systems
1. Determine the number of input variables in the circuit. For n inputs, list the
binary numbers from 0 to 2" — 1 in a table.
2. Label the outputs of selected gates with arbitrary symbols.
3. Obtain the truth table for the outputs of those gates that are a function of
the input variables only.
.
4 Proceed to obtain the truth table for the outputs of those gates that are a
function of previously defined values until the columns for all outputs are
determined.
FIGURE 3-3
Logic Diagram for Binary Adder
Section 3-3 Design Procedure 83
TABLE 3-1
Truth Table for Binary Adder
X y z f2 f2 T, T2 T3 F\
0 0 0 0 1 0 0 0 0
0 0 1 0 1 0 1 1 1
0 1 0 0 1 0 1 1 1
0 1 1 1 0 0 1 0 0
1 0 0 0 1 0 1 1 1
1 0 1 1 0 0 1 0 0
1 1 0 1 0 0 1 0 0
1 1 1 1 0 1 1 0 1
respectively. This verifies the operation of the circuit as a binary adder. The design
of a binary adder with a different gate structure is presented in Section 3-4.
The design of combinational circuits starts from the specification of the problem
and culminates in a logic circuit diagram or a set of Boolean functions from which
the logic diagram can be obtained. The procedure involves the following steps:
1. From the specifications of the circuit, determine the required number of inputs
and outputs and assign a letter symbol to each.
2. Derive the truth table that defines the required relationship between inputs
and outputs.
3. Obtain the simplified Boolean functions for each output as a function of the
input variables.
4. Draw the logic diagram.
A truth table for a combinational circuit consists of input columns and output
columns. The input columns are obtrained from the 2n binary numbers for the n
input variables. The binary values for the outputs are determined from the stated
specifications. The output functions specified in the truth table give the exact
definition of the combinational circuit. It is important that the verbal specifications
be interpreted correctly in the truth table. Word specifications are very often
incomplete and any wrong interpretation may result in an incorrect truth table.
The output binary functions listed in the truth table are simplified by any avail¬
able method such as algebraic manipulation, the map method, or by means of
computer generated simplification programs. Usually there is a variety of simplified
expressions from which to choose. In a particular application, certain criteria will
serve as a guide in the process of choosing an implementation. A practical design
must consider such constraints as the minimum number of gates, minimum number
of inputs to a gate, minimum propagation time of the signal through the gates,
minimum number of interconnections, limitations of the driving capability of each
gate, and various other criteria that must be taken into consideration when designing
with integrated circuits. Since the importance of each constraint is dictated by the
84 Chapter 3 Combinational Systems
Example 3-1 Design a combinational circuit with three inputs and one output. The output must
be logic-1 when the binary value of the inputs is less than three and logic-0 otherwise.
Use only NAND gates.
The design of the circuit is undertaken in Figure 3-4. We designate the inputs
with the letter symbols X, Y, Z, and the output with F. The truth table is listed
X Y z F
0 0 0 1
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 0
1 1 1 0
FIGURE 3-4
Solution to Example 3-1
Code Converter
When a combinational circuit has two or more outputs, each output must be
expressed separately as a function of all the input variables. An example of a
multiple output circuit is a code converter. A code converter is a circuit that
translates information from one binary code to another. The inputs of the circuit
provide the bit combination of the elements as specified by the first code and the
outputs generate the corresponding bit combination of the second code. The com¬
binational circuit performs the transformation from one code to the other. The
design of a code converter will be illustrated by means of an example that converts
the binary coded decimal (BCD) to the excess-3 code for the decimal digits.
Since both codes use four bits to represent each decimal digit, there must be
four input variables and four output variables. Designate the inputs by A, B, C,
D and the outputs by W, X, T, Z. The truth table relating the input and output
variables is shown in Table 3-2. The bit combinations for the inputs and their
Section 3-3 Design Procedure 85
TABLE 3-2
Truth Table for Code Converter Example
A B c D IV X y z
0 0 0 0 0 0 0 l 1
1 0 0 0 1 0 1 0 0
2 0 0 1 0 0 1 0 1
3 0 0 1 1 0 1 1 0
4 0 1 0 0 0 1 1 1
5 0 1 0 1 1 0 0 0
6 0 1 1 0 1 0 0 1
7 0 1 1 1 1 0 1 0
8 1 0 0 0 1 0 1 1
9 1 0 0 1 1 1 0 0
corresponding outputs are obtained directly from Table 1-5. Note that four binary
variables may have 16 bit combinations, but only 10 are listed in the truth table.
The six input bit combinations 1010 through 1111 are not listed under the input
columns. These combinations have no meaning in the BCD code, and we can
assume that they will never occur. Since they will never occur, it does not matter
what binary values we assign to the outputs and therefore, we can treat them as
don’t care conditions.
The maps in Figure 3-5 are plotted to obtain the simplified Boolean functions
for the outputs. Each one of the four maps represent one of the outputs of the
circuit as a function of the four inputs. The l’s in the map are obtained directly
from the truth table by going over the output columns one at a time. For example,
the column under output W has l’s for minterms 5, 6, 7, 8, and 9. Therefore, the
map for W must have five l’s in the squares that correspond to these minterms.
The six don’t care minterms 10 through 15 are each marked with an X in all the
maps. The simplified functions in sum of products are listed under the map of each
variable.
The two-level AND-OR logic diagram for the circuit can be obtained directly
from the Boolean expressions derived from the maps. There are, however, various
other possibilities for a logic diagram that implements the circuit. For example,
expressions may be manipulated algebraically for the purpose of using common
gates. The manipulation shown below illustrates the flexibility obtained with mul¬
tiple output systems when implemented with three levels of gates.
W = A + BC + BD = A + B(C + D)
X = BC + BD + BCD = B(C + D) + BCD
Y = CD + CD = C® D
Z = D
The logic diagram that implements the above expressions is drawn in Figure 3-6.
C C
CD A CD _
00 01 r 11 10 00 01 11 ICH
AB AB
00 00
11 1 ’i 11
01 1 1 1 01 1
>B >B
11 X X X X 11 X X X X
A< j
A<
10 1 1 X X 10 1 X X
V V
D D
W = A + BC + BD X = BC + BD + BCD
C C
CD 00 A
01 01 1 1
>B >B
11 11 X X X X
< j A<
j
10 10 1 X X
v
D D
Y = CD + CD Z = D
FIGURE 3-5
Maps for BCD to Excess-3 Code Converter
FIGURE 3-6
Logic Diagram of BCD to Excess-3 Code Converter
Section 3-3 Design Procedure 87
FIGURE 3-7
Seven-Segment Display
TABLE 3-3
Truth Table for BCD to Seven-Segment Decoder
A B c D a b c d e f 9
0 0 0 0 1 1 1 1 1 1 0
0 0 0 1 0 1 1 0 0 0 0
0 0 1 0 1 1 0 1 1 0 1
0 0 1 1 1 1 1 1 0 0 1
0 1 0 0 0 1 1 0 0 1 1
0 1 0 1 1 0 1 1 0 1 1
0 1 1 0 1 0 1 1 1 1 1
0 1 1 1 1 1 1 0 0 0 0
1 0 0 0 1 1 1 1 1 1 1
1 0 0 1 1 1 1 1 0 1 1
All other inputs 0 0 0 0 0 0 0
88 Chapter 3 Combinational Systems
meaningless display for the unused combinations. A better choice may be to turn
off all the segments when any one of the unused input combinations occur. This
can be accomplished by assigning all 0’s to minterms 10 through 15.
The information from the truth table can be transferred into seven maps from
which the simplified output functions can be derived. The plotting of the seven
functions in maps is left for an exercise (see Problem 3-10). One possible way of
simplifying the seven functions results in the following Boolean functions:
TABLE 3-4
Truth table of half adder
Inputs Outputs
x y C S
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 0
bits is added to the next higher order pair of significant bits. A combinational
circuit that performs the addition of two bits is called a half adder. One that performs
the addition of three bits (two significant bits and a previous carry) is called a full
adder. The name of the circuits stem from the fact that two half adders are employed
to implement a full adder. The full adder circuit is the basic arithmetic component
from which all other arithmetic circuits are constructed.
Half Adder
A half adder is an arithmetic circuit that generates the sum of two binary digits.
The circuit has two inputs and two outputs. The input variables are the augend
and addend bits to be added and the output variables produce the sum and carry.
We assign the symbols X and Y to the two inputs and S (sum) and C (carry) to
the outputs. The truth table for the half adder is listed in Table 3-4. The C output
is 1 only when both inputs are 1. The S output represents the least significant bit
of the sum. The Boolean functions for the two outputs can be easily obtained from
the truth table.
S = XY + XY = X®Y
C = XY
The half adder can be implemented with one exclusive-OR and one AND gate as
shown in Figure 3-8.
Full Adder
A full adder is a combinational circuit that forms the arithmetic sum of three input
bits. It consists of three inputs and two outputs. Two of the input variables, denoted
by X and Y, represent the two significant bits to be added. The third input, Z,
FIGURE 3-8
Logic Diagram of Half Adder
90 Chapter 3 Combinational Systems
TABLE 3-5
Truth Table of Full Adder
Inputs Outputs
X Y z C S
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
represents the carry from the previous lower significant position. Two outputs are
necessary because the arithmetic sum of three bits ranges in value from zero to
three, and binary two and three need two digits. Again, the two outputs are
designated by the symbols S for sum and C for carry; the binary variable S gives
the value of the least significant bit of the sum; and the binary variable C gives
the output carry.
The truth table of the full adder is listed in Table 3-5. The values for the outputs
are determined from the arithmetic sum of the three input bits. When all input
bits are 0, the outputs are 0. The S output is equal to 1 when only one input is
equal to 1 or when all three inputs are equal to 1. The C output has a carry of 1
if two or three inputs are equal to 1.
The maps for the two outputs of the full adder are shown in Figure 3-9. The
simplified sum of product functions for the two outputs are
C = XY + XZ + YZ
This implementation requires seven AND gates and two OR gates. However, the
map for output S is recognized as an exclusive-OR function as discussed in Section
2-7. Furthermore, the C output function can be manipulated as shown in Figure
Y Y
YZ YZ A
00 01 r 11 10 ' 00 01 11 10
x X
o i 1 0 1
xO 1 i xO 1 1 1
Z z
S = XYZ + XYZ + XYZ + XYZ C = XY + XZ ± YZ_
= X ® Y © Z = XY + Z(XY + XY)
= XY + Z(X © Z)
FIGURE 3-9
Maps for Full Adder
Section 3-4 Arithmetic Circuits 91
■c
FIGURE 3-10
Logic Diagram of Full Adder
3-9 to include the exclusive-OR of X and Y. The Boolean functions for the full
adder in terms of exclusive-OR operations can be expressed as follows:
S = A® Y ® Z
C = XY + Z(X ® Y)
The logic diagram for this implementation is shown in Figure 3-10. It consists of
two half adders and an OR gate.
B3 A3 Z?2 A2 Bi A-\ B0 Aq
c4 S3 S2 Si So
FIGURE 3-11
4-Bit Parallel Adder
92 Chapter 3 Combinational Systems
requires n full adders with each output carry connected to the input carry of the
next-higher-order full adder.
Consider the two binary fiumbers A = 1011 and 5 = 0011. Their sum S =
1110 is formed with a four-bit parallel adder as follows:
The input carry in the least significant position is 0. Each full adder receives the
corresponding bits of A and B and the input carry, and generates the sum bit for
5 and the output carry. The output carry in each position is transferred to the input
carry of the next-higher-order position.
The 4-bit adder is a typical example of a digital component which is available
in medium scale integration (MSI) packages. It can be used in many applications
involving arithmetic operations. Observe that the design of this circuit by the usual
method would require a truth table with 512 entries since there are nine inputs to
the circuit. By using an iterative method of cascading an already known full adder
circuit, it is possible to obtain a simple and straightforward implementation.
Binary Adder-Subtractor
The subtraction of binary numbers can be done most conveniently by means of
complements as discussed in Section 1-4. Remember that the subtraction A — B
can be done by taking the 2’s complement of B and adding it to A. The 2’s
complement can be obtained by taking the l’s complement and adding one to the
least significant bit. The l’s complement can be implemented easily with inverter
circuits and we can add one to the sum by making the input carry of the parallel
adder equal to 1.
The circuit for subtracting A - B consists of a parallel adder as shown in Figure
3-11 with inverters placed between each B terminal and the corresponding full
adder input. The input carry C0 must be equal to 1. The operation performed
becomes A plus the l’s complement of B plus 1. This is equal to A plus the 2’s
complement of B. For unsigned numbers, this gives A — B if A > B or the 2’s
complement of (5 - A) if A < B. For signed numbers, the result is A - B
provided there is no overflow. (See Section 1-5).
The addition and subtraction operations can be combined into one circuit with
one common binary adder. This is done by including an exclusive-OR gate with
each full adder. A 4-bit adder-subtractor circuit is shown in Figure 3-12. Input 5
controls the operation. When 5 = 0 the circuit is an adder and when 5=1 the
circuit becomes a subtractor. Each exclusive-OR gate receives input 5 and one of
the inputs of B. When 5 = 0, we have B ® 0 = B. The full adders receive the
value of B, the input carry is 0 and the circuit performs A plus B. When 5=1,
we have 5 0 1 = 5 and C0 = 1. The circuit performs the operation A plus the
2’s complement of 5.
Section 3-4 Arithmetic Circuits 93
FIGURE 3-12
Adder-Subtractor Circuit
BCD Adder
Computers or calculators that perform arithmetic operations directly in the decimal
number system represent decimal numbers in binary coded form. An adder for
such a system must employ arithmetic circuits that accept coded decimal numbers
and present results in the same code. For binary addition, it is sufficient to consider
a pair of significant bits together with a previous carry. A decimal adder requires
a minimum of nine inputs and five outputs since four bits are required to code
each decimal digit and the circuit must have an input and output carry. There is a
wide variety of possible decimal adder circuits, depending upon the code used to
represent the decimal digits. Here we consider a decimal adder for the BCD code.
The rules for BCD addition were established in Section 1-6. First, the BCD
digits are added as if they were two 4-bit binary numbers. When the binary sum
is less than or equal to 1001 (decimal 9), the corresponding BCD digit sum is
correct. However, when the binary sum is greater than 1001, we obtain a nonvalid
BCD result. The addition of binary 0110 (decimal 6) to the binary sum converts
it to the correct BCD representation and also produces an output carry as required.
Consider the addition of two decimal digits in BCD with an input carry. Since
each digit does not exceed 9, the sum cannot be greater than 9 + 9 + 1 = 19.
The logic circuit that checks for the necessary BCD correction can be derived by
detecting the occurrence of the binary numbers from 1010 through 10011 (decimal
10 through 19). It is obvious that a correction is needed when the binary sum has
an output carry. This condition occurs when the sum is greater than or equal to
16. The other six combinations from 1010 through 1111 that need a correction have
a 1 in the most significant position and a 1 in the second or third significant position.
A BCD adder that adds two BCD digits and produces a sum digit in BCD is
shown in Figure 3-13. It has two 4-bit binary adders and a correction circuit. The
two decimal digits together with an input carry are added in the first 4-bit binary
adder to produce the binary sum. The condition for correction can be expressed
by the following Boolean function.
94 Chapter 3 Combinational Systems
Addend Augend
Input
carry
BCD sum
FIGURE 3-13
Block Diagram of BCD Adder
C = K + Z:Z3 + Z2Z3
C is the output carry from the BCD adder and K is the output carry from the first
binary adder. The two terms with the Z variables detect the binary outputs from
1010 through 1111.
When the BCD carry is equal to 0, nothing is added to the binary sum. This
condition occurs if the sum of the two digits plus input carry is less than or equal
to binary 1001. When the output carry is equal to 1, binary 0110 is added to the
binary sum through the second 4-bit adder. This condition occurs when the sum
is greater than or equal to 1010. Any output carry from the second binary adder
can be neglected.
A decimal parallel adder that adds two n decimal digits needs n BCD adders.
The output carry from each BCD adder must be connected to the input carry of
the adder in the next higher position.
Binary Multiplier
Multiplication of binary numbers is performed in the same way as with decimal
numbers. The multiplicand is multiplied by each bit of the multiplier, starting from
the least significant bit. Each such multiplication forms a partial product. Successive
Section 3-4 Arithmetic Circuits 95
£?i Bo Ao
A-1 Ao
A0B-[ AqBq
A-\B0
Ci Co Ay
FIGURE 3-14
A 2-Bit by 2-Bit Binary Multiplier
partial products are shifted one position to the left. The final product is obtained
from the sum of the partial products.
To see how a binary multiplier can be implemented with a combinational circuit,
consider the multiplication of two 2-bit numbers as shown in Figure 3-14. The
multiplicand bits are and B0, the multiplier bits are A1 and A0 and the product
is C3C2C1C0. The first partial product is formed by multiplying B}B0 by A(). The
multiplication of two bits such as A0 and B0 produces a 1 if both bits are 1; otherwise
it produces a 0. This is identical to an AND operation. Therefore, the partial
product can be implemented with AND gates as shown in the diagram. The second
partial product is formed by multiplying BAB() by A1 and is shifted one position to
the left. The two partial products are added with two half adder (HA) circuits.
Usually there are more bits in the partial products and it will be necessary to use
full adders to produce the sum of the partial products. Note that the least significant
bit of the product does not have to go through an adder since it is formed by the
output of the first AND gate.
A combinational circuit binary multiplier with more bits can be constructed in
a similar fashion. A bit of the multiplier is ANDed with each bit of the multiplicand
in as many levels as there are bits in the multiplier. The binary output in each level
of AND gates is added in parallel with the partial product of the previous level to
form a new partial product. The last level produces the product. For J multiplier
bits and K multiplicand bits we need J x K AND gates and (/ — 1) AT-bit adders
to produce a product of J + K bits.
As a second example, consider a multiplier circuit that multiplies a binary number
of four bits by a number of three bits. Let the multiplicand be represented by
B3B2BlB0 and the multiplier by A2A1A0. Since K = 4 and J = 3, we need 12 AND
gates and two 4-bit adders to produce a product of 7 bits. The logic diagram of
the multiplier circuit is shown in Figure 3-15.
96 Chapter 3 Combinational Systems
C6 C5 C4 C3 C2 Cl
FIGURE 3-15
A 4-Bit by 3-Bit Binary Multiplier
3-5 DECODERS
Discrete quantities of information are represented in digital computers with binary
codes. A binary code of n bits is capable of representing up to 2n distinct elements
of the coded information. A decoder is a combinational circuit that converts binary
information from the n coded inputs to a maximum of 2n unique outputs. If the
n-bit coded information has unused bit combinations, the decoder may have fewer
than 2n outputs.
The decoders presented in this section are called n-to-ra-line decoders where m
< 2n. Their purpose is to generate the 2n (or fewer) minterms of n input variables.
A decoder has n inputs and m outputs and is referred to as an n x m decoder.
The logic diagram of a 3-to-8-line decoder is shown in Figure 3-16. The three
inputs are decoded into eight outputs, each output representing one of the minterms
of the three input variables. The three inverters provide the complement of the
Section 3-5 Decoders 97
Dq — A 2A i/4 o
D-\ — A 2A ]Aq
D2 — A 2A i/4 o
D3 = A 2AiAq
D4 — A2A iA 0
D5 — 1-^0
Dq — A2A-\Aq
D7 — A2A-\Aq
FIGURE 3-16
3-to-8-Line Decoder
inputs, and each one of the eight AND gates generates one of the minterms. A
particular application of this decoder is a binary-to-octal conversion. The input
variables represent a binary number and the outputs represent the eight digits in
the octal number system. However, a 3-to-8-line decoder can be used for decoding
any three-bit code to provide eight outputs, one for each element of the code.
The operation of the decoder may be clarified from the truth table listed in
Table 3-6. For each possible input combination, there are seven outputs that are
equal to 0 and only one that is equal to 1. The output variable equal to 1 represents
the minterm equivalent of the binary number that is available in the input lines.
Some decoders are constructed with NAND instead of AND gates. Since a
TABLE 3-6
Truth Table for 3-to-8-Line Decoder
Inputs Outputs
a2 A A0 D7 D6 D5 d4 d3 D2 D, Do
0 0 0 0 0 0 0 0 0 0 1
0 0 1 0 0 0 0 0 0 1 0
0 1 0 0 0 0 0 0 1 0 0
0 1 1 0 0 0 0 1 0 0 0
1 0 0 0 0 0 1 0 0 0 0
1 0 1 0 0 1 0 0 0 0 0
1 1 0 0 1 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0 0
98 Chapter 3 Combinational Systems
E At Ao Do Di D2 Do
0 0 0 0 1 1 1
0 0 1 1 0 1 1
0 1 0 1 1 0 1
0 1 1 1 1 1 0
1 X X 1 1 1 1
FIGURE 3-17
A 2-to-4-Line Decoder with Enable Input
NAND gate produces the AND operation with an inverted output, it becomes
more economical to generate the decoder minterms in their complement form.
Furthermore, most commercial decoders include one or more enable inputs to
control the circuit operation. A 2-to-4-line decoder with an enable input constructed
with NAND gates is shown in Figure 3-17. The circuit operates with complemented
outputs and a complemented enable input E. The decoder is enabled when E is
equal to 0. As indicated by the truth table, only one output can be equal to 0 at
any given time, all other outputs are equal to 1. The output with a value of 0
represents the minterm selected by inputs Al and A0. The circuit is disabled when
E is equal to 1, regardless of the values of the other two inputs. When the circuit
is disabled, none of the outputs are equal to 0 and none of the minterms are
selected. In general, a decoder may operate with complemented or uncomple¬
mented outputs. The enable input may be activated with a 0 or with a 1 signal.
Some decoders have two or more enable inputs that must satisfy a given logic
condition in order to enable the circuit.
Decoder Expansion
There are occasions when a certain size decoder is needed, but only smaller sizes
are available. When this occurs, it is possible to combine two or more decoders
with enable inputs to form a larger decoder. Thus, if a 6-to-64-line decoder is
needed, it is possible to construct it with four 4-to-16-line decoders.
Figure 3-18 shows how decoders with enable inputs can be connected to form
a larger decoder. Two 2-to-4-line decoders are combined to achieve a 3-to-8-line
decoder. The two least significant bits of the input are connected to both decoders.
The most significant bit is connected to the enable input of one decoder and through
an inverter to the enable input of the other decoder. When A2 = 0, the upper
decoder is enabled and the other is disabled. The lower decoder outputs become
inactive with all outputs at 0. The upper decoder generates the minterms D0 through
D3 using the values of A! and A(). When A2 = 1, the enable conditions are reversed
and minterms D4 through D7 are generated. Note that these decoders are enabled
with a logic-1 signal.
Section 3-5 Decoders 99
Do
D,
■D 2
■D 2
D4
d5
■d6
1 D~j
FIGURE 3-18
A 3 x 8 Decoder Constructed with Two 2x4 Decoders
The example demonstrates the usefulness of the enable input in decoders or any
other combinational logic component. Enable inputs are a convenient feature for
interconnecting two or more integrated circuits for the purpose of expanding the
digital function into a similar function with more inputs and outputs.
Example 3-2 Implement a full adder circuit with a decoder and OR gates.
From the truth table of the full adder (Table 3-5) we obtain the functions for
the combinational circuit in sum of minterms.
S(X, T, Z) = 1, 2, 4, 7)
C(A, y, Z) - lm(3, 5, 6, 7)
100 Chapter 3 Combinational Systems
FIGURE 3-19
Implementing a Full Adder Using a Decoder
Since there are three inputs and a total of eight minterms, we need a 3-to-8-line
decoder. The implementation is shown in Figure 3-19. The decoder generates the
eight minterms for X, Y, Z. The OR gate for output S forms the logical sum of
minterms 1,2,4, and 7. The OR gate for output C forms the logical sum of minterms
3, 5, 6, and 7. ■
A function with a long list of minterms requires an OR gate with a large number
of inputs. A function having a list of k minterms can be expressed in its complement
form with 2n — k minterms. If the number of minterms in a function F is greater
than 2n/2 then its complement F can be expressed with fewer minterms. In such a
case, it is advantageous to use a NOR gate instead of an OR gate. The OR portion
of the gate produces the logical sum of the minterms of F. The output of the NOR
gate complements this sum and generates the normal output F.
If NAND gates are used for the decoder, as in Figure 3-17, the external gates
must be NAND gates instead of OR gates. This is because a two level NAND gate
circuit implements a sum of minterms function and is equivalent to a two level
AND-OR circuit (see Section 2-6).
The decoder method can be used to implement any combinational circuit. How¬
ever, its implementation must be compared with all other possible implementations
to determine the best solution. In some cases this method may provide the best
solution, especially if the combinational circuit has many outputs and each output
function is expressed with a small number of minterms.
3-6 ENCODERS
An encoder is a digital function that performs the inverse operation of a decoder.
An encoder has 2n (or less) input lines and n output lines. The output lines generate
the binary code corresponding to the input value. An example of an encoder is
the octal-to-binary encoder whose truth table is given in Table 3-7. It has eight
inputs, one for each of the octal digits, and three outputs that generate the cor¬
responding binary number. It is assumed that only one input has a value of 1 at
any given time; otherwise the circuit has no meaning.
Section 3-6 Encoders 101
TABLE 3-7
Truth Table for Octal-to-Binary Encoder
Inputs Outputs
D7 De D5 d4 d3 D2 D, Do A2 A-\ A0
0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 1 0 0 0 0 1 1
0 0 0 1 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0 1 0 1
0 1 0 0 0 0 0 0 1 1 0
1 0 0 0 0 0 0 0 1 1 1
The encoder can be implemented with OR gates using inputs determined directly
from the truth table. Output A0 = 1 if the input octal digit is 1 or 3 or 5 or 7.
Similar conditions apply for the other two outputs. These conditions can be ex¬
pressed by the following output Boolean functions:
A0 = + D3 + D5 + D7
A i — D2 + D3 T Dfr + D-j
A2 = D4 + D5 + D6 + D-j
The encoder can be implemented with three OR gates.
The encoder defined in Table 3-7 has the limitation that only one input can be
active at any given time. If two inputs are active simultaneously, the output produces
an undefined combination. For example, if D3 and De are 1 simultaneously, the
output of the encoder will be 111 because all the three outputs are equal to 1. This
does not represent a binary 3 nor a binary 6. To resolve this ambiguity, encoder
circuits must establish an input priority to ensure that only one input is encoded.
If we establish a higher priority for inputs with higher subscript numbers and if
both D3 and D6 are 1 at the same time, the output will be 110 because D6 has
higher priority than D3.
Another ambiguity, in the octal-to-binary encoder is that an output of all 0’s is
generated when all the inputs are 0, but this output is the same as when D0 is equal
to 1. This discrepancy can be resolved by providing one more output to indicate
that at least one input is equal to 1.
Priority Encoder
A priority encoder is a combinational circuit that implements the priority function.
The operation of the priority encoder is such that if two or more inputs are equal
to 1 at the same time, the input having the highest priority will take precedence.
The truth table of a four-input priority encoder is given in Table 3-8. The X’s
designate don’t care conditions. Input D3 has the highest priority; so regardless of
the values of the other inputs, when this input is 1, the output for AXA0 is 11 (binary
3). D2 has the next priority level. The output is 10 if D2 = 1 provided that D3 =
102 Chapter 3 Combinational Systems
TABLE 3-8
Truth Table of Priority Encoder
Inputs Outputs
D3 d2 d, D0 A A0 V
0 0 0 0 0 0 0
0 0 0 1 0 0 1
0 0 1 X 0 1 1
0 1 X X 1 0 1
1 X X X 1 1 1
0, regardless of the values of the other two lower-priority inputs. The output for
Dx is generated only if higher-priority inputs are 0, and so on down the priority
levels. The valid output designated by V is set to 1 only when one or more of the
inputs are equal to 1. If all inputs are 0, V is equal to 0, and the other two outputs
of the circuit are not used.
The maps for simplifying outputs A1 and A0 are shown in Figure 3-20. The
minterms for the two functions are derived from Table 3-8. Although the table has
only five rows, when each don’t care is replaced first by 0 and then by 1, we obtain
all 16 possible input combinations. For example, the third row in the table with
001X represents minterms 0010 and 0011 since X can be assigned either 0 or 1. The
simplified functions obtained from the maps are listed under each map. The con¬
dition for output V is an OR function of all the input variables. The priority encoder
is implemented in Figure 3-21 according to the following Boolean functions:
Aq = D3 + DlD2
A i — D2 + D3
V — Dq + Di + D2 + D3
D^ 0i
A
oo oi r 7i uT^ 00 01 1 T(P
oo 00 1 1
01 1 1 1 1 01
r 0; >D;
11 1 1 1 1 11 1 1 1 1
dA D'! J
10 1 1 1 1 10 1 1 1 1
~v~
00 00
A i — D2 + 0; ^0 — 03 + 0102
FIGURE 3-20
Maps for Priority Encoder
Section 3-7 Multiplexers 103
FIGURE 3-21
Logic Diagram of a 4-Input Priority Encoder
3-7 MULTIPLEXERS
A multiplexer is a combinational circuit that selects binary information from one
of many input lines and directs it to a single output line. The selection of a particular
input line is controlled by a set of selection variables. Normally, there are 2n input
lines and n selection variables whose bit combinations determine which input is
selected.
A 4-to-1-line multiplexer is shown in Figure 3-22. Each of the four inputs D0
through D3 is applied to one input of an AND gate. Selection lines Sx and S0 are
decoded to select a particular AND gate. The outputs of the AND gates are applied
to a single OR gate to provide the 1-line ouput. To demonstrate the circuit op-
Function table
FIGURE 3-22
4-to-1-Line Multiplexer
104 Chapter 3 Combinational Systems
eration, consider the case when S^q = 10. The AND gate associated with input
D2 has two of its inputs equal to 1 and the third input connected to D2. The other
three AND gates have at least one input equal to 0, which makes their outputs
equal to 0. The OR gate output is now equal to the value of D2, providing a path
from the selected input to the output. The function table in the figure lists the
input that provides the path to the output for each combination of the binary
selection variables. A multiplexer is also called a data selector since it selects one
of many inputs and steers the binary information to the output line.
The AND gates and inverters in the multiplexer resemble a decoder circuit, and
indeed, they decode the input selection lines. In general, a 2"-to-l-line mutliplexer
is constructed from an n-to-2n decoder by adding 2" input lines to it, one from each
data input. The size of the multiplexer is specified by the number 2" of its data
input lines and the single output line. It is then implied that it also contains n
selection lines. The multiplexer is often abbreviated as MUX.
A multiplexer can be constructed with transmission gates. The transmission gate
is available only with CMOS type integrated circuits, and its operation is explained
in conjunction with Figure 2-37. A 4-to-l-line multiplexer implemented with trans¬
mission gates (TG) is shown in Figure 3-23. The TG circuit provides a transmission
path between the horizontal input and output lines when the two vertical control
inputs have the value of 1 in the uncircled terminal and 0 in the circled terminal.
FIGURE 3-23
Multiplexer with Transmission Gates (TG)
Section 3-7 Multiplexers 105
With an opposite polarity in the control inputs, the path disconnects, and the circuit
behaves like an open switch. The two selection inputs and S0 control the trans¬
mission path in the TG circuits. Inside each box is marked the condition for the
circuit to be closed. Thus, if S0 = 0 and Sx = 0 there is a closed path from input
D0 to output Y and the other three inputs are disconnected by one of the other
TG circuits.
As in decoders, multiplexers may have an enable input to control the operation
of the unit. When the enable input is in the inactive state, the outputs are disabled,
and when it is in the active state, the circuit functions as a normal multiplexer.
The enable input is useful for expanding two or more multiplexers into a multiplexer
with a larger number of inputs.
In some cases, two or more multiplexers are enclosed within a single integrated
circuit package. The selection and the enable inputs in multiple-unit construction
are usually common to all multiplexers. As an illustration, a quadruple 2-to-l-line
multiplexer is shown in Figure 3-24. The circuit has four multiplexers, each capable
(enable)
FIGURE 3-24
Quadruple 2-to-1-Line Multiplexer
106 Chapter 3 Combinational Systems
of selecting one of two input lines. Output Y() can be selected to come from either
input A0 or B{). Similarly, output Yy may have the value of Ax or Bu and so on.
Input selection line S selects one of the lines in each of the four multiplexers. The
enable input E must be active for normal operation. Although the circuit contains
four multiplexers, we can also think of it as a circuit that selects one of two 4-bit
data lines. As shown in the function table, the unit is enabled when E = 1. Then,
if S = 0, the four A inputs have a path to the four outputs. On the other hand, if
5=1, the four B inputs are applied to the outputs. The outputs have all 0’s when
E = 0, regardless of the values of S.
4 x 1 MUX
y- So
X- Si
X Y Z F
0 0 0 n
U
0 0 1 ? —
0 1 0 z- i
0 1 1 0 F=I
0- 2
1 0 0 0
1 0 1 0 F=0 1 —— 3
1 1 0
1 F=1
1 1 1 1
FIGURE 3-25
Implementing a Boolean Function with a Multiplexer
Section 3-7 Multiplexers 107
X is connected to the S{ input and Y to the S0 input. The values for the data input
lines are determined from the truth table of the function. When XY = 00, output
F is equal to Z because F = 0 when Z = 0 and F = 1 when Z = 1. This requires
that variable Z be applied to data input 0. The operation of the multiplexer is such
that when XY = 00, data input 0 has a path to the output which makes F equal
to Z. In a similar fashion we can determine the required input to lines 1, 2, and 3
from the value of Fwhen XY = 01,10, and 11, respectively. This particular example
shows all four possibilities that can be obtained for the data inputs.
The general procedure for implementing any Boolean function of n variables
with a multiplexer with n — 1 selection inputs and 2"”1 data inputs follows from
the above example. The Boolean function is first listed in a truth table. The first
n — 1 variables listed in the table are applied to the selection inputs of the mul¬
tiplexer. For each combination of the selection variables, we evaluate the output
as a function of the last variable. This can be 0, 1, the variable, or the complement
of the variable. These values are then applied to the data inputs in the proper
order. As a second example, consider the implementation of the following Boolean
function:
F(A, B, C, D) = 2 m{ 1, 3, 4, 11, 12, 13, 14, 15)
This is implemented with a multiplexer with three selection inputs as shown in
Figure 3-26. Note that the first variable A must be connected to selection input S2
so that A, B, C correspond to selection inputs S2, S1? and S0, respectively. The
values for the data inputs are determined from the truth table listed in the figure.
The corresponding data line number is determined from the binary combination
of ABC. For example, when ABC = 101, the table shows that F = D\ so input
variable D is applied to data input 5. The binary constants 0 and 1 correspond to
two signal values. If TTL type integrated circuits are used, then logic-0 corresponds
to signal ground and logic-1 is equivalent to a five-volt signal.
Do
Di
D2
D3
FIGURE 3-27
1-to-4-Line Demultiplexer
Demultiplexer
A demultiplexer is a digital function that performs the inverse operation of a
multiplexer. A demultiplexer receives information from a single line and transmits
it to one of 2n possible output lines. The selection of the specific output is controlled
by the bit combination of n selection lines. A l-to-4-line demultiplexer is shown
in Figure 3-27. The data input E has a path to all four outputs, but the input
information is directed to only one of the outputs as specified by the two selection
lines and S0. For example, if = 10, output D2 will be the same as the input
value of E, while all other outputs remain inactive at logic-0.
A careful inspection of the demultiplexer circuit will show that it is identical to
a 2-to-4-line decoder with enable input. For the decoder, the data inputs are S1
and S0 and the enable is input E. For the demultiplexer, input E provides the data
while the other inputs accept the selection variables. Although the two circuits
have different applications, their logic diagrams are exactly the same. For this
reason, a decoder with enable input is referred to as a decoder/demultiplexer.
Often used digital components such as adders, decoders, and multiplexers are
available commercially in integrated circuits and are classified as MSI functions.
Standard graphic symbols have been developed for these and other components
so that the user can recognize each function from the unique graphic symbol
assigned to it. This standard, known as ANSI/IEEE Std. 91-1984, has been ap¬
proved by industry, government, and professional organizations and is consistent
with international standards.
The standard uses a rectangular shape outline to represent each particular logic
function. Within the outline there is a general qualifying symbol denoting the logical
operation performed by the unit. For example, the general qualifying symbol for
Section 3-8 Standard Graphic Symbols 109
a multiplexer is MUX. The size of the outline is arbitrary and can be either a
square or rectangular shape with arbitrary length-width ratio. Input lines are placed
on the left and output lines are placed on the right. If the direction of signal flow
is reversed, it must be indicated by arrows. The rectangular shape symbols for the
digital gates were introduced in Figure 2-25.
An example of a standard graphic symbol is the 4-bit parallel adder shown in
Figure 3-28. The qualifying symbol for an adder is the Greek letter X. The preferred
letters for the arithmetic operands are P and Q. The bit-grouping symbols in the
two types of inputs and the sum output are the decimal equivalent of the weights
of the bits to the power of 2. Thus, the input labeled 3 corresponds to the value
of 23 = 8. The input carry is designated by Cl and the output carry by CO.
Before introducing the graphic symbols of other components, it is necessary to
review some terminology. As mentioned in Section 2-8, a positive logic system
defines the more positive of two signal levels (designated by H) as logic-1 and the
more negative signal level (designated by L) as logic-0. Negative logic assumes the
opposite assignment. A third alternative is to employ a mixed-logic convention
where the signals are considered entirely in terms of their H and L values. At any
point in the circuit, the user is allowed to define the logic polarity by assigning
logic-1 to either the H or L signal. The mixed-logic notation uses a small right-
angle triangle graphic symbol to designate a negative logic polarity at any input or
output terminal. (See Figure 2-42f.)
Integrated circuit manufacturers specify the operation of integrated circuits in
terms of H and L signals. When an input or output is considered in terms of positive
logic, it is defined as active-high. When it is considered in terms of negative logic,
it is assumed to be active-low. Active-low inputs or outputs are recognized by the
presence of the small triangle polarity indicator graphic symbol. When positive
logic is used exclusively throughout the entire system, the small triangle polarity
symbol is equivalent to the small circle that designates a negation. In this book we
assume positive logic throughout, and we will employ the small circle when drawing
logic diagrams. When an input or output line does not include the small circle, we
will define it to be active if it is logic-1. A line that includes the small circle symbol
FIGURE 3-28
Standard Graphic Symbol for a 4-Bit Parallel Adder
110 Chapter 3 Combinational Systems
will be considered active if it is in the logic-0 state. However, we will use the small
triangle polarity symbol to indicate active-low assignment in all drawings that rep¬
resent standard diagrams. This will conform with integrated circuit data books
where the polarity symbol is usually employed. The easiest way to understand what
has been said is to realize that the small triangle polarity symbol is equivalent to
the small circle negation symbol when positive logic is used.
FIGURE 3-29
Standard Graphic Symbol for a Decoder
Section 3-8 Standard Graphic Symbols 111
and produces a different binary code on a number of outputs. Instead of using the
qualifying symbol X/Y, the coder can be specified by the code name. For example,
the 3-to-8-line decoder of Figure 3-29(a) can be symbolized with the name BIN/
OCT since the circuit converts a 3-bit binary code into an 8 output octal value.
When the digital component represented by the outline is also a commercial in¬
tegrated circuit, it is customary to write the IC pin number along each input and
output line.
At any given time, only one out of the eight AND gates can be active. The active
A
X- Gl
Y- G2
B
A- 1
B - 1
C- 2
C
FIGURE 3-30
Example of a G (AND) Dependency
112 Chapter 3 Combinational Systems
AND gate is determined from the inputs associated with the G symbol. These
inputs are marked with weights equal to the powers of 2. For the eight AND gates
listed above, the weights are 0, 1, and 2, corresponding to the numbers 2°, 21, and
22, respectively. The AND gate that is active at any given time is determined from
the sum of the weights of the active inputs. Thus, if inputs 0 and 2 are active, the
AND gate that is active has the number 2° + 22 = 5. This makes G5 active and
the other seven AND gates inactive.
The standard graphic symbol for the multiplexer is shown in Figure 3-31. The
label MUX identifies the device as a multiplexer. The symbols inside the block are
part of the standard notation, but the symbols marked outside are user defined
symbols. In order to understand the standard notation, we use the same external
variables here as in the logic diagrams of the multiplexers in Section 3-7.
The diagram of Figure 3-31 (a) represents an 8-to-l-line multiplexer with enable
(EN) input. The AND dependency is marked with Gj and is associated with the
inputs enclosed in brackets. These inputs have weights of 0, 1, and 2. They are
actually what we have called the selection inputs. The eight data inputs are marked
with numbers from 0 to 7. The net weight of the active inputs associated with the
G symbol specify the number in the data input that is active. For example, if
selection inputs S2SlS0 = HO, then inputs 1 and 2 associated with G are active.
This gives a numerical value for the AND dependency of 22 + 21 = 6, which
makes G6 active. Since G6 is ANDed with data input number 6, it makes this
input active. Thus the output will be equal to data input D6 provided that the
enable input is active.
The diagram of Figure 3-31(b) represents the quadruple 2-to-l-line multiplexer
whose logic diagram is shown in Figure 3-24. The enable and selection inputs are
common to all four multiplexers. This is indicated in the standard notation by the
indented box at the top of the diagram which represents a common control block.
The inputs to a common control block control all lower sections of the diagram.
MUX MUX
E - EN _
S - 0} G y
E - EN
cn
9, l G° An o
2j 7 B0- 1 V'o
Dn 0 A^- 0
D1 1 Bi 1 Vi
Do 2
Do 3 ^2- 0
Da 4 B2- 1 U
DK 5
nc 6 A 3- 0
D7 7 b3 1 G
FIGURE 3-31
Standard Graphic Symbols for Multiplexers
Section 3-8 Standard Graphic Symbols 113
The common enable input EN is active when in the high level state. The AND
dependency Gi represents two AND gates GO and G1. When S = 0, GO is active
and the inputs marked with 0 are active. When S = 1, Gl is active and the inputs
marked with 1 are active. The active inputs are applied to the corresponding outputs
if EN is active.
Dependency Notation
The most important aspect of the standard logic symbols is the dependency notation.
Dependency notation is used to provide the means of denoting the relationship
between different inputs or outputs without actually showing all the elements and
interconnections between them. We have already defined the G (AND) depend¬
ency in connection with the symbol for the multiplexer. The ANSI/IEEE standard
defines ten other types of dependencies. Each dependency is denoted by a letter
symbol (except EN). The letter appears at the input or output and is followed by
a number. Each input or output affected by that dependency is labeled with that
same number.
The eleven dependencies and their corresponding letter designation are as fol¬
lows:
The G and EN dependencies were introduced in this section. The control de¬
pendency C is used to identify a clock input in a sequential element and to indicate
which input is controlled by it. The set S and reset R dependencies are used to
specify internal logic states of an SR flip-flop. The C, S, and R dependencies are
explained in Section 4-3 in conjunction with the flip-flop circuit. The mode M
dependency is used to identify inputs that select the mode of operation of the unit.
The mode dependency is presented in Chapter 5 in conjunction with registers and
counters. The address A dependency is used to identify the address input of a
memory. It is introduced in Chapter 6 in conjunction with the memory unit.
The Z dependency is used to indicate interconnections inside the unit. It signifies
the existence of internal logic connections between inputs, outputs, internal inputs
and internal outputs, in any combination. The X dependency is used to indicate
the controlled transmission path in a transmission gate similar to the one shown
in Figure 2-37.
114 Chapter 3 Combinational Systems
FIGURE 3-32
Graphic Symbol for an Adder-Subtractor
Description
Open-circuit output
FIGURE 3-33
Qualifying Symbols Associated with Inputs and Outputs
REFERENCES
1. Peatman, J. B. Digital Hardware Design. New York: McGraw-Hill, 1980
2. Blakeslee, T. R. Digital Design with Standard MSI and LSI. 2nd ed. New York:
Wiley, 1979.
3. Mano, M. M. Digital Design. Englewood Cliffs: Prentice-Hall, 1984.
116 Chapter 3 Combinational Systems
4. Sandige, R. S. Digital Concepts Using Standard Integrated Circuits. New York: McGraw-
Hill, 1978.
5. IEEE Standard Graphic Symbols for Logic Functions. (ANSI/IEEE Std. 91-1984.) New
York: The Institute of Electrical and Electronics Engineers.
6. Kampel, I. A Practical Introduction to the New Eogic Symbols. Boston: Butterworths,
1985.
7. The TTL Data Book. Vol. 2. Dallas: Texas Instruments, 1985.
8. High-Speed CMOS Logic Data Book. Dallas: Texas Instruments, 1984.
PROBLEMS
3-1 Determine the Boolean functions for outputs J and K as a function of the four inputs
in the circuit of Figure P3-1.
D
J
C
B
K
FIGURE P3-1
Circuit for Problem 3-1
3-2 Obtain the truth table for the circuit shown in Figure P3-2. Draw an equivalent circuit
for F with fewer NAND gates.
F
Y
FIGURE P3-2
Circuit for Problem 3-2
3-3 Verify that the circuit of Figure P3-3 generates the exclusive-NOR function.
FIGURE P3-3
Circuit for Problem 3-3
Section Problems 117
3-4 A majority function is generated in a combinational circuit when the output is equal
to 1 if the input variables have more l’s than 0’s. The output is 0 otherwise. Design
a 3-input majority function.
3-5 Design a combinational circuit that detects an error in the representation of a decimal
digit in BCD. In other words, obtain a logic diagram whose output is equal to 1 when
the inputs contain any one of the six unused bit combinations in the BCD code.
3-6 Design a combinational circuit that accepts a three-bit number and generates an output
binary number equal to the square of the input number.
3-7 Design a combinational circuit whose input is a four-bit number and whose output is
the 2’s complement of the input number.
3-8 Design a combinational circuit that converts a decimal digit from the 8 4-2-1 code to
BCD (see Table 1-5).
3-9 Design a combinational circuit that converts a decimal digit from the 2 4 2 1 code to
the 8 4-2-1 code (see Table 1-5).
3-10 (a) Plot the seven maps for each of the outputs for the BCD to seven-segment decoder
specified in Table 3-3.
(b) Simplify the seven output functions in sum of products and determine the total
number of gates that will be needed to implement the decoder.
(c) Verify that the seven output functions listed in the text give a valid simplification.
Compare the number of gates with the circuit obtained in part (b).
3-11 Draw the logic diagram of the BCD to seven-segment decoder from the Boolean
functions listed in Section 3-3 of the text. Use only 21 NAND gates. Assume that
both the complemented and uncomplemented inputs are available.
3-12 Design a combinational circuit that forms the binary sum of two 2-bit numbers AXA0
and BXB0. Do not use half adders or full adders. Design the circuit starting with a
truth table.
3-13 The logic diagram of the first stage of a 4-bit adder as implemented in integrated
circuit type 74283 is shown in Figure P3-13. Verify that the circuit implements a full
adder.
FIGURE P3-13
Circuit for Problem 3-13
118 Chapter 3 Combinational Systems
3-14 Construct a BCD to excess-3 code converter with a 4-bit adder. Remember that the
excess-3 code digit is obtained by adding three to the corresponding BCD digit. What
must be done to change the circuit to an excess-3 to BCD code converter?
3-15 The adder-subtractor circuit of Figure 3-12 has the following values for input select S
and data inputs A and B. In each case, determine the values of the outputs S3, S2, Su
SQ, and C4.
s A B
F2 = X + Y
F3 = XY + XY
3-25 A combinational circuit is specified by the following three Boolean functions. Imple¬
ment the circuit with a decoder constructed with NAND gates (similar to Figure
3-17) and external NAND gates.
FX(A, £, C) = 2m(0, 5, 7)
3-26 Draw the logic diagram of a 2-to-4-line decoder with only NOR gates. Include an
enable input.
3-27 Design a 4-input priority encoder with inputs and outputs as in Table 3-8 but with
input D0 having the highest priority.
3-28 Derive the truth table of an octal-to-binary priority encoder.
3-29 Construct an 8-to-l-line multiplexer with enable input using transmission gates.
3-30 Construct a 16-to-l-line mutliplexer with two 8-to-l-line multiplexers and one 2-to-l-
line multiplexer. Use standard block diagram symbols.
3-31 Implement a full adder with a dual 4-to-1-line multiplexer.
3-32 Implement the following Boolean function with a multiplexer.
F(A, B, C, D) = 2 m(0, 3, 5, 6, 8, 9, 14, 15)
3-33 Implement the Boolean function defined in the truth table of Figure 3-26 with a 4-to-
1-line multiplexer and external gates. Connect inputs A and B to the selection lines.
The input requirements for the four data lines will be a function of variables C and
D. These values are obtained by expressing F as a function of C and D for each of
the four cases when AB = 00, 01, 10, and 11. These functions may have to be
implemented with external gates.
3-34 Rearrange the truth table for the circuit of Figure 3-17 and verify that it can function
as a demultiplexer.
3-35 Draw the graphic symbol for a BCD-to-decimal decoder with enable input. This is
similar to Figure 3-29 but with four data inputs and ten outputs.
3-36 Draw the graphic symbol for a binary-to-octal decoder with three enable inputs, E1,
E2, and E3. The circuit is enabled if El = 1, E2 = 0, and E3 = 0 (assuming positive
logic). The qualifying symbol name for the decoder is BIN/OCT. The enable symbol
EN is placed at the output of an AND gate with inputs El, El, and E3. The rectangular
shape AND gate symbol is placed within the rectangular shape outline of the decoder.
(This is the same as TTL type integrated circuit 74138.)
3-37 Draw the graphic symbol diagram of a dual 4-to-l-line multiplexer with separate enable
inputs and common selection inputs. (This is the same as TTL type integrated circuit
74153.)
3-38 Define in your own words:
(a) Positive and negative logic. (d) Common control block.
(b) Active-high and active-low. (e) Dependency notation.
(c) Polarity indicator.
3-39 Show an example of a graphic symbol that has the three Boolean dependencies G, V,
and N. Draw the equivalent interpretation.
4
SEQUENTIAL
LOGIC
4-1 INTRODUCTION
The digital circuits considered thus far have been combinational where the outputs
at any point in time are entirely dependent upon the inputs that are presented at
that time. Although every digital system is likely to have a combinational circuit,
most systems encountered in practice also include storage elements, which requires
that the system be described in terms of sequential circuits.
A block diagram of a sequential circuit is shown in Figure 4-1. It consists of a
combinational circuit and storage elements that together form a feedback system.
The storage elements are devices capable of storing binary information within them.
The binary information stored at any given time defines the state of the sequential
circuit. The sequential circuit receives binary information from external inputs.
These inputs, together with the present state of the storage elements, determine
the binary value of the outputs. They also determine the condition for changing
the state of the storage elements. The block diagram demonstrates that the outputs
Inputs
FIGURE 4-1
Block Diagram of a Sequential Circuit.
120
Section 4-1 Introduction 121
in a sequential circuit are a function not only of external inputs but also of the
present state of the storage elements. The next state of the storage elements is also
a function of the inputs and the present state. Thus, a sequential circuit is specified
by a time sequence of inputs, outputs, and internal states.
There are two main types of sequential circuits, and their classification depends
on the timing of the signals. A synchronous sequential circuit is a system whose
behavior can be defined from the knowledge of its signals at discrete instants of
time. The behavior of an asynchronous sequential circuit depends upon the order
in which the inputs change, and the state of the circuit can be affected at any
instant of time. The storage elements commonly used in asynchronous sequential
circuits are time-delay devices. The storage capability of a time-delay device is due
to the fact that it takes a finite time for the signal to propagate through the device.
In practice, the internal propagation delay of logic gates is of sufficient duration
to produce the needed delay so that actual delay units may not be necessary. In
gate type asynchronous systems, the storage elements consist of logic gates where
propagation delay provides the required storage. Thus, an asynchronous sequential
circuit may be regarded as a combinational circuit with feedback. Because of the
feedback among logic gates, the system may operate in an unpredictable manner
and sometimes may even become unstable. The various problems encountered in
asynchronous systems impose many difficulties on the designer, and for this reason
they are very seldom used.
A synchronous sequential circuit employs signals that affect the storage elements
only at discrete instants of time. Synchronization is achieved by a timing device
called a clock generator that produces a periodic train of clock pulses. The clock
pulses are distributed throughout the system in such a way that storage elements
are affected only upon the arrival of each pulse. In practice, the clock pulses are
applied with other signals that specify the required change in the storage elements.
The outputs of storage elements change only when clock pulses are present. Syn¬
chronous sequential circuits that use clock pulses in the input of storage elements
are called clocked sequential circuits. Clocked sequential circuits are the type most
frequently encountered in practice. They seldom manifest instability problems and
their timing is easily broken down into independent discrete steps, each of which
can be considered separately.
The storage elements employed in clocked sequential circuits are called flip-
flops. A flip-flop is a binary storage device capable of storing one bit of information.
Normally, a sequential circuit will use many flip-flops to store as many bits as
necessary. The block diagram of a synchronous clocked sequential circuit is shown
in Figure 4-2. The outputs can come from either the combinational circuit or from
the flip-flops. The flip-flops receive their inputs from the combinational circuit and
also from a train of pulses that occur at fixed intervals of time as shown in the
timing diagram. The next state of the flip-flops can change only during a clock
pulse transition. When a clock pulse is not active, the feedback loop is broken
because the flip-flop outputs cannot change even if the outputs of the combinational
circuit change in value. Thus, the transition from one state to the other occurs only
at predetermined time intervals dictated by the clock pulses.
A flip-flop circuit has two outputs, one for the normal value and one for the
complemented value of the bit that is stored in it. Binary information can enter a
122 Chapter 4 Sequential Logic
Inputs-►- Outputs
Combinational
circuit
Flip-flops
Clock pulses
flip-flop in a variety of ways, a fact which gives rise to different types of flip-flops.
This chapter presents the types of flip-flops available and examines their operation
and logical properties. It then proceeds to develop methods and procedures for
the analysis and design of synchronous clocked sequential circuits.
4-2 LATCHES
A flip-flop circuit can maintain a binary state indefinitely (as long as power is
delivered to the circuit), until directed by an input signal to switch states. The
major differences among the various types of flip-flops are in the number of inputs
they possess and the manner in which the inputs affect the binary state. The most
basic types of flip-flops operate with signal levels and are referred to as latches.
The latches introduced here are the basic circuits from which all flip-flops are
constructed. Although latches can be useful for storing binary information, they
are not practical for use in synchronous sequential circuits. The types of flip-flops
employed in sequential circuits are presented in the next section.
SR Latch
The SR latch is a circuit with two cross-coupled NOR gates or two cross-coupled
NAND gates. It has two inputs labeled S for set and R for reset. The SR latch
constructed with two cross-coupled NOR gates is shown in Figure 4-3. The latch
has two useful states. When output <2 = 1 and Q = 0, it is said to be in the set
state. When <2 = 0 and Q = 1, it is in the reset state. Output Q and Q are normally
the complements of each other. An undefined state occurs when both outputs are
equal to 0. This occurs when both inputs are equal to 1 at the same time.
Under normal conditions, both inputs of the latch remain at 0 unless the state
has to be changed. The application of a momentary 1 to the S input causes the
latch to go to the set state. The S input must go back to 0 before any other changes
can occur. As shown in the function table, there are two input conditions that
cause the circuit to be in the set state. The first condition is the action that must
Section 4-2 Latches 123
S R Q Q
1 0 1 0
Set state
0 0 1 0
0 1 0 1
Reset state
0 0 0 1
1 1 0 0 Undefined
FIGURE 4-3
SR Latch with NOR Gates
be taken by input S to bring the circuit to the set state. Removing the active input
from S leaves the circuit in the same state. After both inputs return to 0 it is possible
to shift to the reset state by momentarily applying a 1 to the R input. We can then
remove the 1 from R and the circuit remains in the reset state. Thus, when both
inputs S and R are equal to 0, the latch can be in either the set or the reset state,
depending on which input was a 1 just prior to the change.
If a 1 is applied to both the S and R inputs of the latch, both outputs go to 0.
This produces an undefined state because it results in an unpredictable next state
when both inputs return to 0. It also violates the requirement that outputs Q and
Q be the complement of each other. In normal operation this condition is avoided
by making sure that l’s are not applied to both inputs simultaneously.
The SR latch with two cross-coupled NAND gates is shown in Figure 4-4. It
operates with both inputs normally at 1 unless the state of the latch has to be
changed. The application of a momentary 0 to the S input causes output Q to go
to 1, putting the latch in the set state. When the S input goes back to 1, the circuit
remains in the set state. After both inputs go back to 1, we are allowed to change
the state of the latch by placing a 0 in the R input. This causes the circuit to go to
the reset state and stay there even after both inputs return to 1. The condition that
is undefined for the NAND latch is when both inputs are equal to 0 at the same
time.
Comparing the NAND with the NOR latch we note that the input signals for
the NAND require the complement values of those used for the NOR latch.
Because the NAND latch requires a 0 signal to change its state, it is sometimes
S R Q Q
0 1 1 0
Set state
1 1 1 0
1 0 0 1
Reset state
1 1 0 1
o
1 1 Undefined
o
FIGURE 4-4
SR Latch with NAND Gates
124 Chapter 4 Sequential Logic
c s Ft Next state of Q
Q 0 X X No change
1 0 0 No change
1 0 1 Q = 0; Reset state
1 1 0 Q - 1; Set state
c 1 1 1 Indeterminate
Q
R
(a) Logic diagram (b) Function table
FIGURE 4-5
SR Latch with Control Input
referred to as an S-R latch. The bar above the letters designates the fact that the
inputs must be in their complement form to activate the circuit.
The operation of the basic SR latch can be improved by providing an additional
control input that determines when the state of the latch can be changed. An SR
latch with a control input is shown in Figure 4-5. It consists of the basic SR latch
and two additional NAND gates. The control input C acts as an enable signal for
the other two inputs. The output of the NAND gates stays at the logic-1 level as
long as the control input remains at 0. This is the quiescent condition for the SR
latch. When the control input goes to 1, information from the S or R input is
allowed to reach the SR latch. The set state is reached with S = 1, R = 0, and
C = 1. To change to the reset state, the inputs must be S = 0, R — 1, and C =
1. In either case, when C returns to 0, the circuit remains in its current state. When
the control input disables the circuit by applying a 0 to C, the state of the output
does not change, regardless of the values of S and R. Moreover, when C = 1 and
both the S and R inputs are equal to 0, the state of the circuit does not change.
These conditions are listed in the function table accompanying the diagram.
An indeterminate condition occurs when all three inputs are equal to 1. This
condition places 0’s in both inputs of the basic SR latch which places it in the
undefined state. When the control input goes back to 0, we cannot positively
determine the next state as it depends on whether the S or R input goes to 0 first.
This indeterminate condition makes the circuit of Figure 4-5 difficult to manage,
and it is seldom used in practice. Nevertheless, it is an important circuit because
all other latches and flip-flops are constructed from it. It should be mentioned that
sometimes the SR latch with control input is referred to as an SR (or RS) flip-flop.
However, to qualify as a flip-flop, the circuit must fulfill the requirements that are
mentioned in the next section.
D Latch
One way to eliminate the undesirable condition of the indeterminate state in the
SR latch is to insure that inputs S and R are never equal to 1 at the same time.
This is done in the D latch shown in Figure 4-6. This latch has only two inputs, D
(data) and C (control). The D input goes directly to the S input, and its complement
is applied to the R input. As long as the control input is at 0, the cross-coupled
SR latch has both inputs at the 1 level and the circuit cannot change state regardless
Section 4-2 Latches 125
D c D Next state of Q
Q 0 X No change
1 0 Q — 0; Reset state
1 1 Q — 1; Set state
FIGURE 4-6
D Latch
FIGURE 4-7
D Latch with Transmission Gates
126 Chapter 4 Sequential Logic
4-3 FLIP-FLOPS
Master-Slave Flip-Flop
The master-slave flip-flop consists of two latches and an inverter. A D-type master-
slave flip-flop is shown in Figure 4-8. The first D latch is called the master and the
second, the slave. When the clock pulse input C is 0, the output of the inverter is
D D Q
D latch D latch
(master) (slave)
C C
FIGURE 4-8
Master-Slave D Flip-Flop
Section 4-3 Flip-Flops 127
c
D
Q- -
FIGURE 4-9
Timing Relationship with a Master-Slave
Flip-Flop
1. The slave latch is enabled and its output Q is equal to the master output Y. The
master latch is disabled because C = 0. When the input pulse changes to the logic-
1 level, the data in the external D input is transferred to the master. The slave,
however, is disabled as long as the pulse remains in the 1 level because its C input
is equal to 0. Any changes in the external D input changes the master output Y
but cannot affect the slave output Q. When the pulse returns to 0, the master is
disabled and is isolated from the D input. At the same time the slave is enabled,
and the value of Y is transferred to the output of the flip-flop at Q.
The timing relationships shown in Figure 4-9 illustrate the sequence of events
that occur in the D-type master-slave flip-flop. Assume that initially the flip-flop
is in the reset state prior to the occurrence of a pulse; so Y = 0 and <2 = 0. The
data input D is equal to 1 and the next clock pulse should change the flip-flop to
the set state with <2 = 1. After the pulse transition from 0 to 1, the master latch
is set and changes Y to 1. The slave latch is not affected because its C input is 0.
Since the master is an internal circuit, its change of state is not noticed in the
output Q. Even though the input may be changing, the output of the flip-flop
remains in its previous state. When the pulse returns to 0, the information from
the master is allowed to pass through to the slave, making the external output
<2 = 1. The external input D can change at the same time that the pulse goes
through its negative transition. This is because once the C input reaches 0, the
master is disabled and its data input has no effect until the next clock pulse. The
timing diagram of Figure 4-9 continues with a second clock pulse that finds the
external D input at 0. The circuit changes to 0 by first switching the master and
then the slave output.
If we replace the master D latch in Figure 4-8 with an SR latch with control
input, we will obtain a master-slave SR flip-flop. Remember that the SR flip-flop
has the undesirable condition of producing an indeterminate next state when inputs
S and R both equal 1 (see function table of Figure 4-5) and so is seldom used in
practice.
A modified version of the SR flip-flop that eliminates the undesirable condition
is the JK flip-flop. In this type of flip-flop, the condition that both inputs are equal
to 1 causes the output to complement its value. The master-slave JK flip-flop is
shown in Figure 4-10. The master is an SR latch with the control input receiving
128 Chapter 4 Sequential Logic
FIGURE 4-10
Master-Slave JK Flip-Flop
the clock pulses. The slave is a D latch that operates with the complement of the
clock pulse. The / input behaves like the S input to set the flip-flop. The K input
is similar to the R input for resetting the flip-flop. The only difference between
the SR and JK flip-flops is their response to the condition when both inputs are
equal to 1. As can be verified from the diagram, this condition complements the
outputs in the JK flip-flop. This is because of the feedback connection from the
outputs to the inputs. When Q = 1 and K = 1 the R input is equal to 1. The S
input is 0, even if / = 1, because Q, being the complement of Q, must be 0. The
next clock pulse will reset the flip-flop and change the Q output to 0. Similarly, if
we start with Q = 0, the clock pulse will set the flip-flop and change output Q to
1. In either case, the condition of / = 1 and K = 1 causes the outputs of the flip-
flop to complement in response to a clock pulse.
Now consider a sequential system containing many master-slave flip-flops, with
the outputs of some flip-flops going to inputs of other flip-flops. Assume that the
clock pulses to all flip-flops are synchronized and occur at the same time. At the
beginning of each clock pulse, some of the masters change state, but all the slaves
remain in the previous state. That means that the outputs of the flip-flops are still
in the present state while the internal masters have changed to the next state. After
the clock pulse returns to 0, some of the outputs change state, but none of the
new states have an effect on any of the masters until the next pulse. Thus the states
of flip-flops in a synchronous system can change simultaneously during the same
clock pulse, even though outputs of flip-flops are connected to inputs of the same
or other flip-flops. This is possible because the new state appears at the outputs
only after the clock pulse has returned to 0.
For reliable sequential circuit operation, all signals must propagate from the
outputs of flip-flops, through the combinational circuit, and back to inputs of
master-slave flip-flops, while the clock pulse remains in the logic-0 level. Any
changes that occur at the inputs of flip-flops after the pulse goes to the logic-1 level
are not recognized by the outputs. In most applications, the clock pulse width is
very narrow compared to the clock period which makes the low level duration of
the clock stay on longer. Since the master triggers on the positive transition of the
pulse and the slave on the negative transition, the master-slave is classified as a
pulse-triggered flip-flop.
Section 4-3 Flip-Flops 129
Edge-Triggered Flip-Flop
An edge-triggered flip-flop ignores the pulse while it is at a constant level but triggers
only during the transition of the clock signal. Some edge-triggered flip-flops trigger
on the positive edge (0 to 1 transition) and others trigger on the negative edge (1
to 0 transition).
The logic diagram of a D-type positive-edge-triggered flip-flop is shown in Figure
4-11. It consists of three SR latches. Two latches respond to the external D (data)
and C (clock) inputs. The third latch provides the outputs for the flip-flop. The S
and R inputs of the output latch are maintained at logic-1 level when C = 0. This
causes the output to remain in its present state. Input D may be equal to 0 or 1.
If D = 0 when C becomes 1, R changes to 0. This causes the flip-flop to go to the
reset state making Q = 0. If now, while C = 1, there is a change in the D input,
terminal R remains at 0. Thus, the flip-flop is locked out and is unresponsive to
further changes in the D input until the clock returns to 0 and another positive
transition occurs. Similarly, if D = 1 when C goes from 0 to 1, S changes to 0.
This causes the circuit to go to the set state making <2 = 1. Any change in D while
C = 1 does not affect the output.
In summary, when the input clock in the positive-edge-triggered flip-flop makes
a positive transition, the value of D is transferred to Q. A negative transition from
1 to 0 does not affect the output; nor is it affected when C is in either the steady
logic-1 level or the logic-0 level. Hence this type of flip-flop responds to the tran¬
sition from 0 to 1 and nothing else.
The timing of the response of a flip-flop to input data and clock must be taken
into consideration when using edge-triggered flip-flops. There is a minimum time
called setup time in which the D input must be maintained at a constant value prior
to the occurrence of the clock transition. Similarly, there is a definite time called
the hold time that the D input must not change after the application of the positive
transition of the pulse. The propagation delay time of the flip-flop is defined as the
FIGURE 4-11
D-Type Positive-Edge-Triggered Flip-Flop
130 Chapter 4 Sequential Logic
time interval between the trigger edge and the stabilization of the output to the
new state. These and other parameters are specified in integrated circuit data books.
Positive-edge-triggered
Master-slave JK flip-flop
D flip-flop
Positive-edge-triggered Negative-edge-triggered
JK flip-flop JK flip-flop
FIGURE 4-12
Standard Graphic Symbols for Latch and Flip-Flops
Section 4-3 Flip-Flops 131
from the adopted polarity transition can be changed by the addition of inverters
in their clock inputs. A preferred procedure is to provide both positive and negative
pulses in the master clock generator. Apply the positive pulses to pulse-triggered
(master-slave) and negative-edge-triggered flip-flops and negative pulses to the
positive-edge-triggered flip-flops. In this way all flip-flop outputs will change at the
same time.
In this book we will assume that all flip-flops are of the positive-edge-triggered
type. This will provide a uniform graphic symbol and consistent timing diagrams.
Characteristic Tables
A characteristic table defines the logical properties of a flip-flop by describing its
operation in tabular form. The characteristic tables of four types of flip-flops are
presented in Table 4-1. They define the next state as a function of the inputs and
present state. Q(t) refers to the present state prior to the application of a pulse.
QU + 1) is the next state one clock period later. Note that the pulse input at C
is not listed in the characteristic table but is implied to occur between time t and
t + 1.
The characteristic table for the JK flip-flop shows that the next state is equal to
the present state when inputs J and K are both equal to 0. This can be expressed
as Q(t + 1) = Q(t) indicating that the clock pulse produces no change of state.
When K = 1 and / = 0, the next clock pulse resets the flip-flop with Q(t + 1) =
0. With J = 1 and K = 0, the flip-flop sets with Q(t + 1) = 1. When both J and
K are equal to 1, the next state changes to the complement of the present state
which can be expressed as Q{t + i) = Q(t)-
The SR flip-flop is similar to the JK when S is replaced by J and R by K except
for the indeterminate case. The question mark for the next state when S and R
are both equal to 1 indicates an unpredictable next state. The SR flip-flop is
important only for historical reasons. Its graphic symbol is similar to the JK with
the inputs marked with S and R instead of J and K.
The next state of a D flip-flop is dependent only on the D input and is inde¬
pendent of the present state. This can be expressed as Q(t + 1) = D(t). Note that
TABLE 4-1
Flip-Flop Characteristic Tables
the D flip-flop does not have a no change condition. This condition can be accom¬
plished either by disabling the clock pulses in the C input or by leaving the clock
pulses and connecting the output back into the D input when the state of the flip-
flop must remain the same.
The T (toggle) flip-flop listed in Table 4-1 is obtained from a JK flip-flop when
inputs J and K are tied together. The graphic symbol for the T flip-flop is the same
as the JK except that the J and K inputs are connected externally to provide a
single input marked T. The characteristic table has only two conditions. When T
= 0 {J = K ~ 0) a clock pulse does not change the state. When T = 1 (/ = K
= 1) a clock pulse complements the state of the flip-flop. Like the SR, the T flip-
flop is important only for historical reasons and is readily obtained from the JK
when needed.
Direct Inputs
Flip-flops available in integrated circuit packages provide special inputs for setting
and resetting the flip-flop asynchronously. These inputs are usually called direct
set and direct reset. They affect the output on the negative (or positive) level of
the signal without the need of a clock. When power is turned on in a digital system,
the states of its flip-flops can be anything. The direct inputs are useful for bringing
all flip-flops in a digital system to an initial state prior to their clocked operation.
The graphic symbol of the JK flip-flop with direct set and reset is shown in
Figure 4-13. The notation Cl, 1J, and IK are examples of control dependency. An
input labeled Cn, where n is any number, is a control input that controls all the
other inputs starting with the number n. In this case. Cl controls inputs 17 and
IK. S and R have no 1 in front of the letter, and therefore, they are not controlled
by the clock at Cl. The S and R inputs have a small circle along the input line to
indicate that they are active when in the logic-0 level.
The function table specifies the circuit operation. The first three entries in the
table specify the operation of the direct inputs S and R. These inputs behave like
a NAND SR latch (see Figure 4-4) and are independent of the clock and the J and
K inputs. The last four entries in the function table specify the clock operation
when both the S and R inputs are inactive and in the logic-1 level. The clock at C
is shown with an upward arrow to indicate that the flip-flop is a positive-edge-
triggered type. The J and K inputs respond to the clock in the usual manner.
-0 S S R c J K Q Q
0 1 X X X 1 0
1J —Q
1 0 X X X 0 1
>C1 0 0 X X X 1 1
1/C D—— Q 1 1 t 0 0 No change
1 1 t 0 1 0 1
-0 R
1 1 t 1 0 1 0
1 1 t 1 1 Complement
FIGURE 4-13
JK Flip-Flop with Direct Set and Reset
Section 4-4 Analysis Procedure 133
The behavior of a sequential circuit is determined from the inputs, the outputs,
and the state of its flip-flops. The outputs and the next state are both a function
of the inputs and the present state. The analysis of a sequential circuit consists of
obtaining a suitable description that demonstrates the time sequence of inputs,
outputs, and flip-flop states.
A logic diagram is recognized as a sequential circuit if it includes flip-flops. The
flip-flops may be of any type and the logic diagram may or may not include a
combinational circuit. In this section, we introduce an algebraic representation for
specifying the logic diagram of a sequential circuit. We then present a state table
and state diagram that describe the behavior of the sequential circuit. Specific
examples will be used throughout the discussion to illustrate the various procedures.
Input Equations
The logic diagram of a sequential circuit consists of flip-flops and combinational
gates. The knowledge of the type of flip-flops used and a list of Boolean functions
for the combinational circuit provide all the information needed to draw the logic
diagram of the sequential circuit. The part of the combinational circuit that gen¬
erates the signals for the inputs of flip-flops can be described by a set of Boolean
functions called input equations. We will adopt the convention of using the flip-
flop input symbol to denote the input equation variable and a subscript to designate
the name of the flip-flop. As an example, consider the following flip-flop input
equations.
JA = XB + YC
Ka = YB + C
JA and Ka are two Boolean variables. The J and K symbols are the inputs of a JK
flip-flop. The subscript letter A is the symbolic name of the flip-flop output. The
implementation of the two input equations is shown in the logic diagram of Figure
4-14. The JK flip-flop has been assigned an output symbol letter A. It has two
inputs / and K and an input clock C. The combinational circuit drawn in the diagram
is the implementation of the algebraic expression given by the input equations.
FIGURE 4-14
Implementing Input Equations
134 Chapter 4 Sequential Logic
The outputs of the combinational circuit, denoted by JA and KA, are then applied
to the J and K inputs of flip-flop A.
From this example we see that a flip-flop input equation is a Boolean expression
for a combinational circuit. The subscripted symbol is a variable name for the
output of the combinational circuit. This output is always connected to the input
of a flip-flop, thus the name input equation.
The flip-flop input equations constitute a convenient algebraic expression for
specifying the logic diagram of a sequential circuit. They imply the type of flip-
flop from the letter symbol, and they fully specify the combinational circuit that
drives the flip-flops. Time is not included explicitly in these equations but is implied
from the clock at the C input of the flip-flop.
An example of a sequential circuit is shown in Figure 4-15. The circuit consists
of two D-type flip-flops, an input X and an output Y. It can be specified by the
following equations:
Da = AX + BX
Db = AX
Y = (A + B)X
The first two are the input equations for the flip-flops and the third equation
specifies the output Y. Note that the input equations use the symbol D which is
the same as the input symbol of the flip-flops. The subscripts A and B designate
the output names given to the two flip-flops.
FIGURE 4-15
Example of a Sequential Circuit
Section 4-4 Analysis Procedure 135
TABLE 4-2
State Table for Circuit of Figure 4-15
Present Next
state Input state Output
A B X A B y
0 0 0 0 0 0
0 0 1 0 1 0
0 1 0 0 0 1
0 1 1 1 1 0
1 0 0 0 0 1
1 0 1 1 0 0
1 1 0 0 0 1
1 1 1 1 0 0
State Table
The time sequence of inputs, outputs, and flip-flop states can be enumerated in a
state table. The state table for the circuit of Figure 4-15 is shown in Table 4-2. The
table consists of four sections labeled present state, input, next state, and output.
The present state section shows the states of flip-flops A and B at any given time
t. The input section gives a value of X for each possible present state. The next
state section shows the states of the flip-flops one clock period later at time t +
1. The output section gives the value of Y for each present state.
The derivation of a state table consists of first listing all possible binary com¬
binations of present state and inputs. In this case we have eight binary combinations
from 000 to 111. The next state values are then determined from the logic diagram
or from the input equations. For a D flip-flip we have the relationship A(t + 1)
= DA{t). This means that the next state of flip-flop A is equal to the present value
of its input D (see Table 4-1). The value of the D input is specified in the input
equation as a function of the present state of A and B and input X. Therefore, the
next state of flip-flop A must satisfy the equation
A(t + 1) = Da = AX + BX
The next state section in the state table under column A has three l’s where the
present state and input value satisfy the conditions AX = 11 or BX =11. Similarly,
the next state of flip-flop B is derived from the input equation
B(t + 1 ) = DB = AX
and is equal to 1 when the present state of A is 0 and input X is equal to 1. The
output column is derived from the output equation
Y = AX + BX
The state table of any sequential circuit with D-type flip-flops is obtained by
the procedure outlined in the above example. In general, a sequential circuit with
m flip-flops and n inputs needs 2m+n rows in the state table. The binary numbers
from 0 through 2m + n — 1 are listed under the present state and input columns.
The next state section has m columns, one for each flip-flop. The binary values
136 Chapter 4 Sequential Logic
Present Next
state Inputs state
A X Y A
0 0 0 0
0 011
0 10 1
0 110
1 0 0 1
1 0 10
1 10 0
1 111
FIGURE 4-16
Logic Diagram and State Table for DA = A ® X © Y
for the next state are derived directly from the D flip-flop input equations. The
output section has many columns as there are output variables. Its binary value is
derived from the circuit or from the Boolean function in the same manner as in a
truth table.
The external outputs of a sequential circuit may come from logic gates or from
outputs of flip-flops. The output section in the state table is necessary only if there
are outputs from logic gates. Any external output taken directly from flip-flops are
already listed in the present state columns of the state table. Therefore, the output
section of the state table is excluded if there are no external outputs from gates.
As an example, suppose we want to obtain the logic diagram and state table of
a sequential circuit that is specified by the input equation
Da = A © A © Y
The Da symbol implies a D-type flip-flop with output designated by the letter
A. The X and Y variables are taken as inputs. The logic diagram and state table
are shown in Figure 4-16. The state table has one column for the present state and
two columns for the inputs. There are no external outputs. The next state column
is derived from the input equation that specifies an odd function (see Section
2-7).
1. Obtain the binary values of each flip-flop input equation in terms of the
present state and input variables.
2. Use the corresponding flip-flop characteristic from Table 4-1 to determine
the next state.
To illustrate this procedure, consider the sequential circuit with two JK flip-flops
A and B and one input X specified by the following input equations:
Section 4-4 Analysis Procedure 137
TABLE 4-3
State Table for Circuit with JK Flip-Flops
0 0 0 0 1 0 0 1 0
0 0 1 0 0 0 0 0 1
0 1 0 1 1 1 1 1 0
0 1 1 1 0 1 0 0 1
1 0 0 1 1 0 0 1 1
1 0 1 1 0 0 0 0 0
1 1 0 0 0 1 1 1 1
1 1 1 1 1 1 0 0 0
JA = B Ka = BX
JB = X KB = AX +AX
The state table is shown in Table 4-3. The binary values listed under the columns
labeled flip-flop inputs are not part of the state table. They are needed for the
purpose of evaluating the next state as specified in step 1 of the procedure listed
above. These binary values are obtained directly from the four input equations in
a manner similar to that for obtaining a truth table from an algebraic expression.
The next state of each flip-flop is evaluated from the corresponding J and K inputs
and the characteristic table of the JK flip-flop listed in Table 4-1. There are four
cases to consider. When J = 1 and K = 0, the next state is 1. When 7 = 0 and
K = 1, the next state is 0. When J = K = 0, there is no change of state and the
next state value is the same as the present state. When J = K = 1, the next state
bit is the complement of the present state bit. Examples of the last two cases occur
in the table when the present state and input (ABX) is 100. JA and KA are both
equal to 0 and the present state of A is 1. Therefore, the next state of A remains
the same and is equal to 1. In the same row of the table, JB and KB are both equal
to 1. Since the present state of B is 0, the next state of B is complemented and
changes to 1.
State Diagram
The information available in a state table may be represented graphically in a form
of a state diagram. In this type of diagram, a state is represented by a circle, and
the transition between states is indicated by directed lines connecting the circles.
Examples of state diagrams are shown in Figure 4-17. The diagram in (a) is for
the sequential circuit of Figure 4-15 and the state table of Table 4-2. The state
diagram provides the same information as the state table and is obtained directly
from it. The binary number inside each circle identifies the state of the flip-flops.
The directed lines are labeled with two binary numbers separated by a slash. The
input value during the present state is labeled first and the number after the slash
gives the output during the present state. For example, the directed line from state
138 Chapter 4 Sequential Logic
(a) For circuit of Figure 4-1 5 (b) For circuit of Figure 4-1 6
and Table 4-2
FIGURE 4-17
State Diagrams
00 to 01 is labeled 1/0, meaning that when the sequential circuit is in the present
state 00 and the input is 1, the output is 0. After the next clock transition, the
circuit goes to the next state, 01. The same clock transition may change the input
value. If the input changes to 0 then the output becomes 1, but if the input remains
at 1 the output stays at 0. This information is obtained from the state diagram
along the two directed lines emanating from the circle with state 01. A directed
line connecting a circle with itself indicates that no change of state occurs.
The state diagram of Figure 4-17(b) is for the sequential circuit of Figure 4-16.
Here we have only one flip-flop with two states. There are two binary inputs and
no outputs. The slash is not included when there are no outputs and only the inputs
are indicated along the directed lines. There are two input conditions for each state
transition in the diagram and they are separated by a comma. Normally, when
there are two input variables, each state will have four directed lines coming out
of the corresponding circle, one for each binary combination of the input values.
There is no difference between a state table and a state diagram except in the
manner of representation. The state table is easier to derive from a given logic
diagram and input equations. The state diagram follows directly from the state
table. The state diagram gives a pictorial view of state transitions and is the form
suitable for human interpretation of the circuit operation. For example, the state
diagram of Fig. 4-17(a) clearly shows that, starting at state 00, the output is 0 as
long as the input stays at 1. The first 0 input after a string of Fs gives an output
of 1 and sends the circuit back to the initial state of 00. The state diagram of Figure
4-17(b) shows that the circuit stays at a given state as long as the two inputs have
the same value (00 or 11). There is a state transition only when the two inputs are
different (01 or 10).
The design of clocked sequential circuits starts from a set of specifications and
culminates in a logic diagram or a list of Boolean functions from which the logic
diagram can be obtained. In contrast to a combinational circuit, which is fully
specified by a truth table, a sequential circuit requires a state table for its speci-
Section 4-5 Design with D Flip-Flops 139
fication. The first step in the design of sequential circuit is to obtain a state table
or an equivalent representation such as a state diagram.
A synchronous sequential circuit is made up of flip-flops and combinational
gates. The design of the circuit consists of choosing the flip-flops and finding a
combinational circuit structure which, together with the flip-flops, produces a circuit
that fulfills the stated specifications. The number of flip-flops is determined from
the number of states in the circuit realizing that n flip-flops can represent up to 2n
binary states. The combinational circuit is derived from the state table by evaluating
the flip-flop input equations and output functions. In fact, once the type and number
of flip-flops are determined, the design process involves a transformation from a
sequential circuit problem into a combinational circuit problem. In this way the
techniques of combinational circuit design can be applied.
Design Procedure
This section presents a procedure for the design of sequential circuits with D-type
flip-flops. The design with JK or any other type of flip-flop is covered in the next
section. The design procedure is carried out by going through the following steps:
1. Obtain the state table from the problem statement or from the state diagram.
2. Derive the flip-flop input equations from the next state conditions in the state
table.
3. Derive the output functions if there are output conditions in the state table.
4. Simplify the input equations and output functions.
5. Draw the logic diagram with D flip-flops and combinational gates as specified
by the input equations and output functions.
TABLE 4-4
State Table for Design Example
Present Next
state Input state Output
A B X A B y
0 0 0 0 0 0
0 0 1 0 1 1
0 1 0 1 0 0
0 1 1 0 1 0
1 0 0 1 0 0
1 0 1 1 1 1
1 1 0 1 1 0
1 1 1 0 0 0
and one output. Two D flip-flops are needed to represent the four states. Label
the flip-flop outputs with the letters A and B, the input with X and the output with
y.
The state table of the circuit is listed in Table 4-4. It is derived directly from
the state diagram. The flip-flop input equations are obtained from the next state
values. The output function is given by the binary values of Y. The three Boolean
equations for the combinational gates can be expressed as a sum of minterms of
the present state variables A and B and the input variable X.
B(t + 1) = Db(A, B, X) = X m( 1, 3, 5, 6)
Y(A, B,X) =2 m( 1, 5)
The Boolean functions are simplified by means of the maps plotted in Figure
4-19. The simplified functions are
Da = AB + BX
Db = AX + BX + ABX
Y = BX
B
BX A
00 01 11 10
^o
1
11 1
~V"
1
□ 1
Da = AB + BX Db = AX + BX + ABX Y = BX
FIGURE 4-19
Maps for Input Equations and Output Y
FIGURE 4-20
Logic Diagram for Sequential Circuit with D Flip-Flops
TABLE 4-5
State Table for Second Design Example
Present Next
state Input state
A B c X A B c
0 0 1 0 0 0 1
0 0 1 1 0 1 0
0 1 0 0 0 1 1
0 1 0 1 1 0 0
0 1 1 0 0 0 1
0 1 1 1 1 0 0
1 0 0 0 1 0 1
1 0 0 1 1 0 0
1 0 1 0 0 0 1
1 0 1 1 1 0 0
141
142 Chapter 4 Sequential Logic
X X 1 X X 1
1 1 1
X X X X X X X X
1 1
X
Da = AX + BX + BC Db = ACX + ABX Dc = X
FIGURE 4-21
Maps for Simplifying Input Equations
flops serve as outputs of the circuit. With three flip-flops it is possible to specify
eight states, but the state table lists only five states. There are three unused states
that are not included in the table. These are binary states 000, 110, and 111. When
an input of 0 or 1 is included with the unused present state values we obtain six
unused combinations for the present state and input columns. These are 0000, 0001,
1100, 1101, 1110, and 1111. These six combinations are not listed in the state table
and may be treated as don’t care minterms.
The three input equations for the D flip-flops are derived from the next state
values and simplified in the maps of Figure 4-21. Each map has six don’t care
minterms in the squares corresponding to binary 0, 1, 12, 13, 14, and 15. The
simplified equations are
Da = AX + BX + BC
Db = ACX + ABX
DC = X
The logic diagram can be obtained directly from the input equations and will not
be drawn here.
One factor neglected up to this point in the design is the initial state of a
sequential circuit. Since one does not know in what state the flip-flops will settle
when the power in a digital system is first turned on, it is customary to provide a
master reset switch to initialize the states of all flip-flops in the system. Typically,
the master reset signal is applied to all flip-flops in their asynchronous inputs (see
Figure 4-13) before the clocked operations start. In most cases, flip-flops are reset
to 0, but some may be set to 1, depending on the initial state desired.
There are occasions where the circuit is not reset to any particular initial state
and may end up being in an unused state. On other occasions, an undesirable noise
signal may send the circuit to an unused state. In both of these cases it is necessary
to ensure that the circuit eventually goes into one of the valid states so it can resume
normal operation. Otherwise, if the sequential circuit circulates among unused
states, there will be no way to bring it back to its intended sequence of state
Section 4-5 Design with D Flip-Flops 143
transitions. Although one can assume that this undesirable condition is not supposed
to occur, a careful designer must ensure that if it occurs, the circuit will resume
its proper operations after a few clock pulses.
It was stated previously that unused states in a sequential circuit can be treated
as don’t care conditions. Once the circuit is designed, the n flip-flops in the system
can be in any one of 2n possible states. If some of these states were taken as don’t
care conditions, the circuit must be investigated to determine the effect of these
unused states. The next state from an unused state can be determined from the
analysis of the circuit. In any case, it is always wise to analyze a circuit obtained
from a design to ensure that no mistakes were made during the design process.
As an illustration, we will analyze the sequential circuit obtained from the pre¬
vious design to determine the effect of the unused states. The analysis of the circuit
may be done by the method outlined in the previous section. The maps of the
input equations may also be of help. We need to start from the logic diagram or
from the input equations specifying the logic diagram and derive the state table,
including all eight states that the three flip-flops can maintain. If the derived state
table matches the information from Table 4-5, then we know that the design is
correct. In addition, we must determine the next states from the unused states 000,
110, and 111.
The maps of Figure 4-21 can help in finding the next state from each of the
unused states. Take for example the unused state 000. If the circuit exhibits a noise
signal and goes erroneously to state 000, an input X = 0 will transfer the circuit
to some next state and an input X = 1 will transfer it to another (or the same)
next state. We first investigate minterm ABCX = 0000 in the three maps (present
state 000 and input 0). We note that this minterm is taken with the l’s of the
function in all three cases. This means that the outputs of all three D flip-flops will
go to 1 during the next clock transition making the next state 111. Minterm ABCX
= 0001 (present state 000 and input 1) is included with the l’s in DA and DB and
with the 0’s in Dc. Therefore, the next state in this case will be 110. The effect of
the other two unused states can be derived in a similar fashion from minterms 1100
through 1111.
The result of the analysis is shown in the state diagram of Figure 4-22. The
FIGURE 4-22
State Diagram for Circuit with Unused States
144 Chapter 4 Sequential Logic
circuit operates as intended as long as it stays within the states 001, 010, Oil, 100,
and 101. If the circuit is forced to one of the unused states 000, 110, or 111 because
of an external disturbance, it eventually goes to one of the valid states within one
or two clock periods. Thus the circuit is said to be self-correcting, since it eventually
goes to a valid state from which it continues to operate as required.
An undesirable situation occurs if the circuit, when in an unused state, circulates
and stays among unused states for all possible input combinations. It is important
to analyze the circuit to see that this does not happen. If it does, the circuit must
be redesigned by specifying valid next states from unused present states in order
to ensure that the circuit returns to its normal operation among the valid states.
The design of a sequential circuit with flip-flops other than the D type is complicated
by the fact that the input equations for the circuit must be derived indirectly from
the state table. When D-type flip-flops are employed, the input equations are
obtained directly from the next state. This is not the case for the JK and other
types of flip-flops. In order to determine the input equations for these flip-flops it
is necessary to derive a functional relationship between the state table and the
input equations.
TABLE 4-6
Flip-Flop Excitation Tables
0 0 0 X 0 0 0 X
0 1 1 X 0 1 1 0
1 0 X 1 1 0 0 1
1 1 X 0 1 1 X 0
0 0 0 0 0 0
0 1 1 0 1 1
1 0 0 1 0 1
1 1 1 1 1 0
D = Q{f+ 1)
Therefore, the values for input D can be taken directly from the values in the next
state column, as was done in the previous section.
The excitation table for the T flip-flop shows that the T input is equal to the
exclusive-OR of the present state and the next state. This can be expressed by the
following excitation function:
T = Q(t) © Q{t + 1)
Design Procedure
The design procedure for sequential circuits with JK flip-flops is the same as with
D flip-flops except that the input equations must be evaluated from the present
state to next state transition derived from the excitation table. To illustrate the
procedure we will design the sequential circuit specified by Table 4-7. This is the
same as Table 4-4 but without the output section. In addition to having columns
for the present state, input, and next state, as in a conventional state table, the
table also shows the flip-flop input conditions from which we obtain the input
equations. The flip-flop inputs in the table are derived from the state table in
146 Chapter 4 Sequential Logic
TABLE 4-7
State Table with JK Flip-Flop Inputs
Present Next
state Input state Flip-Flop inputs
A B X A B JA KA Jb Kb
0 0 0 0 0 0 X 0 X
0 0 1 0 1 0 X 1 X
0 1 0 1 0 1 X X 1
0 1 1 0 1 0 X X 0
1 0 0 1 0 X 0 0 X
1 0 1 1 1 X 0 1 X
1 1 0 1 1 X 0 X 0
1 1 1 0 0 X 1 X 1
conjunction with the excitation table for the JK flip-flop. For example, in the first
row of Table 4-7 we have a transition for flip-flop A from 0 in the present state to
0 in the next state. In Table 4-6 for the JK flip-flop we find that a transition of
states from 0 to 0 requires that input J be 0 and input K be a don’t-care. So 0 and
X are entered in the first row under JA and KA. Since the first row also shows a
transition for flip-flop B from 0 in the present state to 0 in the next state, 0 and X
are inserted in the first row under JB and KB. The second row of the table shows
a transition for flip-flop B from 0 in the present state to 1 in the next state. From
the excitation table we find that a transition from 0 to 1 requires that J be 1 and
K be a don’t care, so 1 and X are copied in the second row under JB and KB. This
process is continued for each row in the table and for each flip-flop, with the input
conditions from the excitation table copied into the proper row of the particular
flip-flop being considered.
The flip-flop inputs in Table 4-7 specify the truth table for the input equations
as a function of present state A and B and input X. The input equations are
simplified in the maps of Figure 4-23. The next state values are not used during
the simplification since the input equations are a function of the present state and
input only. Note the advantage of using JK type flip-flops when designing sequential
circuits. The fact that there are so many don’t care entries indicates that the
combinational circuit for the input equations is likely to be simpler because don’t
care minterms usually help in obtaining simpler expressions. If there are unused
states in the state table, there will be additional don’t care conditions in the map.
The four input equations for the two JK flip-flops are listed under the maps of
Figure 4-23. The logic diagram of the sequential circuit is drawn in Figure 4-24.
As a final example, consider the design of a sequential circuit with T flip-flops.
Using the state table portion of Table 4-7, we obtain the binary values for the T
flip-flop inputs from the excitation functions for A and B.
Ta = A(t) © A(t + 1)
Tb = B{t) © B(t + 1)
Going over the present state and next state values for A and B in the state table
we determine the binary values for TA and TB in the following manner. For each
- B B
BX f A.__
BX f
00 01 11 10 00 01 11 10
A
0 1
/I X X X X A
_)
~Y
X
Ka = BX
Jb — X Kb = AX + A X
= A ® x
FIGURE 4-23
Maps for J and K Input Equations
Clock
FIGURE 4-24
Logic Diagram for Sequential Circuit with JK Flip-Flops
147
148 Chapter 4 Sequential Logic
The algebraic expressions are the simplified input equations from which one can
draw the gates of the sequential circuit. The circuit consists of two T flip-flops,
three AND gates, two OR gates, and an inverter. Remember that a T flip-flop
can be constructed from a JK flip-flop with inputs J and K tied together to form
a single input T.
REFERENCES
1. Mano, M. M. Digital Design. Englewood Cliffs: Prentice-Hall, 1984.
2. Peatman, J. B. Digital Hardware Design. New York: McGraw-Hill, 1980.
3. Kohavi, Z. Switching and Automata Theory. 2nd ed. New York: McGraw-Hill, 1978.
4. Hill, F. J., and Peterson, G. R. Introduction to Switching Theory and Logical Design.
3rd ed. New York: Wiley, 1981.
5. Givone, D. D. Introduction to Switching Circuit Theory. New York: McGraw-Hill,
1970.
6. Roth, C. H. Fundamentals of Logic Design. 3rd ed. New York: West, 1985.
7. Booth, T. L. Introduction to Computer Engineering. 3rd ed. New York: Wiley, 1984.
PROBLEMS
4-1 The D latch shown in Figure 4-6 can be constructed with only four NAND gates. This
can be done by removing the inverter and connecting the output of the upper NAND
gate to the input of the lower gate. Show that the modified circuit is the same as the
original circuit by deriving the Boolean functions to the R input of the SR latch in
each circuit.
4-2 Obtain the logic diagram of a D latch using NOR gates only.
4-3 Draw the logic diagram of a D-type master-slave flip-flop using transmission gates and
inverters.
4-4 Draw the logic diagram of a JK-type master-slave flip-flop using nine NAND gates.
4-5 Draw the timing diagram similar to Figure 4-9 for a JK-type master-slave flip-flop
during four clock pulses. Show the timing signals of C, /, A, Y, and Q. Assume that
initially the output Q is equal to 1. With the first pulse J = 0 and K = 1. Then for
successive pulses J goes to 1, followed by K going to 0, and then J going back to 0.
Assume that each input changes after the negative edge of the pulse.
4-6 Repeat problem 4-5 using a positive-edge-triggered JK flip-flop. Show the timing
diagrams for C, J, K, and Q.
4-7 A set-dominant flip-flop has a set and reset inputs. It differs from a conventional SR
flip-flop in that when both S and R are equal to 1 the flip-flop is set. Obtain the
characteristic table of the set-dominant flip-flop.
4-8 A JN flip-flop has two inputs J and N. Input J behaves like the J input of a JK flip-
flop and input N behaves like the complement of the K input of a JK flip-flop (that
is N = K).
(a) Obtain the characteristic table of the flip-flop.
(b) Show that by connecting the two inputs together one obtains a D-type flip-flop.
4-9 Draw the graphic symbol of the following flip-flops.
Section Problems 149
Da = XY + XA D B — XB + XA Z = B
Clock
FIGURE P4-12
Circuit for Problem 4-12
4-13 Starting from state 00 in the state diagram of Figure 4-17(a), determine the state
transitions and output sequence that will be generated when an input sequence of
010110111011110 is applied.
4-14 Draw the state diagram of the sequential circuit specified by the state table in Table
4-3.
4-15 Draw the logic diagram of a sequential circuit with two JK flip-flops and one input.
The circuit is specified by the input equations associated with the flip-flop inputs in
Table 4-3.
4-16 A sequential circuit has two JK flip-flops, one input X, and one output Y. The logic
diagram of the circuit is shown in Figure P4-16. Derive the state table and state diagram
of the circuit.
150 Chapter 4 Sequential Logic
FIGURE P4-16
Circuit for Problem 4-16
4-17 A sequential circuit has two JK flip-flops A and B, two inputs X and Y, and one output
Z. The flip-flop input equations and output function are as follows:
JB = AX KB = A + XY
FIGURE P4-19
State Diagram for Problems 4-19 and 4-24
Section Problems 151
4-20 Convert a D-type flip-flop into a JK flip-flop using external gates. The gates can be
derived by means of sequential circuit design procedure starting from a state table
with the D flip-flop output as the present and next state and with J and K as inputs.
4-21 Derive the characteristic functions for the JK, D, and T type flip-flops. The charac¬
teristic function is an algebraic function that expresses the next state Q(t + 1) as a
function of the present state Q(t) and the input(s) of the flip-flop.
4-22 Derive an excitation table for the JN flip-flop defined in Problem 4-8.
4-23 Derive the excitation table of the set-dominant flip-flop defined in Problem 4-7.
4-24 Design a sequential circuit for the state diagram given in Figure P4-19 using JK flip-
flops. Analyze the circuit to make sure that it is self-correcting.
4-25 Design a sequential circuit with two JK flip-flops A and B and two inputs E and X.
If E = 0, the circuit remains in the same state regardless of the value of X. When E
= 1 and X = 1, the circuit goes through the state transitions from 00 to 01 to 10 to
11 back to 00, and repeats, When E — 1 and X — 0, the circuit goes through the
state transitions from 00 to 11 to 10 to 01 back to 00, and repeats.
4-26 Design the sequential circuit specified by the state table of Table 4-7 using SR flip-
flops.
4-27 Using the state table part of Table 4-7 (remove the flip-flop input list for J and K),
derive a new list of binary values for the inputs of two T flip-flops TA and TB. Verify
the corresponding input equations listed in Section 4-6 and draw the logic diagram of
the circuit with T flip-flops.
REGISTERS
AND COUNTERS
5-1 INTRODUCTION
152
Section 5-2 Registers 153
5-2 REGISTERS
Various types of registers are available commercially. The simplest register is one
that consists of only flip-flops without any external gates. Figure 5-1 (a) shows such
a register constructed with four D-type flip-flops. The common clock input triggers
all flip-flops on the rising edge of each pulse and the binary data available at the
four inputs are transferred into the 4-bit register. The four outputs can be sampled
at any time to obtain the binary information stored in the register. The clear input
goes to the R inputs of all four flip-flops. When this input goes to 0, all flip-flops
are reset asynchronously. The clear input is useful for clearing the register to all
0’s prior to its clocked operation. The R inputs must be maintained at logic-1 during
normal clocked operation. The symbol Cl for the clock and ID for the input
indicates that the clock enables the D input but not the R input (see Figure 4-13).
The transfer of new information into a register is referred to as loading the
register. If all the bits of the register are loaded simultaneously with a common
clock pulse, we say that the loading is done in parallel. A clock transition applied
to the C inputs of the register of Figure 5-l(a) will load all four inputs in parallel.
In this configuration, the clock must be inhibited from the circuit if the content of
the register must be left unchanged.
h Ao
Clock
Clear
/i A
a2
^3
FIGURE 5-1
4-Bit Register
154 Chapter 5 Registers and Counters
Most digital systems have a master clock generator that supplies a continuous
train of clock pulses. The clock pulses are applied to all flip-flops and registers in
the system. The master clock acts like a pump that supplies a constant beat to all
parts of the system. A separate control signal must be used to decide which specific
clock pulse will have an effect on a particular register. The clock pulses must be
removed from the register when its content must not be changed. This can be done
with a load control input ANDed with the clock as shown in Figure 5-l(b). The
output of the AND gate is applied to the C inputs of the register. When the load
control signal is 0, the output of the AND gate is 0, the clock is inhibited from the
C inputs, and the content of the register remains the same. When the load control
signal is 1, the clock pulses pass through the AND gate to the C terminals and
new information can be transferred into the register with the next positive transition
of the clock.
block diagram symbol for a group of four D-type flip-flops with common clock and
clear inputs. The clock input Cl and the clear input R appear in the upper block
referred to as a common control block. The inputs to a common control block are
considered as inputs to each of the elements in the lower sections of the diagram.
Ml [Load]
>C2
1, 2D
FIGURE 5-3
Standard Graphic Symbols for Registers
156 Chapter 5 Registers and Counters
The notation Cl is a control dependency that controls all the ID inputs. Thus, the
ID input in each flip-flop is triggered by the common Cl input signal. The common
R input resets all flip-flops. The ID symbol is used only once in the upper section
instead of repeating it in each section.
The small right-angle triangle along the R input is a polarity indicator. It signifies
that the input is active-low. When positive logic assignment is used, the low signal
is equivalent to logic-0 and therefore, a small complementing circle can be used
instead. However, we will show the polarity symbol for active-low when drawing
standard block diagram graphic symbols. This will conform with integrated circuit
data books where the polarity symbol is usually employed.
The standard block diagram symbol for a register with parallel load is shown in
Figure 5-3(b). The common control block shows input Ml for the load and C2 for
the clock. The letter M is used to indicate a mode dependency. The symbol [LOAD]
is optional. Each flip-flop section has the notation 1,2D at the input. The 1 refers
to Ml, the 2 refers to C2, and D is the input type of the flip-flop. The symbol
1,2D designates the fact that the D input is triggered with clock C2 provided that
the load input Ml is active. Note that the symbol l,ID is written only once in the
top section and is assumed to be repeated in the lower sections.
The convention used in the dependency notation dictates that the number fol¬
lowing C determines which input is affected by it. In Figure 5-3(a), we chose Cl
and ID. In Figure 5-3(b), the identifying number 1 was chosen for the mode
dependency M and the number 2 for the control dependency C. The D input is
affected by both, and we place both identifying numbers in front of the D symbol.
We could have chosen Ml and Cl instead, and it does not make a difference in
this case.
Serial Serial
input output
Clock
(a) Logic diagram
Serial output
FIGURE 5-4
4-Bit Shift Register
Sometimes it is necessary to control the shift so that it occurs only with certain
pulses but not with others. This can be done by inhibiting the clock from the input
of the register when we do not want it to shift. It will be shown later that the shift
operation can be controlled through the D inputs of the flip-flops rather than
through the clock input. If however, the shift register in Figure 5-4 is used, the
shift can be controlled by connecting the clock through an AND gate with an input
that controls the shift.
Serial Transfer
A digital system is said to operate in a serial mode when information is transferred
and manipulated one bit at a time. Information is transferred one bit at a time by
shifting the bits out of one register and into a second register. This is in contrast
to parallel transfer where all the bits of the register are transferred at the same
time.
The serial transfer of information from register A to register B is done with shift
registers as shown in the diagram of Figure 5-5(a). The serial output of register A
is connected to the serial input of register B. The serial input of register A is shown
to receive 0’s while its data are transferred to register B. It is also possible for
register A to receive other binary information or, if we want to maintain the data
in register A, we can connect its serial output to its serial input so that the infor¬
mation is shifted back into the register. The initial content of register B is shifted
out through its serial output and is lost unless it is transferred to a third shift
register. The shift control input determines when and how many times the registers
are shifted. This is done with an AND gate that allows the clock pulses to pass
only when the shift control is active.
We assume that each shift register has four stages. The control unit that super¬
vises the transfer must be designed to enable the shift registers, through the shift
control signal, for a fixed time of four clock pulses. This is shown in the timing
158 Chapter 5 Registers and Counters
Register A Register B
Shift
control
Clock
Shift
control
ci input_fi_ri_n_n_ Ti T2 73 ^
(b) Timing diagram
FIGURE 5-5
Serial Transfer
diagram of Figure 5-5(b). The shift control signal is synchronized with the clock
and changes value after the negative transition of a pulse. The next four pulses
find the shift control in the active state so that the output of the AND gate connected
to the C inputs of the registers produces four pulses 7\, T2, T3, and T4. Each
positive transition of these pulses causes a shift in both registers. After the fourth
pulse, the shift control changes back to 0 during the negative transition of the
clock, and the shift registers are disabled.
Assume that the binary content of register A before the shift is 1011, and that
of register B is 0010. The serial transfer from A to B occurs in four steps as shown
in Table 5-1. With the first pulse 7\, the rightmost bit of A is shifted into the
leftmost bit of B, the leftmost bit of A receives a 0 from the serial input and, at
the same time, all other bits of A and B are shifted one position to the right. The
next three pulses perform identical operations, shifting the bits of A into B one at
a time while transferring 0’s to A. After the fourth shift, the shift control goes to
0 and the shifts stop. Register B contains 1011 which is the previous value of A.
Register A contains all 0’s.
The difference between serial and parallel modes of operation should be ap¬
parent from this example. In the parallel mode, information is available from all
bits of a register and all bits can be transferred simultaneously during one clock
pulse. In the serial mode, the registers have a single serial input and a single serial
output. The information is transferred one bit at a time while the registers are
shifted in the same direction.
Section 5-3 Shift Registers 159
TABLE 5-1
Serial Transfer Example
Timing
pulse Shift register A Shift register B
Initial value 1 0 1 1 0 0 1 0
After Tx 0 1 0 1 1 0 0 1
After T2 0 0 1 0 1 1 0 0
After T3 0 0 0 1 0 1 1 0
After T, 0 0 0 0 1 0 1 1
Serial Addition
Operations in digital computers are usually done in parallel because it is a faster
mode of operation. Serial operations are slower but have the advantage of requiring
less equipment. To demonstrate the serial mode of operation, we will show the
operation of a serial adder. The parallel counterpart was presented in Section
3-4.
The two binary numbers to be added serially are stored in two shift registers.
Bits are added one pair at a time through a single full adder (FA) circuit as shown
in Figure 5-6. The carry out of the full adder is transferred into a D flip-flop. The
output of this carry flip-flop is then used as the input carry for the next pair of
significant bits. The sum bit in the S output of the full adder could be transferred
into a third shift register, but we have chosen to transfer the sum bits into register
A as the contents of the register are shifted out. The serial input of register B can
receive a new binary number as its contents are shifted out during the addition.
Shift
control
Clock
FIGURE 5-6
Serial Addition
160 Chapter 5 Registers and Counters
The operation of the serial adder is as follows. Register A holds the augend,
register B holds the addend, and the carry flip-flop is reset to 0. The serial output
of A and B provide a pair of significant bits for the full adder at X and Y. The
output of the carry flip-flop provides the input carry at Z. The shift control enables
the clock for both registers and the flip-flop. Each clock pulse shifts both registers
once to the right, transfers the sum bit from S into the leftmost flip-flop of A, and
transfers the output carry into the carry flip-flop. The shift control enables the
registers for as many clock pulses as there are bits in the registers (four pulses in
this example). For each pulse, a new sum bit is transferred to A, a new carry is
transferred to the flip-flop, and both registers are shifted once to the right. This
process continues until the shift control is disabled. Thus, the addition is accom¬
plished by passing each pair of bits and the previous carry through a single full
adder circuit and transferring the sum, one bit at a time, into register A.
Initially we could clear register A to 0 and then add the first number from B.
While B is shifted through the full adder, we can transfer a second number to it
through its serial input. The second number can be added to the contents of register
A while a third number is transferred serially into register B. This may be repeated
to form the addition of two, three, or more numbers and accumulate their sum in
register A.
Comparing the serial adder with the parallel adder described in Section 3-4, we
note the following differences. The parallel adder must use a register with parallel
load whereas the serial adder uses shift registers. The number of full adder circuits
in the parallel adder is equal to the number of bits in the binary number, whereas
the serial adder requires only one full adder and a carry flip-flop. Excluding the
registers, the parallel adder is a combinational circuit, whereas the serial adder is
a sequential circuit because it includes the carry flip-flop. This is typical of serial
operations because the result of each bit-time operation may depend not only on
the present bits but also on previous results which must be stored in temporary
flip-flops.
If there is access to all the flip-flop outputs of a shift register, information entered
serially by shifting can be taken out in parallel from the outputs of all flip-flops.
If a parallel load capability is added to a shift register, then data entered in parallel
can be taken out in serial fashion by shifting out the data in the register. Thus a
shift register with parallel load can be used for converting incoming parallel data
to serial transfer and vice versa.
The logic diagram of a 4-bit shift register with parallel load is shown in Figure
5-7. There are two control inputs, one for the shift and the other for the load.
Each stage of the register consists of a D flip-flop, an OR gate, and three AND
gates. The first AND gate enables the shift operation. The second AND gate
enables the input data. The third AND gate restores the contents of the register
when no operation is required.
The operation of the register is recorded in the function entries of Table 5-2.
When both the shift and load control inputs are 0, the third AND gate in each
^0
^1
A2
FIGURE 5-7
Shift Register with Parallel Load
TABLE 5-2
Function Table for the Register of Figure 5-7
0 0 No change
0 1 Load parallel data
1 X Shift down from A0 to A3
161 6
162 Chapter 5 Registers and Counters
stage is enabled and the output of each flip-flop is applied to its D input. A positive
transition of the clock restores the contents of the register and no change in output
occurs. When the shift input is 0 and the load input is 1, the second AND gate in
each stage is enabled and the input data is applied to the corresponding D input
of the flip-flop. The next positive clock transition transfers the input data into the
register. When the shift input is equal to 1, the first AND gate in each stage is
enabled and the other two are disabled. Since the load input is disabled by the
second AND gate, we mark it with a don’t care entry in the table. The shift
operation causes the data from the serial input to be transferred to flip-flop A(),
the output of A0 to be transferred to flip-flop Al9 and so on down the flip-flop
stages. The next positive transition of the clock shifts the contents of the register
downward with the serial input going to the first stage. Note that because of the
way the circuit is drawn, the shifting occurs in the downward direction. If we rotate
the page a quarter turn counterclockwise, the register will be shifting from left to
right.
Shift registers are often used to interface digital systems situated remotely from
each other. For example, suppose it is necessary to transmit an n-bit quantity
between two points. If the distance is far it will be expensive to use n lines to
transmit the n bits in parallel. It may be more economical to use a single line and
transmit the information serially, one bit at a time. The transmitter accepts the n-
bit data in parallel into a shift register and then transmits the data serially along
the common line. The receiver accepts the data serially into a shift register. When
all n bits are accumulated they can be taken from the outputs of the register in
parallel. Thus the transmitter performs a parallel-to-serial conversion of data and
the receiver does a serial-to-parallel conversion.
50
51
//
FIGURE 5-8
One Typical Stage of a Bidirectional Shift Register with Parallel Load
transferred into the first stage, and the contents of each stage Ai_] are transferred
into stage At. When SjNq = 10 a shift-up operation results in another serial input
going into the last stage, and stage Ai+1 being transferred into stage At. Finally,
when SjSq = 11, the binary information on each parallel input line is transferred
into the corresponding flip-flop, resulting in a parallel load operation.
TABLE 5-3
Function Table for the Register of Figure 5-8
Mode control
Register
s1 So Operation
0 0 No change
0 1 Shift down
1 0 Shift up
1 1 Parallel load
164 Chapter 5 Registers and Counters
SRG4
Shift- M1
Load ■ M2
Clock- >C3/1
Serial input- 1, 3D
Ao
fa- T, 2, 3D
/i- , 2, 3D Ai
/2 - A2
/r ■ A3
FIGURE 5-9
Graphic Symbol for Shift Register
with Parallel Load
SRG4
Clear- Ft
So- 0
Sr
/i- 3, W A
!2 ' 3, 4D A
h ' 3, 4D
A
Serial input1 2, 4 D
FIGURE 5-10
Graphic Symbol for Bidirectional Shift Register
with Parallel Load
C4 /l-» /2<—
C4 is the control dependency for the clock. The /l—» symbol indicates that the
register shifts right (down in this case) when the mode is Ml (SXS0 = 01). The
/2<— symbol indicates that the register shifts left (up in this case) when the mode
is M2 (S^ = 10). The right and left directions are obtained when the page is
turned 90 degrees counterclockwise.
The blocks below the common block represent the four flip-flops. The first flip-
flop has a serial input for shift down denoted by 1,4D (mode Ml, clock C4, input
D). The last flip-flop has a serial input for shift up denoted by 2,4D (mode M2,
clock C4, input D). All four flip-flops have a parallel input denoted by the label
3,4D (mode M3, clock C4, input D). Thus M3 (SjSq = 11) is for parallel load.
The remaining mode M0 (^Sq = 00) has no effect on the outputs because it is not
included in the input labels.
Counters are available in two categories, ripple counters and synchronous counters.
In a ripple counter, the flip-flop output transition serves as a source for triggering
other flip-flops. In other words, the C input of some or all flip-flops are triggered
not by the common clock pulses but rather by the transition that occurs in other
flip-flop outputs. In a synchronous counter, the C inputs of all flip-flops receive
the common clock pulse and the change of state is determined from the present
state of the counter. Synchronous counters are presented in the next two sections.
Here we present the binary ripple counter and explain its operation.
1J
1/C
1J
-0>C^
1/C
O R
1J ■ A-
<£>C 1
1/C
C R
1J
c> Cl
1/C
-o R
Clear ■Logic- 1
FIGURE 5-11
4-Bit Binary Ripple Counter
Section 5-5 Ripple Counters 167
TABLE 5-4
Count Sequence of Binary Counter
0 0 0 0 1 1 1 1
0 0 0 1 1 1 1 0
0 0 1 0 1 1 0 1
0 0 1 1 1 1 0 0
0 1 0 0 1 0 1 1
0 1 0 1 1 0 1 0
0 1 1 0 1 0 0 1
0 1 1 1 1 0 0 0
1 0 0 0 0 1 1 1
1 0 0 1 0 1 1 0
1 0 1 0 0 1 0 1
1 0 1 1 0 1 0 0
1 1 0 0 0 0 1 1
1 1 0 1 0 0 1 0
1 1 1 0 0 0 0 1
1 1 1 1 0 0 0 0
each flip-flop complement if the signal in its C input goes through a negative
transition. The small circle in front of the dynamic indicator symbol next to the
Cl label indicates that the flip-flops respond to the negative edge transition of the
input. The negative transition occurs when the output of the previous flip-flop, to
which C is connected, goes from 1 to 0. A 0-level signal in the R inputs clears the
register to 0 asynchronously. The R label does not have a 1 in front of it which
indicates that its input is independent of the input at Cl.
To understand the operation of a binary counter, refer to its count sequence
given on the left side of Table 5-4. The count starts with binary 0 and increments
by one with each count pulse input. After the count of 15, the counter goes back
to 0 to repeat the count. The least significant bit (A0) is complemented with each
count pulse input. Every time that A0 goes from 1 to 0, it complements Al. Every
time that A1 goes from 1 to 0, it complements A2. Every time that A2 goes from
1 to 0, it complements A3, and so on for any higher-order bits in the ripple counter.
For example, consider the transition from count 0011 to 0100. A0 is complemented
with the count pulse. Since A0 goes from 1 to 0, it triggers A] and complements
it. As a result, Al goes from 1 to 0 which complements A2 changing it from 0 to
1. A2 does not trigger A3 because A2 produces a positive transition and the flip-
flop responds only to negative transitions. Thus the count from 0011 to 0100 is
achieved by changing the bits one at a time from 0011 to 0010 (A0 = 0) then to
0000 (Al = 0) and finally to 0100 (A2 = 1)- The flip-flops change one at a time
in succession and the signal propagates through the counter in a ripple fashion from
one stage to the next.
The standard graphic symbol for a 4-bit binary ripple counter is shown in Figure
5-12. The qualifying symbol for the ripple counter is RCTR. The designation DIV
16 stands for divide by 16. This is the cycle length of the counter as it repeatedly
168 Chapter 5 Registers and Counters
RCTR DIV 16
Clear b* CT - 0
ro Ao
Count b» > +
CT<
A2
.3 A3
FIGURE 5-12
Graphic Symbol for the Binary
Ripple Counter
cycles over 16 counts from 0 to 15. Since the count input does not go to the C
inputs of all stages, it has no Cl label, and the symbol + is used instead to indicate
a count-up operation. The dynamic symbol next to the + together with the polarity
symbol along the input line signify that the count is affected with a negative-edge
transition of the input signal. The symbol CT designates the content of the counter.
An active-low (logic-0) signal in the clear input changes the content of the counter
to 0. The bit-grouping from 0 to 3 in the output represent values for the weights
to the power of 2. Thus 0 represents the value 2° and 3 represents the value 23.
Binary Down-Counter
A binary counter with a normal binary count is considered as an up-counter. A
binary counter with a reverse count is called a down-counter. In a down-counter,
the binary count is decremented by one with every input count pulse. The count
of a Tbit down counter starts from binary 15 and continues to binary 14, 13, 12,
down to 0 and back to 15. The count sequence for the binary down-counter is
listed in Table 5-4.
There are various ways that a binary down-counter can be constructed. As can
be seen from Table 5-4, the down-count is the complement of the up-count. There¬
fore, one way of achieving a down-counter is to use the circuit from Figure 5-11
but take the outputs from the complement outputs of the flip-flops.
Two other possible constructions can be obtained. From an investigation of the
down-count sequence in the table, we find that the least significant bit is comple¬
mented after each count, and other bits are complemented if their previous least
significant bits go from 0 to 1. (Recall that in the up-count the previous bit must
go from 1 to 0 to complement the next bit.) The circuit of Figure 5-11 can be
modified in one of two ways to change it to a down-counter. In the first case, we
connect the complement output of each flip-flop to the C input of the next flip-
flop in sequence. When the normal output of a flip-flop goes from 0 to 1 as required,
the complement output goes from 1 to 0 producing the negative-edge transition
for complementing the next stage. In the second case, we leave the circuit of Figure
5-11 as is except that we use flip-flops that trigger on the positive-edge transition.
This means that the small circle in front of the dynamic indicator next to the Cl
label must be removed from the diagram. When a flip-flop output goes from 0 to
1 it produces a positive-edge transition and the next flip-flop will be complemented.
Section 5-5 Ripple Counters 169
The standard graphic symbol for a binary down-counter is the same as in Figure
5-12 except that the — symbol is used to indicate a count-down operation. A
counter that can count both up and down must have a mode input to select between
the two operations.
RCTR DIV 16
CT = 0
ro
Count1 > +
A
CT <
^2
v. 3 ^3
FIGURE 5-13
BCD Ripple Counter
170 Chapter 5 Registers and Counters
order decade. For instance, the count after 399 will be 400, which in BCD goes
from 0011 1001 1001 to 0100 0000 0000.
X
TABLE 5-5
State Table and Flip-Flop Inputs for Binary Counter
Present Next
state state Flip-Flop inputs
A a2 A A *3 a2 A, A J A3 Ka3 Ja2 Ka2 Jm Kai Jao Kao
0 0 0 0 0 0 0 1 0 X 0 X 0 X 1 X
0 0 0 1 0 0 1 0 0 X 0 X 1 X X 1
0 0 1 0 0 0 1 1 0 X 0 X X 0 1 X
0 0 1 1 0 1 0 0 0 X 1 X X 1 X 1
0 1 0 0 0 1 0 1 0 X X 0 0 X 1 X
0 1 0 1 0 1 1 0 0 X X 0 1 X X 1
0 1 1 0 0 1 1 1 0 X X 0 X 0 1 X
0 1 1 1 1 0 0 0 1 X X 1 X 1 X 1
1 0 0 0 1 0 0 1 X 0 0 X 0 X 1 X
1 0 0 1 1 0 1 0 X 0 0 X 1 X X 1
1 0 1 0 1 0 1 1 X 0 0 X X 0 1 X
1 0 1 1 1 1 0 0 X 0 1 X X 1 X 1
1 1 0 0 1 1 0 1 X 0 X 0 0 X 1 X
1 1 0 1 1 1 1 0 X 0 X 0 1 X X 1
1 1 1 0 1 1 1 1 X 0 X 0 X 0 1 X
1 1 1 1 0 0 0 0 X 1 X 1 X 1 X 1
Section 5-6 Synchronous Binary Counters 171
X X X X
X X X X
> A2
1
v___j V
^0
1 X X X X
X X X X 1
X X X X 1
1 X X X X
1 X X X X 1
1 X X X X 1
1 X X X X 1
1 . X X X X 1
441 — A o Ka*\ - A0
FIGURE 5-14
Maps for Input Equations of a Binary Counter
172 Chapter 5 Registers and Counters
equations for J and K are the same for each flip-flop. This indicates that T flip-
flops could be used instead of JK.
In many applications it is necessary to control the operation of the counter with
a count enable input. If we designate such an input with the variable E, the input
equations for the binary counter can be expressed as follows:
Jaq ~ Kao ~ E
KA1 — A0E
FIGURE 5-15
4-Bit Synchronous Binary Counter
Simplifying the four functions with maps and adding a count enable input E we
obtain the following input equations for the counter (see Problem 5-20).
Dao = ® E
DAi — ® 04oE)
Da2 = ^2 © (AAE)
DA3 — A3 ® (AqA1A2E)
The input equation for any flip-flop A, in state i can be expressed as:
FIGURE 5-16
4-Bit Binary Counter with D Flip-Flops
flip-flops shown in Figure 5-15 is the exclusive-OR gate in each flip-flop input.
This indicates that the D flip-flop together with the exclusive-OR gate correspond
to a T-type flip-flop. One input of the exclusive-OR gate comes from the output
of the D flip-flop and the other input of the gate is equivalent to an input for a T-
type flip-flop. (See Problem 5-21.)
second significant bit is complemented because the first bit is 0. The third significant
bit is complemented because the first two bits are equal to 0. But the fourth bit
does not change because all lower significant bits are not equal to 0.
The logic diagram of a synchronous count-down binary counter is similar to the
circuit of the binary up-counter except that the inputs to the AND gates must come
from the complement outputs of the flip-flops. The two operations can be combined
to form a counter that can count both up and down, which is referred to as an up-
down binary counter. The up-down counter needs a mode input to select between
the two operations. Designate the mode select input by S with S = 1 for up-count
and 5 = 0 for down-count. Let variable E be a count enable input with E = 1 for
normal up or down counting and E = 0 for disabling both counts. If we use T-
type flip-flops (that is T = J = K), a Tbit up-down binary counter can be described
by the following input equations:
Tao — E
The output carries supply the input for complementing the next flip-flop if the
counter is extended to a fifth stage.
The logic diagram of the circuit can be easily obtained from the input equations
but is not drawn here. However, the standard graphic symbol for the 4-bit up-
down counter is shown in Figure 5-17. The qualifying symbol for a synchronous
CTR DIV 16
^0
A
^2
^3
FIGURE 5-17
Graphic Symbol for a 4-Bit Up-Down Binary Counter
176 Chapter 5 Registers and Counters
counter is CTR. The label DIV 16 designates a cycle length of 16 as in the binary
count. There is a single select input S that is split into the two modes Ml and M2
to show the mode of operation. When input S is high, Ml is active and the counter
counts up. When input S is low, M2 is active and the counter counts down. M2 is
recognized as active-low from the polarity indicator along its input line. Note that
the convention in this symbology is to recognize that a single input exists but this
is a way of assigning to it two possible modes of operation. The count enable input
uses the G dependency with the number 3. The label associated with the clock is
>1,3 + /2,3 -
TABLE 5-6
Function Table for the Register of Figure 5-18
0 0 No change
0 1 Count next binary state
1 X Load inputs
FIGURE 5-18
4-Bit Binary Counter with Parallel Load
177
178 Chapter 5 Registers and Counters
CTR DIV 16
Load 1 Ml
Output
M2 3CT = 1 5
carry
Count1 M3
/o' 1, 4 D Ao
h [2] Ai
/2 ■ [4] A2
h ' [8] A3
FIGURE 5-19
Graphic Symbol for a 4-Bit Binary Counter
with Parallel Load
Counters with parallel load are very useful in the design of digital computers.
In subsequent chapters we will refer to them as registers with load and increment
operations. The increment operation adds one to the contents of a register. By
enabling the count input during one clock period, the content of the register can
be incremented by one.
The standard graphic symbol for the 4-bit counter with parallel load is shown
in Figure 5-19. The single load input is split into two modes labeled Ml and M2.
When the load input is high, Ml is active, and when the load input is low, M2 is
active, as indicated by the polarity symbol. The condition for counting is designated
by the label associated with the clock input.
>C4/2,3 +
This means that the circuit counts up (+ symbol) when M2 and M3 are active
(load = 0, and count = 1) and the clock in C4 goes through a positive transition.
The parallel inputs have the label 1,4D meaning that the D inputs are active when
Ml is active (load = 1) and the clock goes through a positive transition. The output
carry is designated by the label
3 CT = 15
four inputs are connected to logic-0, an all 0’s value is loaded into the register
following the count of 1001. Thus the circuit counts from 0000 through 1001 and
back to 0000, as is required for a BCD counter.
BCD Counter
A BCD counter can be obtained from a binary counter with parallel load as was
shown in the previous section. It is also possible to design a BCD counter using
individual flip-flops and gates. Assuming T-type flip-flops for the counter, we derive
the state table and input conditions as shown in Table 5-7. The T input in each
case is equal to 1 if the flip-flop is complemented during the transition from present
state to next state. The T input is equal to 0 if the next state is the same as the
present state. An output Y is included in the table. This output is equal to 1 when
the present state is 1001. In this way, Y can enable the count of the next decade
while its own decade switches from 1001 to 0000.
The flip-flop input equations are obtained from the flip-flop inputs listed in the
table and can be simplified by means of maps. The unused states for minterms
180 Chapter 5 Registers and Counters
TABLE 5-7
State Table and Flip-Flop Inputs for BCD Counter
r
*8 A, a2 A, *8 A, a2 A, Y TA4 TA2 TA1
0 0 0 0 0 0 0 1 0 0 0 0 1
0 0 0 1 0 0 1 0 0 0 0 1 1
0 0 1 0 0 0 1 1 0 0 0 0 1
0 0 1 1 0 1 0 0 0 0 1 1 1
0 1 0 0 0 1 0 1 0 0 0 0 1
0 1 0 1 0 1 1 0 0 0 0 1 1
0 1 1 0 0 1 1 1 0 0 0 0 1
0 1 1 1 1 0 0 0 0 1 1 1 1
1 0 0 0 1 0 0 1 0 0 0 0 1
1 0 0 1 0 0 0 0 1 1 0 0 1
1010 through 1111 are taken as don’t care conditions. The simplified input equations
for the BCD counter are
TA1 = 1
Ta2 ~ ^1^8
7/14 = ^1^2
Ta8 ~ T A1A2A4
Y = AxA8
The circuit can be drawn with four T flip-flops, five AND gates and one OR gate.
Synchronous BCD counters can be cascaded to form counters for decimal numbers
of any length. The cascading is done by connecting output Y to the T inputs of the
next-higher-order decade.
JB = C Kb = 1
Jc = B Kc = 1
Section 5-7 Other Synchronous Counters 181
TABLE 5-8
State Table and Flip-Flop Inputs for Counter
Present
state Next state Flip-Flop inputs
A B c A B c Ja ka Ks Jc *c
0 0 0 0 0 1 0 X 0 X 1 X
0 0 1 0 1 0 0 X 1 X X 1
0 1 0 1 0 0 1 X X 1 0 X
1 0 0 1 0 1 X 0 0 X 1 X
1 0 1 1 1 0 X 0 1 X X 1
1 1 0 0 0 0 X 1 X 1 0 X
The logic diagram of the counter is shown in Figure 5-21(a). Since there are two
unused states, we analyze the circuit to determine their effect. The state diagram
so obtained is drawn in Figure 5-21(b). If the circuit ever goes to one of the unused
states, the next count pulse transfers it to one of the valid states and continues to
count correctly. Thus the counter is self-correcting. A self-correcting counter is
one that can start from any state and eventually reach the normal count sequence
even if it starts from an unused state.
A B C
Clock
Logic-1
(a) Logic diagram
FIGURE 5-21
Counter with Arbitrary Count
182 Chapter 5 Registers and Counters
Timing Sequence
The sequence of operations in a digital system is specified by a control unit. The
control unit that supervises the operations in a digital system may contain special
timing signals that determine the time sequence in which the operations are exe¬
cuted. The timing signals can be generated by means of a counter and a decoder
as shown in Figure 5-22. The 2-bit binary counter goes through four distinct states.
The decoder receives the output of the counter and decodes the four states into
four distinct timing signals.
The timing diagram of Figure 5-22(b) shows the waveforms of the counter and
decoder outputs. Each decoder output becomes active on the positive transition
of the clock and stays active during one clock period. At any given time, only one
T0
Clock
T\
T2
To
Clock
“i
A
“i
t2
FIGURE 5-22
Generation of Timing Signals
Problems 183
timing signal is active while the others remain inactive. The period of each timing
signal is one fourth of the clock period.
The timing signals, when enabled by the clock pulses, will provide a multiple-
phase clock. For example, if T0 is ANDed with the clock, the output of the AND
gate will generate clock pulses at one-fourth the frequency of the master clock.
The other three decoder outputs, if ANDed with the clock, will also generate clock
pulses at one-fourth frequency of the master clock but will be displaced from each
other by one period. Multiple-phase clocks are useful for triggering registers with
different clocks so that operations can occur at different time periods.
To generate 2n timing signals, we need an n-bit binary counter connected to an
/7-to-2n-line decoder. For example, 16 timing signals can be generated with a 4-bit
binary counter and a 4-to-16-line decoder. The 16 timing signals so obtained are
mutually exclusive. Only one timing signal is active at any given clock period while
the other 15 signals are maintained at logic-0.
REFERENCES
1. Peatman, J. B. Digital Hardware Design. New York: McGraw-Hill, 1980.
2. Blakeslee, T. R. Digital Design with Standard MSI and LSI. 2nd ed. New York:
Wiley, 1979.
3. Hill, F. J., and Peterson, G. R. Digital Logic and Microprocessors. New York:
Wiley, 1984.
4. Fletcher, W. I. An Engineering Approach to Digital Design. Englewood Cliffs: Pren¬
tice-Hall, 1979.
5. IEEE Standard Graphic Symbols for Logic Functions. (ANSI/IEEE Std 91-1984.) New
York: The Institute of Electrical and Electronics Engineers.
6. Kampel, I. A Practical Introduction to the New Logic Symbols. Boston: Butterworths,
1985.
7. Mann, F. A. Overview of IEEE Standard 91-1984. Dallas: Texas Instruments, 1984.
PROBLEMS
5-1 Change the AND gate in Figure 5-1 (b) into a NAND gate. Explain the operation of
the NAND gate for controlling the input data into the register. Draw a timing diagram
showing the relationship between the two inputs and the output of the gate.
5-2 What is the purpose of the buffer gate in the clock input of the register of Figure
5-2?
5-3 Explain the purpose of the common control block when used with the standard graphic
symbology.
5-4 What are the graphic symbols for (a) a polarity indicator and (b) a dynamic indicator.
What do these two indicators signify?
5-5 Draw the graphic symbol of a 4-bit register with parallel load using the label Cl for
the clock and M2 for the load input.
5-6 The content of a 4-bit register is initially 1101. The register is shifted six times to the
184 Chapter 5 Registers and Counters
right with the serial input being 101101. What is the content of the register after each
shift?
5-7 What is the difference between serial and parallel transfer? Explain how to convert
serial data to parallel and parallel data to serial. What type of register is needed?
5-8 The serial adder of Figure 5-6 uses two 4-bit registers. Register A holds the binary
number 0101 and register B holds 0111. The carry flip-flop is initially reset to 0. List
the binary values in register A and the carry flip-flop after each shift.
5-9 What changes are needed in Figure 5-6 to convert it to a serial subtractor that subtracts
the content of register B from the content of register .A? Explain how it is possible to
detect if A < B. What will be the result of the subtraction if A < B?
5-10 Modify the register of Figure 5-7 so it will operate according to the following function
table:
0 0 No change
0 1 Load parallel data
1 0 Shift down
1 1 Clear register to 0
5-11 Draw the logic diagram of a 4-bit register with mode selection inputs S1 and SQ. The
register is to be operated according to the following function table:
Si S0 Register operation
0 0 No change
0 1 Complement output
1 0 Clear register to 0
1 1 Load parallel data
5-12 Draw the four stages of the bidirectional shift register with parallel load shown in
Figure 5-8.
5-13 Explain all the symbols used in the standard graphic diagram of Figure 5-10.
5-14 Using external connections and the shift register from Figure 5-9, construct a bi¬
directional shift register (without parallel load). This can be done by connecting the
outputs into the inputs in the proper order and using the load input to control the
shift left operation.
5-15 (a) A ring counter is a shift register, as in Figure 5-4, with the serial output connected
to the serial input. Starting from an initial state of 1000, list the sequence of states
of the four flip-flops after each shift.
(b) A switch-tail ring counter uses the complement of the serial output for the serial
input. Starting from an initial state of 0000, list the sequence of states after each
shift until the register returns to 0000.
5-16 A flip-flop has a 10 nanosecond delay between the time its C input goes from 1 to 0
and the time the output is complemented. What is the maximum delay in a 10-bit
binary ripple counter that uses these flip flops? What is the maximum frequency the
counter can operate reliably?
5-17 How many flip-flops will be complemented in a 10-bit binary ripple counter to reach
the next count after
(a) 1001100111. (b) 0011111111.
Problems 185
5-18 Using the 4-bit binary ripple counter of Figure 5-12 and a NAND gate, construct a
counter that counts from 0000 through 1011. Repeat for a count from 0000 through
0101.
5-19 Draw the logic diagram of a 4-bit ripple binary down-counter using
(a) Flip-flops that trigger on the positive transition of the clock.
(b) Flip-flops that trigger on the negative transition of the clock.
5-20 Starting from the state table of Table 5-5, obtain the simplified input equations for
the synchronous binary counter with D flip-flops. Include a count enable input E.
5-21 Using sequential circuit design procedure, convert a D-type flip-flop to a T-type flip-
flop. Show that what is needed is an exclusive-OR gate.
5-22 Draw the logic diagram of a 4-bit synchronous up-down binary counter with an enable
input E and a mode input S. Use JK flip-flops.
5-23 Draw the graphic symbol of a 4-bit up-down binary counter shown in Figure 5-17 but
remove the active-low line labeled M2. (Remember that S has only one input.) Modify
the label associated with the clock to confirm to this change but leave the operation
of the circuit the same. (You will need to use a bar over the 1 as in Figure 5-9.)
5-24 Repeat Problem 5-18 but use the synchronous binary counter of Figure 5-19.
5-25 Using two circuits of the type shown in Figure 5-19, construct a binary counter that
counts from 0 through binary 64.
5-26 Verify the flip-flop input equations of the synchronous BCD counter specified in Table
5-7. Draw the logic diagram of the BCD counter and include a count enable input.
5-27 Design a synchronous BCD counter with JK flip-flops.
5-28 Design a binary counter with the following repeated binary sequence. Use JK-type
flip-flops.
(a) 0, 1, 2. (b) 0, 1, 2, 3, 4, 5, 6.
5-29 Design a counter with the following repeated binary sequence: 0, 1,3, 7, 6, 4. Use
T-type flip-flops.
5-30 Design a counter with the following repeated binary sequence: 0, 1,2, 4, 6. Use D-
type flip-flops.
5-31 Add four 2-input AND gates to the circuit of Figure 5-22(a). One input in each gate
is connected to one output of the decoder. The other input in each gate is connected
to the clock. Label the outputs of the AND gates P0, P1, P2, and P3. Show the timing
diagram of the modified circuit.
5-32 Show the circuit and the timing diagram for generating six repeated timing signals T0
through T5.
o__
MEMORY
AND
PROGRAMMABLE
LOGIC
6-1 INTRODUCTION
A digital computer consists of three major units: the central processing unit, the
memory unit, and the input-output unit. The memory unit is a device to which
binary information is transferred for storage and from which information is available
when needed for processing. When data processing takes place, information from
the memory is first transferred to selected registers in the central processing unit.
Intermediate and final results obtained in the central processing unit are transferred
back to memory. Binary information received from an input device is first stored
in memory and information transferred to an output device is taken from memory.
A memory unit is a collection of binary cells which is capable of storing a large
quantity of binary information.
There are two types of memories that communicate directly with the central
processing unit: random-access memory (RAM) and read-only memory (ROM).
Random-access memory can accept new information for storage to be available
later for use. The process of storing new information in memory is referred to as
a memory write operation. The process of transferring the stored information out
of memory is referred to as a memory read operation. Random-access memory
can perform both the write and read operations. Read-only memory can perform
only the read operation. This means that suitable binary information is already
stored inside the memory which can be retrieved or read at any time. However,
the existing information cannot be altered because read-only memory can only
read; it cannot write.
186
Section 6-2 Random-Access Memory (RAM) 187
FIGURE 6-1
Conventional and Array Logic Diagrams for OR Gate
Memory unit
k address lines-►
2k words
Read-►
Write-► n bits per word
FIGURE 6-2
Block Diagram of Memory Unit
the direction of transfer. A block diagram of the memory unit is shown in Figure
6-2. The n data input lines provide the information to be stored in memory and
the n data output lines supply the information coming out of memory. The k address
lines specify the particular word chosen among the many available. The two control
inputs specify the direction of transfer desired: The write input causes binary data
to be transferred into the memory; and the read input causes binary data to be
transferred out of memory.
The memory unit is specified by the number of words it contains and the number
of bits in each word. The address lines select one particular word. Each word in
memory is assigned an identification number called an address. Addresses range
from 0 to 2k - 1, where k is the number of address lines. The selection of a specific
word inside the memory is done by applying the /e-bit binary address to the address
lines. A decoder inside the memory accepts this address and opens the paths needed
to select the word specified. Computer memories may range from 1024 words,
requiring an address of 10 bits, to 232 words, requiring 32 address bits. It is customary
to refer to the number of words (or bytes) in a memory with one of the letters K
(kilo), M (mega), or G (giga). K is equal to 210, M is equal to 220, and G is equal
to 230. Thus, 64K - 216, 2M = 221, and 4G = 232.
Consider, for example, the memory unit with a capacity of IK words of 16 bits
each. Since IK = 1024 = 210 and 16 bits constitute two bytes, we can say that the
memory can accommodate 2048 or 2K bytes. Figure 6-3 shows the possible content
of the first three and the last three words of this memory. Each word contains 16
bits which can be divided into two bytes. The words are recognized by their decimal
addresses from 0 to 1023. An equivalent binary address consists of 10 bits. The
first address is specified using ten 0’s, and the last address is specified with ten l’s.
This is because 1023 in binary is equal to 1111111111. A word in memory is selected
by its binary address. When a word is read or written, the memory operates on all
16 bits as a single unit.
The IK x 16 memory of Figure 6-3 has 10 bits in the address and 16 bits in
each word. If we have a 64K x 10 memory it is necessary to include 16 bits in the
address and each word will consist of 10 bits. The number of address bits needed
in a memory is dependent on the total number of words that can be stored in the
memory and is independent of the number of bits in each word. The number of
bits in the address is determined from the relationship 2k = m, where m is the
total number of words and k is the number of address bits.
Section 6-2 Random-Access Memory (RAM) 189
Memory address
Binary Decimal Memory content
0000000000 0 1011010101011100
0000000001 1 1010101110001001
0000000010 2 0000110101000110
FIGURE 6-3
Contents of a 1024 x 16 Memory
1. Transfer the binary address of the desired word to the address lines.
2. Transfer the data bits that must be stored in memory to the data input lines.
3. Activate the write input.
The memory unit will then take the bits from the input data lines and store them
in the word specified by the address lines.
The steps that must be taken for the purpose of transferring a stored word out
of memory are as follows:
1. Transfer the binary address of the desired word to the address lines.
2. Activate the read input.
The memory unit will then take the bits from the word that has been selected
through the address and apply them to the output data lines. The content of the
selected word does not change after reading.
Commercial memory components available in integrated circuit chips sometimes
provide the two control inputs for reading and writing in a somewhat different
configuration. Instead of having separate read and write inputs to control the two
operations, some integrated circuits provide two control inputs: one input selects
the unit and the other determines the operation. The memory operations that result
from these control inputs are shown in Table 6-1.
The memory select (sometimes called chip select) is used to enable the particular
memory chip in a multichip implementation of a large memory. When the memory
190 Chapter 6 Memory and Programmable Logic
TABLE 6-1
Control Inputs to Memory Chip
0 X None
1 0 Write to selected word
1 1 Read from selected word
select is inactive, the memory chip is not selected and no operation can be per¬
formed. When the memory select input is active, the read/write input determines
the operation to be performed.
RAM 16x4
0
Address 0
inputs 1 5
Memory select- G1
Read/Write 1 EN (READ!
1C2 |WRITE |
A, 2D A
Data
Data outputs
inputs
FIGURE 6-4
Standard Graphic Symbol for a 16 x 4 RAM
Section 6-2 Random-Access Memory (RAM) 191
Timing Waveforms
The operation of the memory unit is controlled by an external device such as a
central processing unit (CPU). The CPU is usually synchronized with its own clock
pulses. The memory, however, does not employ internal clock pulses and its read
and write operations are specified by the two control inputs. The access time of a
memory is the time required to select a word and either read or write it. The CPU
must provide the memory control signals in such a way as to synchronize its internal
clocked operations with the read and write operations of the memory. This means
that the access time of the memory must be within a time period equal to a fixed
number of CPU clock pulse periods.
- 200 nsec -►
Memory
select A
Read/
Write r
Data Data valid
input
(a) Write cycle
500 nsec
Clock
/ n \ / 72 \ / T3 \ Hi
Memory Address valid
address
Memory
select
Read/
Write
FIGURE 6-5
Memory Cycle Timing Waveforms
Types of Memories
The mode of access of a memory system is determined by the type of components
used. In a random-access memory, the word locations may be thought of as being
separated in space, with each word occupying one particular location. In a se¬
quential-access memory, the information stored in some medium is not immediately
accessible but is available only at certain intervals of time. A magnetic tape unit
is of this type. Each memory location passes the read and write heads in turn, but
information is read out only when the requested word has been reached. In a
Section 6-3 Memory Decoding 193
random-access memory, the access time is always the same regardless of the par¬
ticular location of the word. In a sequential-access memory, the time it takes to
access a word depends on the position of the word with respect to the reading head
position and therefore, the access time is variable.
Integrated circuit RAM units are available in two possible operating modes,
static and dynamic. The static RAM consists essentially of internal flip-flops that
store the binary information. The stored information remains valid as long as power
is applied to the unit. The dynamic RAM stores the binary information in the form
of electric charges that are applied to capacitors. The capacitors are provided inside
the chip by MOS transistors. The stored charge on the capacitors tends to discharge
with time and the capacitors must be periodically recharged by refreshing the
dynamic memory. Refreshing is done by cycling through the words every few
milliseconds to restore the decaying charge. Dynamic RAM offers reduced power
consumption and larger storage capacity in a single memory chip, but static RAM
is easier to use and has shorter read and write cycles.
Memory units that lose stored information when power is turned off are said to
be volatile. Integrated circuit RAMs, both static and dynamic, are of this category
since the binary cells need external power to maintain the stored information. In
contrast, a nonvolatile memory, such as magnetic disk, retains its stored information
after removal of power. This is because the data stored on magnetic components
is manifested by the direction of magnetization, which is retained after power is
turned off. Another nonvolatile memory is the ROM discussed in Section 6-5.
A nonvolatile property is desirable in digital computers to store programs that
are needed while the computer is in operation. Programs and data that cannot be
altered are stored in ROM. Other large programs are maintained on magnetic
disks. When power is turned on, the computer can use the programs from ROM.
The other programs residing on the disks can be transferred into the computer
RAM as needed. Before turning the power off, the user transfers the binary in¬
formation from the computer RAM into a disk if this information must be retained.
In addition to the storage components in a memory unit, there is a need for decoding
circuits to select the memory word specified by the input address. In this section
we present the internal construction of a random-access memory and demonstrate
the operation of the decoder. To be able to include the entire memory in one
diagram, the memory unit presented here has a small capacity of 16 bits arranged
in 4 words of 4 bits each. We then present a two-dimensional coincident decoding
arrangement to show a more efficient decoding scheme which is sometimes used
in large memories.
In addition to internal decoders, a memory unit may also need external decoders.
This happens when integrated-circuit RAM chips are connected in a multichip
memory configuration. The use of an external decoder to provide a large capacity
memory will be demonstrated by means of an example.
194 Chapter 6 Memory and Programmable Logic
Internal Construction
The internal construction of a random-access memory of m words and n bits per
word consists of m x n binary storage cells and associated decoding circuits for
selecting individual words. The binary storage cell is the basic building block of a
memory unit. The equivalent logic of a binary cell that stores one bit of information
is shown in Figure 6-6. Although the cell is shown to include gates and a flip-flop,
internally it is constructed with two transistors having multiple inputs. A binary
storage cell must be very small so that as many cells as possible can be packed into
the small area available in the integrated circuit chip. The binary cell stores one
bit in its internal flip-flop. The select input enables the cell for reading or writing
and the read/write input determines the cell operation when it is selected. A 1 in
the read/write input provides the read operation by forming a path from the flip-
flop to the output terminal. A 0 in the read/write input provides the write operation
by forming a path from the input terminal to the flip-flop. Note that the flip-flop
operates without a clock and is similar to an SR latch.
The logical construction of a small RAM is shown in Figure 6-7. It consists of
four words of four bits each and has a total of 16 binary cells. Each block labeled
BC represents a binary cell with its three inputs and one output as specified in
Figure 6-6(b). A memory with four words needs two address lines. The two address
inputs go through a 2 x 4 decoder to select one of the four words. The decoder
is enabled with the memory select input. When the memory select is 0, all outputs
of the decoder are 0 and none of the memory words are selected. With the memory
select at 1, one of the four words is selected, dictated by the value in the two
address lines. Once a word has been selected, the read/write input determines the
operation. During the read operation, the four bits of the selected word go through
OR gates to the output terminals. (Note that the OR gates are drawn according
to the array logic established in Figure 6-1.) During the write operation, the data
available in the input lines are transferred into the four binary cells of the selected
word. The binary cells that are not selected are disabled and their previous binary
values remain unchanged. When the memory select input that goes into the decoder
Select
Select
Output
FIGURE 6-6
Memory Cell
Section 6-3 Memory Decoding 195
Data inputs
Output data
FIGURE 6-7
Diagram of a 4 x 4 RAM
is equal to 0, none of the words are selected and the contents of all cells remain
unchanged regardless of the value of the read/write input.
Commercial random-access memories may have a capacity of thousands of words
and each word may range from 1 to 64 bits. The logical construction of a large
capacity memory would be a direct extension of the configuration shown here. A
memory with 2k words of n bits per word requires k address lines that go into a k
x 2k decoder. Each one of the decoder outputs selects one word of n bits for
reading or writing.
Coincident Decoding
A decoder with k inputs and 2k outputs requires 2k AND gates with k inputs per
gate. The total number of gates and the number of inputs per gate can be reduced
by employing two decoders with a coincident selection scheme. In this configu¬
ration, two /c/2-input decoders are used instead of one /c-input decoder. One decoder
performs the horizontal A-selection and the other the vertical y-selection in a two-
dimensional matrix selection scheme.
196 Chapter 6 Memory and Programmable Logic
FIGURE 6-8
Two Dimensional Decoding Structure for a IK x 8 RAM
RAM IK x 8
o
Input data- DATA V Output data
A , , 10.
Address-7*-- ADRS
Chip select- CS
Read/Write- RW
FIGURE 6-9
Block Diagram of a IK x 8 RAM Chip
the number of words in memory. The increase in the number of bits per word
requires that we increase the length of the data input and output lines, but the
address length remains the same.
To demonstrate with an example, let us first introduce a typical RAM chip as
shown in Figure 6-9. The capacity of the RAM is 1024 words of 8 bits each. It
requires a TO-bit address and 8 input and output lines. These are shown in the
block diagram by a single line and a number indicating the total number of inputs
or outputs. The CS (chip select) input selects the particular RAM chip and the
RW (read/write) input specifies the read or write operation when the chip is se¬
lected. The triangle symbol shown with the outputs is the standard graphic symbol
for a three-state output. A three-state output may be in one of three possible states:
a signal equivalent to binary 0, a signal equivalent to binary 1, or a high-impedance
state. The high-impedance state behaves like an open circuit: it does not carry any
signal and does not have a logic significance. The CS input of the RAM controls
the behavior of the data output lines. When CS = 0, the chip is not selected and
all its data outputs are in the high-impedance state. With CS = 1 and RW = 1,
the data output lines carry the eight bits of the selected word.
Suppose that we want to increase the number of words in the memory by using
two or more RAM chips. Since every bit added to the address doubles the binary
number that can be formed, it is natural to increase the number of words in factors
of two. For example, two RAM chips will double the number of words and add
one bit to the composite address. Four RAM chips multiply the number of words
by four and add two bits to the composite address.
Consider the possibility of constructing a 4K x 8 RAM with four IK x 8 RAM
chips. This is shown in Figure 6-10. The 8 input data lines go to all the chips. The
three-state outputs can be connected together to form the common 8 output data
lines. This type of output connection is possible only with three-state outputs. This
is because only one chip select input will be active at any time while the other three
chips will be disabled. The 8 outputs of the selected chip will contain l’s and 0’s,
and the other three will be in a high-impedance state with no logic significance to
disturb the output binary signals of the selected chip.
The 4K word memory requires a 12-bit address. The 10 least significant bits of
the address are applied to the address inputs of all four chips. The other two most
significant bits are applied to a 2 x 4 decoder. The four outputs of the decoder
are applied to the CS inputs of each chip. The memory is disabled when the enable
input of the decoder is equal to 0. This causes all four outputs of the decoder to
198 Chapter 6 Memory and Programmable Logic
Address
A_
Memory
enable
Read/
Write
FIGURE 6-10
Block Diagram of 4K x 8 RAM
be in the 0 state and none of the chips are selected. When the decoder is enabled,
address bits 12 and 11 determine the particular chip that is selected. If bits 12 and
11 are equal to 00, the first RAM chip is selected. The remaining ten address bits
select a word within the chip in the range from 0 to 1023. The next 1024 words
are selected from the second RAM chip with a 12-bit address that starts with 01
and follows by the ten bits from the common address lines. The address range for
each chip is listed in decimal under its block diagram in Figure 6-10.
' Section 6-4 Error Detection and Correction 199
8 8
10
Address -7 *"
RAM IK x 8 RAM IK x 8
8 8 8 8
~r DATA DATA ~r
10 10
-7 "
ADRS ~r~ ADRS
Chip select CS CS
Read/write RW RW
8y
FIGURE 6-11
Block Diagram of IK x 16 RAM
Hamming Code
One of the most common error-correcting codes used in random-access memories
was devised by R. W. Hamming. In the Hamming code, k parity bits are added
to an n-bit data word, forming a new word of n + k bits. The bit positions are
numbered in sequence from 1 to n + k. Those positions numbered as a power of
2 are reserved for the parity bits. The remaining bits are the data bits. The code
can be used with words of any length. Before giving the general characteristics of
the code, we will illustrate its operation with a data word of eight bits.
Consider for example the 8-bit data word 11000100. We include 4 parity bits
with the 8-bit word and arrange the 12 bits as follows:
Bit position 1 2 3 4 5 6 7 8 9 10 11 12
Px P2 1 P4 1 0 0 P8 0 1 0 0
The four parity bits Px through P8 are in positions 1, 2, 4, and 8. The eight bits of
the data word are in the remaining positions. Each parity bit is calculated as follows:
Remember that the exclusive-OR operation performs the odd function. It is equal
to 1 for an odd number of l’s in the variables and to 0 for an even number of l’s.
Thus, each parity bit is set so that the total number of l’s in the checked positions,
including the parity bit, is always even.
The 8-bit data word is stored in memory with the 4 parity bits as a 12-bit
composite word. Substituting the four P bits in their proper positions, we obtain
the 12-bit composite word stored in memory.
When the 12 bits are read from memory they are checked again for possible errors.
The parity is checked over the same combination of bits including the parity bit.
The four check bits are evaluated as follows:
A 0 check bit designates a even parity over the checked bits and a 1 designates an
odd parity. Since the bits were stored with even parity, the result C = C8C4C2C1
= 0000 indicates that no error has occurred. However, if C ^ 0, the 4-bit binary
number formed by the check bits gives the position of the erroneous bit. For
example, consider the following three cases:
In the first case, there is no error in the 12-bit word. In the second case there is
an error in bit position number 1 because it changed from 0 to 1. The third case
shows an error in bit position 5 with a change from 1 to 0. Evaluating the XOR
of the corresponding bits we determine the four check bits to be as follows:
Cs C4 Cj2 Cl
No error 0 0 0 0
Error in bit 1 0 0 0 1
Error in bit 5 0 10 1
Thus, for no error we have C = 0000; with an error in bit 1 we obtain C = 0001;
and with an error in bit 5 we get C = 0101. The binary number of C, when it is
not equal to 0000, gives the position of the bit in error. The error can be corrected
by complementing the corresponding bit. Note that an error can occur in the data
word or in one of the parity bits.
The Hamming code can be used for data words of any length. In general, for
k check bits and n data bits, the total number of bits (n + k) that can be accom¬
modated in a coded word is 2k - 1. In other words, the relationship n + k =
2* — 1 must hold. This gives n = 2k — 1 — k (or less) as the number of bits for
the data word. For example, when k = 3, the total number of bits in the coded
word is n + k = 23 - 1 = 7, giving n = 7 - 3 = 4. For k = 4, we have n +
k — 15, giving n — 11. The data word may be less than 11 bits but must have at
least 5 bits; otherwise, only three check bits will be needed. This justifies the use
of 4 check bits for the 8 data bits in the previous example.
The grouping of bits for parity generation and checking can be determined from
a list of the binary numbers from 0 through 2* — 1. (Table 1-2 gives such a list).
202 Chapter 6 Memory and Programmable Logic
The least significant bit is a 1 in the binary numbers 1, 3, 5, 7, and so on. The
second significant bit is a 1 in the binary numbers 2, 3, 6, 7, and so on. Comparing
these numbers with the bit positions used in generating and checking parity bits in
the Hamming code, we note .the relationship between the bit groupings in the code
and the position of the l-bits in the binary count sequence. Note that each group
of bits starts with a number that is a power of 2, for example, 1, 2, 4, 8, 16, and
so forth. These numbers are also the position number for the parity bits.
The Hamming code can detect and correct only a single error. Multiple errors
are not detected. By adding another parity bit to the coded word, the Hamming
code can be used to correct a single error and detect double errors. If we include
this additional parity bit, the previous 12-bit coded word becomes 001110010100P,3
where Pl3 is evaluated from the exclusive-OR of the other 12 bits. This produces
the 13-bit word 0011100101001 (even parity). When the 13-bit word is read from
memory, the check bits are evaluated and also the parity P over the entire 13 bits.
If P = 0, the parity is correct (even parity), but if P = 1, the parity over the 13
bits is incorrect (odd parity). The following four cases can occur:
Note that this scheme cannot detect more than two errors.
Integrated circuits are available commercially that use a modified Hamming
code to generate and check parity bits for a single-error-correction double-error-
detection scheme. One that uses an 8-bit data word and a 5-bit check word is IC
type 74637. Other integrated circuits are available for data words of 16 and 32 bits.
These circuits can be used in conjunction with a memory unit to correct a single
error or detect double errors during the write or read operations.
FIGURE 6-12
ROM Block Diagram
Section 6-5 Read-Only Memory (ROM) 203
FIGURE 6-13
Internal Logic of a 32 x 8 ROM
the data bits of the stored word which is selected by the address. The number of
words in a ROM is determined from the fact that k address input lines are needed
to specify 2k words. Note that the ROM does not have data inputs because it does
not have a write operation. Integrated circuit ROM chips have one or more enable
inputs and come with three-state outputs to facilitate the construction of large
arrays of read-only memories.
Consider for example a 32 x 8 ROM. The unit consists of 32 words of 8 bits
each. There are 5 input lines that form the binary numbers from 0 through 31 for
the address. Figure 6-13 shows the internal logic construction of the ROM. The
five inputs are decoded into 32 distinct outputs by means of a 5 x 32 decoder.
Each output of the decoder represents a memory address. The 32 outputs of the
decoder are connected through fuses to each of the eight OR gates. The diagram
shows the array logic convention used in complex circuits (see Figure 6-1). Each
OR gate must be considered as having 32 inputs. Each output of the decoder is
connected through a fuse to one of the inputs of each OR gate. Since each OR
gate has 32 internal fuses and there are 8 OR gates, the ROM contains 32 x 8 =
256 internal fuselinks. In general, a 2k x n ROM will have an internal k x 2k
decoder and n OR gates. Each OR gate has 2k inputs which are connected through
fuses to each of the outputs of the decoder.
The internal binary storage of a ROM is specified by a truth table that shows
the word content in each address. For example, the content of a 32 x 8 ROM
may be specified with a truth table similar to the one shown in Table 6-2. The
truth table shows the five inputs under which are listed all 32 addresses. Each input
specifies the address of a word of 8 bits whose value is listed under the output
columns. Table 6-2 shows only the first four and the last four words in the ROM.
The complete table must include the list of all 32 words.
The hardware procedure that programs the ROM results in blowing internal
fuses according to a given truth table. For example, programming the ROM ac-
204 Chapter 6 Memory and Programmable Logic
TABLE 6-2
ROM Truth Table (Partial)
Inputs Outputs
u /3 /2 /l /o A7 *6 A5 A4 A3 a2 A, A0
0 0 0 0 0 1 0 1 1 0 1 1 0
0 0 0 0 1 0 0 0 1 1 1 0 1
0 0 0 1 0 1 1 0 0 0 1 0 1
0 0 0 1 1 1 0 1 1 0 0 1 0
1 1 1 0 0 0 0 0 0 1 0 0 1
1 1 1 0 1 1 1 1 0 0 0 1 0
1 1 1 1 0 0 1 0 0 1 0 1 0
1 1 1 1 1 0 0 1 1 0 0 1 1
cording to the truth table given by Table 6-2 results in the configuration shown in
Figure 6-14. Every 0 listed in the truth table specifies a fuse to be blown and every
1 listed specifies a path that is obtained by an intact fuse. As an example, the table
specifies the 8-bit word 10110010 for permanent storage at input address 00011.
The four 0’s in the word are programmed by blowing the fuses between output 3
of the decoder and the inputs of the OR gates associated with outputs A6, A3, A2,
and A0. The four l’s in the word are marked in the diagram with a cross to designate
an intact fuse. When the input of the ROM is 00011, all the outputs of the decoder
are 0 except output 3 which is at logic-1. The signal equivalent to logic-1 at decoder
output 3 propagates through the fuses and the OR gates to outputs A7, A5, A4,
FIGURE 6-14
Programming the ROM According to Table 6-2
Section 6-5 Read-Only Memory (ROM) 205
and Ax. The other four outputs remain at 0. The result is that the stored word
10110010 is applied to the eight data outputs.
Types of ROMs
The required paths in a ROM may be programmed in three different ways. The
first is called mask programming and is done by the semiconductor company during
the last fabrication process of the unit. The procedure for fabricating a ROM
requires that the customer fill out the truth table he wishes the ROM to satisfy.
The truth table may be submitted on a special form provided by the manufacturer
or in a specified format on a computer output medium. The manufacturer makes
the corresponding mask for the paths to produce the l’s and 0’s according to the
customer’s truth table. This procedure is costly because the vendor charges the
customer a special fee for custom masking the particular ROM. For this reason,
mask programming is economical only if a large quantity of the same ROM con¬
figuration is to be ordered.
For small quantities, it is more economical to use a second type of ROM called
a programmable read-only memory or PROM. When ordered, PROM units contain
all the fuses intact giving all l’s in the bits of the stored words. The fuses in the
PROM are blown by application of current pulses through the output terminals
for each address. A blown fuse defines a binary 0 state and an intact fuse gives a
binary 1 state. This allows the user to program the PROM in his own laboratory
to achieve the desired relationship between input addresses and stored words.
Special instruments called PROM programmers are available commercially to fa¬
cilitate this procedure. In any case, all procedures for programming ROMs are
hardware procedures even though the word programming is used. The hardware
procedure for programming ROMs or PROMs is irreversible and, once pro¬
grammed, the fixed pattern is permanent. Once a bit pattern has been established,
the unit must be discarded if the bit pattern is to be changed.
A third type of ROM available is called erasable PROM or EPROM. The
EPROM can be restructured to the initial value even though its fuses have been
blown previously. When the EPROM is placed under a special ultraviolet light for
a given period of time, the short wave radiation discharges the internal gates that
serve as fuses. After erasure, the EPROM returns to its initial state and can be
reprogrammed to a new set of words. Certain PROMs can be erased with electrical
signals instead of ultraviolet light. These PROMs are called electrically erasable
PROM or EEPROM.
The internal operation of a ROM can be interpreted in two ways. The first
interpretation is that of a memory unit that contains a fixed pattern of stored words.
The second interpretation is of a unit that implements a combinational circuit.
From this point of view, each output terminal is considered separately as the output
of a Boolean function expressed as a sum of minterms. For example, the ROM of
Figure 6-14 may be considered as a combinational circuit with eight outputs, each
being a function of the five input variables. Output A-, can be expressed as a sum
of minterms as follows. (The three dots represent minterms 4 through 27 which
are not specified in the figure.)
An intact fuse produces a minterm for the sum and a blown fuse removes the
minterm from the sum.
ROMs are widely used to implement complex combinational circuits directly
from their truth table. They are useful for converting from one alphanumeric code,
such as ASCII, to another, like EBCDIC. They can generate complex arithmetic
operations such as multiplication or division, and in general, they are used in
applications requiring a large number of inputs and outputs.
In practice, when a combinational circuit is designed by means of a ROM, it is
not necessary to design the logic or to show the internal gate connections of fuses
inside the unit. All that the designer has to do is specify the particular ROM by
its IC number and provide the ROM truth table. The truth table gives all the
information for programming the ROM. No internal logic diagram is needed to
accompany the truth table.
Example 6-1 Design a combinational circuit using a ROM. The circuit accepts a 3-bit number
and generates an output binary number equal to the square of the input number.
The first step is to derive the truth table of the combinational circuit. In most
cases this is all that is needed. In other cases, we can use a partial truth table for
the ROM by utilizing certain properties in the output variables. Table 6-3 is the
truth table for the combinational circuit. Three inputs and six outputs are needed
to accommodate all possible binary numbers. We note that output B0 is always
TABLE 6-3
Truth Table for Circuit of Example 6-1
Inputs Outputs
A2 A, A0 B5 B4 B3 B2 Bi B0 Decimal
0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 1 1
0 10 0 0 0 10 0 4
011 0 0 10 0 1 9
10 0 0 1 0 0 0 0 16
10 1 0 110 0 1 25
110 1 0 0 10 0 36
111 1 1 0 0 0 1 49
Section 6-6 Programmable Logic Device (PLD) 207
B0 a2 A ^0 B5 £4 *3 B?
0 0 0 0 0 0 0
B^
0 0 1 0 0 0 0
0 1 0 0 0 0 1
B2 0 1 1 0 0 1 0
1 0 0 0 1 0 0
B3 1 0 1 0 1 1 0
1 1 0 1 0 0 1
1 1 1 1 1 0 0
B5
FIGURE 6-15
ROM Implementation of Example 6-1
The previous example is too simple for actual implementation with a ROM. It
is presented here for illustration purposes only. The design of complex combina¬
tional circuits with a ROM requires that we determine the number of inputs and
outputs of the circuit. The size of ROM needed to implement the circuit is at least
2k x n, where k is the number of inputs and n is the number of outputs. The truth
table accompanying the ROM must list the 2k binary addresses and provide the n-
bit word for each address.
Inputs
Fuses
Inputs
FIGURE 6-16
Basic Configuration of Three PLDs
gates are programmed to provide the product terms for the Boolean functions
which are logically summed in each OR gate. The most flexible PLD is the pro¬
grammable logic array (PLA) where both the AND and OR arrays can be pro¬
grammed. The product terms in the AND array may be shared by any OR gate
to provide the required sum of products implementation. The names PAL and
PLA emerged from different vendors during the development of programmable
logic devices. The implementation of combinational circuits with a PROM was
demonstrated in the previous section. The design of combinational circuits with
PLA and PAL is presented in the next two sections.
Some PLDs include flip-flops within the integrated circuit chip in addition to
the AND and OR arrays. The result is a sequential circuit as shown in Figure
6-17. A PAL or a PLA may include a number of flip-flops connected by fuses to
form the sequential circuit. The circuit outputs can be taken from the OR gates
or from the outputs of the flip-flops. Additional programmable fuses are available
to include the flip-flop variables in the product terms formed with the AND array.
The flip-flops may be of the D or the JK type.
AND-OR array
Outputs
(PAL or PLA)
Flip-flops
FIGURE 6-17
Sequential Programmable Logic Device
Section 6-7 Programmable Logic Array (PLA) 209
The advantage of using the PLD in the design of digital systems is that it can
be programmed to incorporate a complex logic function within one integrated
circuit. The use of programmable logic devices is an alternative to another design
technology called VLSI (very large scale integration) design. VLSI design refers
to the design of digital systems that contain thousands of gates within a single
integrated circuit chip. The basic component used in VLSI design is the gate array.
A gate array consists of a pattern of gates fabricated in an area of silicon which is
repeated thousands of times until the entire chip is covered with identical gates.
Arrays of one thousand to ten thousand gates can be fabricated within a single
integrated-circuit chip depending on the technology used. The design with gate
arrays requires that the designer specifies the layout of the chip and the way that
the gates are routed and connected. The first few levels of fabrication process are
common and independent of the final logic function. Additional fabrication levels
are required to interconnect the gates in order to realize the desired function. This
is usually done by means of computer aided design (CAD) methods. Both the gate
array and the programmable logic device require extensive computer software tools
to facilitate the design procedure.
The PLA is similar to the PROM in concept except that the PLA does not provide
full decoding of the variables and does not generate all the minterms. The decoder
is replaced by an array of AND gates that can be programmed to generate any
product term of the input variables. The product terms are then connected to OR
gates to provide the sum of products for the required Boolean functions.
The internal logic of a PLA with three inputs and two outputs is shown in Figure
6-18. Such a circuit is too small to be available commercially but is presented here
to demonstrate the typical logic configuration of a PLA. The diagram uses the
array logic graphic symbols for complex circuits. Each input goes through a buffer
and an inverter shown in the diagram with a composite graphic symbol that has
both the true and complement outputs. Each input and its complement are con¬
nected through fuses to the inputs of each AND gate as indicated by the intersec¬
tions between the vertical and horizontal lines. The outputs of the AND gates are
connected by fuses to the inputs of each OR gate. The output of the OR gate goes
to an XOR gate where the other input can be programmed to receive a signal
equal to either logic-1 or logic-0. The output is inverted when the XOR input is
connected to 1 (since X 0 1 = X). The output does not change when the XOR
input is connected to 0 (since X © 0 = X). The particular Boolean functions
implemented in the PLA of Figure 6-18 are
Fx = AB + AC + ABC
F2 = AC + BC
The product terms generated in each AND gate are listed along the output of the
gate in the diagram. The product term is determined from the inputs with intact
fuses. The output of an OR gate gives the logic sum of the selected product terms.
210 Chapter 6 Memory and Programmable Logic
Fi
Fo
FIGURE 6-18
PLA with 3 Inputs, 4 Product Terms, and 2 Outputs
The output may be complemented or left in its true form depending on the fuses
associated with the XOR gate.
The fuse map of a PLA can be specified in a tabular form. For example, the
programming table that specifies the fusing of the PLA of Figure 6-18 is listed in
Table 6-4. The PLA programming table consists of three sections. The first section
lists the product terms numerically. The second section specifies the required paths
between inputs and AND gates. The third section specifies the paths between the
AND and OR gates. For each output variable we may have a T (for true) or C
(for complement). The product terms listed on the left are not part of the table;
TABLE 6-4
PLA Programming Table
Inputs Outputs
Product (T) (C)
term A B c Fi F2
AB 1 1 0 _ 1 —
AC 2 1 — 1 1 1
BC 3 -— 1 1 1
ABC 4 0 1 0 1
Section 6-7 Programmable Logic Array (PLA) 211
they are included for reference only. For each product term, the inputs are marked
with 1, 0, or — (dash). If a variable in the product term appears in its true form,
the corresponding input variable is marked with a 1. If it appears complemented,
the corresponding input variable is marked with a 0. If the variable is absent in
the product term, it is marked with a dash.
The paths between the inputs and the AND gates are specified under the column
heading inputs in the programming table. A 1 in the input column specifies an
intact fuse from the input variable to the AND gate. A 0 in the input column
specifies an intact fuse from the complement of the variable to the input of the
AND gate. A dash specifies a blown fuse in both the input variable and its com¬
plement. It is assumed that an open terminal in the input of an AND gate behaves
like a 1.
The paths between the AND and OR gates are specified under the column
heading outputs. The output variables are marked with l’s for those product terms
that are included in the function. Each product term that has a 1 in the output
column requires a path from the output of the AND gate to the input of the OR
gate. Those marked with a dash specify a blown fuse. It is assumed that an open
terminal in the input of an OR gate behaves like a 0. Finally, a T (true) output
dictates that the other input of the corresponding XOR gate be connected to 0,
and a C (complement) specifies a connection to 1.
The size of a PLA is specified by the number of inputs, the number of product
terms and the number of outputs. A typical integrated circuit PLA may have 16
inputs, 48 product terms, and 8 outputs. For n inputs, k product terms, and m
outputs the internal logic of the PLA consists of n buffer-inverter gates, k AND
gates, m OR gates, and m XOR gates. There are 2n x k fuses between the inputs
and the AND array; k x m fuses between the AND and OR arrays; and m fuses
associated with the XOR gates.
When designing a digital system with a PLA, there is no need to show the
internal connections of the unit as was done in Figure 6-18. All that is needed is
a PLA programming table from which the PLA can be programmed to supply the
required logic. As with a ROM, the PLA may be mask programmable or field
programmable. With mask programming, the customer submits a PLA program
table to the manufacturer. This table is used by the vendor to produce a custom-
made PLA that has the required internal logic specified by the customer. A second
type of PLA available is called a field programmable logic array or FPLA. The
FPLA can be programmed by the user by means of certain recommended proce¬
dures. Commercial hardware programmer units are available for use in conjunction
with FPL As.
When implementing a combinational circuit with PLA, careful investigation must
be undertaken in order to reduce the number of distinct product terms, since a
PLA has a finite number of AND gates. This can be done by simplifying each
Boolean function to a minimum number of terms. The number of literals in a term
is not important since all the input variables are available anyway. Both the true
and complement of the function should be simplified to see which one can be
expressed with fewer product terms and which one provides product terms that are
common to other functions.
212 Chapter 6 Memory and Programmable Logic
Example 6-2 Implement the following two Boolean functions with a PLA.
B, C) = Xm(0, 1, 2, 4)
F2(A, = 2 m( 0, 5, 6, 7)
The two functions are simplified in the maps of Figure 6-19. Both the true and
complement of the functions are simplified in sum of products. The combination
that gives a minimum number of product terms is
F, = AB + AC + BC
F2 = AB + AC + ABC
This gives four distinct product terms: AB, AC, BC, and ABC. The PLA pro¬
gramming table for this combination is shown in Figure 6-19. Note that output Fx
is the true output even though a C is marked over it in the table. This is because
Fl is generated with an AND-OR circuit and is available at the output of the OR
gate. The XOR gate complements the function to produce the true Fx output.
B B
BC BC
00 01 11 10 00 01 11 10
A A
1 1 0 1 1 0 0 0
0 0
1 0 0 0 A< 1 0 1 1 1
"V Y
C c
Fj = A B + A C + BC F2 = AB + AC + ABC
F, = AB + AC + BC F2 = AC + AB + ABC
Outputs
AC 2 1-1 1
BC 3 - 1 1 1
ABC 4 0 0 0
FIGURE 6-19
Solution to Example 6-2
Section 6-8 Programmable Array Logic (PAL) 213
The combinational circuit used in Example 6-2 is too simple for implementing
with a PLA. It was presented here merely for demonstration purposes. A typical
commercial PLA has over 10 inputs and 50 product terms. The simplification of
Boolean functions with so many variables should be carried out by means of com¬
puter assisted simplification procedures. This is where computer software is of help
in the design of complex digital systems. The computer aided design program must
simplify each function and its complement to a minimum number of terms. The
program then selects a minimum number of product terms that cover all functions
in their true or complement form. The PLA programming table is then generated
from which is obtained the required fuse map. The fuse map is applied to an LPLA
programmer that goes through the hardware procedure of blowing the internal
fuses in the integrated circuit.
The PAL is a programmable logic device with a fixed OR array and programmable
AND array. Because only the AND gates are programmable, the PAL is easier
to program but is not as flexible as the PLA. Ligure 6-20 shows the logic config¬
uration of a typical PAL. It has four inputs and four outputs. Each input has a
buffer-inverter gate, and each output is generated by a fixed OR gate. There are
four sections in the unit, each composed of a 3-wide AND-OR array. This is the
term used to indicate that there are three programmable AND gates in each section.
Each AND gate has 10 fused programmable inputs. This is shown in the diagram
with 10 vertical lines intersecting each horizontal line. The horizontal line sym¬
bolizes the multiple input configuration of the AND gate. One of the outputs is
connected to a buffer-inverter gate and then fed back into the inputs of the AND
gates through fuses.
Commercial PAL devices contain more gates than the one shown in Ligure
6-20. A typical PAL integrated circuit may have eight inputs, eight outputs, and
eight sections each consisting of an 8-wide AND-OR array. The output terminals
are sometimes bidirectional which means that they can be programmed as inputs
instead of outputs if desired. Some PAL units incorporate D-type flip-flops in the
outputs. The outputs of the flip-flops are fed back through a buffer-inverter gate
into the AND programmed array. This provides a capability for implementing
sequential circuits.
When designing with a PAL, the Boolean functions must be simplified to fit
into each section. Unlike the PLA, a product term cannot be shared among two
or more OR gates. Therefore, each function can be simplified by itself without
regard to common product terms. The number of product terms in each section is
fixed, and if the number of terms in the function is too large, it may be necessary
to use two sections to implement one Boolean function.
As an example of using a PAL in the design of a combinational circuit, consider
the following Boolean functions given in sum of minterms.
214 Chapter 6 Memory and Programmable Logic
Product 0123456789
FIGURE 6-20
PAL with 4 Inputs, 4 Outputs, and 3-Wide AND-OR Structure
TABLE 6-5
PAL Programming Table
1 1 1 0 — w = ABC
2 0 0 1 0 + ABCD
3
4 1 _ _ _ _ X = A
5 — 1 1 1 + BCD
6 _
7 0 1 _ _ _ Y = AB
8 — — 1 1 — + CD
9 — 0 — 0 — + BD
10 _ _ _ _ 1 Z = W
11 1 — 0 0 — + ACD
12 0 0 0 1 — + ABCD
Simplifying the four functions to a minimum number of terms results in the following
Boolean functions:
W = ABC + ABCD
X = A + BCD
Y = AB + CD + BD
Z = ABC + ABCD +ACD + ABCD
= VT + ACD + ABCD
Note that the function for Z has four product terms. The logical sum of two of
these terms is equal to W. By using W it is possible to reduce the number of terms
for Z from four to three.
The PAL programming table is similar to the one used for the PLA except that
only the inputs of the AND gates need to be programmed. Table 6-5 lists the PAL
programming table for the four Boolean functions. The table is divided into four
sections with three product terms in each to conform with the PAL of Figure
6-20. The first two sections need only two product terms to implement the Boolean
function. The last section for output Z needs four product terms. Using the output
from W we can reduce the function to three terms.
The fuse map for the PAL as specified in the programming table is shown in
Figure 6-21. For each 1 or 0 in the table we mark the corresponding intersection
in the diagram with the symbol for an intact fuse. For each dash we mark the
diagram with blown fuses in both the true and complement inputs. If the AND
gate is not used, we leave all its input fuses intact. Since the corresponding input
receives both the true and complement of each input variable, we have A • A =
0 and the output of the AND gate is always 0.
AND gates inputs
Product A A BBCCDDWW
FIGURE 6-21
Fuse Map for PAL as Specified in Table 6-5
As with all PLDs, the design with PALs is facilitated by using computer aided
design techniques. The blowing of internal fuses is a hardware procedure done with
the help of special electronic instruments.
REFERENCES
1. Peatman J. B. Digital Hardware Design. New York: McGraw-Hill, 1980.
2. Blakeslee, T. R. Digital Design with Standard MSI and LSI. 2nd ed. New York:
Wiley, 1979.
216
Problems 217
PROBLEMS
6-1 The following memory units are specified by the number of words times the number
of bits per word. How many address lines and input-output data lines are needed in
each case?
(a) 2K x 16; (b) 64K x 8; (c) 16M x 32; (d) 96K x 12.
6-2 Give the number of bytes stored in the memories listed in Problem 6-1 (a), (b), and
(c). -
6-3 Word number 535 in the memory shown in Figure 6-3 contains the binary equivalent
of 2209. List the 10-bit address and the 16-bit memory content of the word.
6-4 Draw the standard graphic symbol of a 256 x 1 RAM. Include the symbol for three-
state output.
6-5 Show the memory cycle timing waveforms for the write and read operations. Assume
a CPU clock of 2.5 MHz and a memory cycle time of 600 nsec.
6-6 Draw the standard graphic diagram of the 4x4 RAM of Figure 6-7 including three-
state outputs. Construct an 8 x 8 memory using four 4x4 RAM units.
6-7 A 16K x 4 memory uses coincident decoding by splitting the internal decoder into
A-selection and Y-selection.
(a) What is the size of each decoder and how many AND gates are required for
decoding the address?
(b) Determine the X and Y selection lines that are enabled when the input address
is the binary equivalent of 6,000.
6-8 (a) How many 128 x 8 RAM chips are needed to provide a memory capacity of 2048
bytes?
(b) How many lines of the address must be used to access 2048 bytes? How many of
these lines are connected to the address inputs of all chips?
(c) How many lines must be decoded for the chip select inputs? Specify the size of
the decoder.
6-9 A computer uses RAM chips of 1024 x 1 capacity.
(a) How many chips are needed and how should their address lines be connected to
provide a memory capacity of 1024 bytes?
(b) How many chips are needed to provide a memory capacity of 16K bytes? Explain
in words how the chips are to be connected.
6-10 An integrated circuit RAM chip has a capacity of 1024 words of 8 bits each (IK x 8).
(a) How many address and data lines are there in the chip?
(b) How many chips are needed to construct a 16K x 16 RAM?
(c) How many address and data lines are there in the 16K x 16 RAM?
(d) What size of decoder is needed to construct the 16K x 16 memory from the IK
x 8 chips? What are the inputs to the decoder and where are its outputs connected?
218 Chapter 5 Registers and Counters
6-11 Given the 8-bit data word 01011011, generate the 13-bit composite word for the
Hamming code that corrects single errors and detects double errors.
6-12 Given the 11-bit data word 11001001010, generate the 15-bit Hamming code word.
6-13 A 12-bit Hamming code word containing 8 bits of data and 4 parity bits is read from
memory. What was the original 8-bit data word that was written into memory if the
12-bit word read out is
(a) 000011101010 (b) 101110000110 (c) 101111110100
6-14 How many parity check bits must be included with the data word to achieve single
error correction and double error detection when the data word contains (a) 16 bits;
(b) 32 bits; (c) 48 bits.
6-15 It is necessary to formulate the Hamming code for 4 data bits D3, D5, D6, and D7,
together with three parity bits P{, P2, and P4.
(a) Evaluate the 7-bit composite code word for the data word 0010.
(b) Evaluate the three check bits C4, C2, and C\, assuming no error.
(c) Assume an error in bit D5 during writing into memory. Show how the error in
the bit is detected and corrected.
(d) Add a parity bit P8 to include a double error detection in the code. Assume that
errors occurred in bits P2 and D5. Show how the double error is detected.
6-16 Given a 32 x 8 ROM chip with an enable input, show the external connections
necessary to construct a 128 x 8 ROM with four chips and a decoder.
6-17 A ROM chip of 4096 x 8 bits has two chip select inputs and operates from a 5-volt
power supply. How many pins are needed for the integrated circuit package? Draw
a block diagram and label all input and output terminals in the ROM.
6-18 The 32 x 6 ROM together with the 2° line as shown in Figure P6-18 converts a 6-bit
binary number to its corresponding 2-digit BCD number. For example, binary 100001
converts to BCD 011 0011 (decimal 33). Specify the truth table for the ROM.
> 10°
> 101
FIGURE P6-18
Binary-to-Decimal ROM Converter
6-19 Specify the size of a ROM (number of words and number of bits per word) that will
accommodate the truth table for the following combinational circuit components.
(a) A binary multiplier that multiplies two 4-bit numbers.
(b) A 4-bit adder-subtractor (see Figure 3-12).
(c) A quadruple 2-to-l-line multiplexer with common select and enable inputs (see
Figure 3-24).
(d) A BCD to seven segment decoder with an enable input.
Problems 219
6-20 Tabulate the truth table for an 8 x 4 ROM that implements the following four Boolean
functions.
A(X, Y, Z) = 1 m( 1, 2, 4, 6)
B(X, Y, Z) = 1 m(0, 1, 6, 7)
C(X, Y, Z) = Z m(2, 6)
6-21 Obtain the PLA programming table for the four Boolean functions listed in Problem
6-20. Minimize the number of product terms.
6-22 Derive the PLA programming table for the combinational circuit that squares a 3-bit
number. Minimize the number of product terms. (See Figure 6-15 for the equivalent
ROM implementation.)
6-23 List the PLA programming table for the BCD to excess-3 code converter whose
Boolean functions are simplified in Figure 3-5.
6-24 Repeat Problem 6-23 using a PAL.
6-25 The following is a truth table of a 3-input, 4-output combinational circuit. Obtain the
PAL programming table for the circuit and mark the fuses to be blown in a PAL
diagram similar to the one shown in Figure 6-20.
Inputs Outputs
X Y z A B c D
0 0 0 0 1 0 0
0 0 1 1 1 1 1
0 1 b 1 0 1 1
0 1 i 0 1 0 1
1 0 0 1 0 1 0
1 0 1 0 0 0 1
1 1 0 1 1 1 0
1 1 1 0 1 1 1
6-26 Modify the PAL diagram in Figure 6-20 by including three clocked D-type flip-flops
between the OR gates and outputs F2, F3, and F4. The diagram should conform with
the block diagram of a sequential circuit as shown in Figure 6-17. This will require
three additional buffer-inverter gates and six vertical lines for the flip-flop outputs to
be connected to the AND array through programmable fuses. Using the modified
PAL diagram, show the fuse map that will implement a 3-bit binary counter with a
carry output in Fx.
7
REGISTER
TRANSFER
AND COMPUTER
OPERATIONS
7-1 INTRODUCTION
A digital system is a sequential logic system constructed with flip-flops and gates.
It was shown in Chapter 4 that sequential circuits can be specified by means of
state tables. To specify a large digital system with state tables is very difficult, if
not impossible, because the number of states would be prohibitively large. To
overcome this difficulty, digital systems are designed using a modular approach.
The system is partitioned into modular subsystems, each of which performs some
functional task. The modules are constructed from such digital devices as registers,
counters, decoders, multiplexers, arithmetic elements, and control logic. The var¬
ious modules are interconnected by common data and control paths to form the
digital computer system.
Digital modules are best defined by the registers they contain and the operations
that are performed on the binary information stored in them. Examples of register
operations are shift, count, clear, and load. In this configuration, the registers are
assumed to be the basic components of the digital system and the information flow
and processing tasks among the data stored in the registers are referred to as register
transfer operations. The register transfer operations of digital systems are specified
by the following three basic components:
220
Section 7-1 Introduction 221
of the control unit. Chapter 10 demonstrates the detailed design of a central proc¬
essing unit.
P2 <- PI
R 7 6 5 4 3 2 10
15 0 15 8 7 0
R2 PC(H) PC(L)
FIGURE 7-1
Block Diagram of a Register
Section 7-2 Register Transfer 223
t t + 1
Clock
> k
_n_tl
_I L
Transfer occurs here-
(b) Timing diagram
FIGURE 7-2
Transfer from Rl to R2 when 7, = 1
TV R2 <- Rl
TABLE 7-1
Basic Symbols for Register Transfers
Multiplexer Selection
There are occasions when a register receives information from two different sources
at different times. Consider the following conditional statement:
If (7\ = 1) then (RO «- Rl) else if (T2 = 1) then (RO <- R2)
TxT2: RO <- R2
This specifies a hardware connection from two registers, Rl and R2, to one common
destination register RO. This type of operation requires a multiplexer to select
between the two source registers according to the values of the timing variables.
The block diagram of the circuit that implements the above two statements using
4-bit registers is shown in Figure 7-3(a). The quadruple 2x1 multiplexer selects
between the two source registers. When Tx = 1 register Rl is selected and when
Tx = 0, register R2 is selected by the multiplexer. Thus, when 7\ = 1, Rl is loaded
into RO irrespective of the value of T2. When T2 = 1 and Tx = 0, R2 is loaded
into RO. When both Tx and 73 are equal to 0, the multiplexer selects R2 for the
inputs of RO but the inputs are not loaded into the register because the load control
input is equal to 0.
The detail logic diagram of the hardware implementation is shown in Figure
7-3(b). The diagram uses standard graphic symbols as presented in previous chap¬
ters. The graphic symbol for the registers is taken from Figure 5-3(b) and for the
multiplexer from Figure 3-31(b). The enable input ENin the multiplexer is activated
with the same condition as the load input of the destination register.
It is important to be able to relate the information given in a block diagram
with the detail wiring connections in the corresponding logic diagram. In subsequent
discussions we will present other block diagrams for various digital systems. In
order to save space, the detailed logic diagram may be omitted. However, it should
(a) Block diagram
FIGURE 7-3
Use of Multiplexers to Select Between Two Registers
be a straightforward procedure to obtain the logic diagram with detail wiring from
the information given in the block diagram.
7-3 MICROOPERATIONS
A microoperation is an elementary operation performed with the data stored in
registers. The type of microoperations most often encountered in digital computers
are classified into four categories:
225
226 Chapter 7 Register Transfer and Computer Operations
The register transfer microoperation was introduced in the previous section. This
type of microoperation does not change the information content when the binary
information moves from the source register to the destination register. The other
three types of microoperations change the information content during the transfer.
Among all possible operations that can exist in digital systems, there is a basic set
from which all other operations can be obtained. In this section we define a set of
basic microoperations, their symbolic notation, and the digital hardware that im¬
plements them.
Arithmetic Microoperations
The basic arithmetic microoperations are addition, subtraction, increment, dec¬
rement, and shift. Arithmetic shifts are explained later in conjunction with the shift
microoperations. The arithmetic microoperation defined by the following state¬
ment:
RO <- Rl + R2
specifies an add microoperation. It states that the corttents of register R1 are to
be added to the contents of register R2 and the sum transferred to register RO. To
implement this statement with hardware we need three registers and the digital
component that performs the addition operation, such as a parallel adder. The
other basic arithmetic microoperations are listed in Table 7-2. Subtraction is most
often implemented through complementation and addition. Instead of using the
minus operator, we can specify the subtraction by the following statement:
RO <r- Rl + R2 + 1
R2 is the symbol for the l’s complement of R2. Adding 1 to the Ts complement
produces the 2’s complement. Adding the contents of Rl to the 2’s complement
of R2 is equivalent to Rl — R2.
The increment and decrement microoperations are symbolized by a plus-one
and minus-one operation, respectively. These microoperations are implemented
with a combinational circuit or with a binary up-down counter.
The arithmetic operations multiply and divide are not listed in Table 7-2. The
multiplication operation can be represented by the symbol * and the division
be a /. These two operations are valid arithmetic operations but are not included
in the basic set of microoperations. The only place where these operations can be
considered as microoperations is in a digital system where they are implemented
by means of a combinational circuit. In such a case, the signals that perform these
operations propagate through gates, and the result of the operation can be trans-
TABLE 7-2
Arithmetic Microoperations
Symbolic
designation Description
ferred into a destination register by a clock pulse as soon as the output signal
propagates through the combinational circuit. In many computers, the multipli¬
cation operation is implemented with a sequence of add and shift microoperations.
Division is implemented with a sequence of subtract and shift microoperations. To
specify the hardware in such a case requires a list of statements that use the basic
microoperations of add, subtract, and shift.
There is a direct relationship between the statements written in a register transfer
notation and the registers and digital functions that are required for their imple¬
mentation. To illustrate with an example, consider the following two statements:
XTx: R1+-R1 + R2
XTp Rl <- Rl + R2 + 1
Timing variable T1 initiates an operation to add or subtract. If, at the same time,
control variable X is equal to 0 then XT1 = 1 and the contents of R2 are added
to the contents of Rl. If X = 1, then XTl = 1 and the contents of R2 are subtracted
from Rl. Note that the two control functions are Boolean functions and reduce to
0 when 7\ = 0, a condition that inhibits the execution of either operation.
The implementation of the two statements is shown in block diagram form in
Figure 7-4. An n-bit adder-subtractor (similar to the one shown in Figure 3-12)
Clock
FIGURE 7-4
Implementation of Add and Subtract Microoperations
227
228 Chapter 7 Register Transfer and Computer Operations
receives its input data from registers R1 and R2. The sum or difference is applied
to the inputs of R1. The select input S in the adder-subtractor selects the operation
in the circuit. When 5 = 0, the two inputs are added and when S = 1, R2 is
subtracted from Rl. Applying the control variable X to the select input provides
the required operation. The output of the adder-subtractor is loaded into Rl if
XT1 = 1 or if XT, = 1. This can be simplified to only Tl since
XT, + XT, = (X + X)T, = T,
Thus, control variable X selects the operation and timing variable T, loads the
result into Rl. The output carry Cn is transferred to flip-flop C. The function of
flip-flop V is to detect for overflow as explained below.
Overflow
When two numbers of n digits each are added and the sum occupies n + 1 digits,
we say that an overflow occurred. This is true for binary or decimal numbers
whether signed or unsigned. When the addition is performed with paper and pencil,
an overflow is not a problem, since there is no limit to the width of the page to
write down the sum. An overflow is a problem in digital computers because the
length of registers is finite. A result that contains n + 1 bits cannot be accom¬
modated in a register with a standard length of n bits. For this reason, many
computers detect the occurrence of an overflow, and when it occurs, a correspond¬
ing flip-flop is set which can then be checked by the user.
The detection of an overflow after the addition of two binary numbers depends
on whether the numbers are considered to be signed or unsigned. When two
unsigned numbers are added, an overflow is detected from the end carry out of
the most significant position. In the case of signed numbers, the leftmost bit always
represents the sign and negative numbers are in 2’s complement form. When two
signed numbers are added, the sign bit is treated as part of the number and the
end carry does not indicate an overflow (see Section 1-5).
An overflow cannot occur after an addition if one number is positive and the
other is negative, since adding a positive number to a negative number produces
a result which is smaller than the larger of the two original numbers. An overflow
may occur if the two numbers added are both positive or both negative. To see
how this can happen, consider the following example. Two signed binary numbers,
+ 70 and +80, are stored in two 8-bit registers. The range of numbers that each
register can accommodate is from binary +127 to binary -128. Since the sum of
the two numbers is +150, it exceeds the capacity of the 8-bit register. This is true
if the numbers are both positive or both negative. The two additions in binary are
shown below together with the last two carries.
carries: 0 1 carries: 1 0
+ 70 0 1000110 -70 1 0111010
+ 80 0 1010000 -80 1 0110000
+ 150 1 0010110 -150 0 1101010
Note that the 8-bit result that should have been positive has a negative sign bit
and the 8-bit result that should have been negative has a positive sign bit. If,
Section 7-3 Microoperations 229
however, the carry out of the sign bit position is taken as the sign bit of the result,
then the 9-bit answer so obtained will be correct. Since the answer cannot be
accommodated within 8 bits, we say that an overflow occurred.
An overflow condition can be detected by observing the carry into the sign bit
position and the carry out of the sign bit position. If these two carries are not equal,
an overflow condition is produced. This is indicated in the examples where the two
carries are explicitly shown. If the two carries are applied to an exclusive-OR gate,
an overflow will be detected when the output of the gate is equal to 1.
The addition and subtraction of two binary numbers with digital hardware is
shown in Figure 7-4. If the numbers are considered unsigned, then the C bit detects
a carry after addition or a borrow after subtraction. If the numbers are considered
to be signed, then the V bit detects an overflow. If V = 0 after an addition or
subtraction, it indicates that no overflow occurred and the answer in Rl is correct.
If V — 1, then the result of the operation contains n + 1 bits. Only n bits of the
number are in R1. The (n + l)th bit is the sign bit and has been shifted out of
position into the carry bit C.
Logic Microoperations
Logic microoperations are useful for manipulating the bits stored in a register.
These operations consider each bit in the register separately and treat it as a binary
variable. The symbols for the four basic logic microoperations are shown in Table
7-3. The complement microoperation is the same as the l’s complement and uses
a bar on top of the register name. The symbol A is used to denote the AND
microoperation and the symbol V to denote the OR microoperation. By using
these special symbols it is possible to differentiate between the add microoperation
symbolized by a + and the OR microoperation. Although the + symbol has two
meanings, it will be possible to distinguish between them by noting where the
symbol occurs. When this symbol occurs in a microoperation, it denotes an addition
operation. When it occurs in a control or Boolean function, it denotes an OR
operation. The OR microoperation will always use the V symbol. For example, in
the statement
TABLE 7-3
Logic Microoperations
Symbolic
designation Description
The logic microoperations can be easily implemented with a group of gates. The
complement of a register of n bits is obtained with n inverter gates. The AND
microoperation is obtained from a group of AND gates, each of which receives a
pair of bits from two source registers. The outputs of the gates are applied to the
inputs of the destination register. The OR and Exclusive-OR microoperations
require a similar arrangement of gates.
The logic microoperations can change bit values, clear a group of bits, or insert
new bit values in a register. The following examples show how the bits of register
R1 are manipulated by logic microoperations with a logic operand in R2.
The AND microoperation is used for clearing to 0 a bit or a selected group of
bits in a register. The Boolean relationships X • 0 = 0 and X • 1 = X dictate that
a binary variable X when ANDed with 0 produces a 0 but when ANDed with 1 it
does not change the value of X. A given bit or a group of bits in a register can be
cleared to 0 if ANDed with 0. Consider the following example.
10101101 10101011 R1
00000000 11111111 R2
00000000 10101011 R1 <- R1 A R2
The 16-bit logic operand in R2 has 0’s in the high order byte and l’s in the low
order byte. By ANDing this with the contents of Rl, it is possible to clear to 0’s
the high order byte of Rl and leave the bits in the low order byte unchanged.
Thus, the AND operation can be used to selectively clear bits of a register. This
operation is sometimes referred to as masking out the bits because it masks or
deletes all l’s from a selected portion of a register.
The OR microoperation is used to set a bit or a group of bits in a register. The
Boolean relationships X + 1 = 1 and X + 0 = X dictate that the binary variable
X when ORed with 1 produces a 1 but when ORed with 0 it does not change the
value of X. A given bit or a group of bits in a register can be set to 1 if ORed with
1. Consider the following example.
10101101 10101011 Rl
11111111 00000000 R2
The high order byte of Rl is set to all l’s by ORing it with all Ts in the R2 operand.
The low order byte remains unchanged because it is ORed with 0’s.
The XOR (exclusive-OR) microoperation is used to complement a bit or a group
of bits in a register. The Boolean relationships X © 1 = X and X 0 0 = X dictate
that when the binary variable X is XORed with 1 it is complemented but when
XORed with 0 it remains unchanged. By XORing a bit or a group of bits in a
register with 1, it is possible to complement the selected bits. Consider the example
10101101 10101011 Rl
11111111 00000000 R2
01010010 10101011 Rl 4— Rl © Rl
Section 7-3 Microoperations 231
TABLE 7-4
Shift Microoperations
Symbolic
designation Description
The high order byte in R1 is complemented after the XOR operation with the
operand in R2.
Shift Microoperations
Shift microoperations are used for serial transfer of data. They are also used in
arithmetic, logic and control operations. The contents of a register can be shifted
to the left or the right. There are no standard symbols for the shift microoperations.
Here we will adopt the symbols shl and shr for shift left and shift right operations.
For example
R1 <- shl Rl,R2<r- shr R2
are two microoperations that specify a 1-bit shift to the left of register R1 and a
1-bit shift to the right of register R2. The register symbol must be the same on
both sides of the arrow as in the increment operation.
While the bits of a register are shifted, the end bit position receives information
from the serial input. The end position is the rightmost bit of the register during
a shift left operation and the leftmost bit of the register during a shift right operation.
The bit transferred to the end position through the serial input is assumed to be 0
during a logical shift, which is symbolized by shl or shr. In a rotate operation, the
serial output is connected to the serial input and the bits of the register rotate
without any loss of information. The symbol used for the rotate is shown in Table
7-4.
An arithmetic shift is a microoperation that shifts a signed binary number to the
left or right. An arithmetic shift left multiplies a signed binary number by 2. An
arithmetic shift right divides the number by 2. Arithmetic shifts must leave the sign
bit unchanged because the sign of the number remains the same when it is multiplied
or divided by 2.
The leftmost bit in a register holds the sign bit, and the remaining bits hold the
number. Figure 7-5 shows a typical register of n bits. Bit Rn-i in the leftmost
position holds the sign bit. R0 is the least significant bit and /?„_2 is the most
Sign
bit
R.
n — 1 Rnn —
—2 Ri Rr
FIGURE 7-5
Defining Register R for Arithmetic Shifts
232 Chapter 7 Register Transfer and Computer Operations
significant bit of the number. It is assumed that negative numbers have a 1 in the
sign bit and are in 2’s complement form.
The arithmetic shift right leaves the sign bit unchanged and shifts the number
(including the sign bit) to the right. Thus, Rn-i remains the same, Rn-2 receives
the bit from Rn_x and so on for the other bits in the register. The bit in R0 is lost.
The arithmetic shift left inserts a 0 into R0, and shifts all other bits to the left.
The initial bit of Rn-X is lost and replaced by the bit from Rn_2. A sign reversal
occurs if the bit in Rn_l changes in value after the shift. This happens if the
multiplication by 2 causes an overflow. An overflow occurs after an arithmetic shift
left if Rn_! is not equal to Rn-2 before the shift. An overflow flip-flop Vs can be
used to detect an arithmetic shift overflow.
vs = Rn_x®Rn_2
If Vs = 0, there is no overflow, but if Vs = 1, there is an overflow and a sign
reversal after the shift. Vs must be transferred into the overflow flip-flop with the
same clock pulse that shifts the register.
To illustrate with a particular example, consider the transfer given by the fol¬
lowing statement:
R2 RO
The control variables that enable this transfer must select register RO as the source
for the bus and register R2 as the destination. The multiplexer select inputs must
be binary 00. This causes bit 0 of RO to be applied to line 0 of the bus through
233
234 Chapter 7 Register Transfer and Computer Operations
MUX 0. At the same time bit 1 of R0 is applied to line 1 of the bus through MUX
1. This repeats for all other bus lines up to line n-1 which receives bit n-1 of R0
through MUX n-1. Thus, the n-bit value of R0 is placed on the common bus lines
when the MUX select is 00. The destination select inputs must be binary 10. This
activates output 2 of the decoder which in turn activates the load input of R2. With
the next clock transition, the contents of R0, being on the bus, are loaded into
register R2 to complete the transfer.
Control input C
FIGURE 7-7
Graphic Symbol for a Three-State Buffer
Section 7-4 Bus Transfer 235
FIGURE 7-8
Bus Line with Three-State Buffers
state because all four buffers are disabled. When the enable input is active, one
of the three-state buffers will be active depending on the binary value in the select
inputs of the decoder. Careful investigation will reveal that Figure 7-8 represents
another way of constructing a 4 x 1 multiplexer. The diagram shows the inputs
marked with a register name and the bit value in parenthesis. Thus, R0(k) designates
bit k in register RO. The circuit of Figure 7-8 can replace the multiplexer in Figure
7-6 that produces the bus line for bit k. To construct a common bus for four n-bit
registers with three-state buffers requires n groups of four buffers each to produce
the outputs for the n-bit bus. Only one decoder is necessary to select between the
four registers.
There are occasions where it is necessary to employ a bidirectional bus system
that can transfer information in both directions. A bidirectional bus allows the
binary information to flow in either of two directions. A bidirectional bus can be
constructed with three-state buffers to control the direction of information flow in
the bus. One line of a bidirectional bus is shown in Figure 7-9. The bus control
has two selection lines Sin for input transfer and Sout for output transfer. These
selection lines control two three-state buffers connected back to back. When
Sin = 1 and Sout = 0, the bottom buffer is enabled and the top buffer is disabled
by going to a high-impedance state. This forms a path for input data coming from
the bus to pass through the bottom buffer and into the input of a flip-flop register.
When Sout = 1 and Sm = 0, the top buffer is enabled and the bottom buffer goes
to a high-impedance state. This forms a path for output data coming from a register
in the system to pass through the upper buffer and out to the bus line. The bus
line can be disabled by making both control signals 0. This puts both buffers in a
high-impedance state, which prevents any input or output transfer of information
FIGURE 7-9
Bidirectional Bus Line with Three-State Buffers
through the bus line. This condition will exist when an external source is using the
common bus to communicate with some other external destination. The two se¬
lection lines can be used to inform the external modules connected to the bus of
the state which the bidirectional bus is at any given time.
Memory Transfer
The operation of a memory unit was described in Section 6-2. The transfer of
information from a memory word to the outside environment is called a read
operation. The transfer of new information into a memory word is called a write
operation. A memory word will be symbolized by the letter M. The particular
memory word among the many available is selected by the memory address during
the transfer. It is necessary to specify the address of M when writing memory
transfer operations. This will be done by enclosing the address in square brackets
following the letter M.
Consider a memory unit that receives the address from a register called address
register symbolized by AR. The data is transferred to another register called data
register symbolized by DR. The read operation can be stated as follows:
This causes a transfer of information into DR from the selected memory word
specified by the address in AR.
The write operation is a transfer from DR to the selected memory word M. This
can be stated symbolically as follows:
Write: M[AR] «- DR
This causes a transfer of information from DR into the memory word selected by
the address in AR.
In some systems, the memory unit receives address and data from many registers
connected to common buses. Consider the case depicted in Figure 7-10. The address
236
Section 7-4 Bus Transfer 237
for the memory comes from an address bus. Four registers are connected to this
bus and any one may supply an address. The memory data is connected to a
bidirectional data bus. The contents of the selected memory word during a read
operation can go to any one of four registers which are selected by a decoder. The
data word for the memory during a write operation comes from one of four registers
selected by the data bus. The direction of information flow in the data bus is
determined from the bus control inputs. For a read operation, the path is from
memory to a data register. For a write operation the path is from a data register
to memory. Each bidirectional line is controlled by a pair of three-state buffers as
indicated in Figure 7-9.
A memory transfer statement in a multiple register system must specify the
address register and the data register used. For example, the transfer of information
from data register D2 to a memory word selected by the address in register A1 is
symbolized by the statement
M[Al) D2
This is a write operation with A1 supplying the address. The statement does not
specify the buses explicitly. Nevertheless, it implies the required selection inputs
for the address bus to be 01 (for A1) and the register select for write inputs to be
10 (for D2). The bus control activates the write and output control signals.
Select
address
register
Register select
for read
FIGURE 7-10
Memory Unit Connected to Address and Data Buses
238 Chapter 7 Register Transfer and Computer Operations
The read operation in a memory with buses can be specified in a similar manner.
The statement
DO <- M[A3\
symbolizes a read operation from a memory word whose address is given by register
A3. The information coming out of memory is transferred to data register DO.
Again, this statement implies the required selection inputs for the address bus to
be 11 (for A3) and the inputs to the decoder to be 00 (for DO) while the bus control
activates the read and input control signals.
A select
Operation
select
Shift
select
''
Output data
FIGURE 7-11
Block Diagram of a Processor Unit
status bit Z is set to 1 if the output of the ALU contains all 0’s, and cleared to 0
otherwise. Thus, Z = 1 if the result of an operation is zero, and Z = 0 if the result
is nonzero. The sign status bit S is set to the value of the sign bit of the result. The
sign bit is always the leftmost bit out of the ALU.
A typical processor unit will have more than four registers. Computers with 16
or more registers are quite common. The construction of a bus system with a large
number of registers requires larger multiplexers and ALU, otherwise, it is similar
to the organization depicted in Figure 7-11.
239
240 Chapter 7 Register Transfer and Computer Operations
The control unit that supervises the bus system in the processor must direct the
information flow through the buses, the ALU, and the shifter by selecting the
various components in the unit. For example, to perform the microoperation
/?1 <— R2 + R3
the control unit must provide binary selection variables to the following selection
inputs:
The five sets of selection variables must be generated simultaneously and must
be available in the corresponding terminals at the beginning of a clock pulse period.
The binary data from the two source registers must propagate through the multi¬
plexers, the ALU, the shifter, and into the inputs of the destination register, all
during one clock pulse period. Then, when the next clock edge transition arrives,
the binary information on the output bus is loaded into the destination register.
To achieve a fast response time, the ALU is constructed with fast circuits and the
shifter is implemented with combinational gates.
The operation of the multiplexers, the buses, and the destination decoder was
presented in the previous section. The design of an ALU and shifter is undertaken
in the next two sections. The control of the processor unit through its selection
inputs is demonstrated in Section 7-8.
Data
A
input A
A2
A3
F0
4-bit F^ Data
Arithmetic output F
Data Logic Fi
input B Unit
B2 F3
(ALU)
b3
Operation 50
select
51
Mode select 52
FIGURE 7-12
Block Diagram of a 4-Bit ALU
will be presented. The two sections will then be combined to form the arithmetic
logic unit.
Arithmetic Circuit
The basic component of an arithmetic circuit is the parallel adder. A parallel adder
is constructed with a number of full-adder circuits connected in cascade (see Figure
3-11). By controlling the data inputs to the parallel adder, it is possible to obtain
different types of arithmetic operations. The block diagram of Figure 7-13 dem¬
onstrates a possible configuration where one set of inputs to the parallel adder is
controlled by two selection lines Sl and S0. There are n bits in the arithmetic circuit
with two inputs, A and B, and one output F. The n inputs from B go through a
combinational circuit to the Y inputs of the parallel adder. The input carry Cin goes
to the carry input of the full-adder circuit in the least significant bit position. The
output carry Cout is from the full adder in the most significant position. The output
of the parallel adder is calculated from the following arithmetic sum
F = A + Y + Cin
where A is the n-bit binary number at the X inputs and Y is the n-bit binary number
at the Y inputs of the parallel adder. Cin is the input carry which can be equal to
0 or 1. Note that the symbol + in the above equation denotes an arithmetic plus.
By controlling the value of Y with the two selection inputs S1 and S0, it is possible
to obtain a variety of arithmetic operations. This is shown in Table 7-5. If the
inputs from B are ignored and we insert all 0’s into the Y inputs, the output sum
becomes F = A + 0 + Cin. This gives F = A when Cin = 0 and F = A + 1
when Cin = 1. In the first case we have a direct transfer from input A to output
F. In the second case, the value of A is incremented by 1. For a straight arithmetic
addition, it is necessary to transfer the B inputs into the Y inputs of the parallel
241
F = A + Y + Cu
Combinational
circuit
So'
Sy
►C,out
FIGURE 7-13
Block Diagram of an Arithmetic Circuit
TABLE 7-5
Arithmetic Circuit Function Table
242
Section 7-6 Arithmetic Logic Unit (ALU) 243
Inputs Output
Si S0 B, Yi
o o
0 0 0
o
II
0 0 1
0 1 o
-» o
CS
DO
II
0 1 1
1 0 0
1 0 1 0 Y< = S'
1 1 0
1 /■ = 1
1 1 1 1 Y' 1
FIGURE 7-14
Combinational Circuit for One Stage of Arithmetic Circuit
FIGURE 7-15
Logic Diagram of a 4-Bit Arithmetic Circuit
244 Chapter 7 Register Transfer and Computer Operations
full-adder (FA) circuits constitute the parallel adder. The carry into the first stage
is the input carry Cin. All other carries are connected internally from one stage to
the next. The selection variables are Su S0, and Cin. Variables Sj and S() control
all Y inputs of the full adders according to the Boolean function derived in Figure
7-14(b). Cin adds 1 to the sum when it is equal to 1. The eight arithmetic operations
of the circuit as a function of Su S0, and Cin are listed in Table 7-5.
Logic Circuit
The logic microoperations manipulate the bits of the operands by treating each bit
in a register as a binary variable. There are four basic logic operations from which
all others can be derived. They are the AND, OR, XOR (exclusive-OR), and
complement.
Figure 7-16(a) shows one stage of the logic circuit. It consists of four gates and
a multiplexer. Each of the four logic operations is generated through a gate that
performs the required logic. The outputs of the gates are applied to a multiplexer
with two selection variables Sx and S0. These selection variables choose one of the
data inputs of the multiplexer and direct its value to the output. The diagram shows
one typical stage with subscript i. For a logic circuit with n bits, the diagram must
be repeated n times for i = 0, 1, 2, . . n —1. The selection variables are applied
to all stages. The function table in Figure 7-16(b) lists the logic operations obtained
for each combination of the selection variables.
Si So Output Operation
0 0 F = A A B AND
0 1 F = A V B OR
1 0 F = A © B XOR
1 1 F = A Complement
FIGURE 7-16
One Stage of a Logic Circuit
C,
Ai
B,
F,
So
S^
S2
FIGURE 7-17
One Stage of ALU
with selection variable S2. When S2 = 0, the arithmetic output is selected, and
when S2 — 1, the logic output is selected. Note that the diagram shows just one
typical stage of the ALU. The circuit of Figure 7-17 must be repeated n times for
an tt-bit ALU. The output carry C/+1 of a given arithmetic stage must be connected
to the input carry C, of the next stage in sequence. The input carry to the first
stage is the input carry Cin which provides a selection variable for the arithmetic
operations.
The ALU specified in Figure 7-17 provides eight arithmetic and four logic op¬
erations. Each operation is selected through the variables S2, Sj, S0, and Cin. The
input carry Cin is used for selecting an arithmetic operation only.
Table 7-6 lists the 12 operations of the ALU. The first 8 are arithmetic operations
and are selected with S2 = 0. The next 4 are logic operations and are selected with
S2 = 1. The input carry has no effect during the logic operations and is marked
with a 0 for convenience.
TABLE 7-6
Function Table for ALU
Operation Select
S2 S! S0 Cin Operation Function
0 0 0 0 F = A Transfer A
0 0 0 1 F = A + 1 Increment A
0 0 1 0 F = A + B Addition
0 0 1 1 F = A + B + 1 Add with carry
0 1 0 0 F = A + B A plus l’s complement of B
0 1 0 1 F = A + B + 1 Subtraction
0 1 1 0 F = A - 1 Decrement A
0 1 1 1 F = A Transfer A
1 0 0 0 F = A A B AND
1 0 1 0 F = Ay b OR
1 1 0 0 F = A® B XOR
1 1 1 0 F = A Complement A
245
246 Chapter 7 Register Transfer and Computer Operations
F3 F2 F] F0
S3 S2 Si 50
FIGURE 7-18
4-Bit Shifter
Section 7-7 Shifter Unit 247
TABLE 7-7
Function Table for Shifter
H1 H0 Operation Function
shift is executed and the inputs from F go directly to the shifter outputs in S. The
next two values of the selection variables cause a shift left and a shift right operation.
When HXH0 = 11, the multiplexers select the inputs attached to logic-0 and the S
outputs are all equal to 0. Table 7-7 summarizes the operation of the shifter.
The diagram of Figure 7-18 shows only four stages of the shifter. The shifter,
of course, must have n stages in a system with n parallel lines. Inputs lR and lL
are the serial inputs for the shift right and shift left, respectively. Another selection
variable may be employed to specify what goes into IR and 1L during the shift. For
example, a third selection variable, H2, when in one state can select a 0 for the
serial input during the shift. When H2 is in the other state, the data can be rotated
together with the value in the carry status bit. In this way, a carry produced during
an ALU addition operation can be shifted to the right and into the most significant
bit position of a register.
Barrel Shifter
In some processor applications the data must be shifted more than once during a
single operation. A barrel shifter is a circuit that shifts the input data bits by a
number of positions dictated by the binary value of a set of selection lines. The
shift is a cyclic rotation which means that the input binary information is shifted
in one direction and the bit coming from the most significant end of the shifter is
brought back to the least significant position.
A 4-bit barrel shifter is shown in Figure 7-19. It consists of four multiplexers
with two common selection lines S1 and S0. The selection variables determine the
number of positions that the input data will be shifted to the left by rotation. When
SXS0 — 00, no shift occurs and the inputs form a direct path to the outputs. When
SXSo = 01, the input binary information is rotated once with D() going to Yx, D,
going to Y2, D2 going to T3, and D3 circulated back into F0. When Si So = 10, the
input is rotated by two positions, and when SjSq = 11, the rotation is by three bit
positions.
Table 7-8 gives the function table for the 4-bit barrel shifter. For each binary
value of the selection variables, the table lists the inputs that go to the corresponding
output. Thus, to rotate three positions, SjS0 must be equal to 11; and D() goes to
y3, Dx goes to y0, D2 goes to Yx, and D3 goes to Y2.
A barrel shifter with 2n input and output lines requires 2n multiplexers each
having 2n data inputs and n selection inputs. The number of rotation positions is
dictated by the selection variables and can be from 0 (no shift) to 2n - 1 positions.
248 Chapter 7 Register Transfer and Computer Operations
D2 D2 D-\ Dq
Y2 Y2 Yy Y0
FIGURE 7-19
4-Bit Barrel Shifter
TABLE 7-8
Function Table for 4-Bit Barrel Shifter
Select Output
s, So V3 y2 y1 y0 Operation
10
11
F
12
13 C„
14
1 5 H
16
Output data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
A B D F H
FIGURE 7-20
Processor Unit with Control Variables
of the ALU goes through a shifter and into the output bus. The output from the
shifter can be transferred to any one of the registers and can also be directed to
an external destination. The ALU provides the binary data for the four status bits:
C (carry), Z (zero), S (sign), and V (overflow).
There are 16 binary selection inputs in the unit and their combined value specifies
a control word. The 16-bit control word is defined in Figure 7-20(b). It consists of
five parts called fields, with each field designated by a letter symbol. Four of the
fields contain three bits each, and one field has four bits. The three bits of A select
a source register for one input of the ALU. The three bits of B select a register
for the second input of the ALU. The three bits of D select a destination register.
The four bits of F select one of 12 operations in the ALU. The three bits of H
select the type of shift in the shifter unit. The 16-bit control word, when applied
to the selection inputs, specifies a particular microoperation.
250 Chapter 7 Register Transfer and Computer Operations
TABLE 7-9
Encoding of Control Word for Processor Unit
101 R5 R5 R5 F = A V B — ROL
110 R6 R6 R6 F = A® B — ROR
111 Rl Rl Rl F = A — —
The functions of all selection variables are specified in Table 7-9. The 3-bit
binary code listed in the first column of the table specifies the binary code for each
of the five fields. The register selected by fields A, B, and D is the one with the
decimal number equivalent to the binary number in the code. When the A or B
field is 000, the corresponding multiplexer selects the external input data. When
D = 000, no destination register is selected but the contents of the output bus are
available for the external outputs. The encoding of the F field is dependent on the
value of the input carry Cin. The four bits in the F field for each operation are
determined from the three bits in the corresponding first column of the table and
the bit of Cin. The operations listed for the ALU are the same as the ones specified
in Table 7-6.
The first four entries for the code in the H field specify the shift operations of
Table 7-7. The H field has a third selection variable to distinguish between a logical
shift and a shift by rotation. The SHL (shift left) and SHR (shift right) operations
listed in the table are logical shifts, which means that 0 is applied to their corre¬
sponding serial inputs. When the third selection variable in the H field is equal to
1, it indicates a shift by rotation. This is designated in the table by the symbols
ROL (rotate left) and ROR (rotate right). The ROL operation shifts the input
data to the left and inserts the value of the serial output into the serial input. The
same applies to the ROR operation except that the shift is to the right.
A control word of 16 bits is needed to specify a microoperation for the processor.
The control word for a given microoperation can be derived from the selection
variables. For example, the subtract microoperation given by the statement
Rl <- R2 - R3
specifies R2 for the A input of the ALU, R3 for the B input of the ALU, an ALU
operation F = A - B, no shift for the shifter, and Rl for the destination register.
Thus, the control word is specified by the five fields and the corresponding binary
value for each field is obtained from the encoding listed in Table 7-9. The binary
control word for the subtract microoperation is 0100110010101000 and is obtained
as follows:
Section 7-8 Control Word 251
TABLE 7-10
Examples of Microoperations for the Processor
— — —
Field: A B D F H
Symbol: R2 R3 Rl F = A - B No shift
Control word: 010 Oil 001 0101 000
The control word for this microoperation and few others are listed in Table 7-10.
The next example in the table is an add and shift microoperation given by the
statement
R4 «- shr (R5 + R6)
It specifies an arithmetic addition for the ALU and a shift right operation for the
shifter. The sum that is generated in the ALU is shifted to the right, dividing it by
2. The result of the operation is to produce the average value of the two unsigned
binary numbers stored in registers R5 and R6 (provided there is no carry). From
knowledge of the symbols in each field, the control word in binary is derived as
shown in Table 7-10.
The increment and transfer microoperations do not use the B input of the ALU.
For these cases, the B field is marked with a dash. For convenience, we assign 000
to any unused field when formulating the binary control word, although any other
binary number may be used. To put the contents of a register into the output
terminals, we place the contents of the register into the A input of the ALU, but
none of the registers is selected to accept the data. The ALU operation F = A
places the information from the register into the output terminals. To shift or rotate
the contents of a register without performing an operation in the ALU, we must
specify an ALU operation F = A. This places the contents of the A input into the
F output of the ALU without any change. To clear a register to 0, the output bus
is made equal to all 0’s with H = Oil. The destination field D is made equal to
the code for the register.
It is apparent from these examples that many other microoperations can be
generated in the processor unit. The most efficient way to generate control words
with a large number of bits is to store them in a memory unit. A memory unit that
stores control words is referred to as a control memory. The output of the control
memory is applied to the selection inputs of the processor. By reading consecutive
control words from memory, it is possible to initiate the desired sequence of mi¬
crooperations for the processor. This type of control organization, called micro¬
programming, is discussed in more detail in the next chapter.
252 Chapter 7 Register Transfer and Computer Operations
REFERENCES
1. Mano, M. M. Computer System Architecture. Englewood Cliffs: Prentice-Hall, 1982.
PROBLEMS
7-1 Show the block diagram of the hardware that implements the following register transfer
statement:
7-2 The outputs of four registers R0, R1, R2, and R3 are connected through multiplexers
to the inputs of a fifth register R5. Each register is eight bits long. The required
transfers are dictated by four timing variables T0 through T3 as follows:
T0: R5 «- R0
TV R5 *-Rl
T2: R5 <- R2
T3: R5 <- R3
The timing variables are mutually exclusive and only one variable can be equal to 1
at any given time while the other three are equal to 0. Draw a block diagram showing
the hardware implementation of the register transfers. Include the connections nec¬
essary from the four timing variables to the selection lines of the multiplexers and to
the load input of register R5.
7-3 Using two 4-bit registers R1 and R2, a quadruple 2-to-l-line multiplexer with enable,
and four inverters, draw the circuit diagram that implements the following statements:
TV R2 +-R1 Transfer R1 to R2
The three timing variables Tx through T3 are mutually exclusive and only one variable
can be equal to 1 at any given time. Use standard graphic diagrams as in Figure
5-3(b) for the registers and Figure 3-31(b) for the multiplexer.
7-4 Draw the block diagram for the hardware that implements the following statements:
Problems 253
Where AR and BR are two n-bit registers, X and Y are control variables, and T] and
T2 are timing variables. Include the logic gates for the control function. (Remember
that the symbol + designates an OR operation in a control or Boolean function, but
it represents an arithmetic plus in a microoperation.)
7-5 Consider the following register transfer statements for the two 4-bit registers R1 and
R2.
XT: Rl <- Rl + R2
XT: Rl <- R2
When timing variable 7=1, the contents of R2 are added to the contents of Rl if
X — 1, or the contents of R2 are transferred to Rl if A" = 0. Draw a logic diagram
showing the implementation of the two statements. Use standard graphic symbols for
the 4-bit registers (Figure 5-3[b]), the 4-bit adder (Figure 3-28), and the multiplexer
that selects the inputs to Rl (Figure 3-31[b]). In the diagram, show how the control
variables X and T select the inputs to Rl.
7-6 Using a 4-bit counter with parallel load as in Figure 5-19 and a 4-bit adder as in Figure
3-28, draw the logic diagram with standard graphic symbols that implements the fol¬
lowing statements:
7V Rl <— Rl + R2 Add R2 to Rl
TxT2: Rl Rl + 1 Increment Rl
7-7 A digital system has three registers: AR, BR, and PR. Three flip-flops provide the
control variables for the system: S is a flip-flop which is set by an external start signal
to start the system operation; F and R are two flip-flops used for sequencing the
microoperations when the system is in operation. A fourth flip-flop D is set by the
system when the operation is completed. The operation of the digital system is de¬
scribed by the following register transfer statements:
(a) Show that the digital system multiplies the contents of registers AR and BR and
places the product in register PR.
(b) Draw a block diagram of the hardware implementation. Include a start input signal
to set flip-flop S and a done output signal from flip-flop D.
7-8 Assume that registers Rl and R2 in Figure 7-4 hold two w-bit unsigned numbers. When
the select input X is equal to 1, the adder-subtractor circuit performs the arithmetic
operation Rl + 2’s complement of R2. This sum and the output carry Cn are transferred
into Rl and C when Tx = 1 and the clock goes through a positive transition.
(a) Show that if C = 1, then the value transferred to Rl is equal to Rl - R2. But
if C = 0, the value transferred to Rl is the 2’s complement of (R2 - Rl). (See
Section 1-4 and example 1-9 for the procedure of subtracting unsigned numbers
with 2’s complement.)
(b) Indicate how the value in the C bit can be used to detect a borrow after the
subtraction of two unsigned numbers.
7-9 Convert the following decimal numbers to signed binary with eight bits each (including
the sign). Perform the operation with the signed binary numbers and check the last
*
254 Chapter 7 Register Transfer and Computer Operations
two carries. State whether the carries indicate an overflow. Remember that 8-bit
numbers have a capacity range from +127 to —128.
(a) ( + 65) + ( + 36) (c) (-36) + (-90)
(b) ( + 65) - (-90) (d) (-65) - ( + 90)
7-10 Perform the logic AND, OR, and XOR with the two 8-bit numbers 10011100 and
10101010.
7-11 Given the 16-bit value 01011010 11000011. What operation must be performed
(a) to clear to 0 the last eight bits?
(b) to set to 1 the first eight bits?
(c) to complement the middle eight bits?
7-12 The following logic microoperation is performed with registers AR and BR.
R1 <-Rl + R1
s Cin = 0 _cin = 1_
0 F = A + B (add) F = A + 1 (increment)
1 F = A - 1 (decrement) F = A + B + 1 (subtract)
7-23 Show the logic diagram of a 4-bit arithmetic circuit that performs the operations
specified in Table 7-5. Use four multiplexers and four full adders.
7-24 Design a four bit arithmetic circuit with two selection variables 5, and 50 that generates
the following arithmetic operations. Draw the logic diagram of one typical stage.
Si S0
0 0 F = A + B (add) F = A + B + 1
0 1 F = A (transfer) F = A + 1 (increment)
1 0 F - B (complement) F = B + 1 (negate)
1 1 F = A + B F = A + B + 1 (subtract)
7-25 Design an arithmetic circuit with one selection variable S and two data inputs A and
B. When 5 = 0, the circuit performs the addition operation F = A + B. When
5=1, the circuit performs the increment operation F = A + 1.
7-26 Input X, and Y, of each full-adder circuit in an arithmetic circuit has the digital logic
specified by the following Boolean functions
A = A Yt = B'S + B~Cin
where 5 is a selection variable, Cin is the input carry, and A, and B, are the input data
in stage i.
(a) Draw the logic diagram of the 4-bit arithmetic circuit.
(b) Determine the four arithmetic operations performed when 5 and Cin are equal to
00, 01, 10, and 11.
7-27 Design a digital circuit that performs the four logic operations of exclusive-OR, ex-
clusive-NOR, NOR and NAND. Use two selection variables. Show the logic diagram
of one typical stage.
7-28 Add another multiplexer to the shifter of Figure 7-18 with two separate selection lines
G1 and G0. This multiplexer is used to specify the serial input IR during the shift right
operation in the following manner:
Gt G0 Operation
7-32 Specify the control word that must be applied to the processor of Figure 7-20 to
implement the following microoperations:
(a) R2 R\ + 1 (e) R1 shl R1
(b) R3 +-R4 + R5 (f) R2 <- ror R2
(c) R6 <- /?6 (g) R5 +-R3 + Rl
(d) /?7 <— jR7 — 1 (h) /?6 <- /?7
7-33 Given the following 16-bit control word for the processor unit of Figure 7-20, determine
the microoperation that is executed for each control word.
(a) 001 010 011 0101 000 (d) 000 001 000 1000 000
(b) 110 000 001 0000 001 (e) 111 000 011 0000 110
(c) 010 010 010 1100 000
CONTROL LOGIC
DESIGN
8-1 INTRODUCTION
The binary information stored in a digital computer can be classified as either data
or control information. Data are discrete elements of information that are manip¬
ulated to perform arithmetic, logic, shift, and other data processing tasks. These
operations are implemented with digital components such as adders, decoders,
multiplexers, counters, and shift registers. Control information provides command
signals that supervise the various operations in the data section to accomplish the
desired data processing tasks. The logic design of a digital system can be divided
into two distinct parts. One part is concerned with the design of the digital circuits
that perform the data processing operations. The other part is concerned with the
design of the control circuit that supervises the operations and determines the
sequence in which they are executed.
The timing for all registers in a synchronous digital system is controlled by a
master clock generator. The clock pulses are applied to all flip-flops and registers
in the system, including the flip-flops and registers in the control unit. The con¬
tinuous clock pulses do not change the state of a register unless the register is
enabled by a control signal. The binary variables that control the selection inputs
of multiplexers and the load inputs of registers are generated in the control sub¬
system.
The relationship between the control logic and the data processor subsystems
in a digital system is shown in Figure 8-1. The data processor part may be a general
purpose processor unit with many registers and a common ALU, or it may consist
of individual registers and associated digital circuits that perform various micro-
257
258 Chapter 8 Control Logic Design
External
input
Output
data
FIGURE 8-1
Control and Data Processor Interaction
operations. The control logic initiates properly sequenced command signals to the
data processor. The control logic uses status conditions from the data processor to
serve as decision variables for determining the sequence of the controlled operations.
The control logic that generates the signals for sequencing the operations in the
data processor is essentially a sequential circuit with internal states that dictate the
control commands for the system. At any given time, the state of the sequential
control initiates a prescribed set of commands. Depending on status conditions and
other external inputs, the sequential control goes to the next state to initiate other
operations. The digital circuits that act as the control logic provide a time sequence
of signals for initiating the microoperations in the data processor subsystem, and
they also determine the next state of the control subsystem itself.
There are two major types of control organization: hardwired control and mi¬
croprogrammed control. In the hardwired organization, the control logic is imple¬
mented with gates and flip-flops similar to a sequential circuit. It has the advantage
that it can be optimized to produce a fast mode of operation. In the micropro¬
grammed organization, the control information such as control functions or control
words are stored as l’s and 0’s in a special memory. A hardwired control, as the
name implies, requires changes in the wiring among the various components if the
design has to be modified or corrected. In the microprogrammed control, any
required changes or modifications can be done merely by changing the contents
of the memory.
In addition to providing the basic principles of both types of control organiza¬
tions, this chapter presents specific examples that illustrate both methods. The
microprogrammed organization is illustrated with an example that controls the
operations of a general purpose processor unit. The various ways available for the
design of a hardwired control are illustrated with an example of a binary multiplier.
The last two sections in the chapter present the organization of a very simple
computer and show how the computer can be designed by the hardwired method.
The design of a computer central processing unit with a microprogrammed control
organization is presented in Chapter 10.
The purpose of the control unit in a digital system is to initiate a series of sequential
steps of microoperations. During any given time, certain microoperations are to
be initiated while others remain idle. The control variables at any given time can
be represented by a string of l’s and 0’s called a control word. As such, control
Section 8-2 Microprogrammed Control 259
words can be programmed to initiate the various components in the data processor
subsystem in an organized manner. A control unit whose binary control variables
are stored in a memory is called a microprogrammed control unit. Each word in
control memory contains within it a microinstruction. The microinstruction specifies
one or more microoperations for the system. A sequence of microinstructions
constitutes the microprogram. Since alterations of the microprogram are not needed
once the control unit is in operation, the control memory can be a read only memory
(ROM). The use of a microprogram involves placing all control variables in words
of ROM for use by the control unit through successive read operations. The content
of the word in ROM at a given address specifies the microoperations for the data
processor subsystem.
A more advanced development known as dynamic microprogramming permits
a microprogram to be loaded initially from the computer console or from an aux¬
iliary memory such as magnetic disk. Control units that use dynamic micropro¬
gramming employ a writable control memory. This type of memory can be used
for writing,(to change the microprogram) but is used mostly for reading. A memory
which is part of a control unit, is referred to as a control memory.
The general configuration of a microprogrammed control unit is demonstrated
in the block diagram of Figure 8-2. The control memory is assumed to be ROM,
within which all control information is permanently stored. The control memory
address register specifies the address of the microinstruction and the control data
register holds the microinstruction read from memory. The microinstruction con¬
tains a control word that specifies one or more microoperations for the data pro¬
cessor. Once these operations are executed, the control must determine its next
address. The location of the next microinstruction may be the next one in sequence,
or it may be located somewhere else in the control memory. For this reason, it is
necessary to use some bits of the present microinstruction to control the generation
of the address of the next microinstruction. The next address may also be a function
of external input conditions. While the microoperations are being executed, the
next address is computed in the next address generator circuit and then transferred
into the control address register to read the next microinstruction. Thus, a mi¬
croinstruction contains bits for initiating microoperations in the data processor part
and bits that determine the address sequence for the control memory itself.
The next address generator is sometimes called a microprogram sequencer, as
it determines the address sequence that is read from control memory. The address
of the next microinstruction can be specified in several ways depending on the
sequencer inputs. Typical functions of a microprogram sequencer are incrementing
the control address register by one, loading into the control address register an
External Control
input word
FIGURE 8-2
Microprogrammed Control Organization
260 Chapter 8 Control Logic Design
Output data
FIGURE 8-3
Microprogrammed Control for Processor Unit
memory contains the 16 bits of a control word for the processor and 10 bits for
selecting the next address in the control address register, CAR.
The status bits from the processor unit are applied to the inputs of MUX2. If
the selected input is equal to 1, then the load input of CAR is enabled, and the 6-
bit address from MUX1 is loaded into CAR. If the selected input is equal to 0,
CAR is incremented by one. Thus, bits 18,19, and 20 of the present microinstruction
select one of the inputs from MUX2 and the binary value of this input determines
the operation performed on CAR.
Input 0 of MUX2 is connected to a binary constant which is always equal to 0.
This input, when selected, generates a 0 output in MUX2 which enables the in-
262 Chapter 8 Control Logic Design
crement operation in CAR. Thus, when MUX2 select bits are equal to 000, CAR
is incremented by one. Similarly, input 1 of MUX2 is always equal to 1; so when
MUX2 select bits are equal to 001, the load input to CAR is enabled and a new
address is loaded into the register. This causes an unconditional branch to the
address given by bits 21 through 26 of the present microinstruction (provided bit
17 is equal to 0). Both the true and complement inputs of C and Z status bits are
applied to MUX2 inputs. In this way, it is possible to specify a branch to a new
address depending on whether C = 1 or C = 0. The other two status bits, S and
V, have only the true value.
The input into CAR is a function of bit 17 of the microinstruction. If bit 17 is
equal to 0, the address field of the microinstruction is loaded into CAR. If bit 17
is equal to 1, an external address is loaded into CAR. The external address is for
the purpose of initiating a new sequence of microinstructions which can be specified
by the external environment.
The operation of the control unit is as follows. At any given clock pulse transition,
the control address register CAR receives a new address. The 26-bit microinstruc¬
tion at this address is read from control memory. The control word of the mi¬
croinstruction specifies a microoperation in the processor and MUX1 and MUX2
determine the next operation for CAR. The signals propagate through the com¬
binational circuits such as ROM, ALU, shifter, and multiplexers but the actual
microinstruction is not terminated until a clock pulse transition occurs. The next
transition of the clock transfers the result of the microoperation into the destination
register in the processor, updates the required status bits, and puts a new address
into CAR. The new address in CAR specifies a microinstruction that is read from
control memory and is executed with the next transition of the clock. This process
repeats for each clock transition. Note that the same clock pulse transition that
executes the microoperation in the processor unit also transfers the next address
to CAR.
Encoding of Microinstructions
The 26 bits of the microinstruction are divided into eight fields. The number of
bits in each field and the symbolic name assigned to each is shown in Table 8-1.
In order to facilitate writing microprograms we will assign a symbolic name to each
binary combination of each field. Fields A, B, and D specify registers Rl through
R1 in the processor unit. Bit combination 000 in fields A and B specifies an input
data symbolized by INP. The destination field D does not select a register when
its binary code is 000 and we will symbolize that with NONE. The encoding of bits
and the corresponding symbols for fields F, H, and MUX2 are specified in the next
three tables. MUX1 select can be either 0 or 1. We designate 0 by the symbol INT
(for internal address) and 1 by EXT (for external address). The 6-bit address field
is designated by the decimal equivalent of the binary address.
The ALU operations are listed in Table 8-2. Each operation is recognized by
the 4-bit binary code assigned to it and its corresponding three letter symbol. The
table also specifies how the status bits are affected by each operation. When the
bit is not affected by the operation we mark it with an N in the table. A Y indicates
that the operation updates the corresponding bit according to the result of the
Section 8-3 Control of Processor Unit 263
TABLE 8-1
Microinstruction Format
INP: input data to processor; NONE: none of the registers are selected; INT: internal
address field of microinstruction; EXT: external address.
operation. The Z (zero) and S (sign) bits are affected by all the operations except
TSF. The S bit after a logic operation is considered as the leftmost bit of the result.
The add and subtract operations also update the C (carry) and V (overflow) bits.
There are two transfer operations in the ALU. The one symbolized by TSF (code
0000) does not change the status bits. The other symbolized by TRC (code 0111)
resets the C bit to 0 and updates the Z and S bits.
The shifter operations are listed in Table 8-3. The no shift operation is symbolized
by NSH and the all zeros output is recognized by the symbol ZERO. The other
six operations specify shifts and rotates either to the left or right. SHL and SHR
receive 0 in their corresponding serial inputs. ROL and ROR rotate the bit from
the serial output into the corresponding serial input. RLC and RRC insert the
value of the status bit C into the serial input and transfer the serial output bit into
the C flip-flop. Note that the rotate with carry operations affect the carry status
bit.
The binary select input to MUX2 and a symbolic name for each combination
are listed in Table 8-4. The binary code 000 chooses a 0 input for the multiplexer
which causes CAR to be incremented. We designate this condition by NEXT,
TABLE 8-2
ALU Operations (F Field)
Status bits’1
code Symbol Z S C V Function
*N = status bit not affected; Y = status bit affected by the operation; 0 = reset to 0.
264 Chapter 8 Control Logic Design
TABLE 8-3
Shifter Operations (H field)
Binary
code Symbol Function
TABLE 8-4
Select Input to MUX2
Binary
code Symbol Function
meaning that the next microinstruction in sequence will be chosen. The binary
code 001 chooses a 1 input for the multiplexer which causes the loading of the
input address into CAR. This is designated by the symbol LAD and is essentially
an unconditional branch operation. The other six inputs to MUX2 cause a branching
to the specified address depending on a given status bit condition or its complement.
Examples of Microinstructions
Before going through an actual microprogram for the control unit it will be in¬
structive to show examples of a few typical microinstructions. Table 8-5 lists six
examples of microinstructions in symbolic form and also gives the corresponding
26-bit binary equivalent. The CAR address is the address where the microinstruction
is assumed to be stored in control memory. The symbols on top of the table are
the eight fields of the microinstruction format.
The first example is for a microinstruction stored in address 36. The ALU
operation in the F field specifies a logical AND which is performed with the contents
of register Rl (field A) and register R2 (field B). The result of the operation is
transferred into register Rl (field D). MUX2 select has the symbol NEXT meaning
that CAR will be incremented by one. The address field and the MUX1 select do
not contribute to the selection of the next address and therefore, these two fields
Section 8-3 Control of Processor Unit 265
TABLE 8-5
Examples of Microinstructions (Not a Microprogram)
36 R1 R2 R\ AND NSH —
NEXT —
are marked with a dash. The microinstruction can be specified with the following
register transfer statement:
R1 <— R\ A R2, CAR «- CAR + 1
The binary values for the microinstruction are listed under the symbols in each
field. These values are obtained from Tables 8-1 through 8-4. The fields marked
with a dash are not used, and therefore, any binary number can be substituted for
the dash. For convenience and consistency we will mark these places with 0’s. The
26-bit word that must be stored in control memory at address 36 is 001 010 001
1000 000 0 000 000000.
The second microinstruction in Table 8-5 resides in address 40. The equivalent
register transfer statement for this microinstruction is
R3 +-R3 - 1, CAR 43
It decrements R3 and branches to the microinstruction at address 43. The branching
to address 43 is specified by the LAD and INT symbols in MUX2 and MUX1
fields.
The microinstruction at address 45 is an example where the control word specifies
no operation for the processor. The TSF in the ALU field does not change the
status bits. The NONE in the D field results in no change in the processor registers.
The NSH in the H field does no shifting in the shifter. If we choose 0’s for the
unused fields, then the control word will consist of 16 0’s. This will not produce
any operation in the processor but the input data will be applied to the output
data. A binary microinstruction with 26 0’s produces no operation in the processor
and increments CAR by one. This is equivalent to a no operation microinstruction.
The microinstruction at address 52 performs the following operations:
R4 <- 0, if (S = 1) then (CAR <- 37) else (CAR <- CAR + 1)
The ZERO in the H field produces an all 0’s in the shifter and this output is
266 Chapter 8 Control Logic Design
transferred into R4. The TSF operation is required to make sure that none of the
status bits are affected. The symbol LS in MUX2 selects the S (sign) status bit
from the processor. If S = 1, then the address field of the microinstruction, being
the binary equivalent of 37 in this case, is loaded into CAR. If S — 0, CAR is
incremented. This is the way that all branch conditions operate on CAR.
The microinstruction at address 56 performs the following operations
The external address is selected by MUX1 through the symbol EXT. The LAD
for MUX2 enables the load input of CAR. The address field of the microinstruction
is not used.
Microprogram Example
The first microprogram example has no specific application but it shows how the
status bits are used for conditional branch microinstructions. In this example we
will write a microprogram starting from address 20 that subtracts the contents of
register R2 from the contents of register Rl and places the difference in register
R3. If Rl < R2 we proceed to add Rl to R4. If Rl > R2 then R2 is added to R4.
If Rl = R2 then R4 is increment by one. The contents of R4 are then applied to
the output terminals of the processor and the microprogram routine terminates by
branching to an external address. It is assumed that all binary numbers are unsigned.
The operations to be performed can be summarized as follows:
The condition for C after a subtraction of two unsigned binary numbers is presented
in Section 1-4 and Example 1-9. The subtraction Rl — R2 is done by adding Rl
Section 8-4 Microprogram Examples 267
TABLE 8-6
Register Transfer Statements for Example
TABLE 8-7
Symbolic Microprogram for Example
20 Rl R2 R3 SUB NSH —
NEXT —
TABLE 8-8
Binary Microprogram for Example
Memory content
ROM
address A B D F H MUX ADRS
processor registers receive this information although we could have transferred the
data back to R4 without loss of information.
The binary microprogram is listed in Table 8-8. The binary values are obtained
from the symbolic microinstructions and the corresponding binary codes given in
Tables 8-1 through 8-4. When a ROM is used for the control memory, the binary
microprogram provides the truth table for the hardware fabrication of the unit.
Start (address 8)
FIGURE 8-4
Flowchart for Counting the
Number of 1 ’s
it indicates that R1 contains all 0’s and the routine is terminated by accepting a
new external address. If Z is not equal to 1, the microprogram continues with the
microinstruction at address 11. The RRC (rotate right with carry) operation places
the least significant bit of R1 into C and shifts R1 to the right. The value of C is
checked in the microinstruction at address 12. If it is 0, control goes back to address
11 to rotate again until C becomes a 1. When C = 1, control goes to address 13
TABLE 8-9
Microprogram for Counting the Number of 1’s
8 — —
R2 TSF ZERO _ NEXT _
Binary Multiplier
The multiplication of two binary numbers is done with paper and pencil by suc¬
cessive additions and shifting. This process is best illustrated with a numerical
example. Let us multiply the two binary numbers 10111 and 10011.
23 10111 Multiplicand
19 10011 Multiplier
10111
10111
00000
00000
10111
437 110110101 Product
Section 8-5 Design Example: Binary Multiplier 271
The process consists of looking at successive bits of the multiplier, least significant
bit first. If the multiplier bit is a 1, the multiplicand is copied down; otherwise, 0’s
are copied down. The numbers copied down in successive lines are shifted one
position to the left from the previous number. Finally, the numbers are added and
their sum forms the product. Note that the product obtained from the multiplication
of two binary numbers of n bits each can have up to 2n bits.
When the above procedure is implemented with digital hardware, it is convenient
to change the process slightly. First, instead of providing digital circuits to store
and add simultaneously as many binary numbers as there are Ts in the multiplier,
it is convenient to provide circuits for the summation of only two binary numbers,
and successively accumulate the partial products in a register. Second, instead of
shifting the multiplicand to the left, the partial product is shifted to the right, which
results in leaving the partial product and the multiplicand in the required relative
positions. Third, when the corresponding bit in the multiplier is 0, there is no need
to add all 0’s to the partial product, since this will not alter its value.
Equipment Configuration
The register configuration for the binary multiplier is shown in Figure 8-5. The
multiplicand is stored in register B, the multiplier is stored in register Q, and the
partial product is formed in register A. A binary adder is employed for adding the
content of register B to the content of register A. The C flip-flop stores the carry
after the addition. The P counter is initially set to hold a binary number equal to
the number of bits in the multiplier. The counter is decremented after the formation
of each partial product. When the content of the counter reaches zero, the product
is formed in the double register A and Q and the process stops.
The control logic stays in an initial state until the start signal S becomes a 1.
The system then performs the multiplication. The sum of A and B forms the partial
product which is transferred to A. The output carry from the addition, whether 0
or 1, is transferred to C. Both the partial product in A and the multiplier in Q are
Z = 1 if P = 0
Product
FIGURE 8-5
Block Diagram of a Binary Multiplier
272 Chapter 8 Control Logic Design
shifted to the right. The least significant bit of A is shifted into the most significant
position of Q; the carry from C is shifted into the most significant position of A ;
and 0 is shifted into C. After the shift right operation, one bit of the partial product
is transferred into Q while the multiplier bits in Q are shifted one position to the
right. In this manner, the least significant bit of register <2, designated by Q0,
always holds the bit of the multiplier that must be inspected next. The control logic
receives this bit and also output Z from a circuit that checks P for zero. These two
inputs are the status conditions from the data processor. The start input S is an
external input. The outputs of the control logic initiate the required microoperations
in the register.
Flowchart
A flowchart showing the sequence of operations in the binary multiplier is shown
in Figure 8-6. Initially, the multiplicand is in B and the multiplier in Q. The
multiplication process starts when S becomes 1. Register A and flip-flop C are reset
to 0 and the sequence counter P is loaded with a binary number n, which is equal
to the number of bits in the multiplier.
Next we enter a loop that keeps forming the partial products. The multiplier bit
in Q0 is checked, and if it is equal to 1, the multiplicand in B is added to the partial
product in A. The carry from the addition is transferred to C. The partial product
in A is left unchanged if Q0 = 0. The P counter is decremented by one regardless
of the value in Q0. Registers A and Q are then shifted once to the right to obtain
a new partial product. This shift operation is symbolized in the flowchart in compact
form with the statement
TABLE 8-10
Numerical Example for Binary Multiplier
Multiplicand B = 10111
c A Q p
Multiplier in Q 0 00000 10011 101
Qo = 1; add B 10111
First partial product 0 10111 100
Shift right CAQ 0 01011 11001
Qo = 1; add B 10111
Second partial product 1 00010 Oil
Shift right CAQ 0 10001 01100
Q0 = 0; shift right CAQ 0 01000 10110 010
Qo = 0; shift right CAQ 0 00100 01011 001
Q0 = 1; add B 10111
Fifth partial product 0 11011 000
Shift right CAQ 0 01101 10101
Final product in AQ = 0110110101
274 Chapter 8 Control Logic Design
The type of registers needed for the data processor subsystem can be derived
from the microoperations listed in the flowchart. Register .4 must be a shift register
with parallel load to accept the sum from the adder and must have a synchronous
clear capability to reset the register to 0. Register Q is a shift register. The counter
P is a binary down counter with a facility to parallel load a binary constant. The
C flip-flop must be designed to accept the input carry and have a synchronous reset
capability. Registers B and Q will need a parallel load capability in order to receive
the multiplicand and multiplier prior to starting the multiplication process.
T2 \ P 4- P - 1
T2: P4-P - 1
FIGURE 8-7
Control State Diagram and List of Microoperations
FIGURE 8-8
Control Block Diagram
275
276 Chapter 8 Control Logic Design
Once the control sequence has been established, the sequential system that
implements the control must be designed. Since the control is a sequential circuit,
it can be designed by the sequential logic procedure as outlined in Chapter 4.
However, in most cases this method is difficult to carry out because of the large
number of states and inputs that a typical control circuit may have. As a conse¬
quence, it is necessary to use specialized methods for control logic design which
may be considered as variations of the classical sequential logic method. We will
now present two such design procedures.
TABLE 8-11
State Table for Control Circuit
Present Next
state Inputs state Outputs
Gi Go S z G, G0 To T T2 T3
0 0 0 X 0 0 1 0 0 0
0 0 1 X 0 1 1 0 0 0
0 1 X X 1 0 0 1 0 0
1 0 X X 1 1 0 0 1 0
1 1 X 0 1 0 0 0 0 1
1 1 X 1 0 0 0 0 0 1
Clock
FIGURE 8-9
Logic Diagram of Control for Binary Multiplier Using a Sequence Register and Decoder
obtain the simplified input equations for the flip-flops. The design can be simplified
if we take into consideration the fact that the decoder outputs are available for use
in the design. Instead of using the flip-flop outputs as the present state conditions,
we might as well use the outputs of the decoder to obtain this information. The
outputs of the decoder are T0 through T3. These variables can be used to supply
the present state conditions for the sequential circuit. Moreover, instead of using
maps to simplify the flip-flop input equations, we can obtain them directly from
the state table by inspection. Although this may not result in a minimal circuit,
the possible waste of a few gates may be worth the time saved from the simplicity
of the procedure. For example, from the next state conditions in the state table
we find that the next state of Gx is equal to 1 when the present state is 7\, or when
the present state is T2, or when the present state is T3 provided that Z = 0. These
conditions give the input equation for G1.
DG\ — Tx + T2 + T3Z
Where DGl is the D input of flip-flop Gx. Similarly, the input equation for flip-
flop G0 is
D go = T0S + T2
When deriving input equations by inspection from the state table, we cannot be
sure that the Boolean functions have been simplified in the best possible way. For
this reason, it is advisable to analyze the circuit to ensure that the derived equations
do indeed produce the required state transitions as specified by the original state
diagram.
The logic diagram of the control circuit is drawn in Figure 8-9. It consists of a
register with two flip-flops Gx and G0 and a 2 x 4 decoder. The outputs of the
277
278 Chapter 8 Control Logic Design
decoder are used to obtain the next state of the circuit according to the Boolean
input equations listed above. The outputs of the controller should be connected
to the data processor part of the system to initiate the required microoperations.
D t2 ~ T1 + T3Z
Dt3 ~ T2
The logic diagram of the controller is shown in Figure 8-10. It consists of four D
flip-flops T() through T3 and the associated gates specified by the input equations
Section 8-6 Hardwired Control for Multiplier 279
T2
t3
FIGURE 8-10
One Flip-Flop Per State Controller
listed above. The outputs of the flip-flops must be connected to the corresponding
inputs in the registers of the data processor subsystem.
Initially flip-flop T0 must be set to 1 and all other flip-flops must be reset to 0
so that the flip-flop representing the initial state is enabled. Once started, the one
flip-flop per state controller will propagate from one state to the other in the proper
manner. Only one flip-flop will be set to 1 with each clock pulse transition; all
others are reset to 0 because their D inputs are maintained at 0.
Sometimes, the one flip-flop per state controller is implemented with a register
that has a common asynchronous input for resetting all flip-flops initially to 0. In
that case, it is possible to transfer the circuit into its initial state by modifying the
input equation for T0 as follows:
D / () — T0S + 73Z + To Tx T2 T3
The third term in the equation sets flip-flop T0 to 1 with the first clock pulse, just
after all the flip-flops are reset to 0 asynchronously.
280 Chapter 8 Control Logic Design
In this and the next section we will introduce a simple digital computer and show
how its operation can be defined by means of register transfer statements. We will
then implement the computer by specifying the registers that are needed in the
data processor subsystem and design the control subsystem by the hardwired method.
The purpose here is to introduce the basic components of the digital computer and
show another example of hardwired control. A more extensive study of the various
concepts associated with digital computers will be covered in detail in the next
chapter. The design of a more extensive digital computer is undertaken in
Chapter 10.
Instruction Codes
A digital computer is a general purpose device capable of executing various op¬
erations and, in addition, can be instructed as to what specific operations it must
perform. The user of a computer can control the process by means of a program.
A program is a set of instructions that specifies the operations, operands, and the
sequence in which processing is to occur. The data processing task may be altered
by specifying a new program with different instructions or by specifying the same
instructions with different data. Instruction codes, together with data, are stored
in memory. The control reads each instruction from memory and places it in a
control register. The control then interprets the instruction and proceeds to execute
it by issuing a sequence of microoperations. Every computer has its own unique
instruction set. The ability to store and execute instructions is the most important
property of the general purpose computer.
An instruction code is a group of bits that instructs the computer to perform a
specific operation. It is usually divided into parts, each having its own particular
interpretation. The most basic part of an instruction code is its operation part. The
operation code of an instruction is a group of bits that defines an operation, such
as add, subtract, shift, or complement. The set of machine operations formulated
for a computer depends on the processing it is intended to perform. The total
number of operations obtained determines the set of machine operations.
The number of bits required for the operation code of an instruction is a function
of the total number of operations used. It must consist of at least n bits for up to
2n distinct operations. The designer assigns a bit combination (a code) to each
operation. The control unit of the computer is designed to accept this bit config¬
uration at the proper time in a sequence and to supply the proper commands to
the data processor in order to execute the specified operation. As a specific ex¬
ample, consider a computer using 64 distinct operations, one of them an ADD
operation. The operation code may consist of six bits, with a bit configuration
100110 assigned to the ADD operation. When the operation code 100110 is detected
by the control unit, a command signal is applied to an adder circuit to add two
binary numbers.
The operation part of an instruction code specifies the operation to be performed.
The operation must be performed using data stored in computer registers or in
memory. An instruction code, therefore, must specify not only the operation but
Section 8-7 Example of a Simple Computer 281
also the registers or memory words where the operands are to be found. The
operands may be specified in an instruction code in two ways. An operand is said
to be specified explicitly if the instruction code contains special bits for its iden¬
tification. For example, an instruction code may contain an operation part and a
memory address specifying the location of the operand in memory. An operand is
said to be specified explicitly if it is included as part of the definition of the
operation. For example, an operation that complements a register implies the
register in the operation part of the code.
FIGURE 8-11
Three Possible Instruction Formats
282 Chapter 8 Control Logic Design
Numerical Example
Assume that we have a memory unit with 8 bits per word and that an operation
code contains 8 bits. The placement of the three instruction codes in memory in
binary is shown in Figure 8-12. At address 25 we have an implied instruction that
specifies an operation to increment register R. This operation can be symbolized
by the statement
R <T- R + 1
In memory address 35 and 36 we have an immediate operand instruction that
occupies two 8-bit words. The first word at address 35 is the operation code for
the instruction to transfer the operand to register R, symbolized by the statement
R <— Operand
The operand itself is stored immediately after the operation code at address 36.
In memory address 45 there is a direct address instruction that specifies the
operation
R <— Mfaddress]
The second word of the instruction at address 46 contains the address. Therefore,
the operand to be transferred to register R is the one stored at this address. For
the numerical example shown in the figure, we have the instruction symbolized by
R <— M[70]. The symbol M[70] signifies the contents of the memory word at address
70. Since this word contains the binary equivalent of 28, the result of the operation
is the transfer of the 8-bit word 00011100 into register R.
Operation
Operand = 44
Address = 70
Operand = 28
FIGURE 8-12
Memory Representation of Instructions
Section 8-7 Example of a Simple Computer 283
PC Memory
256 x 8
AR
DR
IR
I
Operation
AC
decoder
Di — Dq
Control
Tn — Tj outputs
TC
FIGURE 8-13
Block Diagram of a Simple Computer
284 Chapter 8 Control Logic Design
TABLE 8-12
List of Registers for the Simple Computer
Register Number
symbol of bits Register name Function
Computer Instructions
Six instructions for the simple computer are listed in Table 8-13. We assume that
there are eight bits in the operation code so it can be stored in one memory word.
With eight bits it is possible to specify up to 256 operations. To simplify the
presentation, we consider here only six operations. The symbolic names associated
with the instructions are useful for listing programs in symbolic form instead of
TABLE 8-13
Six Instructions for the Simple Computer
Operation Symbolic
code name Description Function
using binary codes. The first two instructions are implied instructions that increment
and complement the accumulator register. The next two instructions are immediate
type instructions. These instructions have two words, one for the operation code
and the other for the immediate operand symbolized by OPRD. The OPRD fol¬
lowing the symbol LDI stands for an actual operand that the programmer must
specify. The instruction ADI OPRD adds the specified operand to the content of
the accumulator.
The last two instructions in the table are direct address instructions. LDA is a
symbol for the operation code and the ADRS following it stands for an address
that the programmer must specify with this instruction. The load instruction trans¬
fers a memory operand into the accumulator register. The store instruction transfers
the content of the accumulator into a memory word whose address is given by the
instruction. The actual OPRD and ADRS values, together with their corresponding
operation codes are stored in memory as shown in Figure 8-12.
To demonstrate how the instructions can be used to write a simple program,
consider the arithmetic expression 83 — (52 + 25). The following program performs
the computation and stores the result in memory at address 250. The subtraction
is done by taking the 2’s complement of (52 + 25) and adding it to 83.
from memory into DR. The operation code is then transferred from DR to IR and
PC is incremented by one to prepare it for the address of the next word in memory.
This sequence is called the instruction fetch phase, since it fetches the operation
code from memory and places it in a control register. The timing variables T0 and
7\ of the timing decoder are used as control functions for the fetch phase. This
can be expressed with two register transfer statements as follows
T{. IR DR, PC PC + 1
With timing variable T0, the memory word specified by the address in PC is trans¬
ferred into DR. This word is the operation code of an instruction. Timing variable
Tl transfers the operation code from DR into the instruction register IR and also
increments PC by one. This prepares PC for the next read operation since it now
contains the address of the next instruction word in memory. It is very important
to realize that all the operations are synchronized with a common clock source.
The same clock pulse transition that transfers the content of memory into DR when
T0 = 1, also triggers the timing counter TC and changes its contents from 000 to
001, which causes the timing decoder to go from T0 to T1.
The instruction fetch phase is common to all instructions. The microoperations
and control functions that follow the instruction fetch are determined in the control
section from the present operation code in IR. The output of IR is decoded by the
operation decoder. This decoder has outputs Dx through D6, corresponding to the
binary operation codes 00000001 through 00000110, assigned to the six instructions.
Execution of Instructions
During timing variable T2, the operation code is in IR and only one output of the
operation decoder is equal to 1. The control uses this output to determine the next
microoperation in sequence. The IN A (increment AC) instruction has an operation
code 00000001 which makes decoder output Dl = 1. The execution of this instruc¬
tion can be specified by the following register transfer statement:
D3T2: DR *- M[PC\
the operand symbolized by OPRD is read from memory and placed in DR. Since
the operand is in memory following the operation code, it is read from memory
using the address in PC. The operand read into DR is then transferred to the AC.
PC is incremented once again to prepare it for the address of the next instruction.
In fact, PC is incremented every time a word that belongs to the program is read
from memory. This prepares PC for reading the next word in sequence. Moreover,
at the completion of an instruction execution, the control always resets TC to 0 in
order to return to the fetch phase.
The LDA ADRS instruction has an operation code that makes D5 = 1. The
microoperations needed to execute this instruction are
Start
FIGURE 8-14
Microoperation Sequence for the Simple Computer
Section 8-8 Design of a Simple Computer 289
onstrated. The extension of this principle to a computer with more instructions and
more processor registers should be apparent from this example.
Control Logic
It was shown that the register transfer notation is suitable for defining the operations
specified by computer instructions and is a convenient method for specifying the
sequence of internal operations in a digital computer. We will now show that the
list of control functions and microoperations for a digital system is a convenient
starting point for the design of the system. The list of microoperations specifies
the type of registers and associated digital functions that must be incorporated into
the data processing part of the system. The list of control functions specifies the
logic gates required for the control unit. To demonstrate this procedure, we will
go through the design of the simple computer based on the list of register transfer
statements given in Figure 8-14.
The first step in the design is to scan the register transfer statements and retrieve
all those statements that perform the same microoperation. For example, the micro¬
operation PC <— PC + 1 is listed with timing variable T{ and again with timing
variable T3 for the decoded instructions D3, D4, D5l and Db. The five conditions
can be combined into one statement:
Clock
FIGURE 8-15
Implementation of T1 + (D3 + D4 + D5 + D6)T3\ PC <- PC + 1
290 Chapter 8 Control Logic Design
TABLE 8-14
Hardware Specification of Simple Computer
Design of Computer
The design of the simple computer can be obtained from the information available
in Table 8-14. The block diagram design is shown in Figure 8-16. It consists of the
memory unit, six registers, two decoders, three multiplexers, an 8-bit adder, and
control logic gates. The six registers are the ones listed in Table 8-12. The control
logic gates receive their inputs from the two decoders and generate the 12 control
functions Cx through C12 according to the Boolean functions listed in Table 8-14.
Any register that receives data from two sources needs a multiplexer to select
between the two.
The control functions operate on the registers and memory to produce the re¬
quired microoperations. For example, Table 8-14 shows that the control function
C1 must perform the microoperation DR <— M[PC]. This is a memory read operation
with PC supplying the address and DR receiving the memory word. Therefore, C]
selects the 8 bits from PC through MUX1, enables the read input of the memory,
enables the load input of DR while MUX2 selects its inputs from the memory
output data (because C9 = 0).
The microoperations for the AC are determined from the following statements
in Table 8-14.
The AC can be implemented with a counter that has the capability of comple¬
menting its contents and loading external data. The counter produces the increment
microoperation and the load control enables the input data. When C6 = 1, C7
must be equal to 0, and MUX3 selects the outputs of DR to be loaded into the
AC. When C7 = 1, the outputs of the 8-bit adder are loaded into the AC. The
Section 8-8 Design of a Simple Computer 291
FIGURE 8-16
Hardware Design of the Simple Computer
timing counter TC is incremented with every clock pulse except when C12 = 1,
which resets the counter to 0.
The other control functions enable the appropriate registers and select the proper
paths through the multiplexers. Note that all six registers must be connected to a
common clock pulse generator for a synchronous operation. The clock inputs have
been omitted from the block diagram in order to simplify the drawing.
The registers and other digital functions specified in Figure 8-16 can be designed
292 Chapter 8 Control Logic Design
with integrated circuits. One can readily find commercial MSI circuits for all the
registers, multiplexers, and decoders. The combinational circuit for the control
logic gates can be constructed with individual gates. This part of the computer
would be more efficiently implemented with a programmable logic device as ex¬
plained in Chapter 6.
REFERENCES
1. Mano, M. M. Computer System Architecture. 2nd ed. Englewood Cliffs: Prentice-Hall,
1982.
2. Ercegovac, M. D., and Lang, T. Digital Systems and Hardware!Firmware Algorithms.
New York: Wiley, 1985.
3. Agrawala, A. K., and Rauscher, T. G. Foundations of Microprogramming. New
York: Academic, 1976.
4. Myers, G. J. Digital System Design with LSI Bit-Slice Logic. New York: Wiley, 1980.
5. Andrews, M. Principles of Firmware Engineering in Microprogram Control. Potomac,
MD: Computer Science Press, 1980.
6. Fletcher, W. I. An Engineering Approach to Digital Design. Englewood Cliffs: Pren¬
tice-Hall, 1980.
7. Rhyne, V. T. Fundementals of Digital Systems Design. Englewood Cliffs: Prentice-
Hall, 1973.
8. Clare, C. R. Designing Logic Systems Using State Machines. New York: McGraw-
Hill, 1973.
9. Hill, F. J., and Peterson, G. R. Digital Logic and Microprocessors. New York:
Wiley, 1984.
PROBLEMS
8-1 Define the following terms in your own words: (a) data processor subsystem; (b) control
subsystem; (c) hardwired control; (d) microprogrammed control; (e) control memory;
(f) control word; (g) microinstruction; (h) microprogram; (i) microoperation.
8-2 A microprogram control unit is similar to the one shown in Figure 8-3 with the following
differences: (a) MUX1 has four inputs for CAR; (b) MUX2 has 15 input status bits;
(c) the control memory has 1024 words. Formulate the microinstruction format and
specify the number of bits in each field. What should be the size of the control memory?
8-3 A microinstruction stored in address 35 in the control memory of Figure 8-3 performs
the operation
Give the microinstruction in symbolic form using the symbol LAD for MUX2.
8-4 Give a symbolic microinstruction that resets register R4 to 0 and updates Z and S
status bits without affecting the other two status bits. (Try an exclusive-OR operation.)
8-5 Give a symbolic microinstruction that resets register R3 to 0 and resets the C status
bit to 0. The other three status bits can be anything.
Problems 293
8-6 List the symbolic and binary microinstructions similar to Table 8-5 for the following
register transfer statements.
(a) R3 <- Rl - Rl, CAR <- 17
(b) R5 shr (/?4 + /?5), CAR CAR + 1
(c) If (Z = 0) then (CAR <- 21) else (CAR <- C/1/? + 1)
(d) /?6 <— /?6, C <— 0, C/1/? <— C/1/? + 1 (update Z and S)
8-7 Given the following binary microprogram starting from address 16 (similar to Table
8-8)
(a) List the corresponding symbolic microprogram as in Table 8-7.
(b) List the corresponding register transfer statements as in Table 8-6.
Redesign the control for the binary multiplier so that Q{) appears as a condition in the
state diagram and as an input in the state table.
8-17 Consider the block diagram of the multiplier shown in Figure 8-5. Assume that the
multiplier and multiplicand consist of 16 bits each.
(a) How many bits can be expected in the product, and where is it placed?
(b) How many bits are in the P counter and what is the binary number that must be
loaded into it initially?
(c) Design the combinational circuit that checks for zero in the P counter.
8-18 Design a digital system that multiplies two unsigned binary numbers by the repeated
addition method. For example, to multiply 5x4, the digital system evaluates the
product by adding the multiplicand four times: 5 + 5 + 5 + 5 = 20. Let the
multiplicand be in register BR, the multiplier in register AR. and the product in register
PR. An adder circuit adds the contents of BR to PR. A zero detect circuit Z checks
when AR becomes zero after each time that it is decremented. Design the control by
the hardwired method.
8-19 Design a digital system with three 16-bit registers AR. BR. and CR to perform the
following operations:
(a) Transfer two 16-bit signed numbers to AR and BR after a start signal S is enabled.
(b) If the number in AR is negative, divide the contents of AR by two and transfer
the result to register CR.
(c) If the number in AR is positive but non-zero, divide the contents of BR by two
and transfer the result to register CR.
(d) If the number in AR is zero, reset register CR to 0.
8-20 The state diagram of a control unit is shown in Figure P8-20. It has four states and
two inputs Y and Z. Design the control by
(a) the sequence register and decoder method and
(b) the one flip-flop per state method.
FIGURE P8-20
Control State Diagram for Problem 8-20
8-21 A digital computer has a memory unit with 24 bits per word. The instruction set
consists of 150 different operations. There is only one type of instruction format with
an operation code part and an address part. Each instruction is stored in one word of
memory.
(a) How many bits are needed for the operation code part?
Section Problems 295
(b) How many bits are left for the address part of the instruction?
(c) How many words are there in memory and what must be the memory size?
(d) What is the largest unsigned binary number that can be accommodated in one
word of memory?
8-22 A signed binary number is stored in address 153 of the simple computer. Write a
program that will multiply this number by — 1.
8-23 Derive the control functions listed in Table 8-14 from the information available in the
flowchart of Figure 8-14.
8-24 Specify an instruction format for the simple computer that performs the following
operation:
AC AC + M[ADRS] Add to AC
List the sequence of microoperations for executing this instruction and include it in
the flowchart of Figure 8-14.
8-25 Repeat Problem 8-24 for the following instruction:
8-26 Assume that the memory of the simple computer in Figure 8-13 has 64K x 8 words.
This will require a 16-bit address to specify an 8-bit word in memory.
(a) What should be the number of bits in each of the six registers of the computer?
(b) How many words of memory are now required to store the instruction LDA ADRS
(see Table 8-13)?
(c) List the sequence of microoperations needed to execute this instruction.
8-27 Show the path that the data takes in the hardware of the simple computer of Figure
8-16 when the control function C7 is enabled. Include the effect of the clock. Assume
that DR = 10101010 and AC = 01011111. What happens to DR and AC after the
clock pulse transition when C7 = 1?
9
COMPUTER
INSTRUCTIONS
AND ADDRESSING
MODES
9-1 INTRODUCTION
Other special fields are sometimes employed under certain circumstances, as for
example a field that gives the number of shifts in a shift type instruction or an
operand field in an immediate type instruction.
296
Section 9-2 Address Field 297
The operation code field of an instruction is a group of bits that define various
processor operations, such as add, subtract, complement, and shift. The most
common operations available in computer instructions are enumerated and dis¬
cussed in Sections 9-5 through 9-8. The bits that define the mode field of an
instruction code specify a variety of alternatives for choosing the operands from
the given address field. The various addressing modes that have been formulated
for computers are presented in Section 9-3. The effect of including multiple address
fields in an instruction is discussed in Section 9-2. Other topics covered in this
chapter include stack organization and interrupt handling.
The various computer concepts introduced in this chapter are sometimes clas¬
sified as being part of a broader field referred to as computer organization or
computer architecture. They provide the necessary understanding of the internal
organization and operation of digital computers. In the next chapter we use these
topics to design a central processing unit (CPU).
ADD X
ADD is the symbol for the operation code of the instruction and X gives the address
of the operand in memory. This instruction results in the operation AC <— AC +
M[A]. AC is the accumulator register and M[X] symbolizes the memory word
located at address X.
An example of a processor unit with multiple registers is presented in Section
7-5. The instruction format in this type of computer needs three registers. Thus,
the instruction for the arithmetic addition may be written in symbolic form as
298 Chapter 9 Computer Instructions and Addressing Modes
to denote the operation R3 <— Rl + R2. However, the number of register address
fields in the instruction can be reduced from three to two if the destination register
is the same as one of the source registers. Thus, the instruction
ADD Rl, R2
will denote the operation R2 <— R2 + Rl. Registers Rl and R2 are the source
registers and R2 is also the destination register.
Computers with multiple processor registers employ the MOVE instruction to
symbolize the transfer of data from one location to another. The instruction
MOVE Rl, R2
denotes the transfer R2 <— Rl. Transfer type instructions need two address fields
to specify the source operand and the destination of transfer.
Multiple register type computers employ two or three address fields in the
instruction format. Each address field may specify a processor register or a memory
address. An instruction symbolized by
ADD X, Rl
will specify the operation Rl Rl + M[X]. It has two address fields, one for
register Rl and the other for the memory address X.
The stack organization will be presented in Section 9-4. Computers with stack
organization have instructions that require one address field for transferring data
to and from the stack. Operation type instructions such as ADD do not need an
address field because the operation is performed directly with the operands in the
stack.
To illustrate the influence of the number of address fields on computer programs,
we will evaluate the arithmetic statement
X = (A + B)(C + D)
It is assumed that the computer has two processor registers, R1 and R2. The symbol
M[A] denotes the operand stored in memory at the address symbolized by A. The
symbol * designates multiplication.
The advantage of the three address format is that it results in short programs
for evaluating arithmetic expressions. The disadvantage is that the binary coded
instruction requires more bits to specify three addresses.
As explained in Section 8-8 there is one register in the computer called the
program counter or PC that keeps track of the instructions in the program stored
in memory. The PC holds the address of the instruction to be executed next and
is incremented by one each time a word is read from the program in memory. The
decoding done in step 2 is to determine the operation to be performed and the
addressing mode of the instruction. The location of the operands in step 3 is
determined from the addressing mode and the address field of the instruction. The
computer then executes the instruction and returns to step 1 to fetch the next
instruction in sequence.
In some computers the addressing mode of the instruction is specified using a
distinct binary code. Other computers use a common binary code that designates
both the operation and the addressing mode of the instruction. Instructions may
be defined with a variety of addressing modes and sometimes, two or more ad¬
dressing modes are combined in one instruction.
Section 9-3 Addressing Modes 301
FIGURE 9-1
Instruction Format with Mode Field
Implied Mode
Although most addressing modes modify the address field of the instruction, there
is one mode that needs no address field at all. This is the implied mode. In this
mode, the operand is specified implicitly in the definition of the operation code.
For example, the instruction “complement accumulator” is an implied mode
instruction because the operand in the accumulator register is implied in the def¬
inition of the instruction. In fact, any instruction that uses an accumulator without
a second operand is an implied mode instruction. Operation type instructions in a
stack-organized computer are implied-mode instructions since the operands are
implied to be on top of the stack.
Immediate Mode
In the immediate mode, the operand is specified in the instruction itself. In other
words, an immediate mode instruction has an operand field rather than an address
field. The operand field contains the actual operand to be used in conjunction with
the operation specified in the instruction. Immediate-mode instructions are useful
for initializing registers to a constant value.
must ensure that the memory address is placed in the processor register with a
previous instruction. A reference to the register is then equivalent to specifying a
memory address. The advantage of a register-indirect mode instruction is that the
address field of the instruction uses fewer bits to select a register than would have
been required to specify a memory address directly.
An autoincrement or autodecrement mode is similar to the register-indirect mode
except that the register is incremented or decremented after (or before) its address
value is used to access memory. When the address stored in the register refers to
an array of data in memory, it is convenient to increment the register after each
access to the array. This can be achieved by using a register-increment instruction.
However, because it is such a common requirement, some computers incorporate
a special mode that automatically increments the content of the register after the
memory data is accessed.
Direct-Addressing Mode
In the direct addressing mode the address field of the instruction gives the address
of the operand in memory in a computational type instruction. It is the branch
address in a branch type instruction.
An example of a computational type instruction is shown in Figure 9-2. The
instruction in memory consists of two words. The first word, at address 250, has
the operation code for “load to AC” and a mode field specifying a direct address.
The second word, at address 251, contains the address field symbolized by ADRS
and is equal to 500. The PC holds the address of the instruction. The instruction
is brought from memory into two control registers and PC is incremented twice.
The execution of the instruction results in the operation
AC <— M[ADRS]
Since ADRS — 500 and M[500] = 800, the AC receives the number 800. After
the instruction is executed, the PC holds the number 252, which is the address of
the next instruction in the program.
Memory
FIGURE 9-2
Example Demonstrating a Computational Type Instruction
Section 9-3 Addressing Modes 303
Program
FIGURE 9-3
Example Demonstrating a Branch Type Instruction
Next consider a branch type instruction as shown in Figure 9-3. If the contents
of AC is equal to 0, control branches to ADRS; otherwise the program continues
with the next instruction in sequence. When AC = 0, the branch to address 500
is accomplished by loading the value of the address field ADRS into the PC. Control
then continues with the instruction at address 500. When AC C 0, no branch
occurs; and the PC, which was incremented twice after reading the instruction,
holds the address 302, the address of the next instruction in sequence.
The address field of an instruction is used by the control unit of the computer
to obtain the operand from memory. Sometimes the value given in the address
field is the address of the operand, but sometimes it is just an address from which
the address of the operand is calculated. To differentiate among the various ad¬
dressing modes it is necessary to distinguish between the address part of the in¬
struction as given in the address field and the address used by the control when
executing the instruction.
The effective address is defined to be the memory address obtained from the
computation dictated by the addressing mode. The effective address is the address
of the operand in a computational type instruction. It is the address where control
branches, in response to a branch type instruction. In the direct-address mode, the
effective address is equal to the address part of the instruction. In the register-
indirect mode the effective address is the address stored in the selected register.
Indirect-Addressing Mode
In the indirect-addressing mode the address field of the instruction gives the address
where the effective address is stored in memory. Control fetches the instruction
from memory and uses the address part to access memory again to read the effective
address.
Consider the instruction “load to AC” given in Figure 9-2. If the mode specifies
an indirect address, the effective address is stored in M[ADRS]. Since ADRS =
500 and M[ADRS] = 800, the effective address is 800. This means that the operand
304 Chapter 9 Computer Instructions and Addressing Modes
that is loaded into the AC is the one found in memory at address 800 (not shown
in the figure).
Relative-Addressing Mode
Some addressing modes require that the address field of the instruction be added
to the content of a specified register in the CPU in order to evaluate the effective
address. In the relative-addressing mode the effective address is calculated as fol¬
lows
Effective address = Address part of the instruction
+ Contents of PC
The address part of the instruction is considered as a signed number which can be
either positive or negative. When this number is added to the contents of PC, the
result produces an effective address whose position in memory is relative to the
address of the next instruction in the program.
To clarify this with an example, let us assume that PC contains the number 250
and the address part of the instruction contains the number 500, as in Figure 9-2,
with the mode field specifying a relative address. The instruction at location 250
is read from memory during the fetch phase and PC is incremented by one to 251.
Since the instruction has a second word, control reads the address field into a
control register and PC is incremented to 252. The effective address computation
for the relative addressing mode is 252 + 500 = 752. The result is that the operand
associated with the instruction is 752 locations relative to the location of the next
instruction.
Relative addressing is often used in branch type instructions when the branch
address is in the area surrounding the instruction word itself. It results in a shorter
address field in the instruction format since the relative address can be specified
with a smaller number of bits than the number of bits required to designate the
entire memory address.
Indexed-Addressing Mode
In the indexed-addressing mode the content of an index register is added to the
address part of the instruction to obtain the effective address. The index register
is a special CPU register that contains an index value. The address field of the
instruction defines the beginning address of a data array in memory. Each operand
in the array is stored in memory relative to the beginning address. The distance
between the beginning address and the address of the operand is the index value
stored in the register. Any operand in the array can be accessed with the same
instruction provided the index register contains the correct index value. The index
register can be incremented to facilitate the access to consecutive operands.
Some computers dedicate one CPU register to function solely as an index reg¬
ister. This register is involved implicitly when an index mode instruction is used.
In computers with many processor registers, any one of the CPU registers can be
used as an index register. In such a case, the index register must be specified
explicitly with a register field within the instruction format.
Section 9-3 Addressing Modes 305
A variation of the index mode is the base-register mode. In this mode the content
of a base register is added to the address part of the instruction to obtain the
effective address. This is similar to indexed addressing except that the register is
called a base register instead of index register. The difference between the two
modes is in the way they are used rather than in the way they are computed. An
index register is assumed to hold an index number which is relative to the address
field of the instruction. A base register is assumed to hold a base address and the
address field of the instruction gives a displacement relative to the base address.
Memory
FIGURE 9-4
Numerical Example for Addressing Modes
306 Chapter 9 Computer Instructions and Addressing Modes
TABLE 9-1
Symbolic Convention for Addressing Modes
252 = 752 and the operand is 600. In the index mode the effective address is 500
+ 400 = 900 assuming that R1 is the index register. In the register mode the
operand is in R1 and 400 is loaded into the AC. In the register indirect mode the
effective address is the contents of Rl and the operand loaded into the AC is 700.
Table 9-1 lists the value of the effective address and the operand loaded into
the AC for seven addressing modes. The table also shows the operation with a
register transfer statement and the symbolic convention for each addressing mode.
LDA is the symbol for the load-to-accumulator operation code. In the direct mode
we use the symbol ADRS for the address part of the instruction. The # symbol
precedes the operand NBR in the immediate mode. The symbol ADRS enclosed
in square brackets symbolizes an indirect address. Some computers use the symbol
@ to designate an indirect address. The symbol $ before the address makes the
effective address relative to PC. An index mode instruction is recognized by the
symbol of a register that is placed in parentheses after the address symbol. The
register mode is indicated by giving the name of the processor register following
LDA. In the register indirect mode the name of the register that holds the effective
address is enclosed in parentheses.
A very useful feature included in many computers is a memory stack, also known
as a last-in first-out (LIFO) list. A stack is a storage device that stores information
in such a manner that the item stored last is the first item retrieved. The operation
of a stack is sometimes compared to a stack of trays. The last tray placed on top
of the stack is the first to be taken off. /
The stack is useful for a variety of applications and its organization possesses
special features that facilitate many data processing tasks. A stack is used in some
electronic calculators and computers to facilitate the evaluation of arithmetic
expressions. Its use in computers is mostly for handling of subroutines and interrupts
as explained in Section 9-8.
A memory stack is essentially a portion of a memory unit accessed by an address
that is always incremented or decremented after the memory access. The register
Section 9-4 Stack Organization 307
that holds the address for the stack is called a stack pointer (SP) because its value
always points at the top item of the stack. The two operations of a stack are insertion
and deletion of items. The operation of insertion is called push and it can be thought
of as the result of pushing a new item onto the top of the stack. The operation of
deletion is called pop and it can be thought of as the result of removing one item
so that the stack pops out. However, nothing is physically pushed or popped in a
memory stack. These operations are simulated by decrementing or incrementing
the stack pointer register.
Figure 9-5 shows a portion of a memory organized as a stack. The stack pointer
register SP holds the binary address of the item that is currently on the top of the
stack. Three items are presently stored in the stack, A, B, and C in consecutive
addresses 103, 102, and 101, respectively. Item C is on top of the stack, so SP
contains 101. To remove the top item, the stack is popped by reading the item at
address 101 and incrementing SP. Item B is now on top of the stack since SP
contains address 102. To insert a new item, the stack is pushed by first decrementing
SP and then writing the new item on top of the stack. Note that item C has been
read out but not physically removed. This does not matter as far as the stack
operation is concerned, because when the stack is pushed, a new item is written
on top of the stack regardless of what was there before.
We assume that the items in the stack communicate with a data register DR. A
new item is inserted with the push operation as follows:
SP +-SP - 1
M[SP] <- DR
The stack pointer is decremented so it points at the address of the next word. A
memory write microoperation inserts the word from DR onto the top of the stack.
Note that SP holds the address of the top of the stack and that M[SP] denotes the
memory word specified by the address presently in SP.
A new item is deleted with a pop operation as follows:
DR <- M[SP]
SP *-SP + 1
Memory
Address
100
SP = 101 C 101
B 102
A 103
DR
104
FIGURE 9-5
Memory Stack
308 Chapter 9 Computer Instructions and Addressing Modes
The top item is read from the stack into DR. The stack pointer is then incremented
to point at the next item in the stack.
The two microoperations needed for either thepush or pop are access to memory
through SP and updating SP. Which of the two microoperations is done first and
whether SP is updated by incrementing or decrementing depends on the organi¬
zation of the stack. In Figure 9-5 the stack grows by decreasing the memory address.
The stack may be constructed to grow by increasing the memory address. In such
a case, SP is incremented for the push operation and decremented for the pop
operation. A stack may be constructed so that SP points at the next empty location
above the top of the stack. In this case, the sequence of microoperations must be
interchanged.
A stack pointer is loaded with an initial value. This initial value must be the
bottom address of an assigned stack in memory. From then on, SP is automatically
decremented or incremented with every push or pop operation. The advantage of
a memory stack is that the processor can refer to it without having to specify an
address, since the address is always available and automatically updated in the
stack pointer.
A * B + C * D
The operator * denotes multiplication and is placed between the operands A and
B and between C and D. The operator + denoting addition is between the two
products. To evaluate the arithmetic expression it is necessary to compute the
product A * B, store this product, compute the product C * Z), and then sum the
two products. From this simple example we see that to evaluate arithmetic expres¬
sions in infix notation it is necessary to scan back and forth along the expression
to determine the sequence of operations that must be performed.
The Polish mathematician Jan Lukasiewicz proposed that arithmetic expressions
be written in prefix notation. This representation, referred to as Polish notation
places the operator before the operands. Postfix notation, referred to as reverse
Polish notation, places the operator after the operands. The following examples
demonstrate the three representations.
A + B Infix notation
Reverse Polish notation, also known as RPN, is a form suitable for stack manip¬
ulation. The expression
A * B + C * D
Section 9-4 Stack Organization 309
is written in RPN as
A B * C D * +
and is evaluated as follows. Scan the expression from left to right. When an operator
is reached, perform the operation with the two operands to the left of the operator.
Remove the two operands and the operator and replace them with the number
obtained from the operation. Continue to scan the expression and repeat the
procedure for every operator until there are no more operators.
For the above expression we find the operator * after A and B. We perform
the operation A * B and replace A, B, and * by the product to obtain
(A * B) C D * +
where (A + B) is a single quantity obtained from the product. The next operator
is a * and its previous two operands are C and D; so we perform C * D and obtain
an expression with two operands and one operator:
(A * B) (C * D) +
The next operator is + and the two operands on its left are the two products; so
we add the two quantities to obtain the result.
The conversion from infix notation to reverse Polish notation must take into
consideration the operational hierarchy adopted for infix notation. This hierarchy
dictates that we first perform all arithmetic inside inner parentheses, then inside
outer parentheses, then do multiplication and division, and finally, addition and
subtraction. Consider the expression
(A + B) * [C * (D + E) + F]
To evaluate the expression we must first perform the arithmetic inside the paren¬
theses and then evaluate the expression inside the square brackets. The multipli¬
cation of C * (D + E) must be done prior to the addition of F. The last operation
is the multiplication of the two terms between the parentheses and brackets. The
expression can be converted to RPN by taking into consideration the operation
hierarchy. The converted expression is
AB+DE+C*F+*
Proceeding from left to right, we first add A and B, then add D and E. At this
point we are left with
(A + B) (D + E) C * F + *
Where (A + B) and (D + E) are each a single number obtained from the sum.
The two operands for the next * are C and (D + E). These two numbers are
multiplied and the product added to F. The final * causes the multiplication of the
last result with the number (.A + B). Note that all expressions in RPN are without
parentheses.
The subtraction and division operations are not commutative, and the order of
the operands is important. We define the RPN expression A B — to mean (A -
B) and the expression A B / to represent the division of A / B.
310 Chapter 9 Computer Instructions and Addressing Modes
Stack Operations
Reverse Polish notation combined with a stack provides an efficient way to evaluate
arithmetic expressions. This procedure is employed in some electronic calculators
and also in some computers. The stack is particularly useful for handling long,
complex problems involving chain calculations. It is based on the fact that any
arithmetic expression can be expressed in parentheses-free Polish notation.
The procedure consists of first converting the arithmetic expression into its
equivalent RPN. The operands are pushed onto the stack in the order that they
appear. The initiation of an operation depends on whether we have a calculator
or a computer. In a calculator, the operators are entered through the keyboard.
In a computer they must be initiated by program instructions. The following op¬
erations are executed with the stack when an operation is specified: The two
topmost operands in the stack are popped and used for the operation. The result
of the operation is pushed into the stack, replacing the lower operand. By contin¬
uously pushing the operands onto the stack and performing the operations as
defined above, the expression is evaluated in the proper order and the final result
remains on top of the stack.
The following numerical example will clarify the procedure. Consider the arith¬
metic expression
(3 * 4) + (5 * 6)
3 4 * 5 6 * +
Now consider the stack operations as shown in Figure 9-6. Each box represents
one stack operation and the arrow always points to the top of the stack. Scanning
the RPN expression from left to right, we encounter two operands. First the number
3 is pushed onto the stack, then the number 4. The next symbol is the multiplication
operator *. This causes a multiplication of the two topmost numbers in the stack.
The stack is popped twice for the operands and the product is pushed into the top
of the stack in the lower position of the original operand. Next we encounter the
two operands 5 and 6, and they are pushed onto the stack. The stack operation
that results from the next * removes these two numbers and puts their product,
30, on the stack. The last operation causes an arithmetic addition of the two topmost
numbers in the stack to produce the final result of 42.
3 4 * 5 6 * +
FIGURE 9-6
Stack Operations to Evaluate 3 * 4 + 5 * 6
Section 9-5 Data Transfer Instructions 311
Calculators that use RPN have an Enter key that functions as a push operation.
When a number is keyed in following an Enter, the number is pushed onto the
stack. When a number is keyed in following an operator, the calculator pushes the
number on top of the stack and performs the operation with the two topmost
numbers in the stack. Thus, the above expression is evaluated in an RPN calculator
by using a sequence of keys as follows:
Computer Stack
Most computers have a facility for a memory stack but only a few commercial
computers have the appropriate instructions for evaluating arithmetic expressions
with RPN. Such computers have a stack organized CPU with the top locations of
the stack as registers. The rest of the stack is in memory. In this way, the operations
that must be performed with the top two items of the stack are available in processor
registers for manipulation with arithmetic circuits.
The PUSH and POP instructions require one address field to specify the source
or destination operand. Operation type instructions for the stack such as ADD and
MUL imply the two operands on top of the stack and do not require an address
field in the instruction. The following program shows how the arithmetic statement
A - (A + B) * (C + D)
will be written for a computer stack (TOS stands for top of stack).
PUSH A TOS <— A
PUSH B TOS <- B
ADD TOS <- (A + B)
PUSH C TOS C
PUSH D TOS D
ADD TOS <- (C + D)
MUL TOS (C + D) * (A + B)
POP X M[X\ TOS
Computers provide an extensive set of instructions to give the user the flexibility
to carry out various computational tasks. The instruction set of different computers
differ from each other mostly in the way the operands are determined from the
address and mode fields. The actual operations available in the instruction set are
not very different from one computer to another. It so happens that the binary
code assignment in the operation code field is different in different computers,
even for the same operation. It may also happen that the symbolic name given to
instructions is different in different computers, even for the same instruction. Never¬
theless, there is a set of basic operations that most computers include among their
312 Chapter 9 Computer Instructions and Addressing Modes
Data transfer instructions cause transfer of data from one location to another
without changing the binary information content. Data manipulation instructions
perform arithmetic, logic, and shift operations. Program control instructions pro¬
vide decision making capabilities and change the path taken by the program when
executed in the computer. In addition to the basic instruction set, a computer may
have other instructions that provide special operations for particular applications.
In this section we present a list of some typical data transfer instructions. In the
next section we present the various data manipulation instructions. Program control
instructions are discussed in Section 9-8.
TABLE 9-2
Typical Data Transfer Instructions
Name Mnemonic
Load LD
Store ST
Move MOVE
Exchange XCH
Push PUSH
Pop POP
Input IN
Output OUT
Section 9-6 Data Manipulation Instructions 313
pop instructions transfer data between a memory stack and a processor register.
The input and output instructions transfer data between processor registers and
input and output devices.
Data manipulation instructions perform operations on data and provide the com¬
putational capabilities for the computer. The data manipulation instructions in a
typical computer are usually divided into three basic types:
1. Arithmetic instructions.
2. Logical and bit manipulation instructions.
3. Shift instructions.
314 Chapter 9 Computer Instructions and Addressing Modes
A list of data manipulation instructions will look very much like the list of micro¬
operations given in Chapter 7. One must realize, however, that a microoperation
is an elementary operation executed by the hardware of the computer. An instruc¬
tion when executed in the computer must go through the instruction fetch phase
to read the binary code from memory and the operands must be brought into
processor registers according to the rules specified by the addressing mode. The
last step is the execution of the instruction with one or more microoperations.
Arithmetic Instructions
The four basic arithmetic instructions are addition, subtraction, multiplication, and
division. Most computers provide instructions for all four operations. Some small
computers have only addition and subtraction instructions. The multiplication and
division must then be generated by means of special programs. The four basic
arithmetic operations are sufficient for formulating solutions to any numerical
problem when used with numerical analysis methods.
A list of typical arithmetic instructions is given in Table 9-3. The increment
instruction adds one to the value stored in a register or memory word. A common
characteristic of the increment operation when executed in processor registers is
that a binary number of all l’s when incremented produces a result of all 0’s. The
decrement instruction subtracts one from a value stored in a register or memory
word. A number with all 0’s when decremented, produces a number with all l’s.
The add, subtract, multiply, and divide instructions may be available for different
types of data. The data type assumed to be in processor registers during the exe¬
cution of these arithmetic operations is included in the definition of the operation
code. An arithmetic instruction may specify unsigned or signed integers, binary or
decimal numbers, or floating-point data. The arithmetic operations with binary
and decimal integers was presented in Chapter 1. The floating-point representation
is used for scientific calculations and is presented in the next section.
The number of bits in any register is finite and therefore the results of arithmetic
operations are of finite precision. Most computers provide special instructions to
facilitate double precision arithmetic. A carry flip-flop is used to store the carry
from an operation. The instruction “add with carry” performs the addition with
TABLE 9-3
Typical Arithmetic Instructions
Name Mnemonic
Increment INC
Decrement DEC
Add ADD
Subtract SUB
Multiply MUL
Divide DIV
Add with carry ADDC
Subtract with borrow SUBB
Subtract reverse SUBR
Negate (2’s complement) NEG
Section 9-6 Data Manipulation Instructions 315
two operands plus the value of the carry from the previous computation. Similarly,
the “subtract with borrow” instruction subtracts two operands and a borrow which
may have resulted from a previous operation. The reverse subtract instruction
reverses the order of the operands and performs B - A instead of A — B. The
negate instruction performs the 2’s complement of a signed number which is equiv¬
alent to multiplying it by —1.
TABLE 9-4
Typical Logical and Bit Manipulation
Instructions
Name Mnemonic
Clear CLR
Set SET
Complement COM
AND AND
OR OR
Exclusive-OR XOR
Clear carry CLRC
Set carry SETC
Complement carry COMC
316 Chapter 9 Computer Instructions and Addressing Modes
that remain the same. The AND instruction is also called a mask because it masks
(by inserting 0’s) a selected portion of an operand.
The OR instruction is used to set to 1 a bit or a selected group of bits of an
operand. For any Boolean variable X, the relationships X + 1 = 1 and X + 0 =
X dictate that a binary variable ORed with a 1 produces a 1; but the variable does
not change when ORed with a 0. Therefore, the OR instruction can be used to
selectively set bits of an operand by ORing it with a string of bits with l’s in the
bit positions that must be set to 1. The OR instruction is sometimes called a bit
set instruction.
The XOR instruction is used to selectively complement bits of an operand. This
is because of the Boolean relationships X 0 1 = X and X ® 0 = X. A binary
variable is complemented when XORed with a 1 but does not change in value
when XORed with 0. The XOR instruction is sometimes called a bit complement
instruction.
A few other bit manipulation instructions are included in Table 9-4. Individual
bits such as a carry can be cleared, set, or complemented with appropriate instruc¬
tions. Other status bits or flag bits can be set or cleared by program instructions
in a similar manner.
Shift Instructions
Instructions to shift the content of an operand are provided in several variations.
Shifts are operations in which the bits of the operand are moved to the left or the
right. The bit shifted in at the end of the word determines the type of shift used.
Shift instructions may specify either logical shifts, arithmetic shifts, or rotate type
operations. In any case the shift may be to the right or to the left.
Table 9-5 lists four types of shift instructions. The logical shift inserts 0 into the
end bit position after the shift. The end position is the leftmost bit for shift right
and the rightmost positions for shift left. Arithmetic shifts conform to the rules for
shifting signed numbers. The arithmetic shift right instruction preserves the sign
bit in the leftmost position. The sign bit is shifted to the right together with the
rest of the number, but the sign bit itself remains unchanged. The arithmetic shift
left instruction inserts 0 into the end bit in the rightmost position and is identical
to the logical shift left instruction. For this reason many computers do not provide
TABLE 9-5
Typical Shift Instructions
Name Mnemonic
a distinct arithmetic shift left instruction when the logical shift left instruction is
already available.
The rotate instructions produce a circular shift. Bits shifted out at one end of
the word are not lost, as in a logical shift, but are rotated back into the other end.
The rotate with carry instructions treats the carry bit as an extension of the register
whose word is being rotated. Thus, a rotate left with carry instruction transfers the
carry bit into the rightmost bit position of the register, transfers the leftmost bit
of the register into the carry, and shifts the entire register to the left.
Some computers have a multiple field format for the shift instruction. One field
contains the operation code and the others specify the type of shift and the number
of positions that an operand is to be shifted. A possible instruction format of a
shift instruction may include five fields as follows:
Here OP is the operation code field for specifying a shift; REG is a register address
that specifies the location of the operand. TYPE is a 2-bit field that specifies one
of the four types of shifts (logical, arithmetic, rotate, and rotate with carry); RL
is a 1-bit field that specifies whether a shift is to the right or the left; and COUNT
is a /c-bit field that specifies up to 2k — 1 shifts. With such a format, it is possible
to specify the type of shift, the direction, and the number of shifts, all in one
instruction.
Fraction Exponent
+ .6132789 +04
The value of the exponent indicates that the actual position of the decimal point
is four positions to the right of the indicated decimal point in the fraction. This
representation is equivalent to the scientific notation + .6132789 x 10 + 4.
Decimal floating-point numbers are interpreted as representing a number in the
form
F x 10E
where F is the fraction and E the exponent. Only the fraction and the exponent
are physically represented in computer registers. The base 10 and the decimal point
of the fraction are assumed and are not shown explicitly. A floating-point binary
number is represented in a similar manner except that it uses a base 2 for the
exponent. For example, the binary number +1001.11 is represented with an 8-bit
fraction and 6-bit exponent as
318 Chapter 9 Computer Instructions and Addressing Modes
Fraction Exponent
01001110 000100
The fraction has a 0 in the leftmost position to denote a plus. The binary point of
the fraction follows the sign bit but is not shown in the register. The exponent has
the equivalent binary number +4. The floating-point number is equivalent to
F x 2E = + (.1001110)2 x 2 + 4
A floating-point number is said to be normalized if the most significant digit of
the fraction is nonzero. For example, the decimal fraction 0.350 is normalized but
0.0035 is not. Normalized numbers provide the maximum possible precision for
the floating-point number. A zero cannot be normalized because it does not have
a nonzero digit. It is usually represented in floating-point by all 0’s in both the
fraction and exponent.
Floating-point representation increases the range of numbers that can be ac¬
commodated in a given register. Consider a computer with 48-bit registers. Since
one bit must be reserved for the sign, the range of signed integers will be ± (247 — 1)
which is approximately ± 1014. The 48 bits can be used to represent a floating¬
point number with 36 bits for the fraction and 12 bits for the exponent. The largest
positive or negative number that can be accommodated is
Arithmetic Operations
Arithmetic operations with floating-point numbers are more complicated than with
integer numbers and their execution takes longer and requires more complex hard¬
ware. Adding and subtracting two numbers requires that the decimal points be
aligned since the exponent parts must be equal before adding or subtracting the
fractions. The alignment is done by shifting one fraction and adjusting its exponent
until it is equal to the other exponent. Consider the sum of the following floating¬
point numbers.
.5372400 x 102
+ .1580000 x 10-1
It is necessary that the two exponents be equal before the fractions can be added.
We can either shift the first number three positions to the left, or shift the second
number three positions to the right. When the fractions are stored in registers,
shifting to the left causes a loss of most significant digits. Shifting to the right causes
a loss of least significant digits. The second method is preferable because it only
reduces the precision while the first method may cause an error. The usual align¬
ment procedure is to shift the fraction that has the smaller exponent to the right
Section 9-7 Floating-Point Operations 319
by a number of places equal to the difference between the exponents. After this
is done, the fractions can be added.
.5372400 x 102
+ .0001580 x 102
.5373982 x 102
When two normalized fractions are added, the sum may contain an overflow
digit. An overflow can be corrected by shifting the sum once to the right and
incrementing the exponent. When two numbers are subtracted, the result may
contain most significant zeros in the fraction as shown in the following example:
.56780 x 105
- .56430 x 105
.00350 x 105
A floating-point number that has a 0 in the most significant position is not nor¬
malized. To normalize the number, it is necessary to shift the fraction to the left
and decrement the exponent until a nonzero digit appears in the first position. In
the above example, it is necessary to shift left twice to obtain .35000 x 103. In
most computers, a normalization procedure is performed after each operation to
ensure that all results are in normalized form.
Floating-point multiplication and division do not require an alignment of the
fractions. The product can be formed by multiplying the two fractions and adding
the exponents. Division is accomplished by dividing the fractions and subtracting
the exponents.
In the examples shown we used decimal numbers to demonstrate the arithmetic
operations of floating-point numbers. The same procedure applies to binary num¬
bers with the exception that the base of the exponent is 2 instead of 10.
Biased Exponent
The fraction part of a floating-point number is usually in signed-magnitude rep¬
resentation. The exponent representation employed in most computers is known
as a biased representation. The bias is an excess number which is added to the
exponent so that internally all exponents become positive. As a consequence, the
sign is removed from being a separate entity.
Consider for example the range of decimal exponents from —99 to +99. This
is represented by two digits and a sign. If we use an excess 99 bias then the biased
exponent e will be equal to e — E + 99, where E is the actual exponent. For
E — -99, we have e = -99 + 99 = 0; and for E — +99, we have e = 99 +
99 = 198. In this way, the biased exponent is represented in a register as a positive
number in the range from 000 to 198. Positive biased exponents have a range of
numbers from 099 to 198. The subtraction of the bias 99 gives the positive values
from 0 to +99. Negative biased exponents have a range from 098 to 000. The
subtraction of 99 gives the negative values from -1 to -99.
320 Chapter 9 Computer Instructions and Addressing Modes
The advantage of biased exponents is the fact that they contain only positive
numbers. It is then simpler to compare their relative magnitude without being
concerned with their signs. Another advantage is that the most negative exponent
converts to a biased exponent with all 0’s. The floating-point representation of zero
is then a zero fraction and a zero biased exponent which is the smallest possible
exponent.
Decimal
f Field Significand Equivalent
Even though the/field by itself may not be normalized, the significand is always
normalized because it has a nonzero bit in the most significant position. Since
normalized numbers must have a nonzero most significant bit, this 1 bit is not
included explicitly in the format but must be inserted by the hardware during the
arithmetic computations.
The exponent field uses an excess 127 bias value for normalized numbers. The
range of valid exponents is from -126 (represented as 00000001) through +127
(represented as 11111110). The maximum (11111111) and minimum (00000000)
1 8 23
FIGURE 9-7
Standard Floating-Point Operand Format
Section 9-8 Program Control Instructions 321
TABLE 9-6
Evaluating Biased Exponents
values that the e field can take are reserved to indicate exceptional conditions.
Table 9-6 shows some values of biased exponents and their actual values.
Normalized numbers are numbers that can be expressed as floating-point op¬
erands where the e field is neither all 0’s nor all l’s. The value of the number is
derived from the three fields in the format of Figure 9-7 using the following formula:
( l)s2e — 127 x (1./)
The most positive normalized number that can be obtained has a 0 for the sign bit
for positive sign, a biased exponent equal to 254 and an / field with 23 Ts. This
gives an exponent E = 254 - 127 = 127. The significand is equal to 1 + 1 —
2~23 = 2 — 2~23. The maximum positive number that can be accommodated is
+ 2127 x (2 - 2-23)
The least positive normalized number has a biased exponent equal to 00000001
and a fraction of all 0’s. The exponent is E = 1 — 127 = - 126 and the significand
is equal to 1.0. The smallest positive number that can be accommodated is + 2~126.
The corresponding negative numbers are the same except that the sign bit is negative.
As mentioned before, exponents with all 0’s or all l’s (decimal 255) are reserved
for special conditions:
1. When e = 255 and / = 0, the number represents plus or minus infinity. The
sign is determined from the sign bit 5.
2. When e = 255 and f =f= 0, the representation is considered to be not a number
or NaN, regardless of the sign value. NaNs are used to signify invalid oper¬
ations such as the multiplication of zero times infinity.
3. When e = 0 and / = 0, the number denotes plus or minus zero.
4. When e = 0, and f E 0, the number is said to be denormalized. This is the
name given to numbers with a magnitude less than the minimum value that
is represented in the normalized format.
Name Mnemonic
Branch BR
Jump JMP
Skip next instruction SKP
Call subroutine CALL
Return from subroutine RET
Compare (by subtraction) CMP
Test (by ANDing) TEST
the program counter PC is incremented so that it contains the address of the next
instruction in sequence. After the execution of a data transfer or data manipulation
instruction, control returns to the fetch phase and uses PC to fetch the next in¬
struction in sequence. In contrast, a program control instruction, when executed,
may change the address value in PC and cause the flow of control to be altered.
The change in PC as a result of the execution of a program control instruction
causes a break in the sequence of instruction execution. This is an important feature
of digital computers since it provides control over the flow of program execution
and a capability for branching to different program segments depending on previous
computations.
Some typical program control instructions are listed in Table 9-7. The branch
and jump instructions are used interchangeably to mean the same thing, although
sometimes they are used to denote different addressing modes. The branch is usually
a one address instruction. When executed, the branch instruction causes a transfer
of the effective address into PC. Since PC contains the address of the instruction
to be executed next, the next instruction will be fetched from the location specified
by the effective address.
Branch and jump instructions may be conditional or unconditional. An uncon¬
ditional branch instruction causes a branch to the specified effective address without
any conditions. The conditional branch instruction specifies a condition for the
branch such as a positive or negative result. If the condition is met, PC is loaded
with the effective address and the next instruction is taken from this address. If
the condition is not met, PC is not changed and the next instruction is taken from
the next location in sequence.
The skip instruction does not need an address field. A conditional skip instruction
will skip the next instruction if the condition is met. This is accomplished by
incrementing PC during the execute phase in addition to its being incremented
during the fetch phase. If the condition is not met, control proceeds to the next
instruction in sequence, where the programmer inserts an unconditional branch
instruction. Thus, a conditional skip instruction followed by an unconditional branch
instruction causes a branch if the condition is not met, while a single conditional
branch instruction causes a branch if the condition is met.
The call and return instructions are used in conjunction with subroutine pro¬
grams. Their performance and implementation is discussed later in this section.
The compare and test instructions are not program control instructions because
they do not change the program sequence directly. They are listed in Table 9-7
because of their application in setting conditions for subsequent conditional branch
instructions. The compare instruction performs a subtraction between two oper-
322
Section 9-8 Program Control Instructions 323
ands, but the difference is not retained. However, the status bit conditions are
updated as a result of the operation. Similarly, the test instruction performs the
logical AND of two operands and updates certain status bits without retaining the
result or changing the operands.
TABLE 9-8
Conditional Branch Instructions Relating to Status Bits
Branch if zero BZ Z = 1
Branch if no zero BNZ Z = 0
Branch if carry BC C = 1
Branch if no carry BNC C = 0
Branch if minus BM 5 = 1
Branch if plus BP 5 = 0
Branch if overflow BV V = 1
Branch if no overflow BNV V = 0
324 Chapter 9 Computer Instructions and Addressing Modes
TABLE 9-9
Conditional Branch Instructions for Unsigned Numbers
The relative magnitude of two unsigned binary numbers A and B can be deter¬
mined by subtracting A — B and checking the C and Z status bits. Most commercial
computers consider the C status bit as a carry after addition and a borrow after
subtraction. A borrow occurs when A < B because the most significant position
must borrow a bit to complete the subtraction. A borrow does not occur if A >
B because the difference A — B is positive. The condition for borrow is the inverse
of the condition for carry when the subtraction is done by taking the 2’s complement
of B. Computers that use the C status bit as a borrow after a subtraction, com¬
plement the output carry after adding the 2’s complement of the subtrahend and
call this bit a borrow.
The conditional branch instructions for unsigned numbers are listed in Table
9-9. It is assumed that a previous instruction updated status bits C and Z after a
subtraction A - B. The words higher, lower, and equal are used to denote the
relative magnitude between two unsigned numbers. The two numbers are equal if
A = B. This is determined from the zero status bit Z which is equal to 1 because
A — B = 0. A is lower than B and the borrow C = 1 when A < B. For A to be
lower than or equal to B (A < B) we must have C = 1 or Z = 1. The relationship
A > B is the inverse of A < B and is detected from the complement condition of
the status bits. Similarly, A > B is the inverse of A < B and A =f= B is the inverse
of A = B.
The conditional branch instructions for signed numbers are listed in Table 9-10.
Again it is assumed that a previous instruction updated the status bits S, C, and
Z after a subtraction A - B. The words greater, less, and equal are used to denote
the relative magnitude between two signed numbers. If S = 0, the sign of the
difference is positive, and A must be greater than or equal to 5, provided that
V = 0 indicating that no overflow occurred. An overflow causes a sign reversal as
discussed in Section 7-3. This means that if S = 1 and V — 1, there was a sign
TABLE 9-10
Conditional Branch Instructions for Signed Numbers
reversal and the result should have been positive, which makes A greater than or
equal to B. Therefore, the condition A > B is true if both S and V are equal to 0
or both are equal to 1. This is the complement of the exclusive-OR operation.
For A to be greater than but not equal to B (A > B), the result must be positive
and nonzero. Since a zero result gives a positive sign, we must ensure that the Z
bit is 0 to exclude the possibility of A = B. Note that the condition (S 0 V) or
Z = 0 means that both the exclusive-OR operation and the Z bit must be equal
to 0. The other two conditions in the table can be derived in a similar manner.
The conditions BE (branch on equal) and BNE (branch on not equal) apply to
signed numbers as well and can be determined from Z = 1 and Z = 0, respectively.
The return instruction is implemented by popping the stack and transferring the
return address to PC.
By using a subroutine stack, all return addresses are automatically stored by the
hardware in the memory stack. The programmer does not have to be concerned
or remember where to return after the subroutine is executed.
The concept of program interrupt is used to handle a variety of problems that arise
out of normal program sequence. Program interrupt refers to the transfer of pro¬
gram control from a currently running program to another service program as a
result of an externally or internally generated request. Control returns to the
original program after the service program is executed.
The interrupt procedure is in principle similar to a subroutine call except for
three variations.
After the computer has been interrupted and the corresponding service program
has been executed, the computer must return to exactly the same state that it was
before the interrupt occurred. Only if this happens will the interrupted program
be able to resume exactly as if nothing has happened. The state of the computer
at the end of an execution of an instruction is determined from the contents of the
program counter and other processor registers and the values of various status bits.
The collection of all status bits is sometimes called the program status word or
PSW. The PSW is stored in a separate register and contains the status information
that characterizes the state of the computer. Typically, it includes the status bits
from the last ALU operation and it specifies what interrupts are allowed to occur
and whether the computer is operating in a user or system mode. Many computers
have a resident operating system that controls and supervises all other programs.
When the computer is executing a program that is part of the operating system,
the computer is placed in a system mode. Certain instructions are privileged and
can be executed in the system mode only. The computer is in a user mode when
executing user programs. The mode of the computer at any given time is determined
from special status bits in the PSW.
Some computers store only the program counter when responding to an inter¬
rupt. The program that performs the data processing for servicing the interrupt
must then include instructions to store all register contents and the PSW. Other
computers store the program counter and all status and register contents in response
to an interrupt. In some cases, there exist two sets of processor registers within
the computer. In this way, when the program switches from the user to the system
mode in response to an interrupt, it is not necessary to store the contents of
processor registers because each computer mode employs its own set of registers.
Section 9-9 Program Interrupt 327
The hardware procedure for processing interrupts is very similar to the execution
of a subroutine instruction. The state of the processor is pushed onto a memory
stack and the address of the first instruction of the interrupt service program is
loaded into PC. The address of the service program is chosen by the hardware.
Some computers assign one memory location for the beginning address of the
service program. The service program must then determine the source of the
interrupt and proceed to service it. Some computers assign a separate memory
location for each possible interrupt source. Sometimes, the interrupt source hard¬
ware itself supplies the address of the service routine. In any case, the computer
must possess some form of hardware procedure for selecting a branch address for
servicing the interrupt through program instructions.
Most computers will not respond to an interrupt until the instruction that is in
the process of being executed is completed. Then, just before going to fetch the
next instruction, the control checks for any interrupt signals. If an interrupt has
occurred, control goes to a hardware interrupt cycle. During this cycle, the contents
of PC (and sometimes the state of the processor) is pushed onto the stack. The
branch address for the particular interrupt is then transferred to PC and control
goes to fetch the next instruction. The service program is then executed starting
from the address available in PC. The last instruction in the service program is a
return from the interrupt instruction. When this instruction is executed, the stack
is popped to retrieve the return address which is then transferred to PC.
Types of Interrupts
There are three major types of interrupts that cause a break in the normal execution
of a program. They are classified as
1. External interrupts.
2. Internal interrupts.
3. Software interrupts.
External interrupts come from input or output devices, from timing devices, from
a circuit monitoring the power supply, or from any other external source. Conditions
that cause external interrupts are an input or output device requests a transfer of
data, an external device has completed transfer of data, time out of an event has
occurred, or power failure is pending. Time out interrupt may result from a program
that is in an endless loop and thus exceeds its time allocation. Power failure interrupt
may have as its service program a few instructions that transfer the complete state
of the processor into a nondestructive memory such as a disk in the few milliseconds
before power ceases.
Internal interrupts arise from illegal or erroneous use of an instruction or data.
Internal interrupts are also called traps. Examples of interrupts caused by internal
conditions are register overflow, an attempt to divide by zero, an invalid operation
code, memory stack overflow, and protection violation. These error conditions
usually occur as a result of a premature termination of the instruction execution.
The service programs that process the internal interrupts determine the corrective
measure to be taken in each case.
External and internal interrupts are initiated by hardware conditions. A software
328 Chapter 9 Computer Instructions and Addressing Modes
FIGURE 9-8
External Interrupt Configuration
References 329
tions. When EIF is reset, the interrupt signal is neglected. If EIF is set and the
CPU is at the end of an instruction execution, the computer acknowledges the
interrupt by enabling 1NTACK output. The interrupt source responds to INTACK
by providing an interrupt vector address IVAD to the CPU. The program controlled
EIF flip-flop allows the programmer to decide whether to use the interrupt facility
or not. If an instruction to reset EIF has been inserted in the program, it means
that the programmer does not want the program to be interrupted. An instruction
to set EIF indicates that the interrupt facility will be active while the program is
running.
The computer responds to an interrupt request signal if EIF = 1 and control
has completed executing the present instruction. The microoperations that imple¬
ment the interrupt cycle are as follows:
The return address available in PC is pushed onto the stack and EIF is reset to
disable further interrupts. The program that services the interrupt can set EIF with
an instruction whenever it is appropriate to enable other interrupts. The CPU
assumes that the external source will provide an address in response to an ac¬
knowledge signal. This address is taken as the address of the first instruction of
the program that services the interrupt. Obviously, a program must be written for
that purpose and stored in memory.
The return from an interrupt is done with an instruction at the end of the service
program similar to a return from a subroutine. The stack is popped and the return
address is transferred to PC.
REFERENCES
-j Mano, M. M. Computer System Architecture. 2nd ed. Englewood Cliffs: Prentice-Hall,
1982.
2 Tanenbaum, A. S. Structured Computer Organization. 2nd ed. Englewood Cliffs: Pren¬
tice-Hall, 1984.
3 Wakerly, J. F. Microcomputer Architecture and Programming. New York: Wiley, 1981.
4 Lewin, M. H. Logic Design and Computer Organization. Reading, MA: Addison-
Wesley, 1983.
5 Hayes, J. P. Computer Architecture and Organization. New York: McGraw-Hill, 1978.
g IEEE Standard for Microprocessor Assembly Language. (IEEE Std 694-1985.) New
York: The Institute of Electrical and Electronics Engineers.
7 IEEE Standard for Binary Floating-Point Arithmetic. (ANSI/IEEE Std 754-1985.) New
York: The Institute of Electrical and Electronics Engineers.
330 Chapter 9 Computer Instructions and Addressing Modes
PROBLEMS
9-1 Write a program to evaluate the arithmetic statement
X = (A + B * C) / (D + E * F - G * H)
(3 + 4) [10 (2 + 6) + 8]
9-10 A first-in first-out (FIFO) memory has a memory organization that stores information
in such a manner that the item that is stored first is the first item that is retrieved.
Show how a FIFO memory operates with three counters. A write counter WC holds
Problems 331
the address for writing into memory. A read counter RC holds the address for reading
from memory. An available storage counter ASC indicates the number of words stored
in FIFO. ASC is incremented for every word stored and decremented for every item
that is retrieved.
9-11 Write a program to evaluate the arithmetic statement given in Problem 9-1 using
computer stack instructions.
9-12 A computer with independent I/O system has the following input and output instruc¬
tions.
IN ADRS
OUT ADRS
Where ADRS is the address of an I/O register port. Give the equivalent instructions
for a computer with memory-mapped I/O.
9-13 Assuming an 8-bit computer, show the multiple precision addition of the two 32-bit
unsigned numbers listed below using the add with carry instruction. Each byte is
expressed as a 2-digit hexadecimal number.
6E C3 56 7A + 13 55 6B 8F
9-14 Perform the logic AND, OR, and XOR with the two binary strings 10011100 and
10101010.
9-15 Given the 16-bit value 1001101011001101. What operation must be performed in order
to
(a) clear the first 8 bits to 0
(b) set the last 8 bits to 1
(c) complement the middle 8 bits.
9-16 An 8-bit register contains the value 01111011 and the carry bit is equal to 1. Perform
the eight shift operations given by the instructions listed in Table 9-5. Each time start
from the initial value given above.
9-17 Show how the following two floating-point numbers are to be added to get a normalized
result.
10-1 INTRODUCTION
The central processing unit is the central component of a digital computer. Its
purpose is to interpret instruction codes received from memory and perform arith¬
metic, logic, and control operations with data stored in internal registers, memory
words, or I/O interface units. Externally, the CPU provides a bus system for
transferring instructions, data, and control information to and from the modules
connected to it.
A typical CPU is usually divided in two parts: the processor unit and the control
unit. The processor unit consists of an arithmetic logic unit, a number of registers,
and internal buses that provide the data paths for the transfer of information
between the registers and the arithmetic logic unit. The control unit consists of a
program counter, an instruction register, and timing and control logic. The control
logic may be either hardwired or microprogrammed. If it is hardwired, registers,
decoders, and a random set of gates are connected to provide the logic that de¬
termines the actions required to execute the various instructions. A micropro¬
grammed control unit uses a control memory to store microinstructions and a
sequencer to determine the order by which the microinstructions are read from
control memory. The purpose of this chapter is to present a typical micropro¬
grammed CPU and to show the detailed logic design of the unit including the
microprogram.
The material in this chapter is presented mostly in the form of diagrams and
tables. Background information from previous chapters is not repeated here. How¬
ever, references are given to previous sections of the book where more detailed
information can be found.
333
334 Chapter 10 Design of a Central Processing Unit (CPU)
The design of the sample CPU is carried out in six parts in the following manner:
Section 10-2 shows the procedure for designing an arithmetic logic shift unit.
Section 10-3 presents the hardware of the processor unit.
Section 10-4 specifies a set of instruction formats for the CPU.
Section 10-5 specifies the microinstruction formats for the control memory.
Sections 10-6 through 10-8 show how to write the microprogram for the CPU.
Section 10-9 presents the hardware of the control unit.
The CPU can be designed from the hardware specifications given in Sections
10-3 and 10-9 and by loading the binary microprogram into control memory.
The position of the CPU among the other computer modules is shown in Figure
10-1. The memory unit stores the instructions, data, and other binary coded in¬
formation needed by the processor. It is assumed that the access time of the memory
is fast enough for the CPU to be able to read or write a word within one clock
pulse period. Even though this restriction is not always applicable in a computer
system, we assume it here in order to avoid complicating the design with a wait
FIGURE 10-1
Block Diagram of the Sample Computer
Section 10-2 Arithmetic Logic Shift Unit (ALSU) 335
period that stops the operations within the CPU until the memory cycle is com¬
pleted.
The interface units provide a path for transferring information between the CPU
and external input or output devices connected through the I/O bus. We assume
a memory-mapped I/O method of addressing between the CPU and the registers
in the interface units. By this method, there are no input or output instructions in
the computer because the CPU can manipulate the data residing in interface reg¬
isters with the same instructions that are used to manipulate memory locations.
Each interface unit is organized as a set of registers that respond to the read or
write signals in the normal address space of the 16-bit address. Typically, the bulk
of the address space is assigned to memory words and a small segment is reserved
for interface registers.
The communication between the CPU and external modules takes place via the
address and data buses. The address bus consists of 16 lines and is unidirectional
from the CPU to the other units. The data bus also consists of 16 lines but is
bidirectional, allowing the information to flow in either direction. The read and
write control lines from the CPU specify the direction of transfer in the data bus.
The read signal informs the selected memory word or interface register to transfer
data into the CPU. The write signal informs the selected unit that a data word is
available for transfer from the CPU to the selected memory word or interface
register.
Two other control lines are shown in Figure 10-1 for the interrupt and interrupt
acknowledge signals. Their function is explained in conjunction with Figure 9-8.
(The interrupt vector address IVAD shown in Figure 9-8 is transferred through
the data bus.) Including the clock input and power supply lines, there are 40 external
terminals in the CPU.
The arithmetic logic shift unit (ALSU) is a combinational circuit that performs a
number of arithmetic, logic, and shift microoperations. The control unit activates
the microoperations when it executes the instructions in the program. The ALSU
has a number of selection lines to select a particular operation in the unit. The
selection variables are decoded by means of multiplexers so that k selection vari¬
ables can specify up to 2k distinct operations.
Figure 10-2 shows the general configuration of the ALSU. It is divided into four
distinct subunits each of which is designed separately. There are 16 data lines for
input A and another 16 data lines for input B. Each of the four subunits receives
one or both sets of input data lines and produces a 16-bit output. In addition, all
four subunits receive the two selection variables Si and S0 and they respond to
these two selection variables by generating one of four internal microoperations.
The other two selection variables S2 and S3 are used to select one, and only one,
of the four output functions from the subunits. This is then applied to the common
16-bit output F of the ALSU. Thus, an arithmetic operation is selected when S3S2
= 00, a logic operation is selected when S3S2 = 01, and a shift right or left operation
is selected when S3S2 = 10 or 11, respectively.
336 Chapter 10 Design of a Central Processing Unit (CPU)
c,r
50
51
52
53
FIGURE 10-2
Arithmetic Logic Shift Unit (ALSU)
The detailed design of the arithmetic and logic units are described in Section
7-6. The input Cin acts as a third selection variable for the arithmetic unit to provide
a total of eight arithmetic microoperations. The other three units each generate
four microoperations. Thus there are a total of 20 microoperations in the ALSU.
The list of the 20 microoperations is given in Table 10-1. Input Cin has a meaning
only during an arithmetic operation. During logic operations it has no effect and
can be assumed to be equal to 0. The first 12 operations are taken from Table
7-6 in Section 7-6. The last eight operations are for the two shift units whose internal
construction is described here.
Shift Unit
The shift right unit is shown in Figure 10-3. The 16 inputs of A are designated A0
through Al5 and the 16 outputs of F as F0 through F15. The shift right operation
is accomplished by connecting each input At to an output Ft _ x for i = 1, 2, 3, . . .,
15. The rightmost bit in position A0 is shifted out and stored in the carry flip-flop
for future inspection if necessary. This is done only during the shift right operation
when S3S2 = 10. The output bit from the left most position in F15 comes from the
output of a multiplexer whose selection inputs Sx and S0 determine the type of
Section 10-2 Arithmetic Logic Shift Unit (ALSU) 337
TABLE 10-1
ALSU Function Table
S3 S2 S1 So cin = 0 Cin = 1
0 0 0 0 F = A Transfer F = A + 1 Increment
0 0 0 1 F = A + B Add F = A + B + 1 Add plus 1
0 0 1 0 F = A - B - 1 Subtract minus 1 F = A - B Subtract
0 0 1 1 F = A - 1 Decrement F = A Transfer
0 1 0 0 F = A A B AND
0 1 0 1 F = A\/ B OR
0 1 1 0 F = A® B XOR
0 1 1 1 F = A Complement
1 0 0 0 F = Logical shift right A
1 0 0 1 F = Rotate right A
1 0 1 0 F = Rotate right A with carry
1 0 1 1 F = Arithmetic shift right A
1 1 0 0 F = Logical shift left A
1 1 0 1 F = Rotate left A
1 1 1 0 F = Rotate left A with carry
1 1 1 4
1 F Arithmetic shift left A
shift. When the selection inputs are equal to 00, the type of operation is a logical
shift right which inserts a 0 into F15. A rotate right operation when the selection
inputs are 01 requires that Fl5 = A0. F15 receives the input carry when the operation
is a rotate right with carry. The previous carry may come from either an arithmetic
operation or from a previous shift operation. With selection inputs equal to 11 we
have an arithmetic shift right operation which requires that the sign bit in the
leftmost position remain unchanged so that Fl5 = A15.
Si Sq
Fl5
Fu
Fl3
^12
F
Fo
FIGURE 10-3
Shift Right Unit
338 Chapter 10 Design of a Central Processing Unit (CPU)
The shift left unit is similar to Figure 10-3 except that the shift is to the left so
that each input At is connected to an output Fi + l. Output F0 receives a value from
a 4 x 1 multiplexer with selection variables and S0. The inputs of this multiplexer
determine the type of shift much as the ones defined in Figure 10-3 did. Note that
the arithmetic shift left operation is identical to the logical shift left with 0 insertion
when the signed numbers are in 2’s complement representation.
The block diagram of the processor unit is shown in Figure 10-4. It consists of a
file of 14 registers, an ALSU, and three buses that provide the data path within
the unit. Two sets of multiplexers select a register or the input data for the ALSU.
A decoder selects a destination register by enabling its load input. All registers
and the input and output data are 16 bits wide. The 17 bits of the control word
that select a microoperation in the processor unit are divided into four fields: The
A field specifies the input to the left side of the ALSU. The B field specifies the
Input data
Select
B
Select
function
F
Control word
FIGURE 10-4
Processor Unit Hardware
Section 10-3 Processor Unit 339
input to the right side of the ALSU. The D field specifies the destination register.
The F field designates the operation in the ALSU as given in Table 10-1. A detailed
explanation of the processor unit is to be found in Sections 7-5 through 7-8.
The 14 registers in the processor unit are assigned special tasks by the CPU.
The first eight registers, designated R0 through R1, are available to the user as
general purpose registers that can be manipulated by program instructions. One
register acts as a program counter and the other five registers are used by the
control unit for storing temporary results. The status bits associated with the ALSU
are symbolized by C, Z, S, and V. They are altered to reflect the results of the
carry, zero, sign and overflow in the ALSU.
Read
Write
FIGURE 10-5
Block Diagram of CPU
340 Chapter 10 Design of a Central Processing Unit (CPU)
is available in the data input register DIR. Instructions read during the fetch phase
are transferred from DIR to the instruction register IR. The contents of IR deter¬
mine the operations in the control unit. Data read from memory into DIR are
applied to the data input lines in the processor unit and then manipulated in the
ALSU. The construction of bus buffers for bidirectional transfer was covered in
Section 7-4. The detailed construction of the control unit will be presented in Section
10-9.
The read and write signals are generated in the control unit by enabling cor¬
responding flip-flops for one clock pulse period. It is assumed that the access time
of the memory is sufficiently fast to be able to synchronize the operation of the
memory with the clock pulses in the CPU. This means that the memory or interface
responds to the read signal by placing the selected word in the data bus with enough
time left to transfer it into the DIR prior to the next clock pulse from the one that
enables the flip-flop read operation. In this way, the control can issue a read
operation with one clock pulse and expect the data read from memory to be
available in DIR at the next clock pulse. If we do not impose this requirement,
the operations in the CPU must be delayed a number of clock pulses until the data
word from memory is available in DIR. Note that this implies that the data input
into DIR is not synchronized with the clock pulses in the CPU. DIR is actually a
latch that follows the input data from the data bus as long as the input path is
enabled in the bidirectional data bus by the read signal.
DIR is used only after a read operation to receive the data from the data bus.
For a write operation, the data must be placed in DOR while the address is in AR.
The write flip-flop when enabled by the control unit opens the output path through
the bidirectional data bus buffers. The memory or interface stores the contents of
the data bus in the word or interface register selected by the address bus within a
time equal to one period of a CPU clock pulse.
Programmer Model
The computer as seen by the programmer and user is shown in Figure 10-6. Eight
processor registers are used for manipulating data through program instructions.
The last two registers are used as stack pointer and index register.The program
counter can be changed by the programmer by means of branch type instructions.
The status bits are affected by certain ALSU operations. The other parts of the
computer of interest to the user are the ALSU, the memory unit, and the input
and output addresses of external devices.
Even though the user and programmer can communicate with only 9 registers,
there are actually 20 registers in the CPU. The other 11 registers are exclusively
used by the control unit for internal operations.
CPU Registers
The 20 registers of the CPU can be divided into three groups. 14 registers are in
the register file inside the processor unit. Three registers communicate with the
data and address buses, and three registers are associated with the control unit.
The following is a list of the 14 registers in the processor unit that communicate
with the ALSU.
Section 10-3 Processor Unit 341
Memory unit
64K x 16 Input and output
(1 28K bytes) devices
ji |
8 processor registers
Status bits
S Z c
FIGURE 10-6
The Computer as Seen by the Programmer and the User
The last five registers are used by the control to store temporary results and
necessary constants. The three registers that communicate with the address and
data buses are
AR Address register
DIR Data input register
DOR Data output register
342 Chapter 10 Design of a Central Processing Unit (CPU)
The position of these registers is shown in Figure 10-5. The three registers associated
with the control unit are
IR Instruction register
CAR Control address register
SBR Subroutine register
CAR holds the address of the next microinstruction for control memory. SBR is
used for storing the return address in conjunction with a subroutine call micro¬
instruction. These two registers are presented in Section 10-9 together with the
hardware of the control unit.
General format
2 6 4 4
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 0 Operation code 0 0 0 0 0 0 0 0
W (Branch address)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 1 Operation code 0 0 0 0 0 0 0 0
FIGURE 10-7
Instruction Formats for the Sample CPU
344 Chapter 10 Design of a Central Processing Unit (CPU)
With one exception, type 1 instructions consist of two words. The second word is
designated by W and follows the word of the instruction code. The register and
indirect fields are similar to the corresponding fields in type 0. The MOD field
specifies four addressing modes. In the direct address mode, the second word W
contains the effective address defined as the address of the operand in memory.
In the immediate mode, the value in W is the operand. In the relative mode, the
value in W is added to the content of the program counter PC to obtain the effective
address. In the index mode, the value in W is added to the content of the index
register XR to obtain the effective address. The various addressing modes are
discussed in more detail in Section 9-3.
The SD field specifies the source, the destination, as well as the number of
operands in the instruction. When the first bit in the SD field is equal to 0, it
specifies a two operand instruction, and when equal to 1, it specifies a one operand
instruction. The second bit in the SD field specifies the source and destination
operands. With SD = 00, the source operand is evaluated from the memory word
W and the mode field MOD. The destination operand is determined from the REG
and I fields. With SD — 01, the source and destination operand assignments are
reversed. A one operand instruction, such as increment or shift, may have the
operand either in a register or in memory. If in memory, the operand may be
accessed through the addressing mode using W or the register indirect mode. Note
that there are certain combinations in type 1 format that are not allowed. The
immediate mode can be used only as a memory word source because it makes no
sense to use it as a destination. Also when the SD field is 11, it specifies a one
operand instruction residing in a register or in memory by means of a register
indirect. This case does not use the memory word W and therefore, the instruction
consists of only one word, and the MOD field is not used.
Type 2 format is dedicated exclusively to branch type instructions. The branch
may be conditional or unconditional. The branch address W follows the instruction
code. It is possible to modify this format to include a relative mode branch type
instruction (see Problem 10-26). In this case, bits 0 through 7 are used for an offset
number in the range of +127 through —128 to provide the relative address that
must be added to PC when evaluating the effective address (instead of the second
word W).
Type 3 format specifies an implied mode instruction such as set carry, return
from interrupt, or no-operation. Bits 0 through 7 are not used and they are always
equal to 0.
Computer Instructions
The complete design of the CPU must include a list of all the instructions for the
computer together with the formats to which they belong. A complete list of
instructions will be prohibitively long for our purpose here. However, a possible
list of instructions that may be formulated can be found in Sections 9-5, 9-6, and
9-8. These three sections contain eight tables that list a set of instructions commonly
found in computers.
In order to show the relationship between the instructions and their formats,
we list some typical instructions in Table 10-2. Each instruction is assigned a sym-
Section 10-4 Instruction Formats 345
TABLE 10-2
Some Typical Instructions and Their Codes
bolic name to be used by the programmer and a 6-bit binary code that is to be
decoded by the control unit. The operation performed by the instruction determines
the type of format to which it belongs. If an instruction has two or three operands,
it can be formulated for both type 0 and type 1 formats. If it has one operand, it
must be formulated using a type 1 format. Branch and call instructions are assigned
to type 2 formats, and instructions that do not use an operand or an address field
are assigned to format 3.
Each instruction contains 16 bits which is equivalent to 4 hexadecimal digits.
The 4-digit hexadecimal codes assigned to the ten instructions in Table 10-2 are
controlled by the format type to which they belong. The 6-bit code of the instruction
together with the 2-bit type constitute an 8-bit code which can be specified with
two hexadecimal digits. For example the ADD instruction has a 6-bit operation
code 001001. The first eight bits of the ADD type 0 instruction are 00001001 which
is equivalent to hexadecimal 09. The corresponding ADD instruction for type 1 is
binary 01001001, equivalent to hexadecimal 49. The two small x’s in type 0 and 1
formats are digit values to be determined from the last eight bits of the instruction
which specify the mode and the registers used.
In order to clarify the use of type 0 and 1 formats, it will be instructive to show
by example all the possible combinations that can be formulated for a typical
instruction. The four ADD instructions that can be formulated with type 0 format
are listed in Table 10-3. It is assumed that the source register is R5 and the des-
TABLE 10-3
Example of Type 0 Instruction
Hex
code SI Dl Op-code Operands Operation
TABLE 10-4
Example of Type 1 Instruction with Two Operands
Hex
code SD MOD Mode Op-code Operands Operation
tination register is R2. There are four possible ways that the two indirect bits SI
and DI can be combined, resulting in the four instructions listed in the table. The
notation used for the addressing modes conforms with the notation introduced in
Table 9-1.
Table 10-4 lists all the addressing modes that can be formulated for the type 1
ADD instruction. We assume a REG field 0010 corresponding to register R2. The
third hexadecimal digit in the instruction code desginates the value in SD and MOD
fields. When SD = 00, the destination operand is in register R2 and the MOD
field specifies four ways to obtain the source operand from the second word W.
When SD = 01, the source operand is in register R2 and the MOD field specifies
three ways to obtain the destination operand. As mentioned previously, the im¬
mediate mode can be used only as a source operand and can be listed only with
SD = 00.
Table 10-4 shows seven different ways to formulate a type 1 ADD instruction.
This instruction can be used also with a register indirect mode by making the last
hexadecimal digit equal to A instead of 2. This gives a total of 14 combinations
that we can formulate a type 1 ADD instruction. Including the four instructions
from Table 10-3, we have a total of 18 ways that we can formulate any 2 operand
instruction.
Table 10-5 lists all the addressing modes that can be formulated for the type 1
INR (increment) instruction. The first two digits of the hexadecimal operation code
for INR are 53 as listed in Table 10-2. The next digit of the instruction reflects the
values of SD and MOD. The last digit is made arbitrarily equal to 0 when the
register field is not used; it is equal to 2 when register R2 is used directly, and
equal to hexadecimal A when register R2 is used indirectly. The last two entries
in the table represent a one operand instruction that needs only a register; so the
TABLE 10-5
Example of Type 1 Instruction with One Operand
Hex
code SD MOD Mode Op-code Operand Operation
MOD field is not used and the second word W is not needed. Table 10-5 shows
five different ways that we can formulate a one operand type 1 instruction.
Type 2 and 3 instructions have only one possible combination. Some examples
are
BR W Branch to W
CALL W Call subroutine starting from address W
RET Return from subroutine
Type 2 instructions require an address field given by the memory word W. Type
3 instructions are one word instructions.
CS and BR Fields
The CS field is common to both microinstruction formats. It determines not only
the format type but also the way the next microinstruction is selected from control
memory. Table 10-6 lists the four ways that the 2-bit CS field makes this selection.
348 Chapter 10 Design of a Central Processing Unit (CPU)
TABLE 10-6
Control Sequence and Branch Assignment
Binary code
CS BR Symbol Operation
00 —
NEXT Use next address by incrementing CAR
01 — RET Return from subroutine
10 — MAP Map operation code into CAR
11 0 JUMP Jump to AD if ST bit is satisfied
11 1 CALL Call subroutine if ST bit is satisfied
2 4 4 4 5 4
CS AS BS DS FC MS
CS AS BS DS FC MS
2 1 1 4 11 4
CS BR PS ST AD MS
CS BR PS ST AD MS
FIGURE 10-8(a)
Microinstruction Formats for Control Memory
Section 10-5 Microinstruction Formats 349
FIGURE 10-8(b)
Symbols and Binary Codes for Microinstruction Fields
350 Chapter 10 Design of a Central Processing Unit (CPU)
The 1-bit BR (branch) field comes into play when CS = 11. It determines the type
of branch chosen for the type B microinstruction format. For CS = 11 and BR =
0 we use the symbol JUMP to designate a conditional branch dependent on the
value of the selected status bit in the ST field. The address for the jump is specified
in the 11-bit AD field. When BR = 1, the microinstruction specifies a conditional
CALL subroutine. (The jump and call microinstructions are similar to the branch
and call instructions discussed in Section 9-8). The symbol NEXT is used when the
microprogram chooses the next microinstruction in sequence.The symbol RET
designates a return from subroutine condition.
When CS = 10, the control unit performs a mapping from the bits of the
operation code into an address for control memory. The MAP condition provides
a decoding of the binary instruction. For example, suppose that the type 0 ADD
instruction has an 8-bit operation 00001001 (see Table 10-3). The binary instruction
is in the instruction register IR after it is fetched from memory. Suppose that we
place the microprogram routine that executes this instruction in control memory
starting from address 23. The hardware decoding requires that a mapping or trans¬
formation be carried out from the binary operation code 00001001 into an 11-bit
address 00000010111 for control memory. This mapping must be done for each
instruction in order to obtain the corresponding address of its microprogram rou¬
tine. The binary mapping can be specified in a table that gives the relationships
between each 8-bit operation code and its corresponding 11-bit address for control
memory. The truth table can be implemented with hardware using a programmable
logic device (see Section 6-6).
Figure 10-9 shows a block diagram that may clarify the way that the CS and BR
fields select the address of the next microinstruction. The control memory consists
of 23 bits, but here we show only the 2-bit CS field, the 1-bit BR field, and the
11-bit AD (address) field. The control address register CAR supplies the address
FIGURE 10-9
Selection of Next Address for Control Memory Using the CS and BR Fields
Section 10-5 Microinstruction Formats 351
for control memory. The incrementer is a combinational circuit that adds one to
the present value of CAR. The subroutine register SBR stores the return address
when the microprogram calls a subroutine. For simplicity, we use here a single
register for storing the return address instead of using a register stack.
While the present microinstruction is at the output terminals of the control
memory, an address multiplexer selects the address for the next microinstruction.
This address is loaded into CAR with the next clock pulse transition. The CS field
is applied to the selection inputs of the address multiplexer. If CS = 00, CAR is
incremented by one to proceed with the next microinstruction in sequence. A call
subroutine microinstruction has CS = 11 and BR = 1. This causes the return
address CAR + 1 to be loaded into the subroutine register SBR and the address
in the AD field to be loaded into CAR. The return from subroutine condition
transfers the content of SBR into CAR. An external address is transferred by
mapping the operation code bits of the instruction in the instruction register
IR(8-15) into an 11-bit address for CAR. A jump microinstruction branches to the
address in AD without loading the subroutine register. The jump and call micro¬
instructions shown in Figure 10-9 are unconditional. The conditional jump and call
depend on the values of the ST and PS fields, as will be explained subsequently.
Figure 10-9 is a simplified version of the microprogram sequencer that is part
of the control hardware. A more detailed block diagram of the sequencer can be
found in Figure 10-18.
TABLE 10-7
Selection of ALSU Buses
Binary Symbols
code AS BS DS Register selected
that registers R0 through R1 in the processor unit are available as general purpose
registers and can be chosen by means of program instructions. Looking back at
the instruction formats in Figure 10-7, we note that these registers are specified as
a source in bits 4-6 and as destination in bits 0-2. These bits are part of the binary
instruction that resides in the instruction register 1R after the instruction is read
from memory. When we assign to the AS field binary 1111, the hardware of the
control unit will select a register for the A bus from the decoded value of the 3-
bit code in IR(A-C). When writing symbolic microprograms, we designate this con¬
dition by the symbol R(S) meaning that the register chosen is given by the 3-bit
code in the source field of the instruction. For example, if the 3-bit code in IR(4-
6) is equal to 011 and the AS field of the microinstruction is 1111 (the binary value
for the symbol R(S)), the control will provide a path from register R3 in the
processor into the A bus of the ALSU.
Similarly, we use the symbol R(D) to designate a register chosen by the desti¬
nation field of the instruction in IR(0-2). Note that R(D) can be chosen for all
three fields, but R(S) is only available with the AS field.
When the DS field is specified with the symbol NONE, it is substituted with
the binary value 1111. When this condition exists, none of the registers are selected
to receive the data from the ALSU. This is equivalent to a “no operation” in the
processor unit.
Section 10-5 Microinstruction Formats 353
FC Field
Table 10-8 lists the microoperations that can be specified with the ALSU function
control field FC. These operations are the same as the ones listed in Table 10-1.
Each operation is assigned a symbolic name to be used when writing microprograms.
The last bit in the 5-bit code for FC is the value of the input carry Cin. The input
carry controls the arithmetic operations but has no effect on the logic and shift
operations. The last bit of the binary code is chosen to be 0 for the logic and shift
operations.
Table 10-8 gives a list of the status bits that have significance for each operation.
All four status bits are important after an arithmetic operation of add and subtract.
The other arithmetic and logic operations need only the sign and zero bits because
they do not produce a carry or overflow. (The increment operation produces a
carry at the same time that the number goes back to zero.) All shift operations
affect the carry status bit. The arithmetic shift left operation may produce an
overflow if the sign bit of the number changes after the shift. The status bits are
affected after an arithmetic or logic operation only if they are enabled by a special
code in the MS field. However, the carry bit is always updated with a shift operation
as indicated in Figure 10-3. It will be assumed that the overflow bit will be auto¬
matically updated with an arithmetic shift left operation.
MS Field
Table 10-9 gives the list of the microoperations that can be generated with the 4-
bit MS field. Note that this field is available in both microinstruction formats. When
used with type A format, the MS field specifies a microoperation that can be
generated simultaneously with the microoperation specified for the ALSU.
TABLE 10-8
ALSU Function Control
TABLE 10-9
Miscellaneous Microoperations
0000 —
No operation
0001 READ Enable READ flip-flop
0010 WRITE Enable WRITE flip-flop
0011 LIR Load IR from DIR
0100 SCF Set carry status flip-flop
0101 RCF Reset carry status flip-flop
0110 EST Enable to update the four status bits
0111 ECB Enable to update the C status bit
1000 ESZ Enable to update the S and Z status bits
1001 SEIF Set enable interrupt flip-flop
1010 REIF Reset enable interrupt flip-flop
1011 IACK Generate interrupt acknowledge (Figure 10-1)
The operation symbolized by the READ symbol sets a flip-flop to 1. The output
of this flip-flop provides the read signal for the memory unit. Thus, when the MS
field in the microinstruction is equal to 0001, the next clock pulse sets the READ
flip-flop and a read cycle is initiated. If the next microinstruction does not have
0001 in the MS field, the READ flip-flop is reset to 0 and the memory read cycle
terminates. Similarly, the WRITE operation produces a memory write cycle when
the corresponding WRITE flip-flop is set and then reset.
The operation symbolized by LIR is needed during the fetch phase. The instruc¬
tion read from memory into the data input register DIR is transferred to the
instruction register IR to be decoded by the control. The symbols SCF and RCF
cause the setting or resetting of the carry status bit. This is useful when it is required
to initialize the carry prior to a shift.
The MS field includes special conditions that enable the status bits in the pro¬
cessor to update them only when necessary. A microinstruction that specifies an
arithmetic operation in the ALSU can update all the status bits by including the
EST code in the MS field. If no status bits have to be updated, we must ensure
that none of the three MS codes equivalent to EST, ECB, or ESZ is used. ECB
updates only the carry bit and ESZ updates the sign and zero bits. The status bit
conditions listed in Table 10-8 are given only as a suggestion. It is up to the designer
who writes the microprogram to decide which status bits are to be updated after
each instruction.
Other operations that are specified with the MS field include the setting and
resetting of the EIF (enable interrupt flip-flop) and the generation of an interrupt
acknowledge signal to an external device.
ST and PS Fields
The jump or call microinstruction in type B format is used for branching to a
microinstruction out of sequence depending on a status bit condition. The status
bits available for testing are listed in Table 10-10. The symbol U is used for the
Section 10-6 Examples of Microinstructions 355
TABLE 10-10
Status Bits For Test Multiplexer
ST code 0000. This code, when applied to the select inputs of a multiplexer, makes
the output of the multiplexer always equal to 1. The symbols C, Z, S, and V are
for testing the status bits in the processor. Five bits from the instruction register
IR are available for inspection by the microprogram. These bits specify the ad¬
dressing modes of the instruction. Two status bits associated with the interrupt
cycle are available for detection. The output of the EIF flip-flop indicates whether
interrupts are allowed or prohibited. The interrupt input signal from external de¬
vices is checked by the control to find out if any interrupts are pending (see Figure
9-8).
The 1-bit field PS is associated with the ST field to determine the polarity of
the tested bit. We can either test the true or false value of the status bit by letting
PS be equal to 1 (symbolized by T) or to 0 (symbolized by F), respectively. If the
tested bit polarity is satisfied, control branches to the address specified by the li¬
bit AD field; otherwise, control continues with the next microinstruction in sequence.
For example, a jump on carry, if true, will branch to AD if C = 1 but will continue
with the next microinstruction if C = 0. A call on carry, if false, will branch to
the subroutine at the address given by the AD field if C = 0 but will continue with
next microinstruction if C = 1. An unconditional branch is achieved by specifying
T for the PS field and U for the ST field. This condition will always be true because
the status bit chosen with ST code of 0000 is always equal to 1.
TABLE 10-11
Examples of Symbolic Microinstructions
CS AS BS DS FC MS
Label CSBR PS ST AD MS Comments
The first six examples in the table have the symbols NEXT, RET, or MAP in
the CS field. These are the symbols used with the type A microinstruction format.
The CALL and JUMP symbols are used with the type B format. They are placed
under the common symbol CSBR since they belong to both the CS and BR fields.
Thus, a microinstruction is recognized as being of type A format if it has a symbolic
entry under the CS field. The other symbols of the microinstruction belong to fields
AS, BS, DS, FC, and MS. The type B microinstruction is recognized from the
symbol JUMP or CALL under the combined CSBR fields. The other fields are
PS, ST, AD, and MS.
The first microinstruction in the table specifies an ADD microoperation in the
ALSU and an EST (enable status bits) condition in the MS field. This updates all
four status bits C, Z, S, and V according to the sum produced in the output of the
ALSU. The second microinstruction performs an addition in the ALSU but the
status bits are not affected because the MS field is marked with a dash signifying
a no operation condition.
The third microinstruction has the symbol START in the label column. This is
a symbolic address that must also be present in the address field of a jump or call
microinstruction as shown in example 8. The microinstruction transfers the content
of R(S) (which is the processor register whose binary code is given by the source
field of the instruction) into the control source register SR. The BS field is not
used in this case and is marked with a dash. This is because the TSL (transfer)
operation acts with the A bus data of the ALSU and neglects any value in the B
bus.
The fourth example in the table shows a microinstruction that initiates a memory
read cycle. This is done by transferring the address into the address register AR
and setting the READ flip-flop to 1. The word read from memory at the address
given by AR is assumed to be available in the data input register DIR for use with
the next microinstruction in sequence.
Section 10-6 Examples of Microinstructions 357
The fifth and sixth microinstructions in the table show how to use the RET and
MAP conditions for type A format. The other fields of the microinstruction may
specify a microoperation for the ALSU or the MS field. If the DS field has the
symbol NONE, then no operation is performed in the processor unit. The MS field
performs no operation if it is marked with a dash.
The JUMP and CALL symbols are used with type B format. Example seven
shows a call subroutine microinstruction that branches to the address symbolized
by DEST if IR3 = 1. Example eight is an unconditional jump microinstruction
that also sets the WRITE flip-flop to initiate a memory write cycle. Example nine
shows a jump microinstruction that branches to the address symbolized by FETCE1
if the selected status bit is false, that is if EIF = 0. Note that the nine examples
in Table 10-11 do not constitute a meaningful microprogram. Each microinstruction
is independent of all others and is shown here only as an example for writing
symbolic microinstructions.
Binary Microinstructions
Symbolic microinstructions are convenient when writing microprograms in a way
that people can read and understand. But this is not the way that the microprogram
is stored in control memory. The symbolic microinstructions must be translated to
binary, either by means of a computer program called a microassembler or by the
user if the microprogram is simple. The conversion from a symbolic microinstruction
to its binary equivalent can be done using the encoding information listed in Figure
10-8(b).
Consider for example the first microinstruction in Table 10-11. It can be con¬
verted to binary as follows:
cs AS BS DS FC MS
NEXT SR DR DOR ADD EST
00 1001 1010 1101 00010 0110
The first line lists the symbolic names of the six fields of format A. The next line
gives the corresponding symbols used in the microinstruction. From Figure 10-8(b)
we extract the binary equivalent of each field to obtain the 23 bits of the binary
microinstruction.
The microinstruction in example 6 in Table 10-11 is converted to binary in a
similar fashion.
cs AS BS DS FC MS
MAP — NONE — —
The dashes in the AS, BS, and FC fields are assigned 0’s, although any other binary
value can be used since the information in these fields has no significance when
none of the registers are affected. The dash in the MS field must be converted into
0000 to indicate a “no operation.”
The microoperation in example 8 of Table 10-11 has a type B format. The
symbolic address START must be assigned an 11-bit binary address value. Assum-
358 Chapter 10 Design of a Central Processing Unit (CPU)
CSBR PS ST AD MS
JUMP T U START WRITE
110 1 0000 00000000011 0010
The T in the PS field converts to 1 and the START symbol converts to an 11-bit
address equivalent to binary 3. The total number of bits in the microinstruction
is 23.
Start
FIGURE 10-10
Computer Cycle
//? bit: 15 8 7 6 5 4 3 2 1 0
Operation = ADD
FIGURE 10-11
Type 0 ADD Instruction Format
360 Chapter 10 Design of a Central Processing Unit (CPU)
FIGURE 10-12
Microprogram Flowchart for Type 0 ADD Instruction
Interrupt Phase
The flowchart for the interrupt microprogram is shown in Figure 10-13. EIF (enable
interrupt flip-flop) is an internal flip-flop that can be set or reset by program
instructions or by the hardware. Only when this flip-flop is set to 1 will an interrupt
signal be acknowledged by the CPU. The interrupt signal is detected from the
presence of the status bit symbolized by INTS. If both EIF and INTS are equal to
1, the microprogram goes through an interrupt routine; otherwise it goes back to
fetch the next instruction. The external interrupt procedure is explained in Section
9-9 in conjunction with Figure 9-8.
The interrupt routine consists of pushing the return address from PC onto the
stack and resetting EIF to 0 to disable further interrupts (EIF can be set later by
the program). The interrupt acknowledge INTACK signal is sent to the external
device from which the device responds by placing an interrupt vector address on
the data bus. The content of the data bus in DIR is transferred into PC. Control
then goes to the fetch phase to start the interrupt service program at the vector
address.
It was mentioned in Section 9-9 that the current contents of the status bits must
be stored in the stack after an interrupt request. This can be done with an instruction
in the interrupt service program (see Problem 10-27).
FIGURE 10-13
Flowchart for Interrupt Microprogram
362 Chapter 10 Design of a Central Processing Unit (CPU)
TABLE 10-12
Symbolic Microprogram For One Computer Cycle
cs AS BS DS FC MS
Label CSBR PS ST AD MS Comments
Fetch instruction:
FETCH: NEXT PC AR TSF READ AR <- PC, Read
NEXT PC — PC INC LIR PC ^ PC + 1, IR <-
DIR
MAP — — NONE . — — Map operation code
Symbolic Microprogram
The symbolic microprogram for one computer cycle is listed in Table 10-12. The
FETCH and INTRPT routines are common to all cycles, but the instruction that
is executed depends on the operation code that is mapped into the control memory.
Here we assume a mapping of the type 0 ADD instruction. The microprogram
uses a subroutine symbolized by REGSRC to show how a subroutine is formulated
and terminated with a RET control sequence. A dash in a column indicates that
the field is not used.
The microprogram for the fetch phase follows the sequence dictated by the
flowcharts of Figure 10-10 and consists of three microoperations. The type 0 ADD
microroutine ADDT0 follows the flowchart of Figure 10-12. The source operand
Section 10-7 Microprogram for Computer Cycle 363
Binary Microprogram
The binary form of the microprogram is listed in Table 10-13. It is assumed that
the fetch phase starts from address 0 and the interrupt phase starts from address
64. The microroutine for each instruction will reside in a different part of control
memory as specified by the address that is mapped into CAR. Here we assume
that the routine for the type 0 ADD instruction starts from address 16. The binary
codes for the various fields are obtained from Figure 10-8(b). A dash in the symbolic
microprogram is converted to all 0’s. The binary values of each symbolic address
TABLE 10-13
Binary Microprogram
cs AS BS DS FC MS
Address cs BR PS ST AD MS
is determined from its position in the label column. The total number of bits in
each binary microinstruction is 23.
IR bits: 15 8 7 6 5 4 3 2 1 0
FIGURE 10-14
Type 1 ADD Instruction Format
Section 10-8 Microprogram Routines 365
FIGURE 10-15
Microprogram Flowchart for Type 1 ADD Instruction
If IR6 = 1, then SD = 01. The source operand is evaluated from the register
field and the destination operand is in memory. The indirect bit in IR3 determines
if the register has the operand or the address of the operand. In either case, the
source operand is transferred to SR. The microprogram then calls subroutine
MEMDST to fetch the destination operand from memory and place it in the
destination register DR. The address of the operand is available in AR. The two
operands are added and stored in memory. The microprogram jumps to the in¬
terrupt routine to check for interrupts.
Subroutine MEMSRC shown in Figure 10-16 reads the source operand from
memory and places it in the source register SR. The address in PC is transferred
to AR in order to read the memory word W and place it in DIR. PC is then
incremented by one. Bits IR5 and IRA of the MOD field are checked to determine
the addressing mode of the instruction. In the immediate mode, the operand W
which is now in DIR is transferred into SR. In the other three modes, DIR holds
the address field of the instruction. The effective address is computed and then
transferred to AR to read the operand. The subroutine exits with the source operand
in SR.
366 Chapter 10 Design of a Central Processing Unit (CPU)
FIGURE 10-16
Flowchart for MEMSRC Subroutine
Figure 10-17 shows the flowchart for subroutine MEMDST. It reads the desti¬
nation operand from memory and places it in the destination register DR. The
immediate mode is not used as a destination, and if the instruction uses it by
mistake, the microprogram treats it as a direct mode. The subroutine returns with
the address of the destination in register AR.
The symbolic microprogram can be obtained from the three flowcharts. It will
not be listed here but will be left as an exercise in the Problems section.
TABLE 10-14
Microprogram for Type 1 Increment Instruction
CS AS BS DS FC MS
Label CSBR PS ST AD MS Comments
in the address register AR. The number in DR is incremented and placed in DOR.
The operand in DOR is then written into memory at the address given by AR and
the microprogram jumps to check for interrupt.
If the bit in IR6 is equal to 1, then the SD field is equal to 11 and the operand
is evaluated from the register field R(D). This is done in the microprogram begin¬
ning from the microinstruction at the symbolic address REGINR. If IR3 = 0, the
operand in R(D) is incremented. If IR3 = 1, the instruction specifies a register-
indirect mode and the microprogram jumps to INDINR. The operand is read from
memory into DIR. It is then incremented and placed in DOR. The last micro¬
instruction writes the operand in memory and jumps to check for interrupt. Note
that the status bits S and Z are updated with this instruction.
CS AS BS DS FC MS
Label CSBR PS ST AD MS Comments
SP provides the address for the stack. The item on top of the stack is read from
memory and placed in DIR. The content of DIR is transferred into PC and SP is
incremented by one.
A careful study of the examples given in this section and the previous one should
be helpful for writing microroutines for other instructions. The problems at the
end of the chapter provide additional examples for writing microprogram routines.
Microprogram Sequencer
The block diagram of the microprogram sequencer together with the control mem¬
ory are shown in Figure 10-18. The control memory has 2048 words of 23 bits each
and requires an address of 11 bits. There are two multiplexers in the circuit. The
address multiplexer selects an address from one of four sources and routes it into
the control address register CAR. The new address loaded into CAR is then supplied
to the control memory for reading the next microinstruction. The status multiplexer
tests the value of a selected status bit and the result of the test is applied to an
address selection logic circuit. The output of CAR is incremented and applied to
one of the multiplexer inputs and to the subroutine register SBR. The other three
inputs to the address multiplexer come from the address field AD of the present
microinstruction, from the output of SBR, and from a mapping of the operation
code in IR.
The mapping PLD is a programmable logic device (see Section 6-6) with eight
inputs and 11 outputs. It maps or transforms the 8-bit operation code from its value
in IR(8-15) to an 11-bit control memory address. The value of the address is
determined from the microprogram routine that executes the instruction. For ex¬
ample, if the 8-bit operation code for the type 0 ADD instruction is 00001001 as
chosen in Table 10-2, and the microprogram routine that implements this instruction
starts from address 16 as shown in Table 10-13, the mapping PLD transforms the
8-bit operation code 00001001 to an 11-bit address 00000010000.
The incrementer circuit in the sequencer is not a counter with flip-flops but
rather a combinational circuit constructed with gates. The circuit can be designed
with 11 half adder circuits (see Figure 3-8) connected in cascaded stages. The output
carry from one stage is applied to the input of the next higher order stage. The
input carry in the first least significant stage must be equal to 1 to provide the
increment by one operation.
The ST field of the microinstruction selects one of the status bits from the inputs
of the status multiplexer. The polarity of the selected bit is determined from the
15 8
FIGURE 10-18
Microprogram Sequencer and Control Memory
bit value of the PS field. The exclusive-NOR gate produces an output of 1 if both
of its inputs are equal to 1 or if both of its inputs are equal to 0. Thus the output
of the gate is equal to 1 if the PS field bit is equal to the value of the selected
status bit.
The address selection logic in the sequencer has four inputs and three outputs.
The truth table for this circuit is shown in Table 10-16. Inputs D and C are identical
to the bit values of the CS field and input B is equal to the bit value of the BR
field. Input A receives the status of the selected bit from the status multiplexer.
The values for S1 and S0 are determined from the required path in the address
multiplexer. When CS is equal to 00, 01, or 10, inputs D and C go directly to
Section 10-9 Control Unit 371
TABLE 10-16
Truth Table for Address Selection Logic
Inputs Outputs
CS BR D C B A S1 S0 Load Address MUX selection
00 —
0 0 X X 0 0 0 Increment CAR (NEXT)
01 — 0 1 X X 0 1 0 Subroutine register (RET)
10 — 1 0 X X 1 0 0 Mapping of op-code (MAP)
11 0 1 1 0 0 0 0 0 Increment CAR
11 0 1 1 0 1 1 1 0 AD field (JUMP)
11 1 1 1 1 0 0 0 0 Increment CAR
11 1 1 1 1 1 1 1 1 AD field, load SBR (CALL)
outputs S1 and S0 and the other inputs of the address selection logic have no effect
on the address multiplexer. When CS is equal to 11, the selected input to the
address multiplexer depends on inputs B and A. When input A is equal to 0, it
means that the selected bit in the status multiplexer does not have the required
polarity. In this case, CAR is incremented by one. If input A is equal to 1, both
S1 and S0 must be equal to 1 in order to transfer the address field AD through the
address multiplexer. If input B is also equal to 1, it signifies a call subroutine
microinstruction, and the load input to the subroutine register SBR is activated.
The truth table from Table 10-16 can be used to obtain the simplified Boolean
functions for the address selection logic circuit. Using maps for the two functions
we obtain the following simplified Boolean equations:
= ACD + CD
S0 = ACD + CD
Load - ABCD
The combinational circuit has a common gate for the product term ACD. and
S0 can be implemented with three AND gates, two OR gates, and two inverters.
The condition for storing the return address in SBR is generated by the load signal
with an AND gate with inputs A, B, C, and D.
FIGURE 10-19
Decoding of a Type A Microinstruction
flops. These flip-flops are set to 1 when their D input is equal to 1 while a clock
pulse transition occurs. The outputs of the flip-flops generate the corresponding
read and write signals for the memory unit and also control the bidirectional bus
buffers in the data bus of the CPU (see Figure 10-5). When the D input of a flip-
flop is equal to 0, the next clock transition resets the output to 0.
The two fields AS and BS that select registers for the input buses of the ALSU
go through multiplexers as shown in Figure 10-20. The multiplexer associated with
Output from control memory
To MUX B
select inputs
in processor unit
of Figure 1 0-4
To MUX A
select inputs
in processor unit
of Figure 1 0-4
FIGURE 10-20
Selection of Registers in MUX A and MUX B of Processor Unit
374 Chapter 10 Design of a Central Processing Unit (CPU)
All these operations occur simultaneously with the same common clock pulse
transition. This is repeated for each clock pulse and each microinstruction that is
read from control memory.
REFERENCES
1. Mano, M. M., Computer System Architecture. 2nd ed. Englewood Cliffs: Prentice-Hall,
1982.
2. Tanenbaum A. S. Structured Computer Organization. 2nd ed. Englewood Cliffs: Pren¬
tice-Hall, 1984.
3. Lewin, M. H. Logic Design and Computer Organization. Reading, MA: Addison-
Wesley, 1983.
4. Hamacher, V. C., Vranesic, Z. G., and Zaky S. G. Computer Organization, 2nd
ed. New York: McGraw-Hill, 1984.
5. Prosser, F. and Winkel, D. The Art Digital Design. 2nd ed. Englewood Cliffs:
Prentice-Hall, 1987.
PROBLEMS
10-1 Draw the diagram of the shift left unit similar to Figure 10-3.
10-2 A bidirectional bus line with three-state buffers is shown in Figure 7-9. Using this
figure as a reference, show the construction of one line of the bidirectional data bus
buffer in the CPU block diagram of Figure 10-5.
Problems 375
10-3 Interpret the following hexadecimal instructions using Figure 10-7 and Table 10-2 as
reference. Express each instruction in symbolic form and in register transfer notation,
(a) 4A4B; (b) 0BC9; (c) 5E80; (d) 4B25
10-4 For each of the following symbolic instructions, specify the operation in register
transfer notation and give the corresponding hexadecimal code (see Table 10-2 and
Figure 10-7).
(a) SUB (R3), R5
(b) MOVE R3, (R0)
(c) MOVE #W, (Rl)
(d) PUSH W(X)
10-5 Evaluate the 4-digit hexadecimal code of the instruction that executes the following
operations (use Table 10-2 and Figure 10-7).
(a) R5 <- M[R2\
(b) M[W\ <- R3
(c) XR <- XR - 1
(d) PC <- M[SP], SP +-SP + 1
10-6 Repeat Table 10-4 using a register indirect mode with R2 as the selected register.
10-7 Each set of microoperations listed below can be specified with one microinstruction.
Choose the symbolic name and binary value from Figure 10-8(b) for the fields of the
microinstruction.
(a) DR «- R(D), CAR <- CAR + 1
(b) R0 <- R0 - 1, DIR <- M[AR\, CAR CAR + 1
(c) TR <r-ZR + NR, M[AR] <- DOR, CAR <- SBR
10-8 Convert each of the following 6-digit hexadecimal number to a 23-bit number. Let
the binary number obtained from the conversion be a microinstruction as defined in
Figure 10-8. Interpret the microinstruction and explain its operation.
(a) 1C1400; (b) 620000; (c) 334A26.
10-9 Table 10-7 lists a total of 17 registers in the three fields AS, BS, and DS.
(a) Identify the 14 registers inside the processor unit and the three registers that
communicate with memory.
(b) Identify the nine registers that can be changed by program instructions.
(c) Identify three registers used by the control for temporary storage.
(d) Give examples where registers ZR and NR can be used. Why is it that these two
registers are not listed under the DS field?
(e) What is the meaning of the symbols R(S), R(D), and NONE?
10-10 The NR register defined in Table 10-7 holds a constant for use in microprogram
loops. Give the microinstruction that will transfer the content of NR to the temporary
register TR for possible manipulation.
10-11 Modify the shift left circuit of Problem 10-1 by including the logic for updating the
overflow status bit V during an arithmetic shift left microoperation.
10-12 The carry flip-flop in the status register is updated from the following four sources:
(a) From AQ during a right shift (Figure 10-3).
(b) From A1S during a left shift (Problem 10-1).
(c) From the output carry Cout in the arithmetic unit when signals EST or ECB
(Table 10-9) are enabled in the MS field.
(d) From the SCF and RCF microoperations in the MS field.
Design the gate logic for the input of the carry flip-flop using a JK type flip-flop.
376 Chapter 10 Design of a Central Processing Unit (CPU)
10-13 Convert each of the nine symbolic microinstructions listed in Table 10-11 into a 23-
bit binary equivalent. Assume that DEST = 9, START = 3, and FETCH = 0.
10-14 Determine the time it takes to fetch and execute a type 0 ADD instruction by going
through the microprogram in Table 10-12. Assume that EIF = 1 but that there is
no external interrupt. Assume that each microinstruction takes t nanoseconds. Eval¬
uate the time for each of the four possible combinations of IR{1) and IR(3).
10-15 Write the symbolic microprogram for the type 1 ADD instruction from the infor¬
mation given in the flowchart of Figure 10-15.
10-16 Translate the microprogram listed in Table 10-14 into binary. Assume that the INR
routine starts from address 32 and that INTRPT is at 64.
10-17 Draw a flowchart for the INR microroutine whose symbolic microprogram is listed
in Table 10-14.
10-18 Write a microprogram for a type 0 MOVE instruction.
10-19 Write a microprogram for a type 1 MOVE instruction.
10-20 Write a microprogram for the PLTSH stack instruction. Use the type 1 format with
one operand. Note that all four modes are possible with the memory operand.
10-21 Write a microprogram for the type 1 NEGATE instruction. This instruction forms
the 2’s complement of the operand.
10-22 Write a microprogram for a type 2 CALL subroutine instruction.
10-23 Write a microprogram for the following type 2 instruction:
CALL subroutine if positive and non-zero
Assume that the S and Z status bits have been updated by a previous subtract
instruction.
10-24 Write a microprogram for the logical shift right instruction. Use the type 1 instruction
format (Figure 10-7) with two interpretations. When IR(7) = 1, the instruction has
one operand and produces a single shift. When IR{1) = 0, then the REG and / fields
of the instruction specify the operand to be shifted and W gives the number of times
to shift. In the single shift case, the microprogram checks the SD and MOD fields
to determine the operand. In the multiple shifts case, the SD and MOD fields are
not used.
10-25 Write a microprogram for type 0 unsigned MULTIPLY instruction. The source and
destination fields of the instruction specify the multiplier and multiplicand. The
double length product is always left in registers R0 and R1.
10-26 Modify the type 2 instruction format of Figure 10-7 to include a relative mode branch
instruction. This is done by using bit 13 of the instruction code to distinguish between
the two addressing modes. If bit 13 is equal to 0, the interpretation remains the same
as is shown in Figure 10-7, with W being the branch address. If bit 13 is equal to 1,
bits 8-12 of the instruction specify the operation code and bits 0-7 contain a signed
number in the range of +127 to -128 for the relative address. The second word W
is not used in the relative mode because the branch address is computed by adding
the contents of PC to the address field in IR(0-1) with sign extension. The sign
extension produces a 16-bit number with nine leading 0’s if the sign bit IR(7) = 0
or a 16-bit number with nine leading l’s if the sign bit IR( 7) = 1.
(a) Show any hardware addition that is needed in the CPU of Figure 10-5 to allow
the 16-bit signed number with sign extension to enter the processor unit. (Try a
multiplexer with IR and DIR as inputs going into the processor bus).
Problems 377
(b) What additions must be included in Table 10-9 and Table 10-10?
(c) Rewrite the two branch microprograms of Table 10-15 taking into account this
new modification of the type 2 format.
10-27 The hardware of the processor unit as defined in Section 10-3 does not have a data
path from the status bits to the memory unit. This path is necessary in order to push
the status bits onto the stack after an interrupt or a call to subroutine. Similarly, a
path must be provided to restore the status bits upon return from interrupt or sub¬
routine. Modify the hardware of the CPU and write the microprogram routines for
the instructions “push status bits” and “pop status bits.” (One way that the hardware
may be modified is to include two additional microoperations in Table 10-9 that
transfer the status bits to and from the temporary register 77?.)
10-28 Design the incrementer circuit shown in Figure 10-16 using 11 half adder circuits.
10-29 Derive the simplified Boolean functions for the address select logic from the truth
table listed in Table 10-16.
10-30 Change the exclusive-NOR gate in Figure 10-16 to an exclusive-OR gate. Make any
corrections in the entries of Table 10-18 to conform with this change and redesign the
address selection logic.
10-31 Why is it that the processor unit must be disabled when the two bits of the CS field
of the microinstruction are both equal to 1? Indicate how the hardware of the control
unit fulfills this requirement.
INPUT-OUTPUT
AND
COMMUNICATION
11-1 INTRODUCTION
The input and output subsection of a computer provides an efficient mode of
communication between the central processing unit (CPU) and the outside envi¬
ronment. Programs and data must be entered into computer memory for processing
and results obtained from computations must be recorded or displayed for the user.
Among the input and output devices that are commonly found in computer systems
are keyboards, display terminals, printers, and magnetic disks. Other input and
output devices encountered are magnetic tape drives, digital plotters, optical read¬
ers, analog-to-digital converters, and various data acquisition equipment. Com¬
puters can be used to control various processes such as machine tooling, assembly
line procedures, and industrial control.
The input and output facility of a computer is a function of its intended appli¬
cation. The difference between a small and large system is partially dependent on
the amount of hardware the computer has available for communicating with other
devices and the number of devices connected to the system. Since each device
behaves differently, it would be prohibitive to dwell on the detailed interconnections
needed between the computer and each device. However, there are certain tech¬
niques and procedures that are common to most devices.
In this chapter we present some of the common characteristics found in the
input-output subsystem of computers. The various techniques available for trans¬
ferring data either in parallel, using many conducting paths, or serially, through
communication lines, are presented. A description of the different types of transfer
modes is given, starting from a simple example of program control transfer to a
configuration of systems with multiple processors.
378
Section 11-2 Input-Output Interface 379
Data bus
■Address bus
Control
FIGURE 11-1
Connection of I/O Devices to CPU
into the computer. When the user depresses a key, the interface produces a binary
code corresponding to the particular alphanumeric character in the keyboard. The
most often used code is ASCII (American Standard Code for Information Inter¬
change: see Table 1-6).
The CRT (cathode ray tube) display is often used as an output device for graphics
or text entered from the keyboard and stored in computer memory. The CRT used
in computer displays are the same type as in television sets. The graphics or text
is displayed by positioning an electron beam in the tube and illuminating the surface
at the proper time.
The printer is a useful output device for producing hard copy. Some printers
print only one character at a time across a line. For faster printing, a high-speed
line printer that can print an entire line at once is employed.
Magnetic disks are used for bulk storage of programs and data. The disk has a
high-speed rotational surface which is coated with magnetic material. Access is
achieved by moving a read/write mechanism to a track in the magnetized surface.
When necessary, blocks of data are transferred to and from the disk and computer
memory.
In addition to communicating with the I/O devices, the CPU of a computer must
also communicate with the memory unit through an address and data bus. There
are three ways that external computer buses communicate with memory and I/O.
One method uses common data, address, and control buses for both memory and
I/O. This configuration is referred to as memory-mapped I/O. The common address
space is shared between the interface units and memory words, with each having
a distinct address. Computers that adopt the memory-mapped scheme read and
write from interface units as if they were assigned memory addresses.
The second alternative is to share a common address bus and data bus but use
different control lines for memory and I/O. Such computers have separate read
Section 11-2 Input-Output Interface 381
and write lines for memory and I/O. To read or write from memory, the CPU
activates the memory read or memory write control. To input or output from an
interface, the CPU activates the read I/O or write I/O control. In this way, the
address assigned to memory and I/O interface units are independent from each
other and are distinguished by separate control lines. This method is referred to
as the isolated I/O configuration.
The third alternative is to have two independent sets of data, address, and control
buses. This is possible in computers that include an I/O processor in the system in
addition to the CPU. The memory communicates with both the CPU and I/O
processor through a common memory bus. The I/O processor also communicates
with the input and output devices through separate address, data, and control lines.
The purpose of the I/O processor is to provide an independent pathway for the
transfer of information between external devices and internal memory. The I/O
processor is sometimes called a data channel.
FIGURE 11-2
Example of I/O Interface Unit
382 Chapter 11 Input-Output and Communication
The I/O data from the device can be transferred into either port A or port B.
The interface may operate with an output device or with an input device or with
a device that requires both input and output. If the interface is connected to a
printer, it will only output data; and if it services a card reader, it will only input
data. A magnetic tape unit transfers data in both directions but not at the same
time; so the interface can use only one set of I/O bidirectional data lines.
The control register receives control information from the CPU. By loading
appropriate bits into the control register, the interface and device can be placed
in a variety of operating modes. For example, port A may be defined as an input
port only. A magnetic tape unit may be instructed to rewind the tape or to start
the tape moving in the forward direction. The bits in the status register are used
for status conditions and for recording errors that may occur during the data
transfer. For example, a status bit may indicate that port A has received a new
data item from the device. Another bit in the status register may indicate that a
parity error has occurred during the transfer.
The interface registers communicate with the CPU through the bidirectional
data bus. The address bus selects the interface unit through the chip select input
and the two register select inputs. A circuit must be provided externally (usually
a decoder or a gate) to detect the address assigned to the interface registers. This
circuit enables the chip select (CS) input when the interface is selected by the
address bus. The two register select inputs RSI and RSO are usually connected to
the two least significant lines of the address bus. These two inputs select one of
the four registers in the interface as specified in the table accompanying the diagram.
The content of the selected register is transferred into the CPU via the data bus
when the I/O read signal is enabled. The CPU transfers binary information into
the selected register via the data bus when the I/O write input is enabled.
Handshaking
The control lines out of the interface may be used for a variety of applications
depending on the type of I/O device used. One important application of these lines
is to control the timing of data transfer between the I/O device and the interface.
Two units, such as an interface and the controller of the I/O device to which it is
attached, are designed with different control and clock generators and are said to
be asynchronous to each other. Asynchronous data transfer between two inde¬
pendent units requires that control signals be transmitted between the communi¬
cating units to indicate the time at which data is being transmitted. One method
commonly used is to accompany each data item being transferred with a control
signal that indicates the presence of data in the bus. The unit receiving the data
item responds with another control signal to acknowledge receipt of the data. This
kind of arrangement between two independent units is referred to as handshaking.
The basic principle of the two-wire handshaking procedure of data transfer is
as follows. One control line is in the same direction as the data flow in the bus
from the source to the destination. It is used by the source unit to inform the
destination unit that there is valid data on the bus. The other control line is in the
other direction from the destination to the source. It is used by the destination
Section 11-2 Input-Output Interface 383
unit to acknowledge the acceptance of data. In this way, each unit informs the
other unit of its status and the result is an orderly transfer through the bus.
Figure 11-3 shows the data transfer procedure. The I/O data bus carries binary
information from the source unit to the destination unit. Here we assume that the
interface is the source and the I/O device is the destination, but the same procedure
applies if the transfer is in the other direction. Typically, the bus has multiple data
lines to transfer a given number of bits at a time. The two handshaking lines are
data ready, generated by the source unit, and acknowledge, generated by the
destination unit. The timing diagram shows the exchange of signals between the
two units. The initial state is when both the data ready and acknowledge are disabled
Data valid
Data bus
0 1 1 0
Data ready
0 0 1 1
Acknowledge - ■»
FIGURE 11-3
Asynchronous Transfer Using Handshaking
384 Chapter 11 Input-Output and Communication
and in the 00 state. The subsequent states are 10, 11, and 01. The state sequence
shown in part (c) of the figure lists the events that occur as the transfer goes through
the four states. The source unit initiates the transfer by placing the data on the
bus and enabling its data ready signal. The acknowledge signal is activated by the
destination unit after it receives the data from the bus. The source unit disables
its data ready signal in response to the destination’s acknowledge. The destination
unit then disables its acknowledge signal and the system goes to the initial state.
The source does not send the next data item unless the destination unit shows its
readiness to accept new data by disabling its acknowledge line.
The handshaking scheme provides a high degree of flexibility and reliability
because the successful completion of a data transfer relies on active participation
by both units. If one unit is faulty, the data transfer will not be completed. Such
an error can be detected by means of a timeout mechanism, which produces an
alarm condition if the data transfer is not completed within a predetermined time
interval. The timeout is implemented by means of an internal clock that starts
counting time when the unit enables one of its handshaking control signals. If the
return handshake signal does not respond within a given time period, the unit
assumes that an error occurred. The timeout signal can be used to interrupt the
CPU and execute a service routine that takes appropriate error recovery action.
The transfer of data between two units may be performed in parallel or serial. In
parallel data transfer, each bit of the message has its own path and the total message
is transmitted at the same time. This means that an n-bit message is transmitted
in parallel through n separate conductor paths. In serial data transmission, each
bit in the message is sent in sequence, one at a time. This method requires the use
of one pair of conductors or one conductor and a common ground. Parallel trans¬
mission is faster but requires many wires. It is used for short distances and where
speed is important. Serial transmission is slower but less expensive since it requires
only one pair of conductors.
The way that computers and terminals remote from each other are connected
is via telephone lines and other public and private communication facilities. Since
telephone lines were originally designed for voice communication and computers
communicate in terms of digital signals, some form of conversion may be needed.
The converters are called data sets, acoustic couplers, or modems (from modulator-
demodulator). A modem converts digital signals into audio tones to be transmitted
over telephone lines and also converts audio tones from the line to digital signals
for computer use. Various modulation schemes as well as different grades of com¬
munication media and transmission speeds are used.
Serial data can be transmitted between two points in three different modes:
simplex, half-duplex, or full-duplex. A simplex line carries information in one
direction only. This mode is seldom used in data communication because the
receiver cannot communicate with the transmitter to indicate the occurrence of
errors. Examples of simplex transmission are radio and television broadcasting.
Section 11-3 Serial Communication 385
Asynchronous Transmission
One of the most common applications of serial transmission is for communication
with a keyboard and serial printer. Each character consists of an alphanumeric
code of eight bits with additional bits inserted at both ends of the character code.
In the serial asynchronous data transmission technique, each character consists of
three parts: the start bit, the character bits, and the stop bits. The convention is
for the transmitter to rest at the l-state when no characters are transmitted. The
first bit, called the start bit, is always 0 and is used to indicate the beginning of a
character. An example of this format is shown in Figure 11-4.
A transmitted character can be detected by the receiver from knowledge of the
transmission rules. When a character is not being sent, the line is kept in the 1-
state. The initiation of a character transmission is detected from the start bit, which
is always 0. The character bits always follow the start bit. After the last bit of the
Start Stop
Character bits
bit bits
FIGURE 11-4
Format of Asynchronous Serial Transfer
386 Chapter 11 Input-Output and Communication
character is transmitted, a stop bit is detected when the line returns to the 1-state
for at least one bit time. Using these rules, the receiver can detect the start bit
when the line goes from 1 to 0. A clock in the receiv€r examines the line at proper
bit times. The receiver knows the transfer rate of the bits and the number of
character bits to accept. After the character bits are transmitted, one or two stop
bits are sent. The stop bits are always in the 1-state and frame the end of character
to signify the idle or wait state.
At the end of the character, the line is held at the 1-state for a period of at least
1 or 2 bit times so that both the transmitter and receiver can resynchronize. The
length of time that the line stays in this state depends on the amount of time
required for the equipment to resynchronize. Some older electromechanical ter¬
minals use two stop bits but newer terminals use one stop bit. The line remains in
the 1-state until another character is transmitted. The stop time insures that a new
character will not follow for 1 or 2 bit times.
As an illustration, consider the serial transmission of a terminal with a transfer
rate of 10 characters per second. Each transmitted character consists of a start bit,
8 information bits, and 2 stop bits, for a total of 11 bits. Ten characters per second
means that each character takes 0.1 second for transfer. Since there are 11 bits to
be transmitted, it follows that the bit time is 9.09 msec. The baud rate is defined
as the rate at which serial information is transmitted and is equivalent to the data
transfer in bits per second. Ten characters per second with an 11-bit format has a
transfer rate of 110 baud.
The terminal has a keyboard and a printer. Every time a key is depressed, the
terminal sends 11 bits serially along a wire. To print a character in the printer, an
11-bit message must be received along another wire. The terminal interface consists
of a transmitter and a receiver. The transmitter accepts an 8-bit character from the
computer and proceeds to send a serial 11-bit message to the printer line. The
receiver accepts a serial 11-bit message from the keyboard line and forwards the
8-bit character code into the computer. Integrated circuits are available which are
specifically designed to provide the interface between computer and similar inter¬
active terminals.
Synchronous Transmission
Synchronous transmission does not use start-stop bits to frame characters. The
modems used in synchronous transmission have internal clocks that are set to the
frequency at which bits are being transmitted. For proper operation, it is required
that the clock of the transmitter and receiver modems remain synchronized at all
times. The communication line, however, carries only the data bits, from which
the clock information must be extracted. Frequency synchronization is achieved
by the receiving modem, from the signal transitions that occur in the received data.
Any frequency shift that may occur between the transmitter and receiver clocks is
continuously adjusted by maintaining the receiver clock at the frequency of the
incoming bit stream. In this way, the same rate is maintained in both the transmitter
and receiver.
Contrary to asynchronous transmission, where each character can be sent sep¬
arately with its own start and stop bits, synchronous transmission must send a
Section 11-3 Serial Communication 387
Character-Oriented Protocol
The character-oriented protocol is based on the binary code of a character set. The
code most commonly used is ASCII. It is a 7-bit code with an eighth bit for parity
check. The code has 128 characters, of which 95 are graphic characters and 33 are
control characters. The list of ASCII characters can be found in Table 1-6. The
control characters are used for the purpose of routing data, arranging the text in
the desired format, and for the layout of the printed page. The characters that
control the transmission are called communication control characters. These char¬
acters are listed in Table 11-1. Each character code has seven bits plus an even
parity bit. It is referred to by a three-letter symbol. The role of each character in
the control of data transmission is stated brieflv in the function column of the table.
The SYN character serves as synchronizing agent between the transmitter and
receiver. The 8-bit code 10010110 has the property that, upon circular shifting, it
does not repeat itself until after a full 8-bit cycle. When the transmitter starts
sending characters, it sends a few SYN characters first and then sends the actual
message. The initial continuous string of bits accepted by the receiver is checked
for a SYN character. In other words, with each clock period, the receiver checks
TABLE 11-1
ASCII Communication Control Characters
FIGURE 11-5
Typical Message Format for Character-Oriented Protocol
the last eight bits received. If they do not match the bits of the SYN character,
the receiver accepts the next bit, rejects the previous high-order bit, and again
checks the last eight bits received for a SYN character. This is repeated after each
clock period and bit received until a SYN character is recognized. Once a SYN
character is detected, the receiver has framed an 8-bit character. From here on,
the receiver counts every eight bits and accepts them as the next character. Usually,
the receiver checks two consecutive SYN characters to remove any doubt that the
first one did not occur as a result of a noise signal on the line. Moreover, when
the transmitter is idle and does not have any message characters to send, it sends
a continuous string of SYN characters. The receiver recognizes these characters as
a condition for synchronizing the line and goes into a synchronous idle state. In
this state, the two units maintain bit and character synchronism even though no
meaningful information is communicated.
Messages are transmitted through the data link with an established format con¬
sisting of a heading field, a text field, and an error checking field. A typical message
format for the character-oriented protocol is shown in Figure 11-5. The two SYN
characters assure proper synchronization at the start of the message. Following the
SYN characters is the heading, which starts with an SOH (start of heading) char¬
acter. The heading consists of an address and control information. The STX (start
of text) character terminates the heading and signifies the beginning of text trans¬
mission. The text portion of the message is variable in length and may contain any
ASCII characters except the communication control characters. The text field is
terminated with the ETX (end of text) character. The last field is a block check
character (BCC) used for error checking. It is usually either a longitudinal redun¬
dancy check (LRC) or a cyclic redundancy check (CRC). The LRC is an 8-bit
parity over all the characters of the message in the frame. It is the accumulation
of the exclusive-OR of all transmitted characters. The CRC is a polynomial code
obtained from the message bits by passing them through a feedback shift register
containing a number of exclusive-OR gates. This type of code is suitable for de¬
tecting burst errors occurring in the communication channel.
Bit-Oriented Protocol
The character-oriented protocol was originally developed to communicate with
keyboard, printer, and display devices that use alphanumeric characters exclusively.
As the data communication field expanded, it became necessary to transmit binary
information that is not ASCII text. This happens, for example, when two remote
computers send binary programs to each other over a communication channel. An
arbitrary bit pattern in the text field becomes a problem in the character-oriented
method. This is because any 8-bit pattern that corresponds to one of the com¬
munication control characters will be interpreted erroneously by the receiver.
Section 11-4 Modes of Transfer 389
FIGURE 11-6
Frame Format for Bit-Oriented Protocol
The protocol that has been mostly used to solve this problem is the bit-oriented
protocol.
The bit-oriented protocol is independent of any particular code. It allows the
transmission of a serial bit stream of any length without the implication of character
boundaries. Messages are organized in a specific format within a frame. In addition
to the information field, a frame contains address, control, and error checking
fields. The frame boundaries are determined from a special 8-bit number called a
flag.
The frame format of the bit-oriented protocol is shown in Figure 11-6. A frame
starts with the 8-bit flag 01111110 followed by an address and control sequence.
The information field is not restricted in format or content and can be of any length.
The frame check field is a CRC (cyclic redundancy check) sequence used for
detecting errors in transmission. The ending flag indicates to the receiver station
that the 16 bits just received are the CRC bits. The ending flag can be followed
by another frame or a sequence of flags or a sequence of consecutive l’s. When
two frames follow each other, the intervening flag is simultaneously the ending flag
of the first frame and the beginning flag of the next frame. If no information is
exchanged, the transmitter sends a series of flags to keep the line in the active
state. The line is said to be in the idle state with the occurrence of 15 or more
consecutive l’s. Frames with certain control messages are sent without information
fields. A frame must have a minimum of 32 bits between two flags to accommodate
the address, control, and the frame check fields. The maximum length depends on
the condition of the communication channel and its ability to transmit long messages
error-free.
To prevent a flag from occurring in the middle of a frame, the bit-oriented
protocol uses a method called zero insertion. This requires that a 0 be inserted by
the transmitting station after any succession of five consecutive l’s. The receiver
always removes a 0 that follows a succession of five l’s. In this way, the bit pattern
01111110 is transmitted as 011111010 when it does not signify a flag. The received
sequence is restored to its original value by the removal of the 0 following the five
l’s. As a consequence, no pattern 01111110 is ever transmitted between the be¬
ginning and ending flags.
instructions and may accept the data temporarily, but the ultimate source or des¬
tination is the memory unit. Data transfer between the central computer and I/O
devices may be handled in a variety of modes. Some modes use the CPU as an
intermediate path; others transfer the data directly to and from the memory unit.
Data transfer to and from peripherals may be handled in one of four possible
modes:
Program controlled operations are the result of I/O instructions written in the
computer program. Each data item transfer is initiated by an instruction in the
program. Usually, the transfer is to and from a CPU register and peripheral. Other
instructions are needed to transfer the data to and from the CPU and memory.
Transferring data under program control requires constant monitoring of the pe¬
ripheral by the CPU. Once a data transfer is initiated, the CPU is required to
monitor the interface to see when a transfer can again be made. It is up to the
programmed instructions executed in the CPU to keep close tabs on everything
that is taking place in the interface unit and the external device.
In the program controlled transfer, the CPU stays in a program loop until the
I/O unit indicates that it is ready for data transfer. This is a time consuming process
since it keeps the processor busy needlessly. It can be avoided by using an interrupt
facility and special commands to inform the interface to issue an interrupt request
signal when the data are available from the device. The CPU can proceed to execute
another program. The interface, meanwhile, keeps monitoring the device. When
the interface determines that the device is ready for data transfer, it generates an
interrupt request to the computer. Upon detecting the external interrupt signal,
the CPU momentarily stops the task it is processing, branches to a service program
to process the data transfer, and then returns to the task it was originally performing.
Transfer of data under program control is through the I/O bus and between the
CPU and a peripheral. In direct memory access (DMA), the interface transfers
data into and out of the memory unit through the memory bus. The CPU initiates
the transfer by supplying the interface with the starting address and the number
of words needed to be transferred, and then proceeds to execute other tasks. When
the transfer is made, the interface requests memory cycles through the memory
bus. When the request is granted by the memory controller, the interface transfers
the data directly into memory. The CPU merely delays its operation to allow the
direct memory I/O transfer. Since peripheral speed is usually slower than processor
speed, I/O memory transfers are infrequent compared to processor access to mem¬
ory. DMA transfer is discussed in more detail in Section 11-6.
Many computers combine the interface logic with the requirements for direct
memory access into one unit and call it an I/O processor (IOP). The IOP can
handle many peripherals through a DMA and interrupt facility. In such a system,
the computer is divided into three separate modules: the memory unit, the CPU,
and the IOP. I/O processors are presented in Section 11-7.
FIGURE 11-7
Data Transfer from Device to CPU
391
392 Chapter 11 Input-Output and Communication
FIGURE 11-8
Flowchart for CPU Program to Input
Data
flag. However, when the flag is set, the computer is momentarily interrupted from
proceeding with the current program and is informed of the fact that the flag has
been set. The CPU deviates from what it is doing to take care of the input or
output transfer. After the transfer is completed, the computer returns to the pre¬
vious program to continue what it was doing before the interrupt.
The CPU responds to the interrupt signal by storing the return address from
the program counter into a memory stack and then control branches to a service
routine that processes the required I/O transfer. The way that the processor chooses
the branch address of the service routine varies from one unit to another. In
principle, there are two methods for accomplishing this. One is called vectored
interrupt and the other nonvectored interrupt. In a nonvectored interrupt, the branch
address is assigned to a fixed location in memory. In a vectored interrupt, the
source that interrupts supplies the branch information to the computer. This in¬
formation is called the vector address. In some computers the vector address is the
Section 11-5 Priority Interrupt 393
first address of the service routine. In other computers, the vector address is an
address that points to a location in memory where the first address of the service
routine is stored. The vectored interrupt procedure is presented in Section 9-9 in
conjunction with Figure 9-8.
A typical computer has a number of I/O devices attached to it with each device
being able to originate an interrupt request. The first task of the interrupt system
is to identify the source of the interrupt. There is also the possibility that several
sources will request service simultaneously. In this case, the system must also decide
which device to service first.
A priority interrupt is a system that establishes a priority over the various sources
to determine which condition is to be serviced first when two or more requests
arrive simultaneously. The system may also determine which conditions are per¬
mitted to interrupt the computer while another interrupt is being serviced. Higher
priority interrupt levels are assigned to requests which, if delayed or interrupted,
could have serious consequences. Devices with high speed transfers such as mag¬
netic disks are given high priority and slow devices such as keyboards receive the
lowest priority. When two devices interrupt the computer at the same time, the
computer services the device with the higher priority first.
Establishing the priority of simultaneous interrupts can be done by software or
hardware. A polling procedure is used to identify the highest priority source by
software means. In this method, there is one common branch address for all in¬
terrupts. The program that takes care of interrupts begins at the branch address
and polls the interrupt sources in sequence. The order in which they are tested
determines the priority of each interrupt. The highest priority source is tested first
and if its interrupt signal is on, control branches to a service routine for this source.
Otherwise, the next lower priority source is tested, and so on. Thus, the initial
service routine for all interrupts consists of a program that tests the interrupt sources
in sequence and branches to one of many possible service routines. The particular
service routine reached belongs to the highest priority device among all devices
that interrupted the computer. The disadvantage of the software method is that if
there are many interrupts, the time required to poll them can exceed the time
available to service the I/O device. In this situation, a hardware priority interrupt
unit can be used to speed up the operation.
A hardware priority interrupt unit functions as an overall manager in an interrupt
system environment. It accepts interrupt requests from many sources, determines
which of the incoming requests has the highest priority, and issues an interrupt
request to the computer based on this determination. To speed up the operation,
each interrupt source has its own interrupt vector address to access directly its own
service routine. Thus, no polling is required because all the decisions are established
by the hardware priority interrupt unit. The hardware priority function can be
established either by a serial or parallel connection of interrupt lines. The serial
connection is also known as the daisy chain method.
394 Chapter 11 Input-Output and Communication
FIGURE 11-9
Daisy Chain Priority Interrupt
VAD
PI
Priority in
Enable
_ _ 1
Vector address
Priority out
Interrupt RF -PO
c
request u
from device
Delay
PI RF PO Enable
Open collector
inverter 0 0 0 0
0 1 0 0
1 0 1 0
1 1 0 1
FIGURE 11-10
One Stage of the Daisy Chain Priority Arrangement
open-collector inverter, a circuit that provides the wired logic for the common
interrupt line. If PI = 0, both PO and the enable line to VAD are equal to 0,
irrespective of the value of RF. If PI = 1 and RF = 0, then PO = 1 and the
vector address is disabled. This condition passes the acknowledge signal to the next
device through PO. The device is active when PI — 1 and RF = 1. This condition
places a 0 in PO and enables the vector address for the data bus. It is assumed
that each device has its own distinct vector address. The RF flip-flop is reset after
a sufficient delay to ensure that the CPU has received the vector address.
395
Interrupt
Interrupt
acknowledge
register
from CPU
Highest
priority
Lowest
priority
Mask
register VAD
Interrupt
to CPU
FIGURE 11-11
Priority Interrupt Hardware
The priority encoder is a circuit that implements the priority function. The logic
of the priority encoder is such that, if two or more inputs occur at the same time,
the input having the highest priority takes precedence. The circuit of a four-input
priority encoder can be found in Section 3-6 and its truth table is listed in Table
3-8. Input D3 has the highest priority, and so regardless of the values of other
inputs, when this input is 1, the output is AXA0 — 11. D2 has the next priority
level. The output is 10 if D2 = 1 provided that D3 = 0, regardless of the values
of the other two lower priority inputs. The output is 01 when Dx = 1 provided the
two higher priority inputs are equal to 0; and so on down the priority levels. The
interrupt output labeled V is equal to 1 when one or more inputs are equal to 1.
If all inputs are 0, V is 0 and the other two outputs of the encoder are not used.
This is because the vector address is not transferred to the CPU when V = 0.
The output of the priority encoder is used to form part of the vector address
for the interrupt source. The other bits of the vector address can be assigned any
values. For example, the vector address can be formed by appending six zeros to
the outputs of the encoder. With this choice the interrupt vector for the four
I/O devices are assigned the 8-bit binary numbers equivalent to decimal 0, 1,2,
and 3.
The transfer of data between a fast storage device such as magnetic disk and memory
is often limited by the speed of the CPU. Removing the CPU from the path and
letting the peripheral device manage the memory buses directly would improve the
speed of transfer. This transfer technique is called direct memory access (DMA).
During DMA transfer, the CPU is idle and has no control of the memory buses.
396
Section 11-6 Direct Memory Access (DMA) 397
~\
AB
Bus request - BR
DB *»■ » Data bus High-impedance
CPU > (disabled)
Bus granted * BG RD if BG = 1
WR
J
FIGURE 11-12
CPU Bus Control Signals
A DMA controller takes over the buses to manage the transfer directly between
the I/O device and memory.
The CPU may be placed in an idle state in a variety of ways. One common
method extensively used in microprocessors is to disable the buses through special
control signals. Figure 11-12 shows two control signals in a CPU that facilitate the
DMA transfer. The bus request (BR) input is used by the DMA controller to
request from the CPU to relinquish control of the buses. When this input is active,
the CPU terminates the execution of its present instruction and places the address
bus, the data bus, and the read and write lines into a high-impedance state. After
this is done, the CPU activates the bus granted (BG) output to inform the external
DMA that it can take control of the buses. As long as the BG line is active, the
CPU is idle and the buses are disabled. When the bus request input is disabled by
the DMA, the CPU returns to its normal operation, disables the bus granted output,
and takes control of the buses.
When the bus granted line is enabled, the external DMA controller takes control
of the bus system to communicate directly with the memory. The transfer can be
made for an entire block of memory words, suspending the CPU operation until
the entire block is transferred. This is referred to as burst transfer. The transfer
can be made one word at a time between CPU instruction executions. Such transfer
is called single cycle or cycle stealing. The CPU merely delays its operation for one
memory cycle to allow the direct memory I/O transfer to steal one memory cycle.
DMA Controller
The DMA controller needs the usual circuits of an interface to communicate with
the CPU and I/O device. In addition, it needs an address register, a word count
register, and a set of address lines. The address register and address lines are used
for direct communication with the memory. The word count register specifies the
number of words that must be transferred. The data transfer may be done directly
between the device and memory under control of the DMA.
Figure 11-13 shows the block diagram of a typical DMA controller. The unit
communicates with the CPU via the data bus and control lines. The registers in
the DMA are selected by the CPU through the address bus by enabling the DS
(DMA select) and RS (register select) inputs. The RD (read) and WR (write) inputs
are bidirectional. When the BG (bus granted) input is 0, the CPU can communicate
with the DMA registers through the data bus to read from or write to the DMA
registers. When BG = 1, the CPU has relinquished the buses and the DMA can
communicate directly with the memory by specifying an address in the address bus
398 Chapter 11 Input-Output and Communication
FIGURE 11-13
Block Diagram of a DMA Controller
and activating the RD or WR control. The DMA communicates with the external
peripheral through the request and acknowledge lines by using a prescribed hand¬
shaking procedure.
The DMA controller has three registers: an address register, a word count
register, and a control register. The address register contains an address to specify
the desired location in memory. The address bits go through bus buffers into the
address bus. The address register is incremented after each word is transferred to
memory. The word count register holds the number of words to be transferred.
This register is decremented by one after each word transfer and internally tested
for zero. The control register specifies the mode of transfer. All registers in the
DMA appear to the CPU as I/O interface registers. Thus, the CPU can read from
or write to the DMA registers under program control via the data bus.
The DMA is first initialized by the CPU. After that, the DMA starts and
continues to transfer data between memory and peripheral unit until an entire
block is transferred. The initialization process is essentially a program consisting
of I/O instructions that include the address for selecting particular DMA registers.
The CPU initializes the DMA by sending the following information through the
data bus:
1. The starting address of the memory block where data are available (for read)
or where data are to be stored (for write)
2. The word count, which is the number of words in the memory block.
3. Control to specify the mode of transfer such as read or write.
4. A control to start the DMA transfer.
The starting address is stored in the address register. The word count is stored in
the word count register, and the control information in the control register. Once
Section 11-6 Direct Memory Access (DMA) 399
the DMA is initialized, the microprocessor stops communicating with the DMA
unless it receives an interrupt signal or if it wants to check how many words have
been transferred.
DMA Transfer
The position of the DMA controller among the other components in a computer
system is illustrated in Figure 11-14. The CPU communicates with the DMA through
the address and data buses as with any interface unit. The DMA has its own address
which activates the DS and RS lines. The CPU initializes the DMA through the
data bus. Once the DMA receives the start control bit, it can start the transfer
between the peripheral device and the memory.
When the peripheral device sends a DMA request, the DMA controller activates
the BR line, informing the CPU to relinquish the buses. The CPU responds with
its BG line, informing the DMA that its buses are disabled. The DMA then puts
the current value of its address register onto the address bus, initiates the RD or
WR signal, and sends a DMA acknowledge to the peripheral device.
FIGURE 11-14
DMA Transfer in a Computer System
400 Chapter 11 Input-Output and Communication
When the peripheral device receives a DMA acknowledge, it puts a word in the
data bus (for write) or receives a word from the data bus (for read). Thus, the
DMA controls the read or write operations and supplies the address for the mem¬
ory. The peripheral unit can then communicate with memory through the data bus
for direct transfer between the two units while the CPU is momentarily disabled.
For each word that is transferred, the DMA increments its address register and
decrements its word count register. If the word count does not reach zero, the
DMA checks the request line coming from the peripheral. For a high speed device,
the line will be activated as soon as the previous transfer is completed. A second
transfer is then initiated, and the process continues until the entire block is trans¬
ferred. If the peripheral speed is slower, the DMA request line may come somewhat
later. In this case, the DMA disables the bus request line so the CPU can continue
to execute its program. When the peripheral requests a transfer, the DMA requests
the buses again.
If the word count reaches zero, the DMA stops any further transfer and removes
its bus request. It also informs the CPU of the termination by means of an interrupt.
When the CPU responds to the interrupt, it reads the content of the word count
register. The zero value of this register indicates that all the words were successfully
transferred. The CPU can read this register at any time, as well check the number
of words already transferred.
A DMA controller may have more than one channel. In this case, each channel
has a request and acknowledge pair of control signals that are connected to separate
peripheral devices. Each channel also has its own address register and word count
register within the DMA controller. A priority among the channels may be estab¬
lished so that channels with high priority are serviced before channels with lower
priority.
DMA transfer is very useful in many applications. It is used for fast transfer of
information between magnetic disks and memory. It is also useful for updating the
display in an interactive terminal. Typically, an image of the screen display of the
terminal is kept in memory which can be updated under program control. The
contents of the memory can be transferred to the screen periodically by means of
DMA transfer.
Instead of having each interface communicate with the CPU, a computer may
incorporate one or more external processors and assign them the task of com¬
municating directly with all I/O devices. An input-ouput processor (IOP) may be
classified as a processor with direct memory access capability that communicates
with I/O devices. In this configuration, the computer system can be divided into a
memory unit, and a number of processors comprised of the CPU and one or more
IOPs. Each IOP takes care of input and output tasks, relieving the CPU of the
housekeeping chores involved in I/O transfers. A processor that communicates with
remote terminals over telephone and other communication media in a serial fashion
is called a data communication processor (DCP).
Section 11-7 Multiple Processor Systems 401
FIGURE 11-15
Block Diagram of a Computer with I/O Processor
operates independent of the CPU and continues to transfer data from external
devices and memory.
The data formats of peripheral devices differ from memory and CPU data for¬
mats. The IOP must structure data words from many different sources. For ex¬
ample, it may be necessary to take four bytes from an input device and pack them
into one 32-bit word before the transfer to memory. Data are gathered in the IOP
at the device rate and bit capacity while the CPU is executing its own program.
After the input data is assembled into a memory word, it is transferred from IOP
directly into memory by stealing one memory cycle from the CPU. Similarly, an
output word transferred from memory to the IOP is directed from the IOP to the
output device at the device rate and bit capacity.
The communication between the IOP and the devices attached to it is similar
to the program control method of transfer. Communication with the memory is
similar to the direct memory access method. The way by which the CPU and IOP
communicate depends on the level of sophistication included in the system. In very
large scale computers, each processor is independent of all others and any one
processor can initiate an operation. In most computer systems, the CPU is the
master, while the IOP is a slave processor. The CPU is assigned the task of initiating
all operations but I/O instructions are executed in the IOP. CPU instructions
provide operations to start an I/O transfer and also to test I/O status conditions
needed for making decisions on various I/O activities. The IOP, in turn, typically
asks for CPU attention by means of an interrupt. It also responds to CPU requests
by placing a status word in a prescribed location in memory to be examined later
by a CPU program. When an I/O operation is desired, the CPU informs the IOP
where to find the I/O program and then leaves the transfer details to the IOP.
Instructions that are read from memory by an IOP are sometimes called com¬
mands, to distinguish them from instructions that are read by the CPU. An in¬
struction and a command have similar functions. Commands are prepared by ex¬
perienced programmers and are stored in memory. The command words constitute
the program for the IOP. The CPU informs the IOP where to find the commands
in memory when it is time to execute the I/O program.
The communication between CPU and IOP may take different forms depending
on the particular computer considered. In most cases, the memory unit acts as a
message center where each processor leaves information for the other. To appre¬
ciate the operation of a typical IOP, we will illustrate, by a specific example, the
method by which the CPU and IOP communicate. This is a simplified example
that omits many operating details in order to provide an overview of basic concepts.
Section 11-7 Multiple Processor Systems 403
Continue
FIGURE 11-16
CPU-IOP Communication
404 Chapter 11 Input-Output and Communication
to the CPU. The CPU responds to the interrupt by issuing an instruction to read
the status from the IOP. The IOP responds by placing the contents of its status
report into a specified memory location. The status word indicates whether the
transfer has been completed or if any errors occurred during the transfer. From
inspection of the bits in the status word, the CPU determines if the I/O operation
was completed satisfactorily, without errors.
The IOP takes care of all data transfers between several I/O units and memory
while the CPU is processing another program. The IOP and CPU compete for the
use of memory so the number of devices that can be in operation is limited by the
access time of the memory. It is not possible to saturate the memory by I/O devices
in most systems, as the speed of most devices is much slower than the CPU.
However, some very fast units, such as magnetic disks, can use an appreciable
number of the available memory cycles. In that case, the speed of the CPU may
deteriorate because it will often have to wait for the IOP to conduct memory
transfers.
FIGURE 11-17
Time Shared Common Bus Multiple Processor Organization
Local bus
Common
shared
memory
System bus
FIGURE 11-18
Dual-Bus Structure for Multiple Processors
A single common bus is restricted to one transfer at a time. This means that
when one processor is communicating with the memory, all other processors are
either busy with internal operations or must be idle waiting for the bus. The
processors in the system can be kept busy more often through the implementation
of a dual-bus structure as depicted in Figure 11-18. Here we have a number of
local buses, each connected to its own local memory and to one or more processors.
Each local bus may be connected to a CPU, an IOP, or any combination of
processors. A system bus controller links each local bus to a common system bus.
The memory connected to the common system bus is shared by all processors. If
an IOP is connected directly to a system bus. The I/O devices attached to it may
be made available to all processors. Only one processor can communicate with the
shared memory and other common resources through the system bus at any given
time. The other processors are kept busy communicating with their local memory
and I/O devices.
Although the system shown in Figure 11-18 qualifies as a multiple processor
system it can be classified more correctly as a multiple computer system. This is
because a CPU, IOP, and memory, when connected together with a local bus,
constitute a computer system in their own right. This type of multiple processor
organization is the one most commonly employed in the design of multiple micro¬
processor systems.
Interprocessor Communication
The various processors in a multiple processor system must be provided with a
facility for communicating with each other. The most common procedure is to set
aside a portion of memory which is accessible to all processors. The primary use
of the common memory is to act as a message center similar to a mailbox, where
each processor can leave messages for other processors and pick up messages
intended for it.
The sending processor structures a request, a message, or a procedure, and
405
406 Chapter 11 Input-Output and Communication
places it in the memory mailbox. Status bits residing in common memory are
generally used to indicate the condition of the mailbox, whether it contains mean¬
ingful information and for which processor intended. The receiving processor can
check the mailbox periodically to determine if there are valid messages for it. The
response time of this procedure can be time consuming, since a processor will
recognize a request only when it performs the polling of messages. A more efficient
procedure is for the sending processor to alert the receiving processor directly by
means of an interrupt signal. This can be accomplished through a software initiated
interprocessor interrupt. It is done by an instruction in the program of one processor
which when executed, produces an external interrupt condition in a second proc¬
essor. This alerts the interrupted processor of the fact that a new message was
inserted by the interrupting processor.
In addition to shared memory, a multiple processor system may have other
shared resources. For example, a magnetic disk storage unit connected to an IOP
may be available to all CPUs. This provides a facility for sharing of system programs
stored in the disk. A communication path between two CPUs also can be established
through a link between two IOPs associated with two different CPUs. This type
of link allows each CPU to treat the other as an I/O device so that messages can
be transferred through the I/O path.
Each processor in a multiple processor system must request access to common
memory and other shared resources through a common bus system. If no other
processor is currently using the common bus, the requesting processor may be
granted access immediately. However, the requesting processor must wait if another
processor is currently using the system bus. Furthermore, other processors may
request the system bus at the same time. Arbitration must be performed to resolve
this multiple contention for the shared resources. Arbitration procedures service
all processor requests on the basis of established priority. The bus arbitration
technique bears a strong resemblance to the interrupt priority logic discussed in
Section 11-5.
A multiple processor system is considered to be a tightly coupled system. This
is characteristic of a system that has all its major components (such as CPU, IOP,
and I/O devices) in close proximity. Computers that are interconnected with each
other by means of remote communication lines form a computer network. The
computers in the network may be close to each other or in geographically remote
locations. Synchronous serial transfer is employed to send messages between the
computers. Data and control are transmitted in packets and each packet follows a
prescribed communication protocol. The distinction that is made between a tightly
coupled computer system and a computer network is that the former uses shared
memory to communicate between the processors. The computers in a network
communicate with each other in a serial fashion through a communication medium.
REFERENCES
1. Mano, M. M. Computer System Architecture. 2nd ed. Englewood Cliffs: Prentice-Hall,
1982.
2. Lippiatt, A. G. and Wright, G. L. The Architecture of Small Computer Systems.
2nd ed. Englewood Cliffs: Prentice-Hall, 1985.
Problems 407
PROBLEMS
11-1 The addresses assigned to the four registers of the I/O interface of Figure 11-2 are
equal to the binary equivalent of 12, 13, 14, and 15. Show the external circuit that
must be connected between an 8-bit I/O address from the CPU and the CS, RSO,
and RSI inputs of the interface.
11-2 Six interface units of the type shown in Figure 11-2 are connected to a CPU that
uses an I/O address of eight bits. Each one of the six chip select (CS1) inputs is
connected to a different address line. Thus, the high-order address line is connected
to the CS input of the first interface unit and the sixth address line is connected to
the CS input of the sixth interface unit. The two low-order address lines are connected
to the RSI and RSO of all six interface units. Determine the 8-bit address of each
register in each interface. (Total of 24 addresses.)
11-3 Derive a timing diagram and a sequence of events flow chart (as in Figure 11-3) for
a transfer from the I/O device into the interface unit assuming that the interface
initiates the transfer with a request handshake line. The other handshake is a data
ready line from the device to the interface.
11-4 A commercial interface unit uses different names for the handshake lines associated
with the transfer of data from the I/O device into the interface unit. The interface
input handshake line is labeled STB (strobe), and the interface output handshake
line is labeled IBF (input buffer full). A low-level signal on STB loads data from the
I/O bus into the interface data register. A high-level signal on IBF indicates that the
data item has been accepted by the interface. IBF goes low after an I/O read signal
from the CPU when it reads the contents of the data register.
(a) Draw a block diagram showing the CPU, the interface, and the I/O device along
with the pertinent interconnections between the three units.
(b) Draw a timing diagram for the handshaking transfer.
(c) Obtain a sequence of events flowchart for the transfer from the device to the
interface and from the interface to the CPU.
11-5 How many characters per second can be transmitted over a 1200-baud line in each
of the following modes? (Assume a character code of eight bits.)
(a) Synchronous serial transmission.
(b) Asynchronous serial transmission with two stop bits.
(c) Asynchronous serial transmission with one stop bit.
11-6 The address of a terminal connected to a data communication processor consists of
two letters of the alphabet or a letter followed by one of the 10 numerals. How many
different addresses can be formulated?
11-7 Sketch the timing diagram of the eleven bits (similar to Figure 11-4) that are trans¬
mitted over an asynchronous serial communication line when the ASCII letter C is
transmitted with even parity.
408 Chapter 11 Input-Output and Communication
11-8 What is the difference between synchronous and asynchronous serial transfer of
information?
11-9 What is the minimum number of bits that a frame must have in the bit-oriented
protocol?
11-10 Show' how the zero insertion works in the bit-oriented protocol when a zero followed
by the 10 bits that represent the binary equivalent of 1023 is transmitted.
11-11 Show the block diagram (similar to Figure 11-7) for the data transfer from the CPU
to the interface and then to the I/O device. Determine a procedure for setting and
clearing the flag bit.
11-12 Using the configuration established in Problem 11-11, obtain a flowchart (similar to
Figure 11-8) for the CPU program to output data.
11-13 What is the basic advantage of using interrupt initiated data transfer over transfer
under program control without an interrupt?
11-14 What happens in the daisy chain priority interrupt shown in Figure 11-9 when device
1 requests an interrupt after device 2 has sent an interrupt request to the CPU but
before the CPU responds with the interrupt acknowledge?
11-15 Consider a computer without priority interrupt hardware. Any one of many sources
can interrupt the computer and any interrupt request results in storing the return
address and branching to a common interrupt routine. Explain how a priority can
be established in the interrupt service program.
11-16 What should be done in Figure 11-11 to make the four VAD values equal to the
binary equivalent of 76, 77, 78, and 79?
11-17 Design a parallel priority interrupt hardware for a system with eight interrupt sources.
11-18 (a) Obtain the truth table of an 8 x 3 priority encoder.
(b) The three outputs x, y, z, from the priority encoder are used to provide an 8-
bit vector address in the form lOlxyzOO. List the eight addresses starting from
the one with the highest priority.
11-19 Why are the read and write control lines in a DMA controller bidirectional? Under
what condition and for what purpose are they used as inputs? Under what condition
and for what purpose are they used as outputs?
11 -20 It is necessary to transfer 256 words from a magnetic disk to a memory section starting
from address 1230. The transfer is by means of the DMA as shown in Figure 11-14.
(a) Give the initial values that the CPU must transfer to the DMA controller.
(b) Give the step-by-step account of the actions taken during the input of the first
two words.
11-21 What is the purpose of the system bus controller in Figure 11-18? Explain how the
system can be designed to distinguish between references to local memory and ref¬
erences to commonly shared memory.
MEMORY
MANAGEMENT
409
410 Chapter 12 Memory Management
in a typical memory hierarchy. At the bottom of the hierarchy are the relatively
slow magnetic tapes used to store removable files. Next are the magnetic disks
used as backup storage. The main memory occupies a central position by being
able to communicate directly with the CPU and with auxiliary memory devices
through an I/O processor. When programs not residing in main memory are needed
by the CPU, they are brought in from auxiliary memory. Programs not currently
needed in main memory are transferred into auxiliary memory to provide space
for currently used programs and data.
A special very high speed memory is sometimes used to increase the speed of
processing by making current programs and data available to the CPU at a rapid
rate. The cache memory included in Figure 12-1 is employed in computer systems
to compensate for the speed differential between main memory access time and
processor logic. Processor logic is usually faster than main memory access time
with the result that processing speed is mostly limited by the speed of main memory.
A technique used to compensate for the mismatch in operating speeds is to employ
an extremely fast, small memory between the CPU and main memory with an
access time close to processor logic propagation delays. This type of memory is
called a cache memory. It is used to store segments of programs, currently being
executed in the CPU, and temporary data, frequently needed in the calculations.
By making programs and data available at a rapid rate, it is possible to increase
the performance rate of the processor. The organization of cache memories is
presented in Section 12-4.
In a computer system where the demand for service is high, it is customary to
run all programs in one of two modes: a batch mode or timesharing mode. In the
batch mode, the programs are prepared off-line without the direct use of the
computer. An operator loads all programs into the computer where they are ex¬
ecuted one at a time. The operator retrieves the printed output and returns it to
the user. What makes the batch mode efficient is the fact that programs can be
fed into the computer as fast as they can be processed. In this way it is ensured
that the computer is busy processing information most of the time.
In the time-sharing mode, many users communicate with the computer via re¬
mote interactive terminals. Because of slow human response compared to computer
speed, the computer can respond to multiple users at the same time. This is ac¬
complished by having many programs reside in memory while the system allocates
a time-slice to each program for execution in the CPU.
FIGURE 12-1
Memory Hierarchy in a Computer System
Section 12-2 Pipeline Processing 411
A major concept common to both batch and time-sharing modes is their use of
multiprogramming. Multiprogramming refers to the existence of many programs
in different parts of main memory at the same time. Thus, it is possible to keep
all parts of the computer busy by working with several programs in sequence. For
example, suppose a program is being executed in the CPU and an I/O transfer is
required. The CPU initiates the I/O processor to start executing the transfer. This
leaves the CPU free to execute another program. In a multiprogramming system,
when one program is waiting for input or output transfer, there is another program
ready to use the CPU.
With multiprogramming, the need arises for running partial programs, for vary¬
ing the amount of main memory in use by a given program, and for moving programs
around the memory hierarchy. Computer programs are sometimes too long to be
accommodated in the total space available in main memory. Moreover, a computer
system uses many programs and all the programs cannot reside in main memory
at all times. A program with its data normally resides in auxiliary memory. When
the program or a segment of the program is to be executed, it is transferred to
main memory to be executed by the CPU. Thus, one may think of auxiliary memory
as containing the totality of information stored in a computer system. It is the task
of the operating system to maintain in main memory a portion of this information
that is currently active. The part of the computer system that supervises the flow
of information between auxiliary memory and main memory is called the memory
management system. The hardware for a memory management system is presented
in Section 12-5.
Other topics covered in this chapter are pipeline processing and associative
memory. Pipeline processing is a technique for speeding the operations in a com¬
puter system. The associative memory is a content addressable type memory that
is often used as part of a memory management system.
Aj B, C,
FIGURE 12-2
Example of Pipeline Processing
* Bt + Cl for i = 1,2,3, . . 7
The five registers are loaded with new data every clock pulse. The effect of each
clock pulse is shown in Table 12-1. It takes three clock pulses to fill up the pipe
and retrieve the first output from R5. From there on, each clock pulse produces
a new output and moves the data one step down the pipeline. This happens as long
as new input data flow into the system. When no more input data are available,
the clock pulses must continue until the last output emerges out of the pipeline.
Note that a pipeline processor performs simultaneous operations in each seg¬
ment. No matter how many segments there are in the system, once the pipeline is
full, it takes only one clock pulse to obtain an output, regardless of how many
steps are required to execute the entire process. If the time it takes to process the
suboperation in each segment is an interval t, and if there are k segments, then
each complete computation is executed in k x t intervals. However, since successive
Section 12-2 Pipeline Processing 413
TABLE 12-1
Content of Registers in Pipeline Example
1 Bx — — _
2 A2 b2 Ai * Bx Q —
3 a3 B, A2 * B2 c2 Aj * Bx + C]
4 a4 B4 a3 * b3 c3 A2 * Bn “T C-,
5 a5 b5 A4 * B4 c4 A3 * B3 + C3
6 a6 b6 a5 * b5 C5 A4 *B4 + C4
7 a7 b7 A6 * Bb Q A5 * B3 + C5
8 — — A7 * b7 Cv a6 * b6 + c6
9 — — — — Ay * By + C7
operations are overlapped in the pipeline, the results are always delivered at every
t interval after a setup time of k x t that it takes to fill up the pipeline.
Any operation that can be decomposed into a sequence of suboperations of
about the same complexity can be implemented by a pipeline processor. The pro¬
cedure is efficient only in those applications where the same computation must be
repeated on a stream of input data. Pipeline data processing has been applied
mostly to floating-point arithmetic operations.
Instruction Pipeline
Pipeline processing can occur not only in the data stream but in the instruction
stream as well. An instruction pipeline reads consecutive instructions from memory
while previous instructions are being executed in other segments. This causes the
instruction fetch and execute phases to overlap and perform simultaneous opera¬
tions. The only digression associated with such a scheme is that one of the instruc¬
tions may cause a branch out of sequence. In that case, the pipeline must be emptied
and all the instructions that have been read from memory after the branch instruc¬
tion must be discarded.
An instruction pipeline can be implemented by means of a first-in first-out
(FIFO) buffer. This is a type of unit that forms a queue rather than a stack.
Whenever the execute phase is not using memory, the control increments the
program counter and uses its address value to read consecutive instructions from
memory. The instructions are inserted into the FIFO buffer so that they can be
executed on a first-in first-out basis. Thus, an instruction stream can be placed in
a queue, to wait for decoding and execution by the processor.
The instruction stream queuing mechanism provides an efficient way for reducing
the average access time to memory for reading instructions. Whenever there is
space in the FIFO buffer, the CPU executes an instruction fetch phase. The buffer
acts as a queue from which control extracts instructions for execution. If the CPU
executes an instruction that transfers control of a location out of normal sequence,
the buffer is reset and the pipeline is declared empty. Control then fetches the
instruction from the branch address and begins to refill the buffer from the new
FIGURE 12-3
Four-segment CPU Pipeline
location. Often, branch instructions form a small fraction of the total number of
instructions executed, so efficiency can be increased by this kind of instruction
pipeline.
The instruction pipeline can be extended to include other phases in the CPU
cycle. As an example, Figure 12-3 shows how the instruction cycle in the CPU can
be processed with a four-segment pipeline. While an instruction is being executed
in the processor, the next instruction in sequence is busy fetching an operand from
memory. The effective address may be calculated in a separate arithmetic circuit
for the third instruction and, whenever the memory is available, the fourth and all
subsequent instructions can be fetched and placed in a FIFO instruction queue.
Thus, up to four suboperations in the instruction cycle can overlap and up to four
different instructions can be in process at the same time.
Once in a while, an instruction in the sequence may be a program control type
that causes a branch out of normal sequence. In that case, the pending operations
in the last two segments are completed and all information stored in the instruction
Section 12-3 Associative Memory 415
buffer is deleted. The pipeline then restarts from the new address stored in the
program counter. Similarly, an interrupt request, when acknowledged, will cause
the pipeline to empty and start again from a new address value.
There are certain difficulties that will prevent the CPU pipeline from operating
at its maximum rate. Different segments may take different times to operate on
the incoming information. Some segments are skipped for certain operations. For
example, a register mode instruction does not need an effective address calculation.
Two or more segments may require memory access at the same time, causing one
segment to wait until another is finished with the memory. Memory access conflicts
are sometimes resolved by using a memory unit with multiple modules and storing
the programs and data in separate modules. In this way, an instruction word and
a data word can be read simultaneously from two different modules.
Hardware Organization
The block diagram of an associative memory is shown in Figure 12-4. It consists
of a memory array and logic for m words of n bits per word. The argument register
A has n bits, one for each bit of a word. The match register has m bits, one for
416 Chapter 12 Memory Management
Input
Read
Write
Output
FIGURE 12-4
Block Diagram of Associative Memory
each word in memory. Each word is compared in parallel with the content of the
argument register. The words that match the bits of the argument register set a
corresponding bit in the match register. Reading is accomplished by a sequential
access to memory for those words that have corresponding bits in the match register
that have been set.
The internal organization of a typical binary cell consists of an elementary SR
latch for storing the bit and the circuits for reading and writing as depicted in Figure
6-6 in Section 6-3. Additional circuits are needed for matching each word with the
content of the argument register A. The match logic for each word can be derived
from the comparison algorithm for two binary numbers. Let the bits of a word be
designated by F1, F2, F3, up to Fn, where n is the number of bits in the word. The
content of the word will be equal to the argument in A if At = F, for i = 1, 2, 3,
. . ., n. Two bits are equal if both are equal to 1 or if both are equal to 0. The
equality of two bits can be expressed by the exclusive-NOR function
Xi = AFi + AlFl = W
where Xt = 1 if the pair of bits in position i are equal and Xt = 0 if the two bits
are not equal.
For a word to be equal to the argument in A we must have all Xt variables equal
to 1. This is the condition for setting the corresponding match bit My to 1. The
Boolean function for this condition is
Mj = X1X2X3 ...Xn
V. y
To all other words
FIGURE 12-5
Match Logic for Two Words of Associative Memory
many bits as there are words in memory. For every active word stored in memory,
the corresponding bit in the tag register is set to 1. A word is deleted from memory
by resetting its tag bit to 0. Words are stored in memory by scanning the tag register
until the first 0 bit is encountered. This gives the first available inactive word and
a position for writing a new word. After the new word is stored in memory it is
made active by setting its tag bit to 1. An unwanted word when deleted from
memory can be cleared to all 0’s if this value is used to specify an empty location.
FIGURE 12-6
Example of Cache Memory
1. Associative mapping.
2. Direct mapping.
3. Set-associative mapping.
To help in the discussion of these three mapping procedures, we will use a specific
example of a memory organization shown in Figure 12-6. The main memory can
store 32K words of 12 bits each. The cache is capable of storing 512 of these words
at any given time. For every word stored in cache, there is a duplicate copy in
main memory. The CPU communicates with both memories. It first sends a 15-
bit address to cache. If there is a hit, the CPU accepts the 12-bit data word from
cache. If there is a miss, the CPU reads the word from main memory and the word
is then transferred to cache.
Associative Mapping
The fastest and the most flexible cache organization uses an associative memory.
This organization is illustrated in Fig. 12-7. The associative memory stores both
the address and content (data) of the memory word. This permits any location in
cache to store any word from main memory . The diagram shows three words
stored in cache. The address value of 15 bits is shown as a 5-digit octal number
and its corresponding 12-bit data word is shown as a 4-digit octal number. A CPU
address of 15 bits is placed in the argument register and the associative memory
is searched for a matching address. If the address is found, the corresponding 12-
bit data is read and sent to the CPU. If no match occurs, the main memory is
accessed for the word. The address-data pair is then transferred to the associative
cache memory. If the cache is full, an address-data pair must be displaced to make
room for a pair that is needed but is not presently in the cache. The decision
concerning what pair to replace is determined from the replacement algorithm that
420 Chapter 12 Memory Management
Argument register
Address Data
0 10 0 0 3 4 5 0
0 2 7 5 6 5 4 2 7
2 3 4 8 7 4 3 5 8
FIGURE 12-7
Associative Mapping Cache (All Numbers are in Octal)
the designer chooses for the cache. A simple procedure is to replace the words in
cache in round-robin order whenever a new word is requested from main memory.
This constitutes a first-in first-out (FIFO) replacement policy.
Direct Mapping
Associative memories are expensive compared to random-access memories because
of the added logic associated with each cell. The possibility of using a random-
access memory for the cache is investigated in Figure 12-8. The CPU address of
15 bits is divided into two fields. The nine low-order bits constitute the index field
and the remaining six bits form the tag field. The figure shows that main memory
needs an address that includes both the tag and the index bits. The number of bits
in the index field is equal to the number of address bits required to access the
cache memory.
In the general case, there are 2k words in cache memory and 2n in main memory.
The n-bit memory address is divided into two fields: k bits for the index field and
n — k bits for the tag field. The direct mapping cache organization uses the n-bit
address to access the main memory and the k-bit index to access cache. The internal
organization of the words in cache memory is as shown in Figure 12-9(b). Each
word in cache consists of the data word and its associated tag. When a new word
is first brought into the cache, the tag bits are stored alongside the data bits. When
the CPU generates a memory request, the index field is used for the address to
access the cache. The tag field of the CPU address is compared with the tag field
in the word read from cache. If the two tags match, there is a hit and the desired
data word is in cache. If there is no match, there is a miss and the required word
is read from main memory. It is then stored in the cache together with the new
tag, replacing the previous value.
Section 12-4 Cache Memory 421
6 bits 9 bits
Tag Index
1 '
00 000 000
512 x 12
32K x 12 Cache memory
Octal Main memory
address Address = 9 bits
Address = 1 5 bits
Data = 1 2 bits
Data = 1 2 bits 111
77 111
FIGURE 12-8
Addressing Relationships Between Main Memory and Cache
The disadvantage of direct mapping is that the hit ratio may drop considerably
if two or more words with addresses having the same index but different tags are
accessed repeatedly. However, this possibility is minimized by the fact that such
words are relatively far apart in the address range (multiples of 512 locations in
this example).
To see how the direct mapping scheme operates, consider the numerical example
shown in Figure 12-9. The word at address zero is presently stored in cache
(index = 000, tag = 00, data = 1220). Suppose that the CPU now wants to access
the word at address 02000. The index address is 000, so it is used to access the
cache. The two tags are then compared. The cache tag is 00 but the address tag is
02, which does not produce a match. Therefore, the main memory is accessed and
the data word 5670 is transferred to the CPU. The cache word at index address
000 is then replaced with a tag of 02 and data of 5670.
Memory Index
address Memory data address Tag Data
000 0 0 1 2 2 0
111 0 2 6 7 1 0
FIGURE 12-9
Direct Mapping Cache Organization
Index Tag Data Tag Data
FIGURE 12-10
Set Associative Mapping Cache with Set Size of Two
Set-Associative Mapping
It was mentioned previously that the disadvantage of direct mapping is that two
words with the same index but with different tag values cannot reside in cache at
the same time. A third type of cache organization, called set-associative mapping,
is an improvement over the direct mapping organization in that each word of cache
can store two or more words of memory under the same index address. Each data
word is stored together with its tag, and the number of tag-data items in one word
of cache is said to form a set. An example of a set-associative cache organization
for a set size of two is shown in Figure 12-10. Each index address refers to two
data words and their associated tags. Each tag requires six bits and each data word
has 12 bits, so the word length is 2(6 + 12) = 36 bits. An index address of nine
bits can accommodate 512 words. Thus, the size of cache memory is 512 x 36. It
can accommodate 1024 words of main memory since each word of cache contains
two data words. In general, a set-associative cache of set size k will accommodate
k words of main memory in each word of cache.
The octal numbers listed in Figure 12-10 refer to the main memory contents
illustrated in Figure 12-9(a). The words stored at addresses 01000 and 02000 of
main memory are stored in cache memory at index address 000. Similarly, the
words at addresses 02777 and 00777 are stored in cache at index address 777. When
the CPU generates a memory request, the index value of the address is used to
access the cache. The tag field of the CPU address is then compared with both
tags in the cache to determine if a match occurs. The comparison logic is done by
an associative search of the tags in the set similar to an associative memory search,
hence the name set-associative. The hit ratio will improve as the set size increases
because more words with the same index but different tags can reside in cache.
An increase in the set size increases the number of bits in the words of cache and
requires more complex comparison logic.
In a memory hierarchy system, programs and data are first stored in auxiliary
memory. Portions of a program or data are brought into main memory as they are
needed by the CPU. Virtual memory is a concept used in some computer systems
that permits the user to construct his program as though he had a large memory
space, equal to the total of auxiliary memory. Each address that is referenced by
the CPU goes through an address mapping from the so-called virtual or logical
422
Section 12-5 Virtual Memory Management 423
address to a physical address in main memory. Virtual memory is used to give the
programmer the illusion that he has a very large memory at his disposal, even
though the computer may have a relatively small main memory. A virtual memory
system provides a mechanism for translating program generated addresses into
corresponding main memory locations. This is done dynamically, while programs
are being executed in the CPU. The translation or mapping is handled automatically
by the hardware by means of mapping tables.
In a multiprogramming environment where many programs reside in memory,
it becomes necessary to move programs and data around in memory, to vary the
amount of memory in use by a given program, and to prevent a program from
changing other programs. The demands on computer memory brought about by
multiprogramming have created the need for a memory management system. A
memory management system is a collection of hardware and software procedures
for managing the various programs residing in memory. The memory management
software is part of an overall operating system available in the computer. Here we
are concerned with the hardware unit associated with the memory management
system.
Logical address
Physical address
FIGURE 12-11
Address Translation in a Memory Management System
Section Problems 425
number given in the logical address. The sum produces a pointer address to an
entry in the page table. The value in the page table provides the block number in
physical memory. The concatenation of the block number with the offset produces
the final physical mapped address.
The two mapping tables may be stored in two separate small memories or in
main memory. In either case, a memory reference from the CPU will require three
accesses to memory: one from the segment table, one from the page table, and
one from main memory. This will slow the system significantly, compared to a
conventional system that requires only one reference to memory. To avoid this
speed penalty, a fast associative memory is used to hold the most recently referenced
table entries. (This memory is sometimes called a translation lookaside buffer
abbreviated TLB.) The first time a given block is referenced, its value together
with the corresponding segment and page numbers are entered into the associative
memory. Thus, the mapping process is first attempted by associative search with
the given segment and page numbers. If it succeeds, the mapping delay is only that
of the associative memory. If no match occurs, the slower table mapping procedure
is used and the result transformed into the associative memory for future reference.
REFERENCES
1. Mano, M. M. Computer System Architecture. 2nd ed. Englewood Cliffs: Prentice-Hall,
1982.
2. Hanlon, A. G. “Content-Addressable and Associative Memory Systems: A Survey.”
IEEE Trans, on Electronic Computers. EC-15 (Aug. 1966): 509-521.
3. Bell, J., Casasent, D., and Bell, C. G. “An Investigation of Alternative Cache
Organizations.” IEEE Trans, on Computers. C-23(Apr. 1974): 346-351.
4. Denning, P. J. “Virtual Memory.” Computing Surveys. (Sept. 1970): 153-187.
PROBLEMS
12-1 Explain the need for auxiliary memory devices. How are they different from main
memory and from other peripheral devices?
12-2 Explain the need for memory hierarchy. What is the main reason for not having a
large enough main memory for storing all the available information in a computer
system?
12-3 Define multiprogramming and explain the function of a memory management unit
in computers that use the multiprogramming organization.
12-4 In certain scientific computations it is necessary to perform the arithmetic operation
(At + B,) (C, + A) wilh a stream of numbers. Specify a pipeline configuration
to carry out this task. List the contents of all registers in the pipeline for i = 1
through 6.
426 Chapter 12 Memory Management
12-5 Obtain the complement function for the match logic of one word in an associative
memory. In other words, show that the complement of MJ is obtained from the
logical sum of exclusive-OR functions. Draw the logic diagram for My and terminate
it with an inverter to obtain Mr
12-6 Obtain the Boolean function for the match logic of one word in an associative memory
taking into consideration a tag bit that indicates whether the word is active or inactive.
12-7 A digital computer has a memory unit of 64K x 16 and a cache memory of IK
words. The cache uses direct mapping.
(a) How many bits are there in the tag and index fields of the address?
(b) How many bits are there in each word of the cache, and how are they divided
into functions?
12-8 A set-associative mapping cache has a set size of 2. The cache can accommodate a
total of 2048 words from main memory. The main memory size is 128K x 32.
(a) Formulate all pertinent information required to construct the cache memory.
(b) What is the size of the cache memory?
12-9 The access time of a cache memory is 100 nsec and that of main memory 1000 nsec.
The hit ratio is 0.9. What is the average access time of the system?
12-10 An address space is specified by 24 bits and the corresponding memory space by 16
bits.
(a) How many words are there in the address space?
(b) How many words in the memory space?
(c) If a page consists of 2K words, how many pages and blocks are there in the
system?
12-11 The logical address space in a computer system consists of 128 segments. Each
segment can have up to 32 pages of 4K words in each. Physical memory consists of
4K blocks of 4K words in each. Formulate the logical and physical address formats.
12-12 Give the binary number of the logical address formulated in Problem 12-11 for
segment 36 and word number 2000 in page 15.
INDEX
> 1
*
' *
»
<■
•»
v ■
-> m
■ ■
efts
In order to analyze and design digital systems, one requires a solid founda¬
tion in hardware concepts. M. Morris Mano presents the necessary infor¬
mation in this introduction to the principles of computer hardware
organization and design. Computer Engineering: Hardware Design
covers all aspects of computer hardware engineering from basic digital cir¬
cuits to the structures of a complete computer system.
immm
The book contains three logically organized parts. The first part deals
with digital circuits from the gate and flip-flop level. It covers basic digital
circuits, and the analysis and design of combinational and sequential - :
circuits. The second part introduces digital design from the register transfer ■-T^vfC
unit using both hardware and microprogram methods. Finally, the third part
focuses on the hardware components of the digital computer. Included are the
design of a CPU using microprogrammed control, input and output
procedures, and the hardware associated with memory management. :
629263
PRENTICE HALL
i4A5-3
Englewood Cliffs, N.J. 07632