Microprocessors and Interfacing Programming and Hardware 68000 Version
Microprocessors and Interfacing Programming and Hardware 68000 Version
ANDR
/- =
L. ROOD
*
6 3 0 3 0 .
8010
yers)
raxeY
a
68
bg
|l
oS
q
co)
Wa
ot
“6
co
=)
ed
6
od
e
MICROPROCESSORS
AND
INTERFACING
68000 VERSION
MICROPROCESSORS
AND
INTERFACING
PROGRAMMING
AND HARDWARE
68000 VERSION
DOUGLAS V. HALL
ANDREW L. ROOD
GLENCOE
Macmillan/McGraw-Hill
Lake Forest, Illinois Columbus, Ohio Mission Hills, California Peoria, Illinois
IBM PC, IBM PC/XT, IBM PC/AT, IBM PS/2, and MicroChannel Architecture are registered
trademarks of IBM Corporation. The following are registered trademarks of Intel Corporation: 386,
i486, i860, ICE, iRMX. Borland, Sidekick, Turbo Assembler, TASM, Turbo Debugger, and Turbo C++
are registered trademarks of Borland International, Inc. Microsoft, MS, MS DOS, Windows 3.0,
Codeview, and MASM are registered trademarks of Microsoft Corporation. Apple and Macintosh
are registered trademarks of Apple Computer Inc. UNIX is a registered trademark of AT&T Inc. The
URDA P68000 MLab is a registered trademark of University Research and Development Associates.
Consulair is a registered trademark of Consulair Inc. Think C is a registered trademark of Semantec.
MC68000, 68008, 68010, 68020, 68030, and 68030 are registered trademarks of Motorola Inc. Other
product names are registered trademarks of the companies associated with the product name
referred to in the text or figure.
Hall, Douglas V.
Microprocessors and interfacing : programming and hardware : 68000 version / Douglas V.
Hall, Andrew L. Rood.
p. cm.
Includes bibliographical references and index.
ISBN 0-07-025691-8 (text). — ISBN 0-07-025692-6 (experiments manual). — ISBN
0-07-025693-4 (instructor's manual)
1. Microprocessors—Programming. 2. Microprocessors. 3. Computer interfaces. |. Rood,
Andrew L. Il. Title.
QA76.6.H2994 1992 91-48370
004.165—dc20 CIP
ISBN 0-07-025691-8
123456789 A-KP 99 98 97 96 95 94 93 92
TO OUR STUDENTS
oahiet
“oat
ei Ae
* s ed
Pea
st115k)
a : ; .
7 ue oa Pos! 5 “aa ©6352 >
. ee Wie io
Ae _ <a
CONTENTS
Preface xi
CHAPTER 1
Computer Number Systems, Codes, and Digital Devices 1
Computer Number Systems and Codes 1
Adding and Subtracting Binary, Octal, Hex, and BCD Numbers 6
Basic Logic Gates 16
CHAPTER 2
Computers, Microcomputers, and Microprocessors— an Introduction 24
Computers 24
Introduction to the 68000, 68008, 68010, 68012, 68020, 68030, and 68040
Microprocessors 33
The 68000 Internal Architecture 34
Introduction to Programming the 68000 38
CHAPTER 3
Introduction
68000 Family Assembly Language Progra—mming 43
Program Development Steps 43
Constructing the Machine Codes for 68000 Instructions 54
Writing Programs for Use with an Assembler 59
Assembly Language Program Development Tools 63
CHAPTER 4
68000 Assembly Language Programming Techniques 70
More Practice with Simple Sequence Programs 70
Condition Codes and Jumps 76
IF-THEN, IF-THEN-ELSE, and Multiple IF-THEN-ELSE Programs 84
WHILE-DO Implementation and Example 90
REPEAT-UNTIL Implementatio n and Example 96
Debugging Assembly Language Programs 109
CHAPTER 5
Subroutines and Macros 113
Writing and Using Subroutines 113
Writing and Using Assembler Macros 140
CHAPTER 6
68000 Instruction Descriptions and Assembler Directives 144
Addressing Terminology 144
Instruction Descriptions 145
Assembler Directives 162
CHAPTER 7
68000 System Connections, Timing, and Troubleshooting 166
68000 Hardware Overview 166
Analyzing a Small System: the URDA® MDS 174
Vil
Addressing Memory and Ports in Microcomputer Systems 179
68000 Timing Parameters 187
Troubleshooting a Simple 68000-Based Microcomputer r39
CHAPTER 8
Interrupts and Interrupt-Service Routines 200
68000 Interrupts and Interrupt Responses 200
Hardware Interrupt Applications 214
CHAPTER 9
Digital Interfacing 243
Programmable Parallel Ports and Handshake Input/Output 243
Interfacing a Microprocessor to Keyboards 259
Interfacing to Alphanumeric Displays 268
Interfacing Microcomputer Ports to High-Power Devices 280
Optical Motor Shaft Encoders 286
CHAPTER 10
Analog Interfacing and Industrial Control 293
Review of Operational-Amplifier Characteristics and Circuits 293
~ Sensors and Transducers 298
D/A Converter Operation, Interfacing, and Applications 303
A/D Converter Type, Specifications, and Interfacing 307
A Microcomputer-based Scale 310
A Microcomputer-based Industrial Process-Control System 321
A 68000-based Process-Control System 323
Developing the Prototype of a Microcomputer-based Instrument 335
Digital Filters 337
CHAPTER 11
DMA, DRAMs, Cache Memories, Coprocessors, and EDA Tools 341
Introduction 341
The 68020 Multimaster Mode 342
Direct Memory Access (DMA) Data Transfer 342
Interfacing and Refreshing Dynamic RAMs 348
A Coprocessor— The 68881 Math Coprocessor 360
Computer-based Design and Development Tools 370
CHAPTER 12
C: A High-level Language for System Programming 380
Introduction—A Simple C Program Example 380
Program Development Tools for C 382
Programming in C 385
Implementing Standard Program Structures in C 400
CHAPTER 13
Microcomputer System Peripherals 426
Microcomputer Displays 426
Raster-Scan CRT Graphics Displays 433
Vill CONTENTS
CRT Terminals 434
Raster-Scan Color Graphics 434
Vector-Scan CRT Displays 438
Alphanumeric/Graphics LCD Displays 439
Computer Vision 439
Mass Data-Storage Systems 442
Floppy-Disk Data Storage 442
Magnetic Hard-Disk Data Storage 451
Optical-Disk Data Storage 452
Printer Mechanisms 454
Speech Synthesis and Recognition with a Computer 457
CHAPTER 14
Data Communication and Networks 462
Introduction to Asynchronous Serial Data Communication 462
Serial Data Transmission Methods and Standards 468
Asynchronous Communication Software on the Apple Macintosh 481
Synchronous Serial Data Communication and Protocols 498
Local Area Networks 491
CHAPTER 15
Operating Systems, the 68030 Microprocessor, the 68040, and the Future 504
Operating System Concepts and Terms 504
The UNIX Operating System 510
The Intel RMX 86@ Operating System 514
The Motorola 68030 Microprocessor 516
New Directions 519
Epilogue 523
BIBLIOGRAPHY = 525
APPENDIX A MC68000 INSTRUCTION EXECUTION TIMES 527
INDEX = 557
CONTENTS IX
PREFACE
Chapters 2-10
Chapters 2-10 provide you with a comprehensive introduction to microproces-
sors, including interrupt applications, digital and analog interfacing, and
industrial controls. These chapters include an overview of the 68000 micro-
processor family and its architecture, programming language, and systems
connections and troubleshooting.
Because I came into the world of electronics through the route of vacuum
tubes, my first tendency in teaching microprocessors was to approach them
from a hardware direction. However, the more I designed with microprocessors
and taught microprocessor classes, the more I became aware that the real
essence of a microprocessor is what you can program it to do. Therefore,
Chapters 2—5 introduce you to writing structured assembly language programs
for the 68000 microprocessor. The approach taken in this programming
section is to solve the problem, write an algorithm for the solution, and then
simply translate the algorithm to assembly language. Experience has shown
that this approach is much more likely to produce a working program than just
writing down assembly language instructions. The 68000 instruction set is
introduced in Chapters 2—5 as needed to solve simple programming problems,
but for reference Chapter 6 contains a dictionary of all 68000 instructions with
examples for each.
Chapter 7 discusses the signals, timing, and system connections for a simple
68000-based microcomputer. Also discussed in Chapter 7 is a systematic
method for troubleshooting a malfunctioning 68000-based microcomputer
system and the use of a logic analyzer to observe microcomputer bus signals.
XI
Chapter 8 discusses how the 68000 responds to interrupts, how interrupt-
service procedures are written, and the operation of a peripheral device called a
priority-interrupt controller.
Chapters 9 and 10 show how a microprocessor is interfaced with a wide
variety of low-level input and output devices. Chapter 9 shows how a micro-
processor is interfaced with digital devices such as keyboards, displays, and
relays. Chapter 10 shows how a microprocessor is interfaced with analog
input/output devices such as A/Ds, D/As, and a variety of sensors. Chapter 10
also shows how all the “‘pieces’’ are put together to produce a microprocessor-
based scale and a simple microprocessor-based process control system. Chap-
ter 10 concludes with a discussion of how microprocessors can be used to
implement digital filters.
Chapters 11-15
Chapters 11-14 are devoted to the hardware, software, and peripheral inter-
facing for a microcomputer such as those in the Apple Macintosh Family.
Chapter 11 discusses motherboard circuitry, including DRAM systems, cach-
es, math coprocessors, and peripheral interface buses. Chapter 11 also shows
how to use a schematic capture program to draw the schematic, a simulator
program to verify the logic and timing of the design, and a layout program to
design a printed-circuit board for the system. Knowledge of these electronic
design automation tools is essential for anyone developing high-speed micro-
processor systems.
At the request of many advisors from industry, Chapter 12 introduces you to
the C programming language, which is used to write a large number of
system-level programs. This chapter takes advantage of the fact that it is very
easy to learn C if you are already familiar with 68000-type assembly language.
A section in this chapter also shows you how to write simple programs that
contain both C and assembly language modules.
Chapter 13 describes the operation and interfacing of common peripherals
such as CRT displays, magnetic disks, and printers. Chapter 14 shows how a
microcomputer is interfaced with communication systems such as modems
and networks.
Finally, Chapter 15 starts with a discussion of the needs that must be met by
multiuser/multitasking operating system and then describes how the features
of the 68020, 68030, and 68040 processors meet these needs. This section of
the chapter also includes discussions of how to develop programs for the 68020
in a variety of environments. The chapter and the book conclude with an
introduction to parallel processors, and I think you will find these developing
areas as fascinating as I have.
Chapters 2-10
I suggest following Chapters 2—10 as an instructional block, as each chapter
builds on the preceding chapter. These nine chapters represent ideal coverage
for a ‘‘short course”’ in microprocessors. The remaining chapters represent an
opportunity for the instructor to tailor assignments for the students’ needs or
perhaps to give an individual student added study in recent developments in
the architecture in microprocessors.
xil PREFACE
Chapter 11
Individual topics from Chapter 11 could be selected for study as students gain
knowledge of the ‘‘tools’’ available for designing computer-based systems. The
DRAM section is very important.
Chapter 12
Instructors may wish to assign or leave for outside reading Chapter 12 on
programming in C, a new chapter. At the very least you should take a careful
look at the simple programming examples and the development of tools for C. If
class time does not permit assigning this chapter, you may wish to use selected
examples and programs in your lecture presentations. This chapter can be
C
included in any course sequence that does not have a separate class in
programming.
Chapter 13
Portions of the peripherals chapter may be assigned as required, depending
upon the course syllabus. The CRT, disk, and printer sections are highly
recommended.
Chapter 14
This is an important chapter, given the ever-expanding use of data communi-
cations. It should be assigned, if at all possible, unless the curriculum includes
the
a separate course in data communications. Of primary importance are
sections on modems and LANs.
Chapter 15
The final chapter is on the cutting edge of the development of new microproces-
this
sors. It is our hope that all students will have the opportunity to read
chapter. At the very least students should read the section on the 68030. This
is a final chapter, yet it is only the beginning of their study of microprocessors.
SPECIAL FEATURES
In response to feedback from industry and from a variety of electronics
instructors of the INTEL version of Microprocessors and Interfacing: Program-
ming and Hardware, this book contains these new or enhanced features.
1. The order of the topics in Chapters 4 and 5 has been improved, based on
instructor feedback.
2. A greatly expanded section on digital signal processing hardware and
software has been added to Chapter 10.
c
3. A section in Chapter 11 describes and shows an example of how electroni
design automation tools such as schematic capture programs, simulator
programs, and PC board layout programs are used to develop the hardware
for a microcomputer system.
4. At the request of industry advisors, Chapter 12 isa completely new chapter
that contains a solid introduction to the C programming language, including
examples of programs with C and assembly language modules.
to
5. Chapters 13 and 14, the systems peripherals chapters, have been updated
reflect advances in technology such as VGA graphics, optical-d isk storage,
laser printers, and digital video interactive. The chapters now include both
assembly language and C interface program examples.
6. The network section of Chapter 14 has been expanded to reflect the current
importance of networks.
7. Chapter 15 now contains an extensive description of the features of the
PREFACE XIll
68030 and 68040 processors and a discussion of how these features are
used in multitasking environments such as UNIX.
IMPORTANT SUPPLEMENTS
This book and the Experiments Manual written to accompany it contain many
hardware and software exercises students can do to solidify their knowledge of
microprocessors. An IBM PC or IBM PC-compatible computer, or an Apple
Macintosh can be used to edit, assemble, link/locate, run, and debug many of
the 68000 assembly language programs.
The Experiments Manual contains 40 laboratory exercises that are directly
coordinated to the text. Each experiment includes chapter references, required
equipment, objectives, and experimental procedures.
The Instructor’s Manual contains answers to the review questions. It also
includes experimental notes and answers to selected questions for the Experi-
ments Manual.
The Instructor’s Manual includes disk directories. There are two disks
available. This set of disks contains the source code for all the programs in the
text and Experiments Manual. The disks are available for instructors and may
be obtained directly from the publisher. The Instructor’s Manual contains
instructions for obtaining the disks.
ADDITIONAL GOALS
One of the main goals of this book is to teach you how to decipher manufactur-
er’s data sheets for microprocessor and peripheral devices, so the book
contains relevant parts of many data sheets. Because of the large number of
devices discussed, however, it was not possible to include complete data sheets.
If you are doing an in-depth study, it is suggested that you acquire or gain
access to the latest editions of Motorola Microprocessors and Peripherals
handbooks. The bibliography at the end of the book contains a list of other
books and periodicals you can refer to for further details on the topics discussed
in the book.
ACKNOWLEDGMENTS
I wish to express my profound thanks to the people around me who helped
make this book a reality. Thanks to Pat Hunter, whose cheerful encouragement
helped me through seemingly endless details. She proofread the original
manuscript, worked out the answers to the end-of-chapter problems to verify
that they are solvable, and made suggestions and contributions too numerous
to mention. Thanks to Richard Cihkey of New England Technical Institute in
New Britain, Connecticut, who meticulously worked his way through the
original manuscript and made many valuable suggestions. Thanks to Mike
Olisewski of Instant Information, Inc., who helped me “‘C the light’’ in Chapter
12 and contributed his industry perspective on the topics that should be
included in the book. Thanks to Dr. Michael A. Driscoll of Portland State
University, who helped me fine-tune Chapter 15. Thanks to Intel Corporation
for letting me use many drawings from their data books so that this book could
lead readers into the real world of data books. Finally, thanks to my wife
Rosemary, my children Linda, Brad, Mark, Lee, and Kathryn, and to the rest of
my family for their patience and support during the long effort of rewriting this
book.
Douglas V. Hall
XIV PREFACE
The 68000 version of this text was produced from Douglas Hall’s original
Intel version and his updated notes for the second edition of the Intel version.
Thanks to Motorola Incorporated, to University Research and Development
Associates, to Consulair Incorporated, to Semantec, and to Apple Computer
Incorporated for their excellent products, which are used in many real-world
applications as well as many instructional environments. Thanks to Douglas
Hall for asking me to participate. Thanks to John Beck and to the entire team at
Glencoe (Macmillan/McGraw-Hill) for their help, inspiration, and guidance in
helping me complete work on the 68000 version. Thanks also to my parents: to
my mother for always encouraging my writing interests and to my father for his
own explorations into the writing of textbooks. Finally, sincere thanks to my
wife, Terry, for her constant support and encouragement during the years it
has taken to complete this version of the text.
If you have suggestions for improving the book or ideas that might clarify a
point for someone else, please communicate with us through the publisher.
Andrew L. Rood
PREFACE XV
P ;
ae
:| ars ~~ ae AS 7 ah
ok kh ca
| LENE Ene TS Saree A eee aiken
a Pee ee ale eee | PieTE tine o
- '
athe Bavsonpely
ysweeu ay
; s ; ao ta
MICROPROCESSORS
AND
INTERFACING
68000 VERSION
Computer Number Systems, Codes,
and Digital Devices
Before starting our discussion of microprocessors and the decimal number system, then, there are 10 sym-
microcomputers, we need to make sure that some key bols, 0 through 9. When the count in any digit position
concepts of the number systems, codes, and digital passes that of the highest-value symbol, a carry of 1 is
devices used in microcomputers are fresh in your added to the next digit position and the other digit rolls
mind. If the short summaries of these concepts in this back to zero. A car odometer is a good example of this.
chapter are not enough to refresh your memory, then it A number system can be built using powers of any
is a good idea to review the concepts in a current digital number as place holders or digits, but some bases are
text before going on in this book. more useful than others. It is difficult to build electron-
ic circuits that can store and manipulate 10 different
voltage levels, but it is relatively easy to build circuits
that can handle 2 levels. Therefore, a binary, or
OBJECTIVES base-2, number system is used.
22749 = 2 Binary
Least Significant
Binary Digit
J
2)227 = _113 R1 A ar eat
POTS ERIS IE ee 56 Alive cee 2a m2
Be Ts Gy eh a
haps RO Nc) ane)
7h re =A SEN opi UE ae
(a)
2) 14" 7 RO xX 146 = 0O
2) wala 3 R1 x 32° = 32
Check
ATK AS 1 Rl x 64 = 64
2 1 1D
2) 1S 0 Rl x 128 = 128
te Sx 0 .25 {] 227 Check
aX dae 25 Most Significant
Binary Digit
625
“, 227,, = 11100011,
(b)
FIGURE 1-2 Converting decimal to binary. (a) Digit value method. (b) Divide
by 2 method. (c) Decimal fraction conversion.
2 CHAPTER ONE
digits can represent 2”, or 4, numbers, 0-11; and three You convert from octal to binary by replacing each
binary digits can represent 2°, or 8, numbers. Thus N octal digit with its 3-bit binary equivalent.
decimal digits can represent 10% numbers and N bina-
ry digits can represent 2" numbers. Eight binary digits
can represent 2°, or 256, numbers, 0-255. Hexadecimal
Some once-popular minicomputers, such as_ the
Octal PDP-8, have 12 parallel data lines. Four octal digits
provide an easy way to represent the binary data
Binary is not a very compact code. This means that it 12 parallel lines. For example,
word on these
requires many more digits to express a number than is easily written as 4127 octal.
100001010111 binary
does, for example, decimal. Twelve binary digits can
Most microprocessors have 4-bit, 8-bit, 16-bit, or 32-
describe a number only up to 4095,,. Computers re-
bit data words. For these microprocessors, it is more
quire binary data, but people working with computers
logical to use a code that groups the binary digits in
have trouble remembering the long binary words pro- Hexadecimal, or base
groups of four rather than three.
duced by the verbose code. One solution to the problem
16, code does this. Figure 1-4a shows the digit values
is to use the octal, or base-8 code. As you can see in
for hexadecimal, which is often just called hex. Since
Figure 1-3a, the digits in this code represent powers of
hex is base 16, you need 16 possible symbols for each
8. The symbols then are 0-7. You can convert a
digit. The table in Figure 1-4b show the symbols for
decimal number to the octal equivalent number with hex code. Following the decimal symbols 0 through 9,
the same trick you used to convert decimal to binary.
the letters A through F are used for values 10 through
Figure 1-3b shows the technique for decimal-to-octal
15.
conversion. Decimal 327 is equal to 507,. Verification
As mentioned before, each hex digit is equal to four
of this is shown by converting the octal to decimal in binary digits. To convert the binary number 11010110
the second half of Figure 1-3b.
to hex, mark off groups of four, moving to the left from
Because 8 is an integral power of 2, conversions from
the binary point, as shown in Figure 1-4c. Then write
binary to octal and from octal to binary are quite
the hex symbol for the value of each group of four. The
simple. If you have a binary number such as 1 0101
0110 group is equal to 6 and the 1101 group is equal to
1111, starting from the binary point and moving to the
13. Since 13 is D in hex, 11010110 binary is equal to
left, mark off the binary digits in groups of three, as
D6 in hex. Thus, 8 bits are represented by 2 hex digits.
shown in Figure 1-3c. Each group of three binary digits
In order to make it easier to read binary numbers, we
is equal to one octal digit. For this example, 111] isa 7,
will follow the convention of adding a space between
011 is a 3, and 101 isa 5. Therefore, 101011111, is
every four digits. Thus 11010110 will be written
equal to 537,.
1101 0110.
In Motorola’s manuals, a dollar sign (S) is used before
a number to indicate that it is a hexadecimal number.
40965126481 +4 & = For example, D6 hex is usually written SD6. Intel’s
84 8° 82 g'8°. refee Sac 83 manuals for the 8086 family use an H after a number
to indicate hexadecimal. For example, D6 hex is writ-
(a) ten D6H in Intel manuals. The Motorola syntax is used
in this text.
= mate Octal S2iin = 507, If you want to convert from decimal to hexadecimal,
32) Decimal
Figure 1-4d shows a familiar trick to use. The result
LSD shows that 227,, is equal to SE3. As you can see, hex is
an even more compact code than decimal. Two hexa-
= 40 R Van ee
8)327 decimal digits can indicate a number up to 255. Only 4
hex digits are needed to represent a 16-bit binary
number.
R <x 64 = 320
8) 5a) To illustrate how hexadecimal numbers are used in
MSD 327 digital logic, a service manual tells you that the 8-bit
wide data bus of a 68008 microprocessor should con-
(b) tain $3F during a certain operation. Converting $3F to
binary gives the pattern of 1s and Os (0011 111 1) you
Binary 101 O11 111. would expect to find with your oscilloscope or logic
analyzer on the parallel lines. The $3F is simply a
oats e : t Binary Point shorthand that is easier to remember and less prone to
Octal 5 3 7
errors.
(c) To convert from octal code to hex code, the easiest
way is to write the binary equivalent of the octal and
FIGURE 1-3. Octal numbers. (a) Value of placeholders. then convert the binary digits, four at a time, into the
(b) Conversion of decimal to octal. (c) Conversion of appropriate hex digits. Reverse the procedure to get
binary to octal. from hex to octal.
see in Table 1-1, the simplest BCD code uses the first
10 numbers of standard binary code for the BCD
numbers O through 9. The hex codes A through F are
invalid BCD codes. Each decimal digit then is individu-
ally represented by its 4-bit binary equivalent, as
illustrated in Fig. 1-5.
GRAY CODE
| Gray code is another important binary code, which is
often used for encoding shaft-position data from ma-
chines such as computer-controlled lathes. This code
has the same possible combinations as standard bina-
ry, but as you can see in the 4-bit example in Table 1-1,
they are arranged in a different order. Notice that only
CO
COME
Co
COND
=13 one binary digit changes at a time as you count up in
this code.
If you need to construct a Gray-code table larger than
$
—_=oiaf that in Table 1-1, a handy way to do so is to observe the
pattern of 1s and Os and just extend it. The LSD
(pres column starts with one O and then has alternating
— groups of two 1s and two Os as you go down the
column. The second LSD column starts with two Os
14 = and then has alternating groups of four 1s and four Os.
15a FS
em
eS
Gj)
By
Sy)
Ce
Gey
35
be)
@)
Ww)
fal
ce The third column starts with four Os and then has
alternating groups of eight 1s and eight Os. By now you
(b)
should see the pattern. Try to figure out the Gray code
1101 0110, for the decimal number 16. You should get 1 1000.
Ty rN
Seven-Segment Display Code
(c)
Since seven-segment displays such as the one shown
2279 Steen in Fig. 1-6 are now so common in everything from
16)22% = 14 R3. XN -= 23
Gu « RE X16 = 224 Cl ae be ce die | i soar
227 f
/.
SD
LE
227, = E3:6
(d)
e
‘[_f-
EREST
DP d =
BCD Codes
STANDARD BCD
In applications such as frequency counters, digital
voltmeters, or calculators, where the output is a deci-
mal display, a binary-coded decimal, or BCD, code is
often used. The advantage of BCD for these applica- FIGURE 1-6 Seven-segment LED display. (a) Segment
tions is that information for each decimal digit is labels. (b) Schematic of common-cathode type. (c)
contained in a separate 4-bit binary word. As you can Schematic of common-anode type.
4 CHAPTER ONE
5
DIGITAL DEVICES
Wk Lte
Af)ecee[recs/eecefeoe:
Opes
NUMBER
KR
oO
COMPUTER
+tTM
(Ge
(oy (>
4 3d0Qaoasd4iv
AWidsSId;) TWWID3G TWLOO | AHYVNIG | WALSAS
TWWID30
|
-VX3SH
(NO = 1) AV1dSIG LNAWDSS-N3ARS | 031031434 $3d09 IVWWID3Sd
NOWWOD wWaWNN $1d0)
L-L
41aV1
calculators to gasoline pumps, the segment code for parity check is wanted, a parity bit is added to the basic
such displays has been included in Table 1-1. Some 7-bit code in the MSB position. The binary word 1100
single seven-segment displays will display the last six 0100, for example, is the ASCII code for uppercase D
numbers (10-15) of this code as the hexadecimal digits with odd parity. Table 1-3 gives the meanings of the
A-F. In Table 1-1, a 1 indicates that the segment is control character symbols used in the ASCII code table.
lighted, which is true for displays such as the common-
cathode LED display in Figure 1-6b. For some displays, BCDIC
such as the common-anode LED display shown in BCDIC code is the Binary-Coded Decimal Interchange
Figure 1-6c, a low actually lights the segment, so you Code used with some computers. It uses 7 bits plus a
have to invert all the values. parity bit. The lower 4 bits are referred to as the
numeric bits. The upper 4 bits contain a parity bit and
3 zone bits. The arrangement of these bits is shown at
Alphanumeric Codes
the bottom of Table 1-2. To save space in Table 1-2, the
When communicating with or between computers, you hex equivalent of the binary digits is used for the
need a binary-based code that can represent letters of BCDIC code expressed with even parity.
the alphabet as well as numbers. Common codes used
for this have from 5 to 12 bits per word and are referred EBCDIC
to as alphanumeric codes. To detect possible errors in Another alphanumeric code commonly encountered in
these codes, an additional bit, called a parity bit, is IBM equipment is the Extended Binary-Coded Decimal
often added as the most significant bit. Interchange Code, or EBCDIC. This is an 8-bit code
Parity is a term used to identify whether a data word without parity. A ninth bit can be added for parity. To
has an odd or even number of ls. If a data word save space in Table 1-2, the 8 binary digits of EBCDIC
contains an odd number of 1s, the word is said to have are represented with their 2-digit hex equivalent.
odd parity. The binary word 011 0111 with five 1s has
odd: parity. The binary word 011 OOOO has an even SELECTRIC
number of 1s (two), so it has even parity.
In practice the parity bit may function as follows. Selectric is a 7-bit code used in the familiar IBM
The system that is sending a data word checks the spinning-ball typewriters and printers. Table 1-2 also
parity of the word. If the parity of the data word is odd, shows this code, for reference. Each bit position in the
the system will set the parity bit toa 1. This makes the code controls an operation of the spinning ball.
parity of the data word plus parity bit even. If the parity From most significant to least significant bit, the
of the data word is even, the sending system will reset meaning of the seven bits are ROTATE 5, TILT 1, TILT
the parity bit to a 0. This again makes the parity of the 2, SHIFT, ROTATE 2A, ROTATE 2, and ROTATE 1. In
data word plus parity even. The receiving system addition to this 7-bit code, Selectrics have separate
checks the parity of the data word plus parity bit that it machine commands for space, return, backspace,
receives. If the receiving system detects odd parity in tabs, bell, and index.
the received data word plus parity, it can assume an
error occurred and tells the sending system to send the HOLLERITH
data again. The system is then said to be using even Hollerith is a 12-bit code used to encode data from
parity. The system could have been set up to use those computer cards that threaten you with a fate
(maintain) odd parity in a similar manner. worse than death if you ‘‘fold, spindle, or mutilate’”’
The difficulty with this method of detecting errors them. Figure 1-7 shows a standard 12-row by 80-
introduced during transmission is that two errors in- column card. The 12 data rows are labeled, starting
troduced into a data word may keep the correct parity; from the top; as 12,11, 0, I, 2),.354, 5, 627,68; Qn ine
therefore, the parity checker won’t indicate an error. top 3 rows are called zone punches and the bottom 10
Other, more complex methods, such as CRC and Ham- rows are Called digit punches. Note that the zero row is
ming codes, can be used to detect multiple errors in included in both categories. A punched hole represents
transmitted data and even to correct errors. Some of a 1 and a data word is described by the 12 bits ina
these are described in a later chapter on data commu- vertical column. The card in Figure 1-7 shows the
nication and formats for data memory storage. Hollerith code for the numbers and letters printed
across the top of the card. Table 1-3 shows the entire
ASCIl code and the punched-hole equivalent for each charac-
ter. Since Hollerith code uses very few of the possible
Table 1-2 shows several alphanumeric codes. The first
combinations for 12 bits, it is not very efficient. There-
of these is ASCII, or American Standard Code for
fore, it is usually converted to ASCII or EBCDIC for use.
Information Interchange. This is shown in the table as
a 7-bit code. With 7 bits you can code up to 128
characters, which is enough for full upper- and lower- ADDING AND SUBTRACTING BINARY,
case alphabets, numbers, punctuation marks, and
control characters. The code is arranged so that if only
OCTAL, HEX, AND BCD NUMBERS
uppercase letters, numbers, and a few control charac- The previous section of this chapter reviewed common
ters are needed, only the lower 6 bits are required. If a number systems and codes used with computers. This
6 CHAPTER ONE
ES Ze i
38
=O 20
EBCDIC =e
33
ce
SC H
eZ0W]
Saal xX
Zzoa
12a &) Bh 4
5 0 7 D 12
7 D 2 5 8
12
1
1
11
(continued)
~elotdtoOd
CO ate Z2ElnNcoK-NSOl
=>5©
ASCII i.) oc ~ rr)= = oa
>a n=
i
a
SYMBOL SYMBOL oO an oe — EBCDIC | SYMBOL (7) = oO oes
now
wos i=
wr
— 00om
4 E
a
a
6 B
=o
6 0
Ol
oroe)
4B
N
Os
OK“
om
CK
or
0 3
OD Oo)
NO)
7
Nm
NMT] nme]
Oo-at
2 3
OD OD
Ears 7 6
<t
=
F 4 ie a
Oo
MOON 0 wmnonaoalo-
oO
5 3 5
CODm~ Oo
3 4 Om~
m™~ Oo
6
7 7 5
aAD] OD
DD CO
Fas 7 4
Fao a} @)
a
Qo
-- NowmowMmortr]
---ViIl_A~@®]qmMoOQa
VY «3 +.
~~MNITLMMNRR
>
--V -=— ©o
+t
oO
iI
A |
oO
An~ om
4 9
8) ~
fazeefoe eves]
OmOd
CNC
@&
3 E
OOS] SN
= -—-ANAmM+]
A A
qmoa
Ge
B B
oOoOmn~OIL
LS
c C
D D wm
onr-wm
m0Oo to
SeDorn
E E (a0
F F 4
nNOMI/TTNOM~]
oaaqag;t
4 F
MAND
G G
H H me
<MIo
IT
7.
NOY Dre
MK
-7 aolarnm|t+mo
C
ere
| | N
J J 07
andn;anonww
ILNDON]T
Yu
SNe K K 12¢
OF
ew
jaan
Lv L 5 9 =
+WwW
6 F
Se
1E
ore
Oncnnr-
6 9
Oe
NwOr-
OBDANM
ee
0D
oo oe
ODN
NOt
OO
Oanwnr Orne
1
1
o>)
Ow
Ww
OY
Onnr- =
SOON
(continued)
8 CHAPTER ONE
HEX
CODE HOLES
ASCll FOR 7-BIT | BCDIC
SYMBOL AScil | SYMBOL BCDIC | SYMBOL | EBCDIC | SYMBOL
5 5 U 14 U U SaE 4
5 6 Vv 5 5 V V OnE é
5 7 Ww 5 6 W WwW 258 6
5 8 Xx hay Xx x Sat 7
5 9 Y 1 8 Y Vv 0 9 8
5 A Z 5 9 ZL Z Se 9
5 B [ TaD [ [ i IP Sie
5 C SG 1€£ NL Sa2
5 D ] IED ] 8 2
5 E Oo 3 € q Sal
5 F = 6 0 = = 0 8 Sy)
6 0 RaeaS Ss
we)
(Sj
ep)
ammmmmm
* OAs
ron
OOoOrNDOf 1
6 1 a 871 a 6 4 a I @ 4
Gam b 8 2 b i) @ b 12 © 2
Ome Cc 8 3 Cc ay a Cc WZ Ors
Qoom]-|/>—/—|IN<~XS<c
6 4 d 8 4 d 5 5 d 12 @ 4
6 5 e Sao e 15 e 12 05
6 6 f 8 6 f 4 6 f /2aO mG
a 7 g ih I g Aa g IZ © 7
sa
+o 6 8 h 8 8 h eet h ZEROS
6 9 i 8 9 i 2 bh i 12 09
6 A j ea j Op 7 j 1201 4
6 B k 9 2 k re k IZ 2
(} (¢ | 9 3 | iy 4 | 12 &
6 D 9 4 m 6 7 m 1211 4
Ome 9 5 n i n 12115
Ome 9 6 fo) (4 fo) 12 Vil @
iQ 9 7 p 0 5 p WZ a
ih q 9 8 q Ome 9 ZA te}
yD? r 9 9 r i & r 17/2 Ie)
aS s A 2 s a s I @© 2
7 4 t A 3 t it 7 t Hil OS
rs u A 4 u 5 6 u li @ 4
PMG Vv A 5 v 6 6 v lle ORS
aa, w A 6 w 2 0 w lOn 6
7 8 x Aaa. x i) 7/ x ia) @) #7
Tee) y A 8 y Oma y ORS
-:
Ni<o 7A
-ononrnQgloorsd3g]/-—-x*~-
xo
<a z A 9 z Sa] z 1109
iy {3} { 8 B { 12 0
7G | 4 F | 1211
7D } 9 B } ii @
i Az ¢ 4A ~ ii @ 4
iw] m lee 7
mr F DRE ws 07 DEERE IZ YY
BCDIC SELECTRIC
HEX DIGIT HEX DIGIT R,1,T, SR,,R,R,
—————— a,
PCBA 999728 HEX DIGIT HEX DIGIT
(i2asss7e
0123456789
0 14 12.1304 5 16 17-1813 20.2122 29.0025 BP
ABCDEFGHIJK LMNOPORSTUVWXYZ oy Da aE
MLE DDDD2 3 979029:000 02 00 a405 Gs oe0s 505)a0 59 545586If58596061 ff656465 6667 x 6970.71727014°75267170-790]
ns
ZONE
GOGGRRaRE | PUNCHES
Oo
2—
OrTT
1011 12 13 14 1S 16 17 18 19 2021 2223
PA Re
242526 27 28 29 30 3! 32 33 34 25 36 37 38-39 40 41 47 43.44 45 45 47 48 49.50 51 5253
aa ee eee ee
TC
545556 5)58 59.60 61 62 63 54 GS 66 67 68 69 70 TI72 73 74 7S 7677 75 79 90
ea Aaa
]
VENA PANO AARAON A AQP QAA RAM WAQQRAM |B QDI RADAR DO RID BERN ELAD LARD DOERQEOBED
12.3.4 5 6 7 8 940M 12 13 14 35 16 17 18 19 2021 22 23 24 25 26 27 28 29 30 3) 32 93 34 35 3637 3839 40 41 42 43 44 45 46 47 48.49 50 51 52.53 54 55 56 57 58 5960 61 62 63 64 65 66 67 68 69 10 1172 73 74 75 16 7) 13:79 90
333333333333338333333333333083333333383333333833333333333903303333333333333333393
$4444444464446444844444444644448
4444444468 44454440444444444444444454444444444 bd
12.3.4 5 6 7 B 91011 12 13 14 15 16 17 18 19 20 71 22 23.24 25 26 27 28 29.30 31 32 33.34 35 36 27 3829-40 4s 42 43 44 4E 55 47 48 49:50 51 52 53 54 55 56 57 5B $2 SD 61 62 63 64 S° G6 67 6869 70 7) 72:75:74 TS710 7) 78 19 80 DIGIT
§555555555555555055555955555559855555555855555558555555555555555555555555555555555 PUNCHES
BEGEESGFEHE GFK EGE SME CESS ERESC CEM ESC CCE SEM EGC EEE GM CCE E GFE GEE GEE EEGEEEEEEE GEES EEES
123.45 6 7 8 91011 12 13 14 15 16 17 18 19 20 21 22 23 24 75 26 27 28.29 30 3 32 33 34 35 36 37 3B 39 40 41 42 43 44 45 46 47 48.49 50 51 52.53 54 55 56 57 58 59 60 G1 62 63 G4 65 66 67 68 69 70 1 72:73:14 75:16 77 18:75 80
TUPI I Te Le a ee Teel er ener aie aT
BEGKKRKBESSCISHERSHRSKREMS
GR BHKKKHKRGHMHSSHHCR GMS Ih HGP S SSSR CPBMMMM SRE HBRHSERLEPHBISS
12:3°4 5 6 7 8 91910 12:19 14 15 75 17 18 19 20 21 2273.24 25 26 27 28 2930 3; 32 33:34 35 36 37 38 35 U4" 47 4344 45 46 47 48 46°59 £157.53 4 55 56 57 58 59 60 Gt E? 63 64 tz 6567 G6869 HN 727s 7 6 7 5 BO
99999999993999999999H999999995999999999999999999999H9579999999939999999199938989959
i)
- ie 5083 PRINTED INU SA
(b)
section reviews how to do computations in the previ- The way to do this is to reserve the MSB of the data
ously described number systems. word as a sign bit and to use the rest of the bits of the
data word to represent the size (magnitude) of the
quantity. A computer that works with 8-bit words will
represent signed numbers with the MSB (bit 7) as the
Binary
sign bit and the lower 7 bits as a representation of the
ADDITION
Figure 1-8a shows the truth table for addition of two
binary digits and carry in (C,,) from addition of previ-
NUL NULL DIRECT CONTROL 2
ous digits. Figure 1-8b shows the result of adding two
SOH START OF HEADING DIRECT CONTROL 3
8-bit binary numbers using these rules. Note that
STX START TEXT DIRECT CONTROL 4
since the result can be only aOorl1,1+0+C,y=0
ETX END TEXT NEGATIVE
plus a carry into the next digit, and 1 + 1 +C, = 1 plus
EOT END OF TRANSMIS- ACKNOWLEDGE
a carry into the next digit.
SION SYNCHRONOUS
ENQ ENQUIRY IDLE
2’s COMPLEMENT BINARY ACK ACKNOWLEDGE END TRANSMIS-
One way of representing negative numbers in binary is BEL BELL SION BLOCK
by using 2’s complement binary. When you handwrite BS BACKSPACE CANCEL
a number which represents some physical quantity HT HORIZONTAL TAB END OF MEDIUM
such as temperature, you can simply put a + sign in LF LINE FEED SUBSTITUTE
front of the number when you wish to indicate that the VT VERTICAL TAB ESCAPE
number is positive. You can write a — sign when you FF FORM FEED FORM SEPARATOR
wish to indicate that the number is negative. However, CR CARRIAGE RETURN GROUP SEPARATOR
if you want to store values such as temperatures, SO SHIFT OUT RECORD
which can be positive or negative, in a computer SI} SHIFT IN SEPARATOR
memory, there is a problem. Since the computer mem- DLE DATA LINK ESCAPE UNIT SEPARATOR
ory can only store 1s or Os, some way must be estab- DC1 DIRECT CONTROL 1
lished to represent the sign of the number with a 1
ora O. TABLE 1-3 Definitions of control characters.
10 CHAPTER ONE
Sign bit
INPUTS OUTPUTS
+ 7 anton
+ 46 0: 0101110
+105 0: 1101001
be 1; 1110100
151001010 Sign and
— 54
—117 1 |0001011 Re ae
nan 40 1: 1010010
FIGURE 1-9 Positive and negative numbers represented
with a sign bit and 2’s complement.
S=A®BOLy
Cour =A*B+CwlA @ B) number is negative, as indicated by a sign bit of 1, then
the magnitude is expressed in 2’s complement. To get
(a) the magnitude of this negative number expressed in
standard binary, invert each bit of the data word,
10011010 including the sign bit, and add 1 to the result. For
+ 11011100 example, given the word 1110 1011, invert each bit to
get 0001 0100. Then add 1, resulting in 0001 0101.
[1] 01110110
This equals 21,,, so you know that the original num-
fe Carry bers represent —21,,. Again, try converting a few of the
numbers in Figure 1-9 for practice.
(b) Figure 1-10 shows some examples of addition of
signed binary numbers of this type. Sign bits are added
FIGURE 1-8 Binary addition. (a) Truth table for 2 bits together, just as the other bits are. Figure 1-10a shows
plus carry. (b) Addition of two 8-bit words. the results of adding two positive numbers. The sign
bit of the result is zero, so the result is positive. The
second example, in Figure 1-10b, adds —9 to +13, or,
magnitude of the numbers. The usual convention is to in effect, subtracts 9 from 13. As indicated by the zero
represent a positive number with a O sign bit and a sign bit, the result of this, 4, is positive and is in true
negative number with a 1 sign bit. binary form.
To make computations with signed numbers easier, Figure 1-10c shows the result of adding —-13 toa
the magnitude of negative numbers is represented in a smaller positive number, +9. The sign bit of the result
special form called 2’s complement. The 2’s comple- is a 1. This indicates that the result is negative and the
ment of a binary number is formed by inverting each magnitude is in 2’s complement form. Remember, to
bit of the data word and adding 1 to the result. Some convert a 2’s complement result to a signed number in
examples should help clarify this. true binary form,
The number +7,) is represented in 8-bit sign-and-
magnitude form as 0000 0111. The sign bit is zero,
which indicates a positive number. The magnitude of 1. Invert each bit, to produce 1’s complement.
positive numbers is represented in straight binary, so
2. Addi.
the least significant bits of 0000 0111 represent 7).
To represent —7,, in 8-bit 2’s complement sign-and- _ 3. Place a minus sign in front of the number to
magnitude form, start with the 8-bit code for +7, 0000 indicate that the result is negative.
0111. Invert each bit to get 1111 1000. Then add 1 to
get 1111 1001. This result is the correct representa-
tion of —7,.. Figure 1-9 shows other examples of The final example in Figure 1-10d shows the results
positive and negative numbers expressed in 8-bit sign- of adding two negative numbers. The sign bit of the
and-magnitude form. For practice, try generating each result is a 1, and the result is negative and in 2’s
of these yourself to see if you get the same result as complement form. Again, inverting each bit, adding 1,
shown. and prefixing a minus sign will put the result in a more
To reverse this procedure and find the magnitude of recognizable form.
a number expressed in sign-and-magnitude form, pro- Now let’s consider the range of numbers that can be
ceed as follows. If the number is positive, as indicated represented with 8 bits in sign-and-magnitude form.
by a sign bit of O, then the least significant 7 bits Eight bits can represent a maximum of 2°, or 256,
represent the magnitude directly in binary. If the numbers. Since we are representing both positive and
12 CHAPTER ONE
10101010
0 0 0 0 0 —01100100
01000110
(6)
(a)
77,, 01001101 01001101
=e 01011000 Complement +10101000
See COMPLeMment
—11,, [0] 11110101 00001010
Nee 10100111
Matiy Add one + 1
+ 1 Indicates ————
result negative = 101i ln
Two's comp 10101000 and in two’s
Carry complement form
(d)
FIGURE 1-12 Binary subtraction. (a) Truth table for two bits and borrow. (b)
Pencil method. (c) 2’s complement positive result. (d) 2's complement negative
result.
type of shifts required make it awkward to implement. of the partial products is shifted right rather than each
One of the multiplication methods used by comput- partial product being shifted left.
ers is repeated addition. To multiply 7 x 55, for exam- A point to note about multiplying numbers is the
ple, the computer can just add seven 55s. For large number of bits the product requires. For example,
numbers, however, this method is slow. To multiply multiplying two 4-bit numbers can give a product with
786 x 253, for example, requires 252 add operations. as many as 8 bits, and two 8-bit numbers can give a
Most computers use an add-and-shift-right method. 16-bit product.
This method takes advantage of the fact that, for
binary multiplication, the partial product can only be BINARY DIVISION
either the top number if the multiplier digit isa 1 ora0O Binary division can also be performed in several ways.
if the multiplier digit is a 0. The method does the same Figure 1-14 shows two examples of the pencil method.
thing as the pencil method except that the partial This is the same process as decimal long division.
products are added as they are produced and the sum However, it is much simpler than decimal long division
because the digits of the result (quotient) can be only O
or 1. A division is attempted on part of the dividend. If
11 1011 Multiplicand this is not possible because the divisor is larger than
x 9 x 1001 Multiplier that part of the dividend, a O is entered into the
quotient. Another attempt is then made to divide using
99 1011
one more digit of the dividend. When a division is
0000 \ possible, a 1 is entered in the quotient. The divisor is
Partial products then subtracted from the portion of the dividend used.
0000
The process is continued as with standard long divi-
1011 sion until all the dividend is used. As shown in Figure
1100011 Product 1-14b, Os can be added to the right of the binary point
and division continued to convert a remainder to a
FIGURE 1-13 Binary multiplication. binary equivalent.
14 CHAPTER ONE
34, 28, BCD
35 0011 0101
a7: = Sins
+23 +0010 0011
15, Te
58 0101 1000
FIGURE 1-17 Octal subtraction.
(a)
3C 46 60,6 POT ah
FIGURE 1-18 Hexadecimal subtraction. FIGURE 1-20 BCD subtraction.
Logic Gates
Figure 1-21b shows the symbols and truth tables for
simple logic gates. A symbol with a flat back and a
round front indicates that the device performs the
logical AND function. This means that the output will
be asserted if the A input is asserted AND the B input
is asserted. Again, a bubble or lack of bubble is used to
indicate the assertion level of each input and output.
The first AND symbol in Figure 1-21b has no bubbles,
so the inputs and the output are active high. The
output then will be asserted high if the A input is
asserted high AND the B input is asserted high. The
bubble on the output of the second AND symbol in
Figure 1-21b indicates that this device, commonly
called a NAND gate, has an active low output. If the A
input is asserted high and the B input is asserted high,
then the Y output will be asserted low. Look at the
truth table in Figure 1-21b to see if you agree with this.
Figure 1-21c shows the other two possible cases for
the AND symbol. The first of these has bubbles on the
inputs and on the outputs. If you see this symbol in a
schematic, you should immediately see that the output
will be asserted low if the A input is asserted low AND
the B input is asserted low. The second AND.symbol in
Figure 1-2lc has no bubble on the output, so the
output will be asserted high if the A AND B inputs are
(d) both asserted low.
A logic symbol with a curved back indicates that the
FIGURE 1-21 Buffers and logic gates. (a) Buffers. (b) output of the device will be asserted if the A input is
AND-NAND. (c) OR-NOR. (d) Exclusive OR. asserted OR the B input of the device is asserted. Again
16 CHAPTER ONE
a bubble or lack of bubble is used to indicate the
assertion level for an input or output. Note in Figure
1-21b and 1-21c that each of the AND symbol forms
has an equivalent OR symbol form. An AND symbol
with active high inputs and an active high output, for
example, represents the same device (a 74LS08, per-
haps) as an OR symbol with active low inputs and an
active low output. Use the truth table in Figure 1-21b
to convince yourself of this. The bubbled-OR represen-
tation tells you that if one input is asserted low, the
output will be low, regardless of the state on the other
input. As we will show later in this chapter, this is
often a useful way to think of the operation of an AND
gate.
Figure 1-21d shows the symbol and truth table for
an exclusive-OR gate. The output of this device will be
asserted if the A input is asserted OR if the B input is
asserted, but the output will not be asserted if both A
AND B are asserted.
You need to be able to read any of these symbols
9D~ ~) Ol
because most logic designers will use the symbol that
best describes the function they want a device to
perform in a particular circuit.
DATA S
Ding.G
CKD
Q
CLR
CLEARo
CLOCK ©
FIGURE 1-23 Registers. (a) Simple data storage. (b) Shift register.
18 CHAPTER ONE
feature of ROMs is that they are nonvolatile. This
0 means that the information stored in them is not lost
when the power is removed from them.
@)
Figure 1-25a shows the schematic symbol of a com-
ORI
mon ROM. As indicated by the eight data outputs,
@ 4
DO-D7, this ROM stores 8-bit data words. The data
1 0
outputs are three-state outputs. This means that each
1 0 output can be at a logic low state, a logic high state, or
1 1 in a high-impedance, floating state. In the high-impe-
1 1 dance state an output is essentially disconnected from
0 60 anything connected to it. If the CE input of the ROM is
OO not asserted, then all the outputs will be in the high-
Om impedance state. Also, most ROMs switch to a lower
Oma
power consumption condition if CE is not asserted. If
the CE input is asserted, the device will be powered up,
1 0
and the output buffers will be enabled. Therefore, the
1 0
outputs will be at a normal logic low or logic high state.
1 1
You will soon see why this is important if you don’t
1 1 Oo:
=>
Cdl
CO
lw
CO
OCU
w=
=]
OO
O=o
=
happen to remember.
(a) (b)
You can think of the binary words stored in the ROM
as being in a long, numbered list. The number that
FIGURE 1-24 Four-bit, presettable binary counter. (a) corresponds to each stored word is called its address.
Schematic symbol. (b) Count sequence. In order to get a particular word onto the outputs of the
ROM, you have to do two things: You have to apply the
address of that word to the address inputs, Ay—A,,, and
you have to assert the CE input to turn on the outputs.
ROMs, RAMs, and Buses Incidentally, you can tell the number of binary words
stored in the ROM by the number of address inputs;
The next topics we need to review are the devices the number of words is equal to 2", where N is the
which store large numbers of binary words and how number of address lines. The device in Figure 1-25a
combinations of these devices can be connected to- has 15 address lines, Ay—Aj,,, so the number of words is
gether. 2'°, or 32,768. In a data sheet this device would be
referred to as a 32K X 8 ROM. This means 32K
ROMs addresses by 8 bits per address.
The term ROM stands for read-only memory. There Now, let’s see why we want three-state outputs on
are several types of ROM that can be written to, read, this ROM. Suppose that we want to store more than
erased, and written to with new data, but the main 32K data words. We can do this by connecting two or
ADDRESS DATA Ao
INPUTS OUTPUTS
ADDRESS
BUS
dD,
(a)
any one of the ROMs can output data on the common ADDRESS
data bus. If these ROMs had standard two-state out- INPUTS
puts, a serious problem would occur, because each
device would be trying to output an addressed word
onto the data bus. The resulting argument between
data outputs would probably destroy some of the out-
puts and give meaningless information on the data
bus. Since the ROMs have three-state outputs, howev-
er, we can use external circuitry to make sure that only
one ROM at a time has its outputs enabled. The very
READ/WRITE eee
important principle here is that whenever several out-
puts are connected on a bus, the outputs should all be CHIP ENABLE
three-state, and only one set of outputs should be
enabled at a time.
FIGURE 1-26 RAM schematic symbol.
At the beginning of this section we mentioned that
some ROMS can be erased and rewritten or repro-
grammed with new data. Here is a summary of the
different types of ROM: To write to the RAM, we apply the desired address to
the address inputs, assert the CE input low to turn on
Mask-programmed ROM—Programmed during manu- the device, and assert the R/W input low to tell the
facture; cannot be altered. RAM we want to write to it. We then apply the data
word we want to store to the data lines of the RAM fora
PROM—User-programmed by blowing fuses; cannot specified time. To read a word from the RAM, we
be altered except by blowing additional fuses. address the desired word, assert CE low to turn on the
device, and assert R/W high to tell the RAM we want to
EPROM—Electrically programmed by user; erased by
read from it. For a read operation, the output buffers on
ultraviolet light shone on quartz window in package.
the data lines will be enabled and the addressed data
EEPROM—Electrically programmed by user; erased word will be present on the outputs.
with electrical signals instead of ultraviolet light. The static RAMs we have just reviewed store binary
words in a matrix of flip-flops. In dynamic RAMs
(DRAMs), binary 1s and Os are stored as electrical
STATIC AND DYNAMIC RAMs charges or no charges on a tiny capacitor. Since these
The name RAM stands for random-access memory, tiny capacitors take up less space on a chip than a
but since ROMs are also random-access memories, a flip-flop would, a dynamic RAM chip can store many
better name would probably be read-write memories. more bits than a static RAM chip of the same size. The
RAMs are also used to store binary words. A static disadvantage of dynamic RAMs is that the charge
RAM is essentially a matrix of flip-flops. Therefore, we leaks off the capacitors. The logic state stored in each
can write a new data word in a RAM location at any capacitor must be refreshed every 2 ms or so. A device
time by applying the word to the flip-flop data inputs called a dynamic RAM refresh controller can be used
and clocking the flip-flop. The stored data word will to refresh a large number of dynamic RAMs in a
remain on the flip-flop outputs as long as the power is system. Some newer dynamic RAM devices contain
left on. This type of memory is volatile because data is built-in refresh circuitry, so they appear static to
lost when the power is turned off. external circuitry.
Figure 1-26 shows the schematic symbol for a com-
mon RAM. This RAM has 12 address lines, Aj—A,,, so
Arithmetic Logic Units
it stores 2'* (4096) binary words. The eight data lines
tell you that the RAM stores 8-bit words. When we are Previous sections of this chapter reviewed ANDing,
reading a word from the RAM, these lines function as ORing, exclusive-ORing, adding, and subtracting of
outputs. When we are writing a word to the RAM, binary numbers. A device that can perform any of
these lines function as inputs. The chip enable input, these functions and others on binary words is an
CE, is used to enable the device for a read or for a write. arithmetic logic unit, or ALU. Figure 1-27a shows a
The read/write (R/W) input will be asserted high if we block diagram for the 74LS181, which is a 4-bit ALU.
want to read from the RAM, and it will be asserted low This device can perform any one of 16 logic functions
if we want to write a word to the RAM. Here’s how all or any one of 16 arithmetic functions on two 4-bit
these lines work for reading from and writing to the binary words. The function performed on the two
device. words is determined by the logic level applied to the
20 CHAPTER ONE
ACTIVE-HIGH DATA
SELECTION
M=H M—L: ARITHMETIC OPERATIONS
LOGIC as =
74LS181 SS OZ ao lnoO. FUNCTIONS Cy =H (no carry)
L F=A F=APLUS1
L F=A+B F=(4+B8)PLUS 1
L F=A+B F=(A+B) PLUS 1
L F = MINUS1 (2’s COMPL) | F= ZERO
L F=A PLUS AB F=A PLUS AB PLUS 1
L F=(A+B) PLUS AB F = (A+B) PLUS
AB PLUS 1
L F =A MINUS B MINUS 1 F=A MINUSB
L F = AB MINUS 1 F=AB
H F=A PLUS AB F=A PLUS AB PLUS1
H F=APLUSB F=APLUSB PLUS 1
H F=(A +B) PLUS AB F=(A+B) PLUS AB PLUS 1
H =AB F = AB MINUS 1 F=AB
H =i F=APLUSA F=APLUSA PLUS 1
H =A+B F=(A+B)PLUSA F=(A+B) PLUS A PLUS 1
H =A+B F=(A+B)PLUSA F = (A+B)PLUS A PLUS 1
H |
eee
ey
Sp
aie.
See
Wadi
CaS
ce
lee
ee
(pe Se
Jawan
ea
am
eae
He
eae
dpe
tee
ler
ie
Ne
eee
li as
ee
eT
i
Es
at
yo
aA”
eB
pe
IL
ee
Gp
emt
eel
fa WH
wh
Ae
wy
WW
Ww
HH
wo
ww= F=A MINUS 1 FH=A
(a) (b)
A; Ame Av An
A 1 © 1 ©
B;
(by dope SG
B 0 i) Mh ae)
F3 Fo Fy Fo
Ao © Oo 2 ©
Fy
Fo EE, Fe
A+B 1 1 f £0
Fi Fy F, Fo
A@®B 1 Om O
FIGURE 1-27. Arithmetic logic unit (ALU). (2) Schematic symbol. (b) Truth table.
(c) Sample AND, OR, XOR operations.
mode input, M, and by the 4-bit binary code applied to For another example of the operation of the
the select inputs, S,)—S3. 74LS181, suppose that the M input is high, S; is high,
Figure 1-27b shows the truth table for the 74LS181. S, is high, S, is high, and Sp is low. According to the
In this truth table A represents the 4-bit binary word truth table, the device will now OR each bit in the A
applied to the Ay—A; inputs and B represents the 4-bit word with the corresponding bit in the B word and give
binary word applied to the B,—B; inputs. F represents the result on the corresponding F output. Figure 1-27c
the 4-bit binary word produced on the F,—F; outputs. If shows the result that will be produced by ORing two
the mode input, M, is high, the device will perform one 4-bit words. Figure 1-27c also shows, for your refer-
of 16 logic functions on the two words applied to the A ence, the result that would be produced by exclusive-
and B inputs. For example, if M is high and we make S, ORing these two 4-bit words together.
high, S, low, S, high, and S, high, the 4-bit word on the If the M input of the 74LS181 is low, then the device
A inputs will be ANDed with the 4-bit word on the B will perform one of 16 arithmetic functions on the A
inputs. The result of this ANDing will appear on the F and B words. Again, the result of the operation will be
outputs. Each bit of the A word is ANDed with the put on the F outputs. Several 74LS181s can be cascad-
corresponding bit of the B word to produce the result ed to operate on words longer than 4 bits. The ripple-
on F. Figure 1-27c shows an example of ANDing two carry input, Cy, allows a carry from an operation on
words with this device. As you can see in this example, previous words to be included in the current operation.
an output bit is high only if the corresponding bit is If the C, input is asserted low, then a carry will be
high in both the A word AND in the B word. added to the results of the operation on A and B. For
22 CHAPTER ONE
11. Express the following decimal numbers in 8-bit
sign-and-magnitude form.
a. +26
bs =7
Ca 26
Gy 125
14. Show the division of 110 0100 by 1010 using the 17. What is the main difference between a D latch and
pencil method. a D flip-flop?
15. Perform the indicated operations on the following 18. The National Semiconductor INS8298 is a
numbers. 65,536-bit ROM organized as 8192 words or bytes
a. Add octal numbers 27 and 16. of 8 bits. How many address lines are required to
b. Subtract octal number 45 from octal number address one of the 8192 bytes?
132.
19. Why do most ROMs and RAMs have three-state
c. S38A + $94
outputs?
d. $17A — S4C
e. 0101 1001 BCD 20. Using Figure 1-27, show the programming of the
+ 0100 0010 BCD select and mode inputs the 74181 requires to
perform the following arithmetic functions.
ie 0111 1001 BCD a, AB
+ 0100 1001 BCD D: Age Baek
GC Age Baa
g. 0101 1001 BCD
— 0010 0110 BCD 21. Show the output word produced when the follow-
ing binary words are ANDed with each other and
ie 0110 0111 BCD when they are ORed with each other.
— 0011 1001 BCD a. 1010 and 0111
b. 1011 and 1100
16. Use the circuit in Figure 1-28.
c. 1101 0111 and 11 1000
a. Is the Y output active high or active low?
b. Is the C signal active high or active low? 22. ANDing an 8-bit binary number with 1111 0000
c. What input conditions on A, B, and C will is sometimes referred to as ‘‘masking’’ the lower
cause the Y output to be asserted? 4 bits. Why?
We live in a computer-oriented society, and we are binary codes for the sequence of instructions you want
constantly bombarded with a multitude of terms relat- the computer to carry out. When you write a computer
ing to computers. Before getting started with the main program, what you are really doing is just writing a
topics in the book, we will try to clarify some of these sequential list of instructions for the computer. The
terms and give an overview of computers and computer second purpose of the memory is to store the binary-
systems. coded data with which the computer is going to be
working. This data might be the inventory records of a
supermarket, for example.
OBJECTIVES INPUT/OUTPUT
At the conclusion of this chapter, you should be able to The input/output, or I/O, section allows the computer
to take in data from the outside world or send data to
1. Define the terms microcomputer, microprocessor, the outside world. Peripherals such as keyboards,
hardware, software, firmware, timeshare, multi- video display terminals, printers, and modems are
tasking, distributed processing, and multiproces- connected to the I/O section. These allow the user and
sing. the computer to communicate with each other. The
actual physical devices used to interface the computer
2. Describe how a microcomputer fetches and exe-
buses to external systems are often called ports. Ports
cutes an instruction. function in a computer just as shipping ports do ina
3. List the registers and other parts in the 68000 country. An input port allows data from a keyboard,
family of CPUs. an A/D (analog-to-digital) converter, or some other
source to be read into the computer under control of
4. Describe the function of the 68000 prefetch queue. the CPU. An output port is used to send data from the
5. Demonstrate the way in which the 68000 address- computer to some peripheral such as a video display
es memory. terminal, a printer, or a D/A (digital-to-analog) con-
verter. Physically, an input or output port is often just
a set of parallel D flip-flops that let data pass through
when they are enabled or clocked by a control signal
COMPUTERS from the CPU.
What Is a Computer?
CENTRAL PROCESSING UNIT
Figure 2-1 shows a block diagram for a simple comput- The central processing unit, or CPU, controls the
er. The major parts are the central processing unit operation of the computer. It fetches binary-coded
(CPU), memory, and the input and output (I/O) circuit- instructions from memory, decodes the instructions
ry. Connecting these parts are three sets of parallel into a series of simple actions, and carries out these
lines called buses. The three buses are the address actions. The CPU contains an arithmetic logic unit, or
bus, the data bus, and the control bus. ALU, which can perform add, subtract, OR, AND,
invert, or exclusive-OR operations on binary words
MEMORY when instructed to do so. The CPU also contains an
The memory section usually consists of a mixture of address counter, which is used to hold the address of
RAM (random-access memory) and ROM (read-only the next instruction or data to be fetched from memo-
memory). It may also have magnetic floppy disks, ry; general-purpose registers, which are used for tem-
magnetic hard disks, or laser optical disks. Memory porary storage of binary data; and circuitry that gene-
has two purposes. The first purpose is to store the rates the control bus signals.
24
DATA BUS
INPUT
DEVICE CONTROL CENTRAL CONTROL
BUS PROCESSING BUS MEMORY
UNIT (RAM AND
OUTPUT
DEVICE
ADDRESS BUS
DATA BUS
1. Input a value from a keyboard connected to
The data bus consists of 8, 16, 32, or more parallel
the port at address $CO15.
signal lines. As indicated by the double-ended arrows
on the data bus line in Figure 2-1, the data bus lines Add 7 to the value read in.
are bidirectional. This means that the CPU can read
3. Output the result to a display connected to
data in on these lines from memory or from a port as
well as send data out on these lines to a memory
the port at address SCO10.
location or to a port. The outputs of many devices ina
system are connected to the data bus, but the outputs
Figure 2-2a shows in diagram form the actions that
of only one device at a time are enabled. Any device
the computer will perform to execute these three in-
outputs connected on the data bus must be three-state
outputs so that they can be floated when the device is structions.
For this example assume that the CPU fetches in-
not in use.
structions and data from memory one word at a time.
Also assume that the binary codes for the instructions
CONTROL BUS
are in sequential memory locations starting at address
The control bus consists of 4 to 10 parallel signal lines. $4000. Figure 2-2b shows the binary codes that would
The CPU sends out signals on the control bus to enable be required in successive memory locations to execute
the outputs of addressed memory devices or port devic- this program on a 68008-based microcomputer.
es. Typical control bus signals are memory read, The first action a computer will do is to fetch the first
memory write, I/O read, and I/O write. To read a byte instruction byte from memory. To do this the CPU
of data from a memory location, for example, the CPU sends out the address of the first instruction byte, in
sends out the address of the desired byte on the this case $4000, to memory. This action is represented
address bus and then sends out a memory-read signal by line 1A in Figure 2-2a. The CPU then sends out a
on the control bus. The memory-read signal enables memory-read signal on the control bus (line 1B in the
the addressed memory device to output the byte of data figure). This causes the memory to output the first
onto the data bus, where it is read by the CPU. instruction byte ($10) on the data bus, as represented
by line 1C. This three-step procedure is repeated in
HARDWARE, SOFTWARE, AND FIRMWARE lines 2A, 2B, and 2C, sending the address $4001 and
When working around computers you almost con- receiving from memory the second instruction byte
stantly hear the terms hardware, software, and firm- (S38). 68000-family CPUs use 2-byte instructions; that
SEQUENCE
(b) (c)
26 CHAPTER TWO
is, every instruction is exactly 2 bytes (1 word) long. A byte of the I/O port address ($10) on lines 10A, 10B,
68008 uses an 8-bit-wide data path so it can access 1] and 10C. The CPU now has all the information that it
byte of data per memory access. Two accesses are needs to execute the instruction. To output a data byte
required to read an entire instruction word. to a port, the CPU first sends out the address of the
The CPU reads the bytes from the data bus and desired port on the address bus (line 10D). Next, it puts
composes them into one instruction word. The CPU the data byte from the accumulator onto the data bus
then decodes the instruction, by which we mean that (line 10E). The CPU then sends out an I/O write signal
the CPU determines from the binary code read in what on the control bus (line 10F). This signal enables the
actions it is supposed to take. In this case the CPU addressed output port device so the data from the data
determines that the code read in represents an input bus lines can pass through it (line 10G). When the CPU
(read) instruction. Also, from decoding this instruction removes the I/O write signal to proceed with the next
word the CPU determines that it needs more informa- instruction, the data output remains latched on the
tion before it can carry out the instruction. The CPU output pins of the port device. Therefore, the computer
must fetch from memory the input port address. To do does not have to keep outputting a value in order for it
this the CPU sends out the next sequential address to remain there.
($4002) to memory, as indicated by line 3A in the All the steps just described may seem like a great
figure. The CPU also sends out another memory-read deal of work just to input a value from a keyboard, add
signal on the control bus (line 3B in Figure 2-2a). This 7 toit, and output the result to a display. Even a simple
enables the memory to put the addressed byte on the computer, however, can run through all these steps in
data bus (line 3C). This byte (SCO) is the first byte of the a few microseconds.
port address. On lines 4A and 4B the CPU requests the
second byte of the I/O port address by sending the
address $4003 and enabling memory. The memory Summary of Simple Computer Operation
responds (line 4C) by placing the byte on the data bus.
When the CPU reads in this fourth byte, $15, it has all 1. A simple computer CPU fetches instructions or
the information it needs to execute the instruction. reads data from memory (reads memory) by send-
To execute the input instruction, the CPU sends out ing out an address on the address bus and a
the port address (SCO15) on the address bus (line 4D) memory-read signal on the control bus. The ad-
and sends out an I/O read signal on the control bus dressed instruction or data is sent from memory to
(line 4E). The addressed port device then puts a byte of the CPU on the data bus.
data on the data bus (line 4F). The CPU reads in the 2. The CPU can write data in RAM memory by send-
byte of data and stores it in an internal register called ing out an address on the address bus, sending out
the accumulator. This completes the first instruction. the data to be written on the data bus, and sending
Having completed the first instruction, the CPU must out a memory-write signal on the control bus.
now fetch its next instruction from memory. To do this
it sends out the next sequential address ($4004) on the 3. To read data from a port, the CPU sends the port
address bus (line 5A). The CPU then sends out a address out on the address bus and sends an I/O
memory-read signal on the control bus (line 5B). This read signal on the control bus. Data from the port
allows the memory to put the addressed byte (S5E) on comes into the CPU on the data bus.
the data bus (line 5C). The CPU reads in the instruction 4. To write data toa port, the CPU sends out the port
byte from the data bus. On lines 6A, 6B, and 6C the address on the address bus, sends the data to be
CPU reads the second byte of the instruction word and written to the port out on the data bus, and sends
decodes the instruction. From the instruction word the an I/O write signal out on the control bus.
CPU determines that it is supposed to add 7 to the
number stored in the accumulator. Assume the result 5. A microcomputer fetches each program instruction
of the addition is left in the accumulator. This com- in sequence, decodes the instruction, and executes
pletes the second instruction. ite
The CPU must now fetch its next instruction. To do
this it sends out the next sequential address ($4006)
on the address bus (line 7A), sends out a memory-read Types of Computers
signal on the control bus (line 7B), and reads in the
addressed byte ($11) from the data bus (line 7C). On
MAINFRAMES
lines 8A, 8B, and 8C the CPU reads the second instruc- Computers come in a wide variety of sizes and capabili-
tion byte. From these bytes the CPU determines that it ties. The largest and most powerful are often called
is now supposed to do an output (write) operation toa mainframes. Mainframe computers may fill an entire
port. The CPU also determines that it must go to room. They are designed to work at very high speeds
memory again to get the address of the port to which it using large data words, typically 64 bits or greater, and
is supposed to output. To do this it sends out the next they have massive amounts of memory. Computers of
sequential address ($4008) on the address bus (line this type are used for military defense control, busi-
9A), sends out a memory-read signal on the control bus ness data processing (an insurance company, for ex-
(line 9B), and reads in the byte (SCO) put on the data ample), and for creating computer graphics displays for
bus by the memory (line 9C). The CPU reads the second science fiction movies. Examples of this type of com-
28 CHAPTER TWO
Oscillator
&
Timing
LED
7-seg
Display
two
PIAS
(VO
interface)
Keyboard
Address Bus
| | Data Bus | |
BRRSRRERKSSS seavcsounees
a)
ae
eae
eww
prrryetiferett
says
Ey
etree
_,
H ot
Lo
|
4 Pe
URWVERSITY OF PITTSBURG
(5985,ALL, MONTE RESERVED
(d)
MASS COMPUTER
DATA HIGH-SPEED
(MAINFRAME
STORAGE PRINTER
OR MINI)
Se
'
> \ ea \
[
jae {_
oe VIDEO VIDEO
VIDEO AREIES TERMINAL VIDEO
LOW-COST
PRINTER TERMINAL
TERMINAL TERMINAL
30 CHAPTER TWO
or even in his or her home. The rate at which a user DISTRIBUTED PROCESSING, OR
usually enters data is very slow in comparison to the MULTIPROCESSING
rate at which a computer can process the data. There- A partial solution for the two potential problems of a
fore, the computer can serve many users by dividing its simple timeshare system is to use a distributed proc-
time among them in small increments. In other words, essor system. Figure 2-6 shows a block diagram for
the computer works on user 1’s program for perhaps a such a system. The system has a powerful central
millisecond, works on user 2’s program for a milli- computer with a large memory and a high-speed print-
second, then works on user 3’s program for a milli- er, as does the simple timeshare system described
second, and so on until all the users have had a turn. In previously. However, in this system each user or group
a few milliseconds the computer will get back to user 1 of users has a microcomputer instead of simply a video
again and repeat the cycle. To each user it will appear display terminal. In other words, each user station is
as if he or she has exclusive use of the computer an independent, functioning microcomputer with a
because the computer processes data as fast as it is CPU, ROM, RAM, and, probably, magnetic or optical
entered. A timeshare system such as this allows sever- disk memory. This means that a person can do many
al users to interact with the computer at the same tasks locally on the microcomputer without having to
time. Each user can get information from or store use the large computer at all. Since the microcomput-
information in the large memory attached to the com- ers are connected to the large computer with a net-
puter. Each user can have an inexpensive printer work, however, a user can access the computing pow-
attached to his or her terminal or can direct program er, memory, or other resources of the large computer
or data output to a high-speed printer attached directly when needed.
to the computer. Distributing the processing around to multiple com-
An airline-ticket-reservation computer might use a puters or processors in a system has several advantag-
timeshare system such as this to allow users from all es. First, if the large computer goes down, the local
over the country to access flight information and make microcomputers can continue working until they need
reservations. A time-multiplexed, or time-sliced, sys- to access the large computer for something. Second,
tem such as this can allow a computer to control many the burden on the large computer is reduced greatly,
machines or processes in a factory. A computer is because much of the computing is done by the local
much faster than the machines or processes it con- microcomputers. Finally, the distributed-processor ap-
trols. Therefore, it can check and adjust many pres- proach allows the system designer to use a local micro-
sures, temperatures, motor speeds, etc. before it needs computer best suited to the task it has to do.
to recheck the first one. A system such as this is often
called a multitasking system because it appears to be
doing many tasks at the same time.
Now let’s take another look at our problem of compu- Computerized Electronics Company: Overview
terizing the electronics company. A timeshare system
seems to be a better idea than a batch system or evena Distributed processing seems to be the best way to
multiprogramming system. We could put a powerful computerize our electronics factory. Engineers can
computer in some central location and run wires from each have personal computers on their desk. With
it to video display terminals on each person’s desk. these they can use available programs to design and
Each user could then run the program needed to do his test circuits. They can access the large computer if
or her particular task. The accountant could run a they need data from its memory. Through the tele-
ledger program, the secretary could run a word proces- phone lines, the engineer with a personal computer
sor program, etc. Each user could access the comput- can access data in the memories of other computers all
er’s large data memory. Incidentally, a large collection over the world. The drafting people can have personal
of data stored in a computer’s memory is often referred computers for simple work or large computer-aided
to as a data base. For a small company a system such design systems for more complex work. Completed
as this might be adequate. However, there are at least work can be stored in the large computer memory. The
two potential problems. accounting department can use personal computers
The first potential problem is, What happens if the with spreadsheet programs to work with financial data
computer is not working? The answer to this question kept in the memory of the large computer. The ware-
is that everything grinds to a halt. In a situation where house supervisor can likewise use a personal computer
people have become dependent upon the computer, not with an inventory program to keep his or her own
much gets done until the computer is up and running records and those in the large computer’s memory
again. The old saying about not putting all your eggs in updated. Corporate officers can have personal comput-
one basket comes to mind here. ers tied into the network. They then can interact with
The second potential problem of the simple time- any of the other systems on the network. Salespeople
share system is saturation. As the number of users can have portable personal computers that they can
increases, the time it takes the computer to do each carry with them in the field. They can communicate
user’s task also increases. Eventually the computer’s with the main computer over the telephone lines using
response time to each user becomes unreasonably a modem. Secretaries doing word processing can use
long. People get very upset about the time they have to individual word processing units or personal comput-
wait. ers. Since word processing is not a high-intensity use
V
MICROCOMPUTER
MICROCOMPUTER
MINICOMPUTER
auy
FLOPPY DISK
HARD DRIVE
z
DISK DRIVE
PRINTER MICROCOMPUTER
for a computer, several video display terminals for word Common Microprocessor Types
processing can be connected to a local microcomputer,
and this local microcomputer can be connected to the
large computer through the network. Users can also MICROPROCESSOR EVOLUTION
send messages to each other over the network. The A common way of categorizing microprocessors is by
specifics of a computer system such as this will obvi- the number of bits with which their ALUs can work at
ously depend on the needs of the individual company a time. In other words, a microprocessor with a 4-bit
for which the system is designed. ALU will be referred to as a 4-bit microprocessor,
regardless of the number of address lines or the num-
SUMMARY AND DIRECTION FROM HERE
ber of data bus lines that it has. The first microproces-
The main concepts that you should understand at this sor, as we use the term, was the Intel 4004, produced
point are multiprogramming, timesharing, or multi- in 1971. It contained 2300 PMOS transistors. The
tasking, and distributed processing, or multiproces- 4004 was a 4-bit device intended to be used with
sing. As you work your way through the rest of this some other devices in making a calculator. Some logic
book, keep an overview of the computerized electronics designers, however, saw that this device could be used
company in the back of your mind. The goal of this to replace PC boards full of combinational and sequen-
book is to teach you how all the parts of a system such tial logic devices. Also, the ability to change the func-
as this work, how the parts are connected together, tion of a system by just changing the programming,
and how the system is programmed at different levels. rather than redesigning the hardware, was very ap-
The first step toward this goal will be a quick look at pealing. These factors pushed the evolution of micro-
the different types of microprocessors available. We processors.
then discuss a specific microprocessor, the Motorola In 1972 Intel came out with the 8008, which was
68000, and the programming of a microcomputer built capable of working with 8-bit words. The 8008, howev-
around a member of this microprocessor family, the er, required 20 or more additional devices to form a
Apple Macintosh. Next we discuss the hardware con- functional CPU. In 1974 Intel announced the 8080,
nections and timing of this microcomputer. From which had a much larger instruction set than the 8008
there we show how the microcomputer is interfaced to and required only two additional devices to form a
a wide variety of peripheral devices. And finally we functional CPU. Also, the 8080 used NMOS transis-
cycle back to our computerized electronics company, tors, so it operated much faster than the 8008. The
the networks it uses, and the system programs it 8080 is referred to as a second-generation micro-
requires. processor.
32 CHAPTER TWO
Soon after Intel produced the 8080, Motorola came earlier minicomputers. After Motorola came out with
out with the MC6800, another 8-bit general-purpose the MC6800, Intel produced the 8085, an upgrade of
CPU. The 6800 had the advantage that it required only the 8080 requiring only a +5-V supply. Motorola then
a +5-V supply rather than the —5-V, +5-V, and +12-V produced the MC6809, which has a few 16-bit instruc-
supplies required by the 8080. For several years the tions but is still basically an 8-bit processor. In 1978
8080 and the 6800 were the top-selling 8-bit micro- Intel came out with the 8086, which is a full 16-bit
processors. Some of their competitors were the MOS processor. Some 16-bit microprocessors, such as the
Technology 6502, used as the CPU in the Apple II National PACE and the Texas Instruments 9900 family
microcomputer, and the Zilog Z80, used as the CPU in of devices, were available previously, but the market
the Radio Shack TRS-80 microcomputer. apparently wasn’t ready. Soon after Intel came out
As designers found more and more applications for with the 8086, Motorola came out with the 16-bit
microprocessors, they pressured microprocessor man- MC68000, and the 16-bit race was off and running.
ufacturers to develop devices with architectures and The 8086 and the 68000 work directly with 16-bit
features optimized for doing certain types of tasks. In words instead of with 8-bit words, they can address a
response to the expressed needs, microprocessors have million or more bytes of memory instead of the 64K
evolved in three major directions during the last 10 bytes addressable by the 8-bit processors, and they
years. execute instructions much faster than the 8-bit pro-
cessors. Also, these 16-bit processors have single in-
DEDICATED CONTROLLERS structions for functions that required a lengthy se-
quence of instructions on the 8-bit processors.
One direction has been toward dedicated controllers.
The evolution along this last path has continued to
These devices are used to control ‘“‘smart’’ machines
32-bit processors that work with gigabytes (10° bytes)
such as microwave ovens, clothes washers, sewing
or terabytes (10!* bytes) of memory. Examples of these
machines, auto ignition systems, and metal lathes.
devices are the Intel 80386, the Motorola MC68020,
Texas Instruments produced millions of their TMS-
and the National 32032.
1000 family of 4-bit microprocessors for this type of
Since we could not possibly describe in this book the
application. In 1976 Intel introduced the 8048, which
operation and programming of even a few of the avail-
contains an 8-bit CPU, RAM, ROM, and some I/O
able processors, we confine our discussions primarily
ports, all in one 40-pin package. Other manufacturers
to one group of related microprocessors, the Motorola
have followed with similar products. These devices are
68000, 68008, 68010, 68012, 68020, 68030, and
often referred to as microcontrollers. Some currently
68040 family. Members of this family are very widely
available devices in this category, the Intel 8051 and
used in personal computers, business computer sys-
the Motorola MC6801, for example, contain program-
tems, and industrial control systems. Our experience
mable counters and UARTS as well as a CPU, ROM,
has shown that learning the programming and opera-
RAM, and I/O ports. A more recently introduced sin-
tion of one family of microcomputers very thoroughly
gle-chip microcontroller, the Intel 8096, contains a
is much more useful than looking at many processors
16-bit CPU, ROM, RAM, a UART, ports, timers, anda
superficially. If you learn one processor family well,
10-bit analog to digital converter.
you will probably find it quite easy to learn another
when you have to.
BIT-SLICE PROCESSORS
A second direction of microprocessor evolution has
been toward bit-slice processors. For some applica- INTRODUCTION TO THE 68000, 68008,
tions general-purpose CPUs such as the 8080 and
68010, 68012, 68020, 68030, AND 68040
6800 are not fast enough or their instruction set is not
suitable. For such applications, several manufacturers
MICROPROCESSORS
produce devices that can be used to build a custom The Motorola 68000 is a 16-bit microprocessor intend-
CPU. An example is the Advanced Micro Devices 2900 ed to be used as the CPU in a microcomputer. The term
family. This family include 4-bit ALUs, multiplexers, 16-bit means that its internal data paths are designed
sequencers, and other parts needed for custom-build- to work with 16-bit binary words. The 68000 has a
ing a CPU. The term slice comes from the fact that 16-bit data bus, so it can read data from or write data
these parts can be connected in parallel to work with to memory and ports either 16 bits at a time or 8 bits at
8-bit words, 16-bit words, or 32-bit words. In other a time. The 68000 has a 24-bit address bus, so it can
words, a designer can add as many slices as needed for address any one of 2”, or 16,777,216, memory loca-
a particular application. Not only does the designer tions. Each of the 16,777,216 memory addresses of the
custom-design the hardware of the CPU, but also he or 68000 represents a byte-wide location. Words are
she custom-makes the instruction set for it using stored in two consecutive memory locations. The main
‘“‘microcode.”’ point here is that the 68000 can read one complete
instruction word (2 bytes) in one operation.
GENERAL-PURPOSE CPUs The 68008, on the other hand, reads from memory 1
The third major direction of microprocessor evolution byte at a time. The 68008 requires two read operations
has been toward general-purpose CPUs, which give a to access both bytes of an instruction word. Recall that
microcomputer most or all the computing power of Figure 2-2b showed the bytes in memory as accessed
34 CHAPTER TWO
Data Registers Prefetch Queue Execution Unit
Instruction Control
Program Counter
Decode Circuitry
Address Bus
Memory
and I/O
Interface
Status Register
Address Registers
:
4 6800 Peripherals H
FFFF
:
1
be nnn nnn nnn nn nnn nn nnn nnn -- 4
fetched from memory before they are actually needed.
The prefetched instruction bytes are held for the EU in
a first in, first out group of registers called a queue.
FIGURE 2-8 URDA P68000 MDS memory map. The CPU can be fetching instruction bytes while the
36 CHAPTER TWO
EVEN BYTE ODD BYTE
(Or BSe TASS 62, ail
15 4 i Wl Wor ©)
LOW ORDER
(a)
An TOP OF STACK
TOP OF STACK
(b)
FIGURE 2-9 (a) 68000 standard data representations in memory with byte
organization. (6) User stack organization.
set to 1 if the addition of two binary numbers produces tions affect them. Certain 68000 instructions check
a carry out of the MSB position. If no carry out of the these condition codes to determine which of two alter-
MSB is produced by the addition, then the carry flag is native actions should be done in executing the instruc-
0. The EU thus effectively runs up a “‘flag’’ to tell you tion.
that a carry was produced. The flag is saved in the The remaining byte in the status register is the
carry bit of the status register (the lowest bit, bit 0). system byte. This byte contains flags that are used to
The five condition codes in this group are the carry control certain operations of the processor. These flags
flag (C), the overflow flag (V), the zero flag (Z), the are different from the five condition codes just de-
negative flag (N), and the extend flag (X). The names scribed in the way they are set or reset. The five
of these flags should give you hints as to what condi- condition flags are set or reset by the EU based on the
results of some arithmetic or logic operation. The
control flags are deliberately set or reset with specific
SYSTEM BYTE USER BYTE
instructions you put in the program. The three control
lor 13 1 8 4 0 flags are the trace mode bit (T), which is used for
TASS
ET TOS XN ZV IC] single-stepping (tracing) through a program; the inter-
TRACE MODE rupt mask (12, 11, and 10), which is used to allow or
SUPERVISOR prohibit the interruption of a program; and the super-
STATE visor state bit (S), which specifies whether the CPU is
INTERRUPT executing in supervisor or user state.
MASK
The supervisor bit in the CPU can be either a 1 ora 0.
EXTEND
If it is a 1, then the CPU is said to be in supervisor state.
NEGAT
CONDITION
ZERO If it is a O, then the CPU is said to be in user state.
CODES
OVERFLOW Because there are two states, the 68000 is often said to
CARRY be a dual-state CPU. When we examine the CPU
Status Register 1-927
instructions in detail in Chapter 6, we will see that
certain instructions behave differently, depending on
FIGURE 2-10 68000 status register format showing bit whether the supervisor state bit is a 1 or a O. These
positions of condition codes, state flags, and interrupt instructions are said to be sensitive instructions be-
mask. cause they are sensitive to the state of the supervisor
38 CHAPTER TWO
guage statement ADD.L DO,D4, when converted to mdchine codes that can be loaded into memory and
machine language and run, will add the contents of executed. Programs can usually be written more
register DO to the contents of register D4. The addition quickly in high-level languages than in assembly lan-
will use two long binary integers, each 32 bits in guage because the high-level language works with
length. The result will be left in register D4. bigger building blocks. However, programs written ina
Looking back at the example assembly language high-level language and interpreted or compiled exe-
statement in Figure 2-11, observe the comment field, cute more slowly than the same programs written in
which starts with a semicolon. This field is very impor- assembly language. Programs that involve a lot of
tant. Comments do not become part of the machine hardware control, such as robots and factory-control
language program. You write comments in a program systems, or programs that must run as quickly as
to remind you of the function that this instruction or possible are usually best written in assembly lan-
group of instructions performs in the program. guage. Programs that manipulate massive amounts of
To summarize why we use assembly language, let’s data, such as insurance company records, are usually
look a little more closely at the assembly language ADD best written in a high-level language. The decision of
statement. The general format of the 68000 ADD which language to use has recently been made more
instruction is difficult because current assemblers allow the use of
many high-level language features and some current
ADD source,destination high-level languages provide assembly language fea-
tures.
The source can be a number written in the instruc-
tion, the contents of a specified register, or the con- OUR CHOICE
tents of a memory location. The destination can be a Throughout this book we use assembly language, for
specified register or a specified memory location. The the most part, because we will be working very closely
source and the destination can both be memory loca- with hardware interfacing. Before we start teaching
tions in the same instruction. you assembly language programming in the next chap-
A later section on 68000 addressing modes shows all ter, however, we want to give you an introduction to
the ways in which the source of an operand and the how the 68000 accesses data.
destination of the result can be specified. The point
here is that the single mnemonic ADD, together witha
specified source and a specified destination, can repre-
How the 68000 Accesses Immediate and
sent a great many 68000 instructions in an easily
Register Data
understandable form.
The question that may occur to you at this point is, If In a previous discussion of the 68000 CPU, we de-
I write a program in assembly language, how do! get it scribed how the 68000 accesses code bytes using a
translated into machine language, which can be loaded program counter (PC). We also described how the
into the microcomputer and executed? There are two 68000 accesses the stack using SP and SSP. Before we
answers to this question. The first method of doing the can teach you assembly language programming tech-
translation is by working out the binary code for each niques, we need to discuss some of the different ways
instruction a bit at a time using the templates given in that a 68000 can access the data on which it operates.
the manufacturer’s data books. We show you how to do The different ways that a processor can access data are
this in the next chapter. It is a tedious and error-prone referred to as its addressing modes. In assembly
task. The second method of doing the translation is language statements the addressing mode is indicated
with an assembler. An assembler is a program that by the way the instruction is written. The 68000
can be run on a personal computer or microcomputer family offers 14 different addressing modes, which are
development system. It reads the assembly language listed in the next chapter. Here we will consider some
instructions and generates the correct binary code for of the basic addressing mode components, which can
each. For developing all but the simplest assembly be combined to define the complex set of addressing
language programs, an assembler and other program- modes provided. We will use the 68000 MOVE instruc-
development tools are essential. We introduce you to tion to illustrate some of the 68000 addressing modes.
these program development tools in the next chapter The MOVE instruction has the format
and describe their use throughout the rest of this book.
MOVE source,destination
40 CHAPTER TWO
GENERATION EA-(An)
ASSEMBLER _ (An) ADDRESS
SYNTAX REGISTER MEMORY ADDRESS
MODE D10 AN
REGISTER n
Nai ane OPERAND
Effective address
Address, data, and control buses
11. a. What is the advantage of using assembly 15. Write the 68000 assembly language statement
language instead of writing a program di- that will perform the following operations:
rectly in machine language?
a. Load the number $7986 into register DO.
b. Describe the operation a 68000 will perform
b. Copy the contents of register DO to register
when it executes ADD.B DO,D1.
A3.
12. What types of programs are usually written c. Copy the contents of register A3 to register
in
assembly language? D3.
d. Load the number $F3 into register D7.
13. Describe the operation that a 68000 will perform
when it executes each of the following instruc- 16. Describe the difference between the instructions
tions:
MOVE.W #82437,D0 and MOVE.W ($2437),DO.
42 CHAPTER TWO
68000 Family Assembly Language
Programming —Introduction
The last chapter showed you the format for 68000 “What do I really want this program to do?’’ If you
assembly language programs and introduced you toa don’t do this, you may write a great program, which
few 68000 instructions. Developing a program, howev- works but does not do what you need it to do. As you
er, requires more than just writing a series of instruc- think about the problem, it is a good idea to write
tions. When you want to build a house, it is a good idea exactly what you want the program to do and the order
first to develop a complete set of plans for the house. in which you want the program to do it. At this point
With the plans you can see if the house has the rooms you do not write down program statements, you just
you need, if the rooms are efficiently placed, and if the write the operations you want in general terms. The
house is structured so that you can easily add onto it if following list might be written for a simple program-
you want to. ming problem:
Likewise, when you write computer programs, it isa
good idea to start by developing a detailed plan or
outline. A good outline helps you to break a large and 1. Read temperature from sensor.
seemingly overwhelming programming job into small
2. Add correction factor of +7.
modules, which can easily be written, tested, and
debugged. The more time you spend organizing your 3. Save result in a memory location.
programs, the less time it will take you to write and
debug them. You should never start writing an assem-
bly language program by just writing down instruc- For a program as simple as this, the three desired
tions! In this chapter we show you how to develop actions are very close to the eventual assembly lan-
assembly language programs in a systematic way. guage statements. For more complex problems, howev-
er, we develop a more extensive outline before writing
the assembly language statements. The next section
shows you some of the common ways of representing
OBJECTIVES program operations in a program outline.
At the conclusion of this chapter, you should be able to
Representing Program Operations
1. Write a task list, flowchart, or pseudocode for a
simple programming problem. The formula or sequence of operations used to solve a
2. Write, code or assemble, and run a very simple
programming problem is often called the algorithm of
the program. The following sections show you several
assembly language program.
ways of representing the algorithm for a program or
3. Describe the use of program development tools program segment.
such as editors, assemblers, linkers, locators, de-
buggers, and emulators. SEQUENTIAL TASK LISTS
4. Properly document assembly language programs. Some programmers use just a sequential list of the
tasks, such as the one in the preceding section, to
show the algorithm for their programs. To give you a
better idea of this form, we will show another slightly
PROGRAM DEVELOPMENT STEPS different example. Suppose that, instead of taking one
data sample from the temperature sensor, we want to
Defining the Problem
take in a data sample every hour for 24 hours, add 7 to
The first step in writing a program is to think very each sample, and put each corrected value in a memo-
carefully about the problem that you want the program ry location. We could write a task list for this problem
to solve. In other words, ask yourself many times, as follows:
43
quite close to the assembly language statements that
will implement them, so you may find them useful. As
Read data sample from temperature sensor.
you determine hardware details, such as port address-
Add 7 to value read in. es for the system on which the program is to run, you
can add this information to the appropriate task state-
Store corrected value in memory location. ment. The next section shows you a more graphic way
Wait 1 hr. of representing the algorithm of a program or program
segment.
Read next sample from temperature sensor.
PROCESS
o> [a] ©
OFF-PAGE CONNECTOR
Y
CONNECTOR
aigSUB-
ean TERMINATION Ce)
44 CHAPTER THREE
letter in it at the bottom of the column. You then start
START
the next column at the top of the same piece of paper
with a small circle containing the same letter. If you
need to continue a flowchart on another page, you can
end the flowchart on the first page with the five-sided
READ VALUE
FROM SENSOR off-page connector symbol containing a letter or num-
ber. You then start the flowchart on the next page with
an off-page connector symbol containing the same
letter or number.
For simple programs and program sections, flow-
charts are a graphic way of showing the operational
flow of the program. We will show flowcharts for many
of the program examples throughout this book. How-
STORE RESULT ever, flowcharts have several disadvantages. First, you
IN MEMORY
can’t write much information in the little boxes. Sec-
ond, flowcharts do not present information in a very
compact form. For more complex problems, flowcharts
|WAIT 1 HOUR tend to become spread out over many pages. They are
very hard to follow back and forth between pages.
Third, and most important, with flowcharts the overall
structure of the program tends to get lost in the de-
tails. The following section describes a more clearly
structured and compact method of representing the
algorithm of a program or program segment.
46 CHAPTER THREE
47
() (#) (9)
dNOS WOOYHSNW AVI dNOS WOOYHSNW AAV
N3HL AVGNNS sl 3874 AVONNS
dNOS NOINO ayvW
PROGRAMMING—INTRODUCTION
dNOS NOINO AVN
NSHL AVGSSNG3M 4I 3S73 *AVGSANGAM NA VL SATIdMWNVS v2 TILNN
dNOS JNOULSANIW JVI dNOS ANOYLSANIW AIVW YH L LIVM
NSHL AVGSANL JI 3S73 *“AVGSANL AYOWAW NI L1NSAY AHOLS
dNOS AY31g9 DIV dNOS AY41459 AVN Z£qaqv
NHL AVGNOW 4! ‘AVGNOW 1 Z(S)LNAWALVLS
L(S)LNAWALVLS JIdNVS VLVG LAD
(S)LNAWALVLS
Fqoo00aGnasd dO AvVd 4SvV9O 4iVadau
NOILIGNOS
A1dNVXa4 AIdNVXA
NOISSSYdxX4
N(S)LNAWALVLS -N
4AGONO0GNASd
4AGO90dNASd
TILNA
WOOYHSNWN
LVAddu
ANOYLSANIW
*Z
IIVAdnos
ASVO
dO
dNOs
SaA
(c) IF-THEN. (d) WHILE-DO. (e) REPEAT- UNTIL. (f) CASE. (g) CASE expressed as
FIGURE 3-3 Standard program structures. (a) SEQUENCE. (b) IF-THEN-ELSE.
LANGUAGE
N(S)LNAW3SLVLS c(S) LNAWALVLS L(S)LNAWALVLS
AdY4149 AAV
LN3SW3LVLS
LYVHIMO14
NOISS3YdX4 ONILOA1SS
(2)
(P) (2)
AWOH IXV1L AAVL SJOVNYNA 440 NYNL
JAIAOW O1 OD aSia NOILV9O1 AYOWAW NI 3HOLS
AIdNVX4
goo4 139_Jl FJOVNYNA NO NYNL Zqav
(S)LNAWALV1S
4qgo090dNaSd
3qo00anasd
NOILIGNOD
dldNVXa4
Z(S)LNAWALVLS
4as14
STIHM
multiple IF-THEN-ELSE.
L LNAWALVLS
ON
LYVHOMO14 dOOT OG-J3TIHM LYVHOMO14s NSH1L-sI LYVHOMOT14 ASTS-NAHL-S1 LYVHIMO14 JDNANOAS AIdWIS
4
Add correction factor of +7. Throughout the rest of this book we show you how to
Store result in memory location. use these structures to represent program actions and
Wait 1 hr. how to implement these structures in assembly lan-
guage.
Note that the REPEAT-UNTIL structure indicates
that the condition is first checked after the statement
SUMMARY OF PROGRAM STRUCTURE
or statements are performed. In other words, a
REPEAT-UNTIL structure indicates that the action or
REPRESENTATION FORMS
series of actions will always be done at least once. Writing a successful program does not consist of just
If you don’t want this to happen, then use the writing down a series of instructions. You must first
WHILE-DO, which indicates that the condition is think carefully about what you want the program to do
checked before any action is taken. As we show and how you want the program to do it. Then you must
later, the structure you use makes a difference in represent the structure of the program in some way
the actual assembly language program you write to that is very clear to you and to anyone else who might
implement it. have to work on the program. If the structure is well
The WHILE-DO and REPEAT-UNTIL structures con- developed, it is usually not a difficult step to write the
tain a simple IF-THEN-ELSE decision operation. How- actual programming language statements that imple-
ever, since this decision is an implied part of these two ment it.
structures, we don’t indicate the decision separately in One way of representing program operations is with
them. a sequential task list. For initial thinking and simple
Another form of the repetition operation that you programming problems, this technique works well. For
might see in high-level language programs is the FOR- more complex programming problems, a sequential list
DO loop. This structure has the form may become very messy because it has little real
structure or standardization. Another way of repre-
FOR COUNT = 1 TON DO senting program operations is with flowcharts. Flow-
statement charts are a very graphic representation, and they are
statement useful for short program segments, especially those
that deal directly with hardware. However, flowcharts
In assembly language we usually implement this type use a great deal of space. Consequently, the flowchart
of operation with a REPEAT-UNTIL structure, so we for even a moderately complex program may take up
have not included a sample of it. several pages. It often becomes difficult to follow pro-
The CASE structure shown in Figure 3-3f is a com- gram flow back and forth between pages. Also, since
pact way of representing a choice among several alter- there are no agreed-upon structures, a poor program-
native actions. The choice is determined by testing mer can write a flowchart that jumps all over the place
some quantity. The example in Figure 3-3f best shows and is even more difficult to follow.
how this is used. This everyday example describes the A third way of representing the operations you want
desired actions for a cook in a restaurant. The pseu- in a program is with a top-down design approach and
docode is just a summary of the thinking he or she standard program structures. The overall program
might go through. The cook or the computer checks the problem is first broken into major functional modules.
value of the variable called ‘‘day’’ and selects the Each of these modules is broken into smaller and
appropriate actions for that day. Each of the indicated smaller modules, until the steps in each module are
actions, such as ‘‘Make celery soup,”’ is itself a se- obvious. The algorithms for the whole program and for
quence of actions that could be represented by. the each module are each expressed with a standard struc-
structures we have described. ture. Only three basic structures, sequence, IF-THEN-
The CASE structure is really just a compact way to ELSE, and WHILE-DO, are needed to represent any
represent a complex IF-THEN-ELSE structure. To il- needed program action or series of actions. However,
lustrate this, Figure 3-3g also shows how the soup- other useful structures, such as IF-THEN, REPEAT-
cook example can be represented as a series of IF- UNTIL, FOR-DO, and CASE, can be derived from these
THEN-ELSE structures. Note that in this example the basic three. A structure can contain another structure
last IF-THEN has no ELSE after it because all the of the same type or of one of the other types. Each
possible days have been checked. You can, if you want, structure has only one entry point and one exit point.
add the final ELSE to the IF-THEN-ELSE chain to send These programming structures may seem restrictive,
an error message if the data does not match any of the but using them usually results in program representa-
choices. The CASE structure does contain the final tions that are easy to understand and for which it is
ELSE, however. The CASE form is more compact for easy to write the programs. A program written in a
documentation purposes, and some high-level lan- structured manner is easier to debug and is much more
guages such as Pascal allow you to implement it direct- understandable to someone else who has to work on it.
ly. However, the IF-THEN-ELSE structure gives you a Furthermore, a program representation developed
much better idea of how you write an assembly lan- with structured programming techniques can be im-
guage program section that chooses between several plemented easily in assembly language or in a high-
alternative actions. level language such as Modula II or C.
48 CHAPTER THREE
Finding the Right Instruction OPERATIONS FOR ADDRESS MANIPULATION
LEA—Load the effective address of the source into
After you get the structure of a program worked out
the address register specified in the destination
and recorded, the next step is to determine the instruc-
field.
tion statements required to do each part of the pro-
gram. Since the examples in this book are based on the PEA—Push the effective address onto the specified
68000 family of microprocessors, now is a good time to stack.
give you an overview of the instructions the 68000 has
for you to use.
You do not usually learn a new language by studying OPERATIONS FOR STACK MANAGEMENT
its dictionary from cover to cover. It is more productive LINK—Create a link on the system stack between a
first to learn a few very useful words and then to learn calling main program and a called subroutine. See
how to put together simple sentences. You can learn Chapter 6 for a description of what a link is.
more words as you need them to express more complex
UNLK—Remove the link between a subroutine and
thoughts. Chapter 6 contains a dictionary of all the
the program that called it.
68000 instructions, with detailed descriptions and
examples for each. You can use this as a reference as
you write programs. Here we simply list the 68000
instructions in functional groups, with single-sen-
tence descriptions, so that you can see the types of Integer Arithmetic Instructions
instructions that are available to you. As you read ADDITION INSTRUCTIONS
through this section, do not expect to understand all
the instructions. When you start writing programs, ADD—Add two registers or two memory locations
you will probably use this section to determine the type that contain integer values.
of instruction and Chapter 6 to get the instruction ADDA—Add an offset or index to an address
details as you need them. After you have written a few register.
programs, you will remember most of the basic in-
struction types and can just look up an instruction ADDI—Add the immediately following data to the
in Chapter 6 to get any additional details you destination.
need. Chapter 4 shows in detail how to use the ADDQ—Add a small value to the destination and
move, arithmetic, logical, and jump instructions. do it quickly.
Chapter 5 shows how to use the call instructions and
the stack. ADDX—Add using the sign-extend bit.
As you skim through the following overview of the
68000 instructions, see if you can find the instructions SUBTRACTION INSTRUCTIONS
needed to do the ‘‘read temperature sensor value from
SUB—Subtract byte from byte, word from word, or
a port, add +7, and store result in memory’’ example
long word from long word.
program.
SUBA—Subtract an offset from an address register.
SUBI—Subtract the immediately following data from
Data Movement Instructions the destination.
SUBQ—Subtract a small value from the destination.
OPERATIONS FOR MOVEMENT OF MEMORY
AND REGISTER CONTENTS SUBX—Subtract using the extend bit.
MOVE—Copy bytes from memory or register to NEG—Negate the specified location.
memory or register. This is the most commonly
used general byte-moving instruction. NEGX—Negate using the extend bit.
EXG—Exchange the contents of two registers. EXT—Sign-extend a register by copying the sign bit.
Shift and Rotate Instructions Bcc—Branch and start executing instructions from a
different address if the specified condition code is true.
ARITHMETIC SHIFT INSTRUCTIONS
DBcc—Decrement a register and branch on condition
ASL—Arithmetic shift left a byte, word, or long
code.
word.
Scc—Set a byte to all Os or all 1s, depending on a
ASR—Arithmetic shift right an operand a specified
condition code.
number of bits.
BRA—Branch always.
LOGICAL SHIFT INSTRUCTIONS
BSR—Branch to subroutine, leaving a return address
LSL—Logical shift left a byte, word, or long word. on the stack.
LSR—Logical shift right an operand a specified
number of bit positions. JUMP. INSTRUCTIONS
JMP—Jump to a new location and begin executing
ROTATE INSTRUCTIONS instructions there.
ROL—Rotate a data register left. JSR—Jump in a subroutine fashion, leaving a
ROR—Rotate a data register right. return address on the stack.
ROXL—Rotate left using the extend bit. NOP—No operation, do nothing for one instruction.
50 CHAPTER THREE
RTD—Return from subroutine and deallocate a memory-mapped I/O port. The MOVEP instruction
memory from the top of the stack. could also be used, but for this example it was not
selected. Often alternative instructions may be used to
RTR—Return from a subroutine and restore the
perform similar operations.
CPU condition codes from the top of the stack.
The ADD@ instruction can be used to add the correc-
tion factor of +7 to the value read in. The ADD or the
ADDI instruction could be used but would not be
optimal in this case. Finally, the MOVE instruction can
System Control Instructions be used to copy the result of the addition to a memory
Some system control operations are ‘“‘normal’’ instruc- location. A major point here is that breaking the
tions that have special operands. For example, a MOVE programming problem into a sequence of steps makes
to the status register is a privileged instruction and it easy to find the instruction or small group of instruc-
hence a system control instruction. Instruction forms tions that will perform each step. The next section
such as MOVE that have already been listed are not shows you how to write the actual program using these
mentioned again here. instructions.
PRIVILEGED INSTRUCTIONS
MOVEC—Move one of the CPU’s internal control Writing a Program
registers to one of the working registers or vice
INITIALIZATION INSTRUCTIONS
versa.
After finding the instructions needed to do the main
MOVES—(68010/68012) Move bytes from another
part of your program, there are a few additional in-
address space into the current address space, as
structions you need to determine before you actually
indicated by internal control registers. write your program. The purpose of these additional
RESET—Assert the RESET line controlling external instructions is to initialize various parts of the system,
devices for 124 clock cycles. such as address registers, flags, and programmable
port devices. An address register, for example, must be
RTE—Return from an exception and restore the loaded with the address in memory where the memory-
CPU status register. mapped I/O port is. Another address register must be
STOP—Load the status register with the loaded with the address in memory where the final,
immediately following data and stop the CPU. corrected sensor reading is to be saved.
If you are using the stack in your program, then you
TRAP-GENERATING INSTRUCTIONS must include an instruction to load the stack pointer
register with the address of the top of the stack. Most
BKPT—Execute a breakpoint-acknowledge bus cycle microcomputer systems contain several programma-
to allow an external debugger to take control here. ble peripheral devices, such as ports, timers, and
CHK—Check a data register against upper and controllers. You must include instructions that send
lower bounds and trap if it is out of bounds. control words to these devices to tell them the function
you want them to perform. Also, you usually need to
ILLEGAL—Simulate an illegal instruction and include instructions that set or clear the control flags,
generate a trap. such as the interrupt enable flag and the direction flag.
TRAP—Cause a trap using the vector number The best way to approach the initialization task is to
specified. make a checklist of all the registers, programmable
devices, and flags in the system on which you are
TRAPV—Cause a trap if the overflow condition code working. Then you can mark the ones you need for a
is set. specific program and determine the instructions need-
ed to initialize each part. An initialization list for a
68000-based system, such as the URDA MDS proto-
typing board, might look like the following.
Multiprocessor Instructions
TAS—Test and set the byte operand in one Initialization List
indivisible operation. This can be used to User stack pointer register
synchronize multiple CPUs in the same system.
Initialize user status register
Now that you have glanced through an overview of Initialize interrupt vectors
the 68000 instruction set, let’s see if you found the
instructions needed to implement the “‘read sensor, Initialize breakpoint locations
add +7, and store result in memory’’ example pro-
Determine available memory
gram. The MOVE instruction can be used to read the
temperature value from an A/D converter connected to Clear data memory
52 CHAPTER THREE
PROGRAMMER _ A.L. Rood
ABSTRACT: This program reads in a temperature value from a sensor connected to a port at address
$4100, adds a correction factor of +7 to the value read in, and then stores the result in a
reserved memory location.
Folate
ADDRESS DATA/CODE LABELS MNEM OPERAND(S)
Bt
Hees ee
ae ols cea
=
SnagBeeler res
Siehoes
ee
[awe [rm [ew
se ee
- 2 re a a
FIGURE 3-4 Assembly language program on standard
coding form.
tion mnemonic.
(a)
We cannot overemphasize the importance of clear,
concise documentation in your programs. Experience
has shown that even a short program that you wrote a ADDQ.B- #7, D0
15 4 WS AZ id OL ON S/n GO) ene 4 ee 1
month ago without comments may not be at all under-
standable to you now. 0: 251 ina lai oe OoN homme 0 0
(b)
54 CHAPTER THREE
instruction. We then construct the codes for the exam-
ple program in Figure 3-4. Other examples are shown Register Direct Addressing
as needed in the following chapters. Figure 3-6 shows Data Register Direct
Address Register Direct
Dn
An
the coding template or format for 68000 instructions Absolute Data Addressing
that MOVE data from a register to a register, from a Absolute Short xxx.WV
Absolute Long xxx.
register to a memory location, from a memory location
Program Counter Relative Addressing
to a register, or from a memory location to a memory Relative with Offset d,9(PC)
Relative with Index Offset d,(PC,Xn)
location. Note that at least 2 code bytes are required for
Register Indirect Addressing
the instruction. Register Indirect (An)
The upper 2 bits of the first byte are an opcode that Postincrement Register Indirect (An)+
Predecrement Register Indirect —(An)
indicates the general type of instruction. These bits Register Indirect with Offset dy¢(An)
should both be set to O to tell the 68000 to perform a Indexed Register Indirect with Offset d,(An,Xn)
Immediate Data Addressing
MOVE operation. Notice that the ADDQ opcode re- Immediate XXX
quires 4 bits, binary 0101, but the first 2 bits are not Quick Immediate #1-#8
binary OO. The size field of the MOVE template uses Implied Addressing
Implied Register SR/USP/SP/PC
bits 13 and 12. The MOVE instruction encodes the size
differently than does the ADDQ instruction. Compare NOTES
Figures 3-5a and 3-6 and note that the byte and word DN
An
=
=
Data Register
Address Register
sizes are encoded differently. Xn = Address or Data Register used as Index Register
SR == Status Register
The remaining 12 bits of the MOVE instruction are PC Program Counter
used to specify a source operand and a destination n uU "llStack Pointer
USP = User Stack Pointer
operand. Each operand requires 6 bits to specify. The 6 (_) = Effective Address
bits give the same type of information for the source de = 8-Bit Offset (Displacement)
d,s = 16-Bit Offset (Displacement
and the destination operands, even though they are #xxx = Immediate Data
arranged slightly differently. Three bits are used to
specify an effective addressing mode and 3 bits are FIGURE 3-7 Motorola MC68000 effective addressing
used to specify the register number to use. The ad- modes and their assembly language syntax.
dressing mode implies whether an address register, a
data register, or no register is to be used.
The 6 bits that specify the source operand in the of the operands it requires. The 68000 provides 14
MOVE instruction are arranged differently than are different addressing modes, but not all are available in
the 6 bits that specify the destination operand. The all parts of all instructions. Figure 3-6 shows which
mode bits and the register number bits are swapped. addressing modes can be used for the source and the
The source requires 3 mode bits then 3 register num- destination operands of the MOVE instruction. The
ber bits, whereas the destination requires 3 register following briefly describes each of the addressing
numbers bits and then 3 mode bits. This ordering of modes available on the 68000 (see Figure 3-7). Please
bits is easiest for the CPU to process in an efficient refer to Figures 3-8 and 3-9 as you read these descrip-
manner. tions.
The addressing mode portions of the MOVE instruc-
tion specify how the 68000 will compute the addresses 1. Data Register Direct. In this addressing mode,
the desired data value is held in one of the data
01 BYTE
11 WORD
40 LONG
A —_q“__ 4 cry 4
DESTINATION SOURCE
OPERAND OPERAND
Address Register Direct, All addressing modes
PC relative, and Immediate are allowed. Program Counter with Displacement 111 010
addressing modes not
Program Counter with Index
allowed.
Immediate 111 100
(b)
SOURCE
ADDRESSING
ADDRESS OO Os Oe Oh Oe 8 iO 8) O Oj) @ ©
REGISTER
INDIRECT quash ios Moreen momen Momnomete
with 15 14-13-42 SAP Oo STS hs eee
DESTINATION DATA DISPLACEMENT
REGISTER REGISTER $207C
D3 DIRECT SOURCE $0000 4100
DESTINATION REGISTER
MOVE BYTE ADDRESSING AO (f)
FIGURE 3-9 MOVE instruction coding examples. (a)
MOVE.L DO,D1. (6) MOVE.B DO,(A1). (c) MOVE.B
$13(A0),D3. (d) MOVE.W #$4100,D7. (e) MOVE.L
0 0) 6) 0 0 0 0 0 0 0 0 1 0 0 1 1 (A4)+,D6. (f) MOVEA.L #$4100,A0.
1a TS elle ee eC Oe COL cian = 0) Ae ae cae lif 0
$1628
$0013
56 CHAPTER THREE
Address Register Indirect with Postincrement. dressing mode can only access the first 2'°, or
This addressing mode is the same as the address 65,536, bytes of memory.
register indirect mode except that the address
9. Absolute Long. In this addressing mode the ad-
register is incremented following the memory ac-
dress of the desired data is placed in the two words
cess, which loads the desired data. For example
(long word) immediately following the instruction
(Al)+ means A1 contains an address that is to be
word in memory. In Motorola terms, this address-
used to access the desired data, and after the data
ing mode requires two words of extension.
is moved to the destination, Al has 1, 2, or 4
added to it, depending on whether the instruction 10. Program Counter with Displacement. This ad-
operates on byte, word, or long data. This address- dressing mode is the same as the address register
ing mode is useful when manipulating stacks in indirect addressing mode except that the program
. memory. Stacks are explained in detail in later counter is used in place of an address register.
chapters.
11. Program Counter with Index. This addressing
Address Register Indirect with Predecrement. mode is the same as the address register indirect
This addressing mode is the same as the address with index except that the program counter is
register indirect addressing mode except that the used in place of an address register. This and the
address register is decremented before the desired previous addressing mode are useful when writ-
data is moved. For example —(A1l) in byte mode ing code that is position-independent. Position
means subtract 1 from the value in Al and use the independent code can be moved about in memory
resulting value as the memory address of the yet still operate properly.
desired data byte.
12. Immediate Data. In the immediate data address-
Address Register Indirect with Displacement. In ing mode, the desired data itself is placed in
this addressing mode the specified displacement memory immediately following the instruction
is added to the specified address register, and the word. If the desired data values are known before-
resulting value is used as the memory address of hand, then this addressing mode can be used;
the desired data. The displacement is a 16-bit separate data memory does not need to be re-
value, which is placed in the word in memory served and addressed to move the desired data to
immediately following the instruction word. For the destination.
example, #$4100(AO) means add hex 4100 to the
value in AO and use the result as the memory The last two addressing modes are not shown in
address of the desired data. This addressing mode Figure 3-8 because they are used only in certain
can be used to access variables a given distance special instructions. When these last two modes
above or below the current top of a stack or stack are used, the instruction opcode will say which of
mark. the two modes is required. These last two special
modes are as follows.
Address Register Indirect with Index. In this
addressing mode the index register can be any one
13. Immediate Quick Data. In the immediate quick
of the data or address registers. This addressing
addressing mode, the data itself is stored in the
mode also uses a displacement, as described in
same word in memory as the instruction. Since
the previous addressing mode, but it uses an 8-bit
the instruction requires many of the word's bits to
displacement rather than a 16-bit displacement.
represent the desired operation, the immediate
The desired memory address is computed by add-
quick data must be represented in only 3 bits.
ing the value in the index register to the value in
This means that the immediate data value must
the specified address register and then adding the
be between O and 7.
displacement to the result and using this final
value as the memory address of the desired value. 14. Implicit Reference. Implicit reference is different
from the preceding addressing modes in that ad-
This addressing mode may sound very complex, dressing is not really required. The instruction
but it is useful for manipulating tables of data as ANDI.W #S0700,SR directs that the value 0700
they are represented in computer memory. The hexadecimal should be logically ANDed together
index register can contain a row number or offset, with the status register. The status register is the
and the displacement can be used to skip over a destination. It does not have a memory address
header in front of the table. The header might associated with it. The destination address is
contain the table’s name, for example. That is, implicit in the instruction encoding.
#$100(D1,A0) means add the value in D1 to the
value in AO, add hex 100 to the result, and use Several of these addressing modes require an addi-
that as the memory address of the desired data. tional value, either a displacement value or an immedi-
ate data value. When the MOVE instruction requires
Absolute Short. In this addressing mode the ad- an additional value, that value is placed in memory
dress of the desired data is placed in the word in immediately following the MOVE instruction word.
memory following the instruction word. This ad- These extra words are called extension words. For
58 CHAPTER THREE
opcode field is binary 00. The size is word, which is First, check your algorithm very carefully to make sure
encoded as binary 11 for MOVEA. The destination that it really does what it is supposed to do. Second,
register number is binary 000. The source addressing initially write just the assembly language statements
mode is immediate word data, which is encoded as and comments for your program. You can check the
binary 111100. For MOVEA, bits 8 through 6 are table in Appendix B to determine how many bytes each
always binary 001. The final encoding for this is instruction takes so you know how many blank lines to
shown in Figure 3-9f. leave between instruction statements. You may find it
helpful to insert 3 or 4 NOP instructions after every 9
MOVEA/L #$4200,A1 or 10 instructions. The NOP instruction doesn’t do
The MOVEA/L #¥S$4200,A1 instruction is exactly the anything but kill time. However, if you accidentally
same as the previous instruction except that the desti- leave out an instruction in your program, you can
nation register is Al instead of AO, and the source replace the NOPs with the needed instruction. This
immediate data is $4200 instead of $4100. There are way you don’t have to rewrite the entire program after
only two bits in this encoding that differ from the the missing instruction.
previous instruction encoding. After you have written the instruction statements,
recheck very carefully to make sure you have the right
MOVE.B (A0),D0 instructions to implement your algorithm. Then, work
out the binary codes for each instruction and write
The MOVE.B (AO),DO instruction moves 1 byte of data them in the appropriate places on the coding form.
from the memory location whose address is in AO into Hand coding is laborious for long programs. When
register DO. In our example the address $4100 has writing long programs, it is much more efficient to use
been placed in AO by one of the preceding instructions. an assembler. The next section of this chapter shows
This address is presumed to be the address that corre- you how to write your programs so you can use an
sponds to an I/O port, where we can read a tempera- assembler to produce the machine codes for the in-
ture value from a sensor. The opcode encoding is structions.
binary 00 and the byte size encoding is binary 01. The
destination addressing mode is data register direct,
encoded as binary 000 using a data register number of
binary 000. The source addressing mode is address WRITING PROGRAMS FOR USE WITH AN
register indirect, encoded as binary 010 using address ASSEMBLER
register number binary 000. The full encoding of this
If you have a 68000 assembler available, you should
instruction is $1010.
learn to use it as soon as possible. Besides doing the
tedious task of producing the binary codes for your
ADDQ.B #7,D0
instruction statements, an assembler also allows you
The ADDQ.B #7,D0 instruction adds 7 to data register to refer to data items by name rather than by numeri-
DO. It has been discussed in detail in previous sections. cal addresses. As you should soon see, this greatly
The instruction encoding is shown in Figure 3-5. reduces the work you have to do and makes your
programs much more readable. In this section we show
MOVE.B D0O,(A1) you how to write your programs so that you can use an
The MOVE.B DO,(A1) instruction moves 1 byte from assembler on them. The assemblers used for the pro-
register DO to the memory location whose address is in grams in this book were the Raven® RV68k cross
register Al. The register was initialized previously to assembler for the 68000 CPU running on the IBM PC
contain the address $4200. This is the memory ad- and the Consulair® MAC68000 assembler for the
dress where the corrected temperature is to be saved. 68000 CPU running on the Apple Macintosh personal
The source addressing mode is data register direct computer. A cross assembler is an assembler that runs
using DO, and the destination addressing mode is on one computer but assembles code for another com-
address register indirect using register Al. See if you puter’s CPU. If you are using another assembler, some
can verify that the final instruction encoding is $1280. features may be slightly different, so consult the manu-
al for the assembler you are using.
SUMMARY OF HAND CODING THE EXAMPLE
PROGRAM
Figure 3-4 shows the example program with all the
Program Format
instruction codes in sequential order as you would The best way to approach this section seems to be to
write them so that you could load the program into show you a simple, but complete, program written for
memory and run it. Codes are in HEX to save space. an assembler and explain the function of the various
parts. By now you are probably tired of the ‘“‘read
temperature, add +7, and store result in memory”
A Few Words about Hand Coding program, so we will use another example.
Figure 3-10 shows a 68000 assembly language
If you have to hand code 68000 assembly language program that multiplies two 16-bit binary numbers,
programs, here are a few tips to make your life easier. with a 32-bit binary result. If you have a development
MOVE.W (MULTIPLICAND)
,DO get one word from memory
MOVE.W (MULTIPLIER)
,D1 get second word, the multiplier
MULS D1,D0 multiply signed 16-bit integers
result is 32-bits long in DO
MOVE.L DO, (PRODUCT) store result into memory
FIGURE 3-10 Assembly language source program to multiply two 16-bit binary
numbers to give a 32-bit result.
system or a computer with a 68000 assembler to ORG directive is used only with the Raven 68000 cross
work on, this is a good program for you to key in, assembler for the IBM PC. The ORG mnemonic should
assemble, and run in order to become familiar with the be followed by a space or spaces and then a number.
operation of your system. If you are working on This number is the memory address where the assem-
a prototyping board such as the URDA MDS, you bly language instructions that follow will be placed
can construct the binary codes for each of the instruc- when the program is loaded into memory. The Raven
tions, load the program into the onboard RAM, and cross assembler generates absolute code. By this we
run the program. In any case, you can use the struc- mean that the code contains absolute memory ad-
ture of this example program as a model for your dresses and must be loaded into memory exactly where
own programs. those addresses indicate.
In addition to program instructions, the example The Consulair MAC68000 assembler, on the other
program in Figure 3-10 contains directions to the hand, is a relative assembler, which generates relocat-
assembler. These directions to the assembler are com- able code. The Consulair assembler does not use the
monly called assembler directives or pseudo-oper- ORG directive. The MAC68000 code can be placed
ations. A section at the end of Chapter 6 lists and anywhere in the 68000’s memory— but only after it is
describes a large number of the available assembler properly linked and located in relation to the memory
directives. Here we discuss the basic assembler direc- addresses where it will actually be loaded. The proc-
tives you need to get started writing programs. We esses of linking and locating are discussed in greater
introduce more of these directives as we need them in detail later in this chapter.
the next two chapters.
Data and Address Naming Directives—EQU,
ORG Directive DC, and DS
The ORG, or origin, directive is used to specify the Programs work with three general categories of data—
origin in memory of the code or data that follows. The constants, variables, and addresses. The value of a
60 CHAPTER THREE
constant does not change during the execution of the OVEN—TEMPERATURE. DC.W is used to specify that
program. The number 7 is an example of a constant the data is of type word (16 bits), and DC.L is used to
you might use in a program. A variable is the name specify that the data is of type long word (32 bits). Ifa
given to a data item that can change during the number is written after the DC.B, DC.W, or DC.L, the
execution of a program. The current temperature of an data item will be initialized with that value when the
oven is an example of a variable. Addresses are re- program is loaded from disk into RAM. The statement
ferred to in many instructions. You may, for example, CONVERSION—FACTORS DC.B $27,$48,$32,S69 will
load an address into a register or jump to an address. declare a data item of 4 bytes and initialize the 4 bytes
Constants, variables, and addresses used in your with the specified 4 values. Note that data variables
programs can be given names. This allows you to refer that are changed during the program should also be
to them by name rather than having to remember or initialized with program instructions so that the pro-
calculate their value each time you refer to them in an gram can be rerun from the start without reloading it
instruction. In other words, if you give names to con- to initialize variables. Figure 3-10 shows three more
stants, variables, and addresses, the assembler can examples of naming and initializing data items.
use these names to find the desired data item or The first example, MULTIPLICAND DC.W $204A,
address when you refer to it in an instruction. Specific declares a data word named MULTIPLICAND and ini-
directives are used to give names to constants and tializes that data word with the value $204A. What
variables in your programs. Labels are used to give this means is that the assembler sets aside two succes-
names to addresses in your programs. sive memory locations and assigns the name MULTI-
PLICAND to the first location. As you will see, this
THE EQU DIRECTIVE allows us to access the data in these memory locations
by name. The MULTIPLICAND DC.W $204A statement
The EQU, or equate, directive assigns a name to also indicates that when the final program is loaded
constants used in your programs. The statement COR- into memory to be run, these memory locations will be
RECTION EQU S07 in a program such as our previous loaded with (initialized to) $204A. Since this is a
example tells the assembler to insert the value $07 Motorola microprocessor, the first address in memory
every time that it finds the name CORRECTION ina will contain the high byte of the word, $40, and the
program statement. In other words, when the assem- second memory address will contain the low byte of the
bler reads the statement ADD #CORRECTION,DO, it word, S4A.
will automatically code the instruction as if you had If the program’s data is eventually put in ROM or
written it ADD $07,DO0. Here’s the advantage of using EPROM, then MULTIPLICAND will function as a con-
an EQU directive to declare constants at the start of stant, because it cannot be changed during program
your program. Suppose that you use the correction execution. However, if the data is eventually put in
factor of +S07 a total of 23 times in your program. Now RAM, then MULTIPLICAND can function as a variable
the company for which you work changes brands of because a new value could be written into those memo-
temperature sensor, and the new correction factor is ry locations during program execution.
+S09. If you used the number $07 in the 23 instruc- The second data declaration example in Figure 3-10,
tions that contain this correction factor, then you will MULTIPLIER DC.W $3B2A, sets aside storage for a
have to go through the entire program, find each word in memory and gives the starting address of this
instruction that uses the correction factor, and update word the name MULTIPLIER. When the program is
the value. Murphy’s Law being what it is, you are likely loaded, the first memory address will be initialized
to miss one or two of these, and the program won’t with $3B, and the second memory location will be
work correctly. If you used an EQU at the start of your initialized with S2A.
program and then referred to CORRECTION by name The third data declaration example in Figure 3-10,
in the 23 instructions, all you have to do is change the PRODUCT DC.L 0, sets aside storage for 1 long word in
value in the EQU statement from $07 to $09 and memory and gives the starting address of the first byte
reassemble the program. The assembler will automati- the name PRODUCT. The 0 part of the statement tells
cally insert the new value of SO9 in all 23 instructions. the assembler to initialize the two words to all zeros.
When we multiply two 16-bit binary numbers, the
NOTE: In large programs consisting of modules product can be as large as 32 bits. Therefore, we must
assembled separately, constants must be de- set aside this much space to store the product. We
clared in each module. The assembler has no way could have used the DC.W directive to declare PROD-
of remembering an EQU value from one module UCT as 2 words or the DC.B directive to declare
when it assembles another module. PRODUCT as 4 bytes. Since, in the program, we move
the result to PRODUCT in one long-word MOVE in-
DC.B, DC.W, AND DC.L DIRECTIVES struction, it is more convenient to declare PRODUCT
The DC.B, DC.W, and DC.L (declare constant) direc- as 1 long word.
tives are used to assign names to variables in your Figure 3-11 shows how the data for MULTIPLICAND,
programs. The DC.B directive after a name specifies MULTIPLIER, and PRODUCT are actually arranged in
that the data is of type byte. The program statement memory starting from the base of the ORG $4100
OVEN—TEMPERATURE DC.B 27, for example, de- address. Addresses in Figure 3-11 start small and grow
clares a variable of type byte and gives it the name larger as we move down the page. Reading down, in
OCTAL
To indicate that you want a number to be evaluated as
base-8, or octal, put a ‘‘0”’ before the string of octal
digits. The statement OLDCOMPUTER DC.W
20 start of MULTIPLICAND 017341 is an example.
4A
NOTE: The Raven cross assembler does not sup-
3B start of PRODUCT
port octal notation.
2A
62 CHAPTER THREE
this data. Find the instruction MOVE.W (MULTIPLI- Naming Addresses— Labels
CAND),DO in the code section of the program in Figure
3-10. This instruction, when executed, will copy a Names representing addresses are called labels. They
word from memory to the DO register. When the as- are written in the label field of an instruction state-
sembler reads through this program the first time, it ment or a directive statement. We have seen labels
will automatically calculate the address of each of the used before with the DC and DS directives to name
named data items. Referring to Figure 3-11, you can variable memory locations. Another major use of labels
see that the address of MULTIPLICAND is $4100. This is to represent the destination for jump and call in-
is because MULTIPLICAND is the first data item de- structions. Suppose, for example, we want the 68000
clared after the ORG $4100 directive. When the as- to jump back to some previous instruction over and
sembler reads the program the second time to produce over. Instead of computing the numerical address to
the binary codes for the instructions, it will insert this which we want to jump, we put a label next to the
address as part of the binary code for the instruction instruction to which we want to jump and write the
MOVE.W (MULTIPLICAND),DO. Since we know that jump instruction as JMP label. Here is a specific exam-
the address of MULTIPLICAND is $4100, we could have ple.
written the instruction as MOVE.W ($4100),DO. How-
ever, there would be a problem if we later changed NEXT: MOVE.B ($4100),DO_ ; Get data sample from
the program by adding another data item be- ; port.
fore MULTIPLICAND but after the ORG $4100 direc- ; Process data value
tive because the address of MULTIPLICAND would ; read in.
be changed. Therefore, we would have to remember
to go through the entire program and correct
the address in all instructions that access MULTI- JMP NEXT : Get next data value
PLICAND. If you use a name to refer to each data ; and process.
item as shown, the assembler will automatically
calculate the correct address of that data item for If you use a label to represent an address as shown in
you and insert this address each time you refer to it in this example, the assembler will automatically calcu-
an instruction. late the address that needs to be put in the code for the
To summarize how this works, then, the instruction jump instruction. The next two chapters show many
MOVE.W (MULTIPLICAND),DO is an example of abso- examples of the use of labels with jump and call
lute addressing, where the absolute address is repre- instructions.
sented by a name. For instructions such as this, the We will now discuss some other parts of the example
assembler will automatically calculate the address of program that you will need to use in your programs.
the named data item and insert this value as part of
the binary code for the instruction.
The ABS_LONG and ABS_SHORT Directives
The next instruction in the program in Figure 3-10
is another example of absolute addressing using a The ABS—LONG and ABS—SHORT, or absolute long
named data item. The instruction MOVE.W (MULTI- and absolute short, directives are used only with the
PLIER),D1 moves the word named MULTIPLIER from Raven cross assembler. These directives tell the as-
memory into register D1. This operates just as does sembler whether to use long or word (short) addresses
the previous MOVE instruction, except that the in absolute addressing modes. ABS—LONG directs the
assembler will calculate the address of MULTIPLIER assembler to generate 32-bit (long) absolute addresses.
as $4102. ABS—SHORT directs the assembler to generate 16-bit
The next instruction, MULS D1,DO, multiplies the (short, or word) absolute addresses.
low word of D1 times the low word of DO and places the
resulting 32-bit product into DO.
The next instruction in the program in Figure 3-10, The END Directive
MOVE.L DO, (PRODUCT), copies the long-word result The END directive, as the name implies, tells the
from DO to memory. The highest byte of DO will be assembler to stop reading. Any instructions or state-
copied to a memory location named PRODUCT. The
ments that you write after the END directive will be
second-highest byte of DO will be copied to the next- ignored. An END directive is required in each assembly
higher address, which we can refer to as PRODUCT +
language program.
1. The second-lowest byte of the product will go into
PRODUCT + 2, and the lowest byte will go into PROD-
UCT + 3.
Figure 3-11 shows how the two words of the product
ASSEMBLY LANGUAGE PROGRAM
are put in memory. Note that the higher byte of a word DEVELOPMENT TOOLS
is always put in the lower memory address. Introduction
This example program should show you that if
you are using an assembler, names are a very con- For all but the very simplest assembly language pro-
venient way of specifying the direct address of data grams, you will probably want to use some type of
in memory. microcomputer development system and program
CRE
OOOO
OSS ‘PORTS USED none
10: ‘PROCEDURES USED none
11: ‘REGISTERS USED DQ,D1,D0
12: :
13: ; Start code here
14: 20004000 ORG $4000 Memory location where code is to start
15:
16: 00004000 207C 2020 4101 MOVEA.L #PRODUCT,AQ address of memory to save product
17:- 00004006 303C 4100 MOVE.W #MULTIPLICAND,DO get one word from memory
18: @020400A 323C 4102 MOVE.W #MULTIPLIER,D1 get second word, the multiplier
19: @000400E C1C1 MULS D1,D@ multiply signed 16-bit integers
20: result Is 32-bits long in DO
21: 80004010 2080 MOVE.L D0,(AQ) store result into memory
225
23: 00004012 4675 RTS return to whoever called me
24:
25: ; End of code section
26:
27: ; Start the data here
28: 00004100 ORG $4100 Memory location where data is to start
29:
30: 80004120 204A MULTIPLICAND: DC.W $204A multiplicand value in memory
31: location, stated in hex
32: 60004102 3B2A MULTIPLIER: DC.W = $3B2A multiplier value
33: 0004104 8020 0000 PRODUCT: DC.L ; initially the product's memory
34: location will contain @
35: ; nd of data
36: 20004108 END
Symbol Name Attribute Hex Decimal
RUDHIPRIGAND Raney. sey terdececie aan eet tie LABEL 00004100 16642
RUTTER seeetenge atecsere chat sie okacs ites. LABEL 00004102 16642
PRODUCT eT na gece tee ee te LABEL 00004104 16644
Obj bytes: 28D/0000001CH
End assembly. Lines: 36 Errors: @
memory. Note that the Raven RV68k assembler gene- When all the modules work, they can be linked togeth-
rates absolute physical addresses. The Consulair er to form a large, functioning program. Also, the object
MAC68000 assembler, on the other hand, does not modules for useful programs—a square root program,
generate absolute addresses. On the Macintosh, a for example—can be kept in a library file and linked
linker or locator will do this later. On the MAC68000 into other programs as needed.
listing, the addresses shown are relative. Also note The linker produces a link file, which contains the
that the MOVE (MULTIPLICAND),DO statement is as- binary codes for all the combined modules. The linker
sembled by the MAC68000 assembler with some also produces a link map file, which contains the
blanks after the basic instruction code. This is done address information about the linked files. The linker,
because the absolute address where MULTIPLICAND however, does not assign absolute addresses to the
starts is not known at the time the program is assem- program; it assigns only relative addresses starting
bled. from zero. This form of the program is said to be
The trailer section of the listing in Figure 3-13 gives relocatable because it can be put anywhere in memory
some additional information about the names used in to be run. If you are going to run your program on a
the program. The statement system such as the Apple Macintosh, you can just load
the link file into memory and run it. If you are going to
PRODUCT . . . LABEL 00004104 16644 run your program on a system such as the URDA MDS,
then you must use a locator program to assign abso-
for example, tells you that MULTIPLICAND is a label
that corresponds to memory address $00004104,
lute addresses to the linker file.
which is equal to decimal 16644.
Locator
Linker
A locator is a program used to assign the specific
A linker is a program used to join together several addresses at which the object code is to be loaded into
object files into one large object file. When writing large memory. A locator program that comes with the IBM
programs, it is usually much more efficient to divide PC DOS is called EXE2BIN. Here’s how you proceed if
the large program into smaller modules. Each module you want to produce a program with absolute address-
can be individually written, tested, and debugged. es that you can download to an URDA MDS from an
66 CHAPTER THREE
directly to the system, then you can use the system
START
debugger to run and debug your program. If your
program is intended to work with external hardware,
such as the prototype of a microprocessor-based in-
DEFINE
PROBLEM strument, then you will probably use an emulator to
run and debug your program. We discuss and show the
use of these program development tools throughout the
rest of this book, but this section should give you an
overview.
DEVELOP
ALGORITHM
CHECKLIST OF IMPORTANT TERMS AND
CONCEPTS IN THIS CHAPTER
CREATE If there are terms in this list you do not remember, use
SOURCE FILE the index to find them in the chapter.
WITH EDITOR
Algorithm
Sequential task list
ASSEMBLE
Flowcharts and flowchart symbols
Structured programming
ASSEMBLY Pseudocode
ERRORS
Top-down and bottom-up design
Sequence, repetition, and decision operations
Mnemonics
Initialization list
Standard program format
Documentation
LOAD
Instruction template
EMULATOR
Opcode
Size
Mode
LOAD
PROGRAM
Register number
Effective addressing modes
Editor
DO 0000 0001
List the major steps in developing an assembly
D1 7004 3333
language program.
D2 0000 0002
What is the main advantage of a top-down design
D3 1010 1010
approach to solving a programming problem?
D4 0000 0004
Why is it necessary to develop a detailed algorithm
D5 elitist lle
for a program before writing any assembly lan-
guage instructions? D6 FFFF FFFE
D7 0000 0007
a. What are the three basic structure types used
when writing programs?
AO 0000 4108
b. What is the advantage of using only these
structures when writing the algorithm for a Al 0000 4104
your microwave and use the result to help you get USP AZ 0000 7EBO
through the rest of the book.
:
Peanut Brittle
:
1 c sugar 1 tsp butter
0.5 c white corn syrup 1 tsp vanilla
68 CHAPTER THREE
9. See if you can spot the grammatical (syntax) l. Sets the MSB of DO toa 1 but does not affect
errors in the following instructions (use Chapter 6 the other bits.
to help you). m. Inverts the lower 4 bits of DO but does not
a. MOVE DO,D1 b. MOVE.B affect the other bits.
#FFEO097,A0
12. Construct the binary code for each of the following
c. ADDQ.W A3,134 d. MOVE.L
68000 instructions.
#3G6(A0),D3
a. MOVE.L A3,D7 MOVE.B —(AO),D3
e. ADDA.W #4000,A2
ADD.W #4013,D0 SUB.B #SFF,D1
10. Show the results that will be in the affected MOVE.L #¥9(A0),D3 ROR.W DO,D3
registers or memory locations after each of the NOP AND.L D7,D3
following groups of instructions execute. Assume ~Q
OO MULS D2,D4 5oo
& MOVEA.L
- that each group of instructions starts with the #$4100,D7
register and memory contents shown in Figure
13. Describe the function of each assembler directive
3-15. (Use Chapter 6.)
and instruction statement in the following short
a. ADD.L #4444,D0 b. MOVE.W
program.
#1234,D7
MOVE.B DO,D6 ROR #4,D7
c. MOVEA.L.W dad. ADDQ.L #7,D3
; pressure read program
#$4000,A0 NOP
PRESSURE—PORT EQU $0400 ; pressure sensor
MOVE.L AO,D5
; connected to port at
SUB.L #0111,D2
; memory location
ADDI.W #1,D2
MOVE.B D2,(AO) ; $0400
CORRECTION EQU $07 __; current correction
11. Write the 68000 instruction that will perform the ; factor, 07
indicated operation. Use the instruction overview ORG $4000 ; start of program
in this chapter and the detailed descriptions in MOVEA.L DATA—HERE,AO
Chapter 6 to help you. MOVE.B_ (A0O),DO
Copies AO to DO. MOVE.B PRESSURE—PORT,D1
Loads $43 into D3. ADDQ.B #CORRECTION,D1
Increments the contents of D2 by 1. MOVE.B D1,PRESSURE
Copies SP to D2. ORG $4100 ; data start
Adds $07 to DO. PRESSURE DC.B 0 ; storage for pressure
Multiplies D3 times D2. END
2 Copies D3 to a memory location at displace-
pees
ment $5C from register A2 using D1 as an 14. Describe how an assembly language program is
index. developed and debugged using system tools such
h. Decrements D2 by 1. as editors, assemblers, linkers, locators, emula-
i. Rotates the MSB of A5 into the LSB position. tors, and debuggers.
Jj. Copies D3 to a memory location whose ad-
15. Write the pseudocode representation for the flow-
dress is in A3 with a displacement of $4000.
chart in Figure 3-14.
k. Masks the lower 4 bits of DO.
The purpose of this chapter is to show you how some of Defining the Problem and Writing the
the standard program structures described in the last Algorithm
chapter are implemented in 68000 assembly language,
how these structures are used to solve some common If you type a 9 on the keyboard of an ASCII-encoded
programming problems, and how some of the 68000 computer terminal, the 8-bit ASCII code sent to the
instructions work. computer will be 0011 1001 binary, or $39. If you type
a5 on the keyboard, the code sent to the computer will
be 0011 0101 binary or $35, the ASCII code for 5. The
ASCII codes for the numbers O through 9 are $30
OBJECTIVES through $39. As you can see, the lower nibble of the
At the conclusion of this chapter, you should be able to ASCII codes contains the 4-bit BCD code for the num-
ber represented by the ASCII code. For many applica-
tions we want to convert the ASCII code coming in from
1. Write flowcharts or pseudocode for simple pro-
gramming problems. the terminal to its simple BCD equivalent. We can do
this by simply replacing the 3 in the upper nibble of the
2. Write 68000 assembly language programs to solve byte with four Os. For example, suppose we read in
IF-THEN, IF-THEN-ELSE, and multiple IF-THEN- 0011 1001 binary, or $39, the ASCII code for 9. If we
ELSE-type programming problems. replace the upper 4 bits with Os, we are left with 0000
1001 binary, or $09. The lower 4 bits contain 1001
3. Implement WHILE-DO and REPEAT-UNTIL pro-
binary, the BCD code for 9. Numbers represented as
gram structures in 68000 assembly language.
one BCD digit per byte are referred to as unpacked
4. Describe the operation of selected data transfer BCD. If two BCD digits are put in a byte, this form is
arithmetic, logical, jump, and loop instructions. referred to as packed BCD. Figure 4-1 shows examples
of ASCII, unpacked BCD, and packed BCD. When we
5. Use direct and indirect addressing modes to access
want to store BCD numbers in memory, the packed
data in your programs.
form is obviously more efficient because it has two BCD
6. Describe a systematic approach to debugging a digits in each byte memory location. The problem we
simple assembly language program using debug- are going to work on here is how to convert two
ger, monitor, or emulator tools. numbers from ASCII code form to unpacked BCD and
then pack the two BCD digits into 1 byte. Figure 4-1
shows the steps in numerical form.
70
The algorithm for this problem can be stated simply: mary in Chapter 3 and the instruction details in
Chapter 6 to find the instructions that perform the
Convert first ASCII number to unpacked BCD. operations you desire. Sometimes several instructions
Convert second ASCII number to unpacked BCD. will be required to perform a complex operation. In this
Move first BCD nibble to upper nibble position in byte. case you should try to break the complex operation into
Pack 2 BCD nibbles in 1 byte. its smaller components until each component can be
performed with one or two instructions.
This sequence doesn’t look much like an assembly
language program, and it shouldn’t. The algorithm at
this point should be general enough that it could be Masking with the AND Instruction
implemented in any programming language or on any
machine. Once you are reasonably sure of your algo- The first operation in the algorithm is to convert a
rithm, then you can start thinking about the architec- number in ASCII form to its unpacked BCD equivalent.
ture and instructions of the specific microcomputer on This is done by replacing the upper 4 bits of the ASCII
which you plan to run the program. Now let’s show you byte with four Os. The 68000 AND instruction can be
how we get from the algorithm to the assembly lan- used to do this operation. Remember from basic logic or
guage program for it. from the review in Chapter 1 that when a 1 ora 0 is
ANDed with a 0, the result is always a 0. ANDing a bit
SETTING UP THE DATA STRUCTURE with a O is called masking that bit, because the
previous state of the bit is hidden, or masked. To mask
One of the first things for you to think about in this 4 bits in a word, then, all you do is AND each bit you
process is the data with which the program will be want to mask with a 0. Remember, a bit ANDed witha
working. You need to ask yourself questions such as 1 is not changed.
According to the description of the AND instruction
1. Will the data be in memory or in registers? in Chapter 6, the instruction has the format AND
2. Is the data of type byte, type word, or perhaps type source, destination. The instruction ANDs each bit of
double word (long)? the specified source with the corresponding bit of the
specified destination and puts the result in the speci-
3. How many data items are there? fied destination. The source can be any data register or
Does the data represent only positive numbers, or a memory location specified in one of those 15 different
does it represent positive and negative (signed) ways. The destination can be a register or a memory
numbers? location. The source and the destination must both be
bytes, they must both be words, or they must both
5. For more complex problems you might ask how the be longs. The source and the destination cannot both
data is structured. For example, is the data in an be memory locations in an instruction.
array or in a record? For this example the first ASCII number is in the low
byte of register DO, so we can just AND an immediate
Let’s see how you can implement this algorithm in number with this register to mask the desired bits. The
68000 assembly language. Although it does not show upper 4 bits of the immediate number should be Os
in the algorithm, we know from a discussion in Chap- because these correspond to the bits we want to mask
ter 3 that we should start the program with a list of in DO. The lower 4 bits of the immediate number
initialization instructions. Start by putting this check- should be 1s because we want to leave these bits
list at the top of the paper. At this point you may not unchanged. The immediate number, then, should be
know exactly which parts on the checklist will have to 0000 1111 binary, or SOF. The instruction to convert
be initialized, but the presence of the list will remind the first ASCII number is AND.B #SOF,DO. When this
you that it has to be done. instruction executes, it will leave the desired unpacked
BCD in DO. Figure 4-2, p. 72, shows how this will work
for an ASCII number of $35 initially in DO.
The Data Structure and Initialization List
For the next action in the algorithm, we want to
For this example program let’s assume that the first perform the same operation on a second ASCII number
ASCII code entered is in the low byte of register DO, and in register D1. The instruction AND.B #SOF,D1 will do
the second ASCII code entered is in the low byte of this for us. After this instruction executes, D1 will
register D1. Since we are not using memory for data in contain the unpacked BCD for the second ASCII num-
this program, we do not need to declare any data. Ina ber.
real application this program would probably be a
subroutine or a part of a larger program. MOVING A NIBBLE WITH THE ROTATE
INSTRUCTION
Choosing Instructions The next action in the algorithm is to move the 4 BCD
bits in the first unpacked BCD byte to the upper nibble
Next look at the major actions that you want the position in the byte. We need to do this so that the 4
program to perform other than moving data from one BCD bits are in the correct position for packing with
place to another. Look through the instruction sum- the second BCD nibble. Take another look at Figure 4-1
72 CHAPTER FOUR
68000 PROGRAM
ABSTRACT Program to produce a packed BCD byte from
two ASCII-encoded digits.
The first ASCII digit (5) is located in the low
byte of DO, and the second ASCII digit (9) is located
in the low byte of Dl.
alr =8'8
=e
Se
~e
Ne
Te
se
END
FIGURE 4-4 68000 assembly language program to produce packed BCD from two ASCII characters.
we use the OR instruction to combine the two BCD is very similar to the data structure for the multiply
nibbles in 1 byte. Any bit ORed with a 1 will become or example in the last chapter. HI~TEMP is declared as a
remain a 1. Any bit ORed with a O will remain the same variable of type byte and initialized with a value of $92.
as it was. In an actual application, the value in HI-TEMP would
probably be put there by another program which reads
the output from a temperature sensor. The statement
Finding the Average of Two Numbers LO—TEMP DC.B $52 declares a variable of type byte
and initializes it with the value $52. The statement
The next example problem deals with more traditional
AV —TEMP DS.B 1 sets aside a byte location to store the
arithmetic, addition and division. Such details as han-
average temperature but does not initialize the location
dling the carry after an addition (if there was one) are
to any value. When the program executes, it will write
discussed.
a value to this location.
alr 11-88
te
me
te
Se
we
wo
se
°
, start the data here
°
e
END
also clear, since both temperatures are byte values. instruction, you should find that the ADD instruction
Now find and read the detailed discussion of this has the format ADD source, destination. A byte (word
instruction in Chapter 6. From this discussion you can or long) from the specified source is added to a byte
determine how the instruction works and see if it will (word or long) in the specified destination. (Note that
do the necessary job. From the discussion of the ADD you cannot directly add a byte to a word or a long or add
74 CHAPTER FOUR
a word to a long.) The result, in any case, is put in the NOTE: The 68010 uses the _ instruction
specified destination. The source can be an immediate MOVE.W CCR,D2 to access the condition-code
number, a register, or a memory location. The destina- portion of the status register.
tion can be a register or a memory location. The source
and the destination cannot both be memory locations Moves to and from the status register are always
in a single instruction. This means that you have to word-size moves.
move one of the operands from memory to a register Next the upper bits (bits 1—7) of D2 are all masked to
before you can do the ADD. Another point to consider Os, leaving only the carry bit unchanged. This mask-
here is that if you add two 8-bit numbers, the sum can ing operation is the same as that of the previous
be larger than 8 bits. Adding SFO and $40, for exam- example; this time, however, the mask is different.
ple, gives $130. The 8-bit destination will contain $30, Here the mask is $01, clearing all but bit 0 (the LSB). In
and the carry will be held in the carry condition code, C the previous example the mask was SOF, clearing only
(bit O of the status register). What this means is that the upper 4 bits (bits 4-7).
you must collect the parts of the result in a location The carry bit is then shifted over 8 bit positions so
large enough to hold all 9 bits. The lower 16 bits of a that it ends up in the low bit of the upper byte of the low
data register are good choices. Before using the regis- word of D2 (that is, bit 8 of D2). This is similar to the
ter, however, you should clear the bits to all Os so bits rotate in the previous example except that here the
10 through 16 of the final result will be 0. To summa- operand size is word, so that the low 16 bits of D2 are
rize, then, you need to clear the lower 16 bits of some rotated; and the rotation shifts D2 by 8 bit positions.
data register such as DO, move one of the numbers you The carry bit is then ORed as a word with the sum in
want to add into that data register, add the other DO. The OR operation leaves the lower byte and the
number from memory to it, and move any carry pro- upper 7 bits of DO unchanged, but bit 8 ends up equal
duced by the addition to the upper half of the 16-bit to the carry bit. If there was a carry, then the carry bit
register containing the result. was a 1 and so bit 8 will also be a 1; if there was no
Now let’s see how you can do this with program carry, then the carry bit was a 0 and so bit 8 will bea 0.
instructions. Take a look now at the first five instruc- We are also relying on the fact that the upper byte of
tion statements of the example program in Figure 4-5. DO was cleared to 0 at the start of the program during
The first instruction, ORG $4000, is an assembler initialization. We know the low bits of D2 will contain
directive telling the assembler to assemble this code at Os because the left-shift operation shifts in Os on the
an address of origin equal to $4000. The next two right as the register is shifted left (see Chapter 6). The
instructions clear the two working registers, DO and result of all this is that the carry bit ends up in bit 8 of
D1. In particular, we are interested in ensuring that DO, which is what we set out to do. The end result is
the upper byte of the lower word of D1 and all the upper that the lower word of DO has the correct 9-bit sum in
bits of DO are all cleared to Os. bits O—8 of register DO.
Next we move the first operand into DO using a The next major action in our algorithm is to divide
MOVE.B instruction. We can now use the ADD.B in- the sum of the two temperatures by 2. Look at the
struction to bring the second temperature from memo- instruction groups in the last chapter to see if the
ry and add it directly to the first temperature now held 68000 has a divide instruction. You should find that it
in register DO. Note that the name of the memory has two divide instructions, DIVS and DIVU. DIVU is
location holding the second temperature, LO_TEMP, for dividing unsigned numbers, and DIVS is used for
is used in the ADD instruction instead of the actual dividing signed binary numbers. Since we are dividing
hex address of the temperature. This makes the pro- unsigned binary numbers in this example, look up the
gram much more readable and easier to understand. DIVU instruction in Chapter 6 to find out how DIVU
The assembler will convert LO_TEMP to the correct works. The DIVU instruction can be used to divide a
address value when it assembles the program (i.e., 32-bit number in any data register by a specified 16-bit
when the assembler translates the program from as- number in a register or in a memory location. After the
sembly language to machine language). division a 16-bit quotient is left in the lower word of the
Following the ADD, we have the sum of the two destination data register, and a 16-bit remainder is left
temperatures in DO; the carry bit has been set, de- in the upper word of the destination data register.
pending on whether or not the addition resulted in a There is a problem if the quotient is too large to fit in
carry. the indicated destination. In a later chapter we discuss
Now that we have done the addition, the next thing to what to do about this problem. Fortunately, for this
do is get the carry bit where we want it. We would like example the data is such that the problem will not
to get the contents of the carry condition code into the arise, since the sum is at most 9 bits and our divisor
least significant bit of the upper byte of the lower word is 2.
of DO—that is, into bit 8 of DO (remember that bits are As you can see, we already have the sum of the two
numbered by Motorola starting with bit 0). First, a temperatures positioned in register DO ready for the
copy is made of the status register in D2. This is DIVU operation. Before we can do the DIVU operation,
accomplished with a MOVE.W SR,D2 instruction, however, we have to get the divisor, $02, into a register
moving one word from the status register to register or memory location to satisfy the requirements of the
D2. DIVU instruction. A simple way to do this is with the
76 CHAPTER FOUR
will be set to indicate that a borrow was needed to is zero. For example, if you subtract two equal num-
perform the subtraction. The extend bit is set to the bers, the zero code will be set to indicate that the result
same value as the carry bit. of the subtraction is zero. If you AND two words
The 68000 compare instruction has the format CMP together and the result contains no Is, the zero code
source, destination. The source can be an immediate will be set to indicate that the result was all Os.
number, a register, or a memory location. The destina- There are a few other very useful instructions be-
tion can be a register or a memory location. Source and sides the more obvious arithmetic and logic instruc-
destination cannot both be memory locations in the tions that affect the zero-condition code. One of these
same instruction. The comparison is done by subtract- is the compare instruction, CMP, which we discussed
ing the contents of the specified source from the previously with the carry flag. As shown there, the
contents of the specified destination. Condition codes zero code will be set to a 1 if the two operands
are updated to reflect the result of the comparison, but compared are equal.
neither the source nor the destination are changed. If Another important instruction that affects the zero
the source operand is greater than the specified desti- code is the decrement and branch instruction, Dec.
nation operand, then the carry/borrow flag will be set This instruction will decrement—or, in other words,
to indicate that a borrow was needed to do the compari- subtract 1 from—a number in a specified register or
son (subtraction). If the source operand is the same size memory location. If, after decrementing, the content of
as or smaller than the specified destination operand, the register or memory location is zero, the zero flag
then the carry/borrow flag will not be set after the will be set. In addition, if the DEQ (decrement and
compare. If the two operands are equal, the zero flag branch if EQual to zero) form of the decrement instruc-
will be set to a 1 to indicate that the result of the tion is used, the instruction will also cause a branch to
compare (subtraction) was all Os. Here is an example occur.
and summary of this for your reference. Here’s a preview of how this is used with the BNZ
form of the decrement and branch. BNZ branches if
CMP.B DO,D1 the result of the decrement is Not equal to Zero.
Suppose that we want to repeat a sequence of actions
Condition C 1, nine times. To do this we first load a register with the
number S09 and execute the sequence of actions. We
DO > D1 1 O
then decrement the register and look at the zero flag to
DO < Dl 0 O
see if the register is down to zero yet. If the zero flag is
DO = D1 (0) il
not set, then we know that the register is not yet down
to zero, so the 68000 automatically branches and goes
The compare instruction is very important because
back and executes the sequence of instructions again.
it allows you to easily determine whether one operand
The following sections will show many specific exam-
is greater than, less than, or the same size as another
ples of how this is done.
operand.
J MP Jump JMP
(M68000 Family)
Assembler
Syntax: JMP (ea)
Attributes: Unsized
Condition Codes:
Not affected.
Instruction Format:
13 1 2 1 0
EFFECTIVE ADDRESS
MODE REGISTER
Instruction Fields:
Effective Address field —Specifies the address of the next instruction. Only
control addressing modes are allowed as shown:
[arena
Was|Wade|Reser
a
mee nn one re a
Pie lw acacea aaa [tad
ree an eee pSne EH
[aero [|
[tere
MC68020, MC68030, AND MC68040 ONLY
EI
Din
(bd,PC,Xn)*
ag
([bd,PC,Xn],od)
([bd,PC],Xn,od)
*Can be used with CPU32.
(a)
FIGURE 4-7 68000 (a) JMP and (b) BRA instructions (p. 79). (continued)
78 CHAPTER FOUR
BRA Branch Always BRA
(M68000 Family)
Operation: PC +d» PC
Assembler
Syntax: BRA (label)
Condition Codes:
Not affected.
Instruction Format:
ee
cece TT OSPR
15 14 13 12 ill 10 &) 8 7 6 5 4 3 2 ] 0
Instruction Fields:
8-Bit Displacement field — Twos complement integer specifying the number
of bytes between the branch instruction and the next instruction to be exe-
cuted.
16-Bit Displacement field — Used for a larger displacement when the 8-bit
displacement is equal to $00.
32-Bit Displacement field — Used for a larger displacement when the 8-bit
displacement is equal to $FF.
NOTE
A branch to the immediately following instruction automatically uses
the 16-bit displacement format because the 8-bit displacement field
contains $00 (zero offset).
80 CHAPTER FOUR
il:
2: 68000 PROGRAM
3: ABSTRACT : This program illustrates a “backward” jump
4:
5 REGISTERS USED : DO
6: PORTS USED : none used
if PROCEDURES : none used
8:
9: air 3-88
10:
Wie
12: 00004000 ORG $4000
ilise
14: 00004000 5680 BACK: ADDQ.L #3,D0 ; add 3 to total
ise
16: 00004002 4E71 NOP - dummy instructions
17: 00004004 4E71 NOP to represent those
18: 00004006 4E71 NOP ; instructions jumped
19: 00004008 4E71 NOP ; back over
20:
21: 0000400A 4EF9 0000 4000 JMP BACK ; loop back through
22: ; series of instructions
23:
24: 00004010 4E71 NOP ‘dummy instructions to
25: 00004012 4E71 NOP represent continuation
26: after loop
27:
28: 00004014 4E75 RTS
29:
30: 00004016 END
BACK Riteacecsteciea
a. cecteris.< caelere Oueiener hens LABEL 00004000 16384
; REGISTERS USED: DO
; PORTS USED none used
s PROCEDURES none used
Q alr 3-88
22: 0000400C 303c 0000 THERE: MOVE.wW #$0000,D0 ; zero accumulator before addition
WEB oo 66646
Hoo OD GbE LABEL 0000400C 16396
82 CHAPTER FOUR
The 68000 Conditional: Branch Instructions or not. Figure 4-10 shows the mnemonics for the
68000 conditional branch instructions. The condi-
As we stated previously, much of the real power of a tional branch instructions are branch conditionally
computer comes from its ability to choose between two (Bcc) and decrement and branch conditionally (DBcc).
courses of action based on whether some condition is The actual assembly language instructions are gener-
present or not. In the 68000 the five condition codes ated by replacing cc with one of the condition mne-
indicate the conditions that are present after an in- monics from Figure 4-10. For example, BVS GO is the
struction. The 68000 conditional branch instructions assembly language instruction to branch if the over-
look at the state of a specified code or codes to deter- flow condition code bit is set to location ‘‘GO.’’ Branch
mine whether a branch (a short jump) should be made
Assembler
Syntax: Bcc (label)
Condition Codes:
Not affected.
Instruction Format:
Ce
7 6 5 4 3 2 1 0
Instruction Fields:
Condition field — The binary code for one of the conditions listed in the table.
8-Bit Displacement field — Twos complement integer specifying the number
of bytes between the branch instruction and the next instruction to be exe-
cuted if the condition is met.
16-Bit Displacement field — Used for the displacement when the 8-bit displace-
ment field contains $00.
32-Bit Displacement field — Used for the displacement when the 8-bit displace-
ment field contains $FF.
NOTE
A branch to the immediately following instruction automatically uses
the 16-bit displacement format because the 8-bit displacement field
contains $00 (zero offset).
“High” and “low” refer to the relationship of two signed values;
“greater” and “less” refer to the relationship of two signed values.
84 CHAPTER FOUR
CMPaIn DO? D2 compare to set flags
BEQ THERE oe
=e if equal then skip correction
END
(b)
FIGURE 4-11 IF-THEN implementations. (a) Conditional jump destinations
closer than +128 bytes. (b) Conditional jump destinations further than +128
bytes.
By now you are probably thinking that this IF-THEN Part of the job of this 68000 is to check a temperature
structure looks very familiar. It should, because a sensor and turn on a green lamp or a yellow lamp,
simple IF-THEN is part of the WHILE-DO and REPEAT- depending on the value of the temperature it reads in.
UNTIL structures. In the discussions of WHILE-DO If the temperature is below 30°C, we want to turn ona
and REPEAT-UNTIL structures later in this chapter, yellow lamp to tell the operator that the solution is not
look for the simple IF-THEN as a building block used to up to temperature. If the temperature is greater than or
help construct the more complex structures. equal to 30°C, we want to light a green lamp. With a
system such as this the operator can visually scan all
IF-THEN-ELSE Programs the lamps on the control panel until he or she sees all
green lamps. When all the lamps are green, the opera-
The IF-THEN-ELSE structure is used to indicate a tor can push the GO button to start making boards.
choice between two alternative courses of action. Fig- The yellow lamp lets the operator know that this part
ure 3-3b shows the flowchart and pseudocode for this of the machine is working, but the temperature is not
structure. Basically the structure has the format yet up to 30°C.
Figure 4-12, p. 86, shows two ways—flowcharts and
IF condition THEN pseudocode—to represent the algorithm for this prob-
action lem. The difference between the two is simply a matter
action of whether we make the decision based on the temper-
ELSE ature being below 30°C or we make the decision based
action on the temperature being greater than or equal to 30°C.
action The two approaches are equally valid, but your choice
determines which conditional jump instruction you
This is a different situation than the simple IF-THEN, choose. Figure 4-13a (pp. 87-88) shows the 68000
because here either one series of actions or another assembly language implementation of the algorithm in
series of actions is done before going on with the next Figure 4-12a.
mainline instruction. An example will show how we For this program segment, assume that we read the
implement this structure. j temperature in from an A/D converter connected to
Suppose that in the computerized factory we dis- input port $SCO15. Also assume that the control for the
cussed in Chapter 2 we have a 68000 microcomputer yellow lamp is connected to bit 0 of port $CO14 and the
that controls a printed-circuit-board-making machine. control for the green lamp is connected to bit 1 of port
READ pH READ pH
SENSOR SENSOR
$C014. A 1 sent to a bit position of port $CO14 turns between two alternative courses of action. In many
on the lamp connected to that line, and a 0 turns it off. situations we want a computer to choose one of several
After we read the data in from the port, we compare it alternative actions based on the value of some variable
with our setpoint value of 30°C. If the input value is read in or on a command code entered by a user. To
below 30°C, then we jump to the instructions that turn choose one alternative from several, we can nest IF-
on the yellow lamp. If the temperature is greater than THEN-ELSE structures. The result has the following
or equal to 30°C, we jump to the instructions that turn form:
on the green lamp. Note that we have implemented this
algorithm in such a way that the BLT instruction will IF condition THEN
always be able to reach the label YELLOW. action
To actually turn on a lamp, we load a 1 in the action
appropriate bit of register DO with a MOVE.B instruc- ELSE IF condition THEN
tion and send the byte-to the lamp-control port, $CO14. action
The instruction sequence MOVE.B #S01,D0; MOVE.B action
DO,(SC014), for example, will light the yellow lamp by ELSE
sending a 1 to bit O of port $C014. action
Figure 4-13b (pp. 88-89) shows another equally action
valid assembly language program segment to solve our
problem. This one uses a branch if greater or equal It is important to note in this structure that the last
instruction, BGE, at the decision point and switches ELSE is part of the IF-THEN just before it. Figure 3-3g
the order of the actions. This program more closely showed a flowchart and pseudocode for a soup-cook
follows the second algorithm statement in Figure 4- example using this structure. The soup-cook example,
12b. Perhaps you can see from these examples why two however, is too messy to implement here. Therefore,
programmers may write very different programs to while the PC board machine from the last section is
solve even very simple programming problems. still fresh in your mind, we will expand that example
to show you how a multiple IF-THEN-ELSE is imple-
Multiple IF-THEN-ELSE Implementation mented.
Suppose that we want to have three lamps on our
In the preceding section we showed how to implement PC-board-making machine. We want a yellow lamp to
and use the IF-THEN-ELSE structure, which chooses indicate that the temperature is below 30°C, a green
86 CHAPTER FOUR
: 68000 Program section for PC board making machine
eeeOVMUBWP
ODO
N
=
PpFee
Vas)
eel
(0)
set
“eal
ise)
(eb)
ee
wal
Uae ; REGISTERS USED: AO, DO
; PORTS USED : $C016 as a control port for the lamp port
$CO15 as a temperature input port
$C014 as a lamp control output (yellow=bit 0, green= bit 1)
; PROCEDURES : mone used
; alr 12-88
20: 00004000 ORG $4000 ; start the code at memory address $4000
28: 00004018 1039 0000 co15 MOVE. wo ($C015),00 ; tead temp from sensor on input port
29: 0000401E 0co0 OO1E CMPI. ao #30,00 ; compare temp to 30 degrees C
30: 00004022 6C00 0008 BGE GREEN ; if temp < 30 go light yellow lamp
31: 00004026 4EF9 0000 403C JMP YELLOW ; elso go light green lamp
33: 0000402C 103C 0002 GREEN: MOVE.B #$02,D0 ; load code to light green lamp
34: 00004030 13C0 0000 C014 MOVE.B DO0,($C014) ; send code to light green lamp
35: 00004036 4EFO 0000 4046 JMP EXIT 3 go to next mainline instruction
37: 0000403c 103C 0001 YELLOW: MOVE.B #$01,00 ; load code to light yellow lamp
38: 00004040 130 0000 C014 MOVE.B DO,($C014) ; send code to light yellow lamp
40: 00004046 2079 0000 C016 EXIT: MOVEA.L $C016,A0 next mainline instruction
SO i ee Greco,
aes Gus LABEL 00004046 16454
GREENDE athe. Geeeete. fou.easement LABEL 0000403C 16444
YELCOW Pam, ae) Sueeee eee LABEL 0000402C 16428
(a)
lamp to indicate that the temperature is greater than or 40°. If the temperature is above or equal to 30° but
equal to 30°C but below 40°C, and a red lamp to below 40°, then you know that the temperature is in
indicate that the temperature is at or above 40°C. the green-lamp range. If the temperature is not less
Figure 4-14, p. 90, shows three ways to indicate what than 40°, then you know that the temperature must be
we want to do here. The first way, in Figure 4-14a, greater than or equal to 40°. In other words, two
simply indicates the desired action next to each temp- carefully chosen tests will direct execution to one of
erature range. You may find this form very useful in the three alternatives.
visualizing problems where the alternatives are based Figure 4-15, pp. 91-92, shows how we can write a
on the range of a variable. Don’t miss the ASCII-to- program for this algorithm in 68000 assembly lan-
hexadecimal problem at the end of the chapter for guage. In the program we first initialize port SCO14 as
some practice with this. Once you get the problem an output port. We then read in the temperature from
defined in this list form, you can easily convert it toa an A/D converter connected to port $CO15. We com-
flowchart or pseudocode. When writing the flowchart pare the temperature read in with the first setpoint
or the pseudocode, it is best to start at one end of the value, 30° ($1E). If the temperature is less than 30°, the
overall range and work your way to the other. For branch if lower than (BLT) instruction will cause a
example, in the flowchart in Figure 4-14b, we start by jump to the label YELLOW. If the jump is not taken, we
checking if the temperature is below 30°. If the temper- know the temperature is greater than or equal to 30°C,
ature is not below 30°, then it must be above or equal to so we go on to the CMPI.B #$28,D0 instruction to see if
30°, and you do not have to do another test to deter- the temperature is less than the second setpoint, 40°
mine this. You then check if the temperature is below ($28). The BLT GREEN instruction will cause a branch
88 CHAPTER FOUR
; 68000 Program section for PC board making machine
; alr 12-88
s8
06
08
s¢
ce
ec
8ee
se
YS
AS
5
ey
Sey
FW
OU : 00004000
OMON
©
|= ORG $4000 ; Start the code at memory address $4000
wn : 00004018
ynNou 1039 0000 C015 MOVE.B ($C015),D0 ; read temp from sensor on input port
: QOO04O1E 0co0 OO1E CMPI.B #30,D0 ; compare temp to 30 degrees C
: 00004022 6000 0008 BLT YELLOW ; if temp < 30 go light yellow lamp
: 00004026 4EFO 0000 403C JMP GREEN ; elso go light green lamp
O : 0000402C
WWW
—|=
nN
@® 103C 0001 YELLOW: MOVE.B #$01,D0 ; load code to light yellow lamp
: 00004030 130 0000 C014 MOVE.B DO,($C014) ; send code to light yellow lamo
: 00004036 4EF9 0000 4046 JMP EXIT ; go to next mainline instruction
Ww
WW
: 0000403c
rele
pe
St 103C 0002 GREEN: MOVE.B #$02,D0 ; load code to light green lamp
WN : 00004040 13C0 0000 C014 MOVE.B 0O0,($C014) ; send code to light green lamp
38:
39: 00004046 2079 0000 C016 EXIT: MOVEA.L $C016,A0 ; next mainline instruction
40:
41: 0000404c 4E75 RTS 3; return to whoever called me
42:
43: 0000404E END
(b) (continued from p. 88)
to the label GREEN if the temperature is less than 40° control the three lamps are connected to port $C0O14.
(S28). If the jump is not taken, we know that the The yellow lamp is connected to bit O, the green is
temperature must be at or above 40°C, so we just go connected to bit 1, and the red is connected to bit 2. We
ahead and turn on the red lamp. turn on a lamp by outputting a 1 to the appropriate bit
For this program we assume that the lines that of port $C014. The instruction sequence MOVE.B
90 CHAPTER FOUR
; 68000 Program section for PC board making machine
: alr 1-89
: 00004018 1039 0000 co15 MOVE.B ($C015),00 ; Tead temp from sensor on input port
: OOO0401E 207C 0000 C011 MOVEA.L #$C011,A0 ; point AO at output port
: 00004024 0co0 OO1E CMPI.B #$1E,D0 ; compare temp to 30 degrees C
: 00004028 6000 0016 BLT YELLOW ; if temp < 30 go light yellow lamp
: 0000402C 0co0 0028 CMPI.B #$28,00 ; compare with 40 degrees
: 00004030 6000 001A BLT GREEN ; if temp < 40 go light green lamp
: 00004034 103¢ 0004 RED: MOVE.B #$04,D0 ; temp >= 40 so load code to light red lamp
: 00004038 2080 MOVE.L DO,(A0) ; send code to light red lamp
Wwo : 0000403A 4EF9 0000 4052 JMP. EXIT ; go to next mainline instruction
WwWoo oe00004040 103C 0001 YELLOW: MOVE.B #$01,00 ; load code to light yellow lamp
: 00004044 2080 MOVE.L DO,(AO) ; send code to light yellow lamp
: 00004046 4EF9 0000 4052 JMP EXIT 3 go to next mainline instruction
: 0000404C 103C 0002 GREEN: MOVE.B #$02,D0 ; load code to light green lamp
: 00004050 2080 MOVE.L DO,(A0) ; send code to light green lamp
: 00004052 207C 0000 C016 EXIT: MOVEA.L #$C016,A0 ; next mainline instruction
~ Ww °: 00004058 1010 MOVE.B (A0),D0 3; read ph sensor
: 0000405A 4E75 RTS ; return to whoever called me
47:
QSo@ oe 0000405C END
92 CHAPTER FOUR
68000 CPU words. Normal 68000 MOVE instructions #804 is written to the control register telling it to put
work perfectly well for this type of I/O. In fact, the only the port at address $CO14 back into normal I/O
way for someone reading your program to tell whether mode. The instruction for performing this is MOVE.B
the CPU is accessing I/O or variables in memory is #$04,(SCO16). It is to the port address $CO14 that we
through the comments you place in the source code. will output a byte to turn the heater on or off.
The 68000 can access as many I/O ports as it can After we input the data from the temperature sensor
memory locations. For the 68000 this means that, in in Figure 4-17a, we compare the value read with 100
theory, 27* or 16 Mbytes can be addressed (the other 8 ($64). The BGE instruction after the compare can be
address lines are not brought “‘off chip’’ on the 68000). read as branch to the label HEATER—OFF if DO is
The 68020, 68030, and 68040 have pins to bring out greater than or equal to 100. Note that we used the
all 32 address lines. The 68010 presents only 24 branch if greater or equal instruction rather than a
address lines. branch if equal instruction. Can you see why? To see
Most common devices used as ports for microcom- the answer, visualize what would happen if we had
puters can be used for input or output. When the power used a BEQ instruction and the temperature of the
is first applied to these devices, they are in the input solution were 101°. On the first check the temperature
mode. If you want to use one of these devices as output would not be equal to 100°, so the 68000 would turn on
ports, you must send the device a control word that the heater. The heater would not be turned off until
switches the device to output mode. Chapter 9 and meltdown.
later chapters describe in detail how you initialize If the heater temperature is below 100°, we turn on
programmable port devices, but to give you an intro- the heater by loading a 1 in the MSB of DO and
duction, we show you here how to initialize one of the outputting this value to the MSB of port $CO14. We
ports in a 6821 on an URDA MDS for use as an output then do an unconditional JMP back to check the
port. To specify the function of one of these program- temperature again.
mable devices, you send a control word to a register When the temperature is at or above 100°, we loada
inside the device. You can find the control word format O in the most significant bit of DO and output this to
for each type of device in the manufacturer’s data port $CO14 to turn off the heater. Here we could have
book. For one of the 6821s on an URDA board, the sent the byte directly using MOVE.B #$80,($CO14).
address of the control register that controls port SCO14 Note that the action of turning off the heater is outside
in the device is S$CO16. To initialize all 8 bits of the basic WHILE-DO structure. This is shown by the
port $CO14 as outputs, first the command byte $00 dotted box in the flowchart in Figure 4-16a and by the
is sent to the control port address $CO16. This tells indentation in the pseudocode in Figure 4-16b.
the I/O device to listen on the I/O port at $C0O14 for a
directional bit vector telling it which bits should be SOLVING A POTENTIAL PROBLEM OF
inputs and which should be outputs. The instruction CONDITIONAL JUMP INSTRUCTIONS
MOVE.B #S00, (SC0O16) accomplishes this in Figure In the example program in Figure 4-17a we used the
4-17a, pp. 93-94. The direction bit vector is then conditional jump instruction BGT to help implement
written directly to the I/O port using the instruc- the WHILE-DO structure. Conditional branch instruc-
tion MOVE.B#SFF,(SCO16). Finally, the control byte tions have a potential problem, of which you should
(a) (continued)
FIGURE 4-17 Assembly language program for heater-control problem. (a) First
approach (pp. 93-94). (b) Improved version (pp. 95-96).
(continued)
become aware at this point. All the conditional branch would then be outside the range of the BGT instruc-
instructions are 8- or 16-bit-type branches. This tion. This will normally not happen on the URDA MDS
means that a conditional jump can only be to a location because it is a small system running small programs.
within the range of —32,768 bytes to +32,767 bytes Figure 4-17b, pp. 95—96, shows how you can change
from the instruction after the conditional jump in- the instructions slightly to solve the problem without
struction. This limit on the range of the jump posed no changing the basic overall WHILE-DO structure. In
problem for the example program in Figure 4-17a this example we read the temperature in as before and
because we were jumping to a location only 8 bytes compare it to 100 (S64). We then use the branch if less
ahead in the program. Suppose, however, that the than instruction, BLT, to branch to the program sec-
instructions for turning off the heater required tion that turns on the heater. This instruction, togeth-
100,000 bytes of memory. The HEATER —OFF label er with the CMP instruction, says branch to the label
94 CHAPTER FOUR
; 68000 Program
=
anwnrWsr
ON ; REGISTERS USED: DO
9: ; PORTS USED : $C016 as a control register for the heater port
10: . $CO15 for temperature data input
ane i. $CO014 MSB for heater control output
ee + PROCEDURES : mone used
NS .
14: : alr 10-88
15: .
16:
17: 00004000 ORG $4000 ; start the code at memory address $4000
18:
19: ; initialize port $C014 as an output port for lamp output
20: 00004000 13FC 0000 0000 MOVE.B #$00,($C016) ; set for direction initialization
C016
21: 00004008 13FC OOFF 0000 MOVE.B #SFF,($C014) ; all bits in port for output
C014
22: 00004010 13FC 0004 0000 MOVE.B #$04,($C016) ; set for 1/0
C016
23: ; initialization complete
24:
25: 00004018 TEMP_IN:
26: 00004018 13C0 0000 C015 MOVE.B DO,($CO15) ; read in temperature data
27: 0000401E OCO0 0064 CMPI.B #100,00 5
28: 00004022 6D00 0008 BLT HEATER_ON ; if temp < 100 go
29: . turn heater ON
30: 00004026 4EF9 0000 403c JMP HEATER_OFF ; temp >= 100 so go
Sis turn heater OFF
Yee
33: 0000402C HEATER_ON:
34: 0000402C 103c 0080 MOVE.B #$80,D0 ; load code for heater on
35: 00004030 13c0 0000 c014 MOVE.B DO,($C014) ; turn heater on
36: 00004036 4EF9 0000 4018 JMP TEMP_IN 3; go and read temperature again
37:
38: 0000403c HEATER_OFF:
39: 0000403c 103c 0000 MOVE.B #$00,00 ; load code for heater off
40: 00004040 13c0 0000 C014 MOVE.B DO0,($C014) ; turn heater off
4i:
42: 00004046 4E75 RTS : return to whoever called me
43:
44: 00004048 END
(b) (continued)
HEATER —ON if DO is less than 100. If the temperature that the destination for the conditional branch in-
is at or above 100, the BLT instruction will act like a struction is always just two instructions away. There-
NOP, and the 68000 will go on to the JMP HEATER— fore, you know that the destination will always be
OFF instruction. Changing the conditional jump in- reachable. Except for very time-critical program sec-
struction and writing the program in this way means tions, you may want to write conditional branch in-
struction sequences in this way so that you don’t have strobe. An example of a strobed data system such as
to worry about the potential problem. The disadvan- this is an ASCII-encoded computer-type keyboard. Fig-
tages of this approach are the time and memory space ure 4-18 shows how the parallel data lines and the
required by the extra JMP instruction. strobe line from such a keyboard are connected to
ports of a microcomputer. When a key is pressed on the
keyboard, circuitry in the keyboard detects which key
REPEAT-UNTIL IMPLEMENTATION is pressed and sends the ASCII code for that key out on
AND the eight data lines connected to port $C014. After the
EXAMPLES
data has had time to settle on these lines, the circuitry
Remember from the discussion in Chapter 3 that the in the keyboard sends out a key-pressed strobe, which
REPEAT-UNTIL structure has the form lets you know that the data on the eight lines is valid.
We have connected this strobe line to the LSB of port
REPEAT S$CO15. A strobe can be an active high signal or an
action
action
DATA BUS TO 68000
96 CHAPTER FOUR
active low signal. For the example here, assume that
START
the strobe signal goes high when a valid ASCII code is
on the parallel data lines.
If we want to read the data from this keyboard, we
can’t do it at just any time. We must wait for the strobe
to go high so that we know that the data we read will be READ STROBE
valid. Basically what we have to do is look at the strobe
signal and test it over and over until it goes high. Figure
4-19a shows how we can represent this operation with
a flowchart and Figure 4-19b shows the pseudocode.
We want to repeat the read strobe and test loop until
the strobe is found to be high. Then we want to exit the
loop ‘and read in the ASCII code byte. Note that, as
shown by the dotted box in the flowchart and the
indentation in the pseudocode, the read ASCII data
action is not part of the basic REPEAT-UNTIL struc-
ture.
PSEUDOCODE
(c) (continued)
98 CHAPTER FOUR
array. For our example program here, we want to add The example program in Figure 4-20c uses several
an inflation factor of $03 to each price in an eight- assembler directives. Let’s review the function of these
element array of prices. Each price is stored in a byte before describing the operation of the program instruc-
location as packed BCD (two BCD digits per byte). The tions. The ORG directives are used to tell the assembler
prices, then, are in the range of 1¢ to 99¢. Figure 4-20a where to locate the program ($4000) and the data
and Figure 4-20b show a flowchart and the pseudocode ($4100) in memory. The END directive lets the assem-
for the operations that we want to perform. Follow bler know that it has reached the end of the program.
through with whichever form you feel more comfort- Now let’s discuss the data structure for the program.
able. The statement COST DC.B $20, $28, $15, $26, $19,
We read one of the BCD prices from memory, add the $27, $16, $29 in the program tells the assembler to set
inflation factor to it, and copy the new value back to the aside successive memory locations for an eight-ele-
array, replacing the old value. After that, a check is ment array of bytes. The array is given the name
made to see if all the prices have been operated on. If COST. When the assembled program is loaded into
they haven’t, then we loop back and operate on the memory to be run, the eight memory locations will be
next price. The two questions that may occur to you at loaded with the eight values specified in the DC.B
this point are, How are we going to indicate in the statement. The statement PRICES DC.B $36, $55,
program which price we want to operate on, and how $27, $42, $38, $41, $29, $59 sets up another eight-
are we going to know when we have operated on all of element array of bytes and gives it the name PRICES.
the prices? To indicate which price we are operating on The eight memory locations will be loaded with the
at a particular time, we use a register as a pointer. To specified values when the assembled program is loaded
keep track of how many prices we have operated on, we into memory. Figure 4-21, p.102, shows how these two
use another register as a counter. The example pro- arrays will be arranged in memory. Note that the name
gram in Figure 4-20c, p. 100, shows one way in which of the array is associated with the address of the first
our algorithm for this problem can be implemented in element of the array.
assembly language. The first three instructions, MOVEA.L PRICES,A1,
MOVE.W #S0008,D1, and MOVE.B #S803,D2, ini-
tialize Al to point to the array of prices, D1 to contain
the starting value of the loop counter, and D2 to
contain the correction factor. These are all stored in
START
CPU registers so that the following loop can execute as
fast as possible with as few references to external
memory as possible. The MOVEA instruction moves an
effective address into Al. We say that Al is then a
GET A PRICE pointer to an element in the array PRICES. We will
soon show you how this pointer is used to step through
the array element by element. The counter register,
D1, is loaded with the number of prices in the array,
ADD INFLATION $08. We use this register as a counter to keep track of
FACTOR
how many prices we have operated on. After we operate
on each price, we decrement the counter by 1. When
the counter reaches O, we know that we have operated
ADJUST RESULT on all the prices. The data register D2 is used to hold
TO BCD
the offset value, $03, so that it remains in the CPU
during the loop.
The MOVE.B (A1),DO instruction copies one of the
PUT RESULT prices from memory to the register DO. The next
BACK IN ARRAY instruction, ABCD D2,D0, adds the immediate number
$03, which we have previously placed in D2, to the
contents of the low byte of register DO. The addition
will be performed using BCD arithmetic.
The next instruction, MOVE.B DO,(A1)+, moves the
resulting byte from data register DO back to memory at
REPEAT
GET A PRICE FROM ARRAY
ADD INFLATION FACTOR
FLOWCHART ADJUST RESULT TO CORRECT BCD
(a) PUT RESULT BACK IN ARRAY
UNTIL ALL PRICES ARE INFLATED
; alr 10-88
FORSRSSOE25 COdeu SCQMe NG a
ORG $4000 ; start code here
DO_NEXT:
MOVE.B (Al) ,DO ; copy a price to DO
ABCD D2,D0 ; add inflation factor
; using BCD arithmetic
; operand size is assumed to be BYTE
MOVE.B DO, (Al)+ ; copy result back to memory and
; increment Al to point to the next price
DBGE D1,DO_NEXT (ee feno clastc mC OmGeGEnexcs
; data follows:
FARSI S SSS Cait mS CCM CT a
ORG $4100
Cost Der. S20, GAG, SiS, S2G—_, SIO, S27, $16, $29
PRICES DC.B SSiGpEES ODN SG2 mES 421 mESS Gly Gail, SHO, SSS
END
(c) (continued)
the same location from which it was originally loaded. array called COST and put the result in the corre-
However, this time the address register Al is incre- sponding element in an array called PRICES. We first
mented (i.e., 1 is added to it) to point to the next byte in initialize Al as a pointer to the first element in the
memory, which is also the next element in the PRICES PRICES array and A2 as a pointer to the first element
array. Recall that this is using the address register in the cost array using MOVEA.L instructions. The
indirect with postincrement addressing mode. Because instruction MOVE.B (A2)+,D0 will copy the first cost
the ‘‘+’’ is after the (Al), you can tell that the incre- value into DO. The pointer to the cost array in A2 is
ment happens after the move-memory reference. automatically incremented to point to the next element
The DBGE D1, DO—NEXT instruction decrements in the array. This is implied by the + after the (A2).
the loop counter, and if the counter is still greater than This is the same as in the previous example. The profit
or equal to 0, it branches back to start another cycle factor in D2 is added to the element using an ABCD
through the loop. The decrement and branch instruc- instruction. The result is then put into the array of
tion allows construction of simple, efficient loops in prices using MOVE.B DO,(A1)+ instruction. Again, the
68000 assembly language. MOVE.B instruction uses the autoincrement address-
The RTS instruction returns control back to the ing mode (indicated by the +), which automatically
URDA MDS monitor program. We look at the RTS increments the pointer in Al to point to the next
instruction in detail in the next chapter. element in the prices array.
Using a pointer to access data items in memory is a Using a pointer to access data items in memory is a
powerful technique that you will want to use in your powerful technique that you will want to use in your
programs. Figure 4-20d shows another example. Here programs. The 68000 has several address registers
we want to add a profit of 15¢ to each element of an that can be used as pointers to data in memory.
; alr 10-88
jooccecc oo COC® BOOQMOM Ceram eae es = ama tae
ORG $4000 start code here
MOVEA™ ESP Ra Cas)Al iota eis ChmA acme ReneE Senaliarialy asOOnishie
el
MOVEA.L COST,A2 het alee ent Zuealsmc OlSiliera latina ys DIOL MiG.e tr
MOVE.W #$0008,D1 IPLELOILAS COMM Gar
MOVES Bilt PRiOisl
ete WZ G ALE MPO Tracer
DIOMENE Xolis
MOVE.B (A2)+,D@ s COPY & Coss eo WY ame
i increment A2 to point to next cost
ABCD bD2,D9 2 Bale weParilc reascor
TOMAR18} TO TCEyer 5 COOy PeSUle Meek CO PRINCES array ame
‘i increment Al to point to the next price
DBGE Dd DIOmNIESXal See LoeenlOt wvas te adonade tame xt
; data follows:
2 cnencbenaisimem
asa: GENES) SECIS Ce aa eae es
ORG $4109 ; start data here
CO Sali DiGeats B20), ABs Saale, SAG. Sl. Sees SSS, ses
One les (Sats 8
END
Figure 4-22, p. 102, summarizes all the ways you can modes involve an address register, an index register (a
tell the 68000 to calculate an effective address and a data or address register), and a displacement encoded
physical address for accessing data in memory. In all directly in the instruction.
cases the effective address is generated as a 32-bit The instruction MOVE.B #100(A0,D1),DO is an ex-
value, which is generated by combining zero, one, or ample of this last, complex addressing mode. Here the
two registers with a displacement or possibly an abso- instruction source uses address register indirect with
lute address held in the instruction stream itself. index addressing. This mode always uses an 8-bit
Typically, address registers are used to hold pointers. displacement (which can be 0). Figure 4-23, p. 103,
These pointers may have an offset added to them in the shows an example of why you might want this type of
form of a displacement in the instruction or as a value complex addressing. Here we have an array of records,
held in a data register. each holding the information about one patient for a
The simplest addressing mode is still absolute ad- hospital. Each record in the array contains the name,
dressing, where the instruction contains the absolute address, and other important information. Let us as-
address itself. The fastest is normally the address sume that here each record is 120 ($78) bytes long and
register indirect mode(s), where the desired address is consists of 6 strings, each 20 bytes long. Let’s assume
held in a CPU address register. The most complex that the array starts at location $4100 in memory. The
$41F0 RECORD 2
where n is the number of times we want to do the instruction. The 68000 also has a Bec instruction, as
sequence of actions. In assembly language you will we have seen, to construct branches independent of a
usually implement this by loading n into a register and decrementing counter. Figure 4-24, p. 104, also shows
counting it down, as shown in Figure 4-20c. that the 68000 has an Scc instruction which sets or
The common need to repeat a sequence of actions a clears an operand depending on a particular condition
specified number of times also led the designers of the code. We could have used Scc for the first example
68000 to give it a group of instructions that make this problem in this chapter.
easier for you. These instructions are the LOOP in- The decrement and conditional branch instructions
structions, which we discuss in the next section. are useful for implementing the REPEAT-UNTIL struc-
ture for those special cases where we want to perform a
68000 Loop Instruction Operation series of actions a fixed number of times or until the
zero flag changes state. These instructions incorporate
As the last example demonstrated, efficient 68000 two operations in each instruction; therefore, they are
loops can be constructed using the decrement and somewhat more efficient than using single instruc-
branch conditionally instructions, forms of the DBcc tions to do the same job. In the next section we
CONDITIONAL
introduce you to instruction timing and show how the for a desired amount of delay. The NOP instructions
DBGE instruction can be used to produce a delay next in the program are not required. The KILL_TIME
between the execution of instructions. label could be right in front of the LOOP instruction. In
this case, only the LOOP instruction would be repeat-
INSTRUCTION TIMING AND DELAY LOOPS ed. We put the NOPs in to show you how you can get
The rate at which 68000 instructions are executed is more delay by extending the time it takes to execute the
determined by a crystal-controlled clock with a fre- loop. The DBGE DO, KILL—TIME instruction will dec-
quency of a few megahertz. Each instruction takes a rement DO and, if DO is not down to zero yet, do a jump
certain number of clock cycles to execute. The to the label KILL_TIME. The program then will exe-
MOVE.B immediate-data, data-register instruction, for cute the two NOP instructions and the DBGE instruc-
example, requires 8 clock cycles to execute, and the tion over and over until DO is counted down to zero.
NOP instruction requires 4 clock cycles. The BNZ The number in DO will determine how long this takes.
instruction requires 10 clock cycles if it does the jump Here’s how you determine the value to put in DO fora
and only 8 clock cycles if it doesn’t do the jump. A set of given amount of delay.
tables in Appendix A shows the number of clock cycles First, you calculate the number of clock cycles need-
required by each instruction. This table shows, for ed to produce the desired delay. If you are running your
example, that the NOP instruction takes 4 cycles, 68000 with a 3.579-MHz clock, then the time for each
indicated by 4(1/0). The (1/0) indicates that one memo- clock cycle is 1/3.579 MHz, or 0.28 ws. Now, suppose
ry read and no memory writes are required. The NOP that you want to create a delay of 1 ms, or 1000 us,
instruction requires only one memory read to access with a delay loop. If you divide the 1000 us desired by
the instruction code word itself. If we were running the 0.28 us per clock cycle, you get the number of clock
with slow memory that required more than 4 cycles to cycles required to produce the desired delay. For this
perform a read, then the (1/0) would tell us how much example, then, you need a total of 3571 (1000/0.28)
extra time would be required. We can ignore the (1/0) clock cycles to produce the desired delay.
for now, since the URDA MDS memory runs without The next step is to write the number of clock cycles
requiring more than 4 cycles per read. The CPU does
not require wait cycles to wait for the memory to catch
up. Using the numbers in this table, you can calculate
how long it takes to execute an instruction or series of
instructions. For example, if we are running a 68000 MOVE.W #N,DO 8 =cCc
with a 3.579-MHz clock, then each clock cycle takes (¢)
KILL_TIME: NOP 4
1/3.579 MHz, or 0.28 ys. An instruction that takes 4 NOP 4
clock cycles then will take 4 clock cycles x 0.28 DBGE DO,KILL_TIME 10
{14
=18 =€
L
LOOP: ; REPEAT
MOVE.B (AO)+, (Al) + ; COPY BYTE FROM SOURCE TO DESTINATION
; INCREMENT SOURCE POINTER, AO
; INCREMENT DESTINATION POINTER, Al
DBGT DO, LOOP ; DECREMENT COUNTER
; UNTIL DO = 0
END
FIGURE 4-26 (continued)
When we start thinking about how we can implement mented all the pseudocode somewhere in your assem-
bly language program.
this algorithm in assembly language, several points
come to mind. We need a pointer to the source string to Figure 4-26c shows the program instructions to
keep track of which string element we are moving ata move the string of bytes. The first three instructions in
given time. This is the same reason we needed a the program initialize the two string pointer registers,
pointer in the price-fixing program in Figure 4-20c. We here AO and Al, and the counter register, here DO. DO
use an address register—for example, AO—for this will function as a counter to keep track of how many
pointer. AO will hold the address of the byte that we are string bytes have been moved at any given time. In this
moving at a given time. We also need a pointer to the case the two LEA instructions operate the same as
location to which we are moving string elements. would two MOVEA instructions, loading effective ad-
Again, any other address register, such as Al, will dresses into AO and Al. The MOVEA instruction is
suffice. Here the register Al is used to hold the address somewhat more flexible and the LEA instruction is
somewhat faster in execution. The instruction
of the location to which a byte is being moved at a given
(AO)+,(Al)+ actually moves 1 byte from
time. Another need is for a counter to keep track of how MOVE.B
many string bytes have been moved so we can deter- where AO is pointing to where Al is pointing and
mine when we have moved all the string. We use the increments both AO and A1 to point to the next byte in
register DO as a counter for this string operation the source string and destination data area. The DBGT
example. Having these pieces in mind, we can expand DO,LOOP instruction decrements the counter, DO, and
the pseudocode for the problem, as shown in Figure tests it to see if all the bytes have been moved. The
4-26b, p. 105. We often describe an algorithm in branch back to move another byte will be taken if
general terms at first and then expand sections as the counter is still greater than 0. Here we are moving
needed to help us see how the algorithm is implement- the string 1 byte at a time. If we know that the string
ed in a specific language. In the expanded version in is of even length, then it would be faster to move the
Figure 4-26b you can see that we need to initialize the string 1 word (2 bytes) at a time using the MOVE.W
two pointers and the counter. The REPEAT-UNTIL loop (AO)+, (A1)+ instruction. In this case we must remem-
consists of moving a byte while incrementing the ber that the count in DO is now a word count, not a byte
pointers to point to the source and destination for the count.
next byte and then decrementing the counter and
branching, depending on whether all the bytes have STRING BYTE TO CHECK
USING THE COMPARE
been moved. As you examine the code in Figure 4-26c,
A PASSWORD
notice that the pseudocode of Figure 4-26b actually
For this program example suppose that we want to
appears word for word as comments in the assembly
compare a password entered by a person who wants to
language program. This good technique links your
use the computer with the correct password stored in
assembly language code to your most detailed
memory. If the passwords do not match, we want to
pseudocode and helps ensure that you have imple-
; aly —s9
ORG $4000 ; start code at $4000
REPEAT: ; REPEAT
MOVE.B (A0O)+,D0 ; GET SOURCE BYTE & INCREMENT SOURCE POINTER
MOVE.B (Al1)+,D1 H GET DEST. BYTE and INCREMENT DEST. POINTER
CMP.B DOFDI ; COMPARE SOURCE BYTE WITH DESTINATION BYTE
BNE SOUND_ALARM ; if characters do not match, go sound alarm
DBGT D2 ,REPEAT ; DECREMENT COUNTER
; UNTIL (STRING BYTES NOT EQUAL) OR (DO = 0)
JMP OK ; the two strings are equal, jump to
; next mainline instruction
SOUND_ALARM:
BEQ OK ; IF STRING BYTES NOT EQUAL THEN
MOVE.B_ #1, ($C011) ; SOUND ALARM
STOP #99 ; STOP and leave 3 in the SR
; data follows:
ORG $4200 ; start data at $4200
END
load these locations with ASCII codes read from the The CMP.B instruction will compare the bytes just
keyboard. accessed and set the condition codes accordingly. If the
Now let’s look at the code segment section of the 2 bytes are not equal, then the BNE instruction will
program. The first three statements initialize the port branch to the SOUND—ALARM code; otherwise the
at $C014 as an output port. The next three instruc- BNE will have no effect. The DBGT instruction is
tions initialize the string pointers AO and A1, and the executed if we ‘‘fall through’’ the BNE instruction—
counter DO, just as in the last example. that is, if the 2 bytes are equal. The DBGT instruction
The next two instructions get 1 byte from each of the decrements the string counter. If there are more bytes
strings to be compared, the source string ‘FAILSAFE’ to compare (the counter is still greater than 0), then the
and the user’s input string. The two instructions also DBGT branches back to the REPEAT label and another
increment the string pointers AO and A1 to point to the pair of string bytes is compared. If the counter has
next bytes in the two strings. counted down to zero, then we know that the two
: 0000 42E0 H Be) ot 0000 24B3 H a 68000 system available, enter and assemble
iat
H
moe peiaaas
0000 4300 1 pe
ee0000 0009
eee i
your source program; then load the object
~~ = --n00002-24400
nn === D3!
[-----<2--=------
0200 0010
code for the program into memory so you can
run and test it. If the program does not work
oe Raa ees i eames 1 has eet iehs: F- Tae RCLE i
1 0000 4500 1 D4 | FFFO CDOO ! correctly, use the approach described in the
PS = eS Sa ee 1 SS SS Seeee 1
last section of this chapter to help you debug
! 0000 4600 ' Dome 4200 0000 -
---------------- 1 f---------------- 1 it.
H 0000 4700 ; pe | 0000 4300 ,
t----------—-~-—--~-~— i] t----------------~ '
Convert a packed BCD byte to two ASCII charac-
A7 H 0000 4800 i OT 0012 FFEO
(pete a al Soe, ct Bae RS |1 [
(ess A i AS aeSe 1 ters for the two BCD digits in the byte. For exam-
ple, given a BCD byte containing $57 (01010111
FIGURE 4-29 Figure for Chapter 4 problems. binary), produce the two ASCII codes $35 and
$37.
MOVE.B DO,(A3)+ Compute the average of 4 bytes stored in an array
DBGT D1,NEXT in memory.
h. MOVE.L #12C2,DO
COUNT—DOWN: DBGT DO,COUNT—~DOWN Compute the average of any number of bytes in an
i. MOVE.L #40,D2 length of STRING_1 array in memory. The number of bytes to be added
MVSTR: MOVE.L (A4)+,(A5)+ ;move four bytes is in the first byte of the array.
DBGT D2,MVSTR Add a 5-byte number in one array to a 5-byte
number in another array. Put the sum in another
Construct the binary codes for the instructions of array. Put the state of the carry flag in byte 6 of
problems 1(a)-—(f). the array that contains the sum. The first value in
each array is the LSB of that number.
Predict the state of the five 68000 condition code
flags (bits) after each of the following instructions 10. A 68000-based process-control system outputs a
or group of instructions executes. Use the register measured Fahrenheit temperature to a display on
contents shown in Figure 4-29. Assume all flags its front panel. You need to write a short program
are reset to O before the instructions execute. Use that converts the Fahrenheit temperature to Cel-
the detailed instruction descriptions in Chapter 6 sius so that the system can be sold in Europe. The
to help you. relationship between Fahrenheit and Celsius is C
a. MOVE.L DO,D3 b. AND.W D2,D3 = oF — 32). The Fahrenheit temperature will
c. ADD.L #-2,D0 d. OR.B D6,D7 always be in the range of 50° to 250°. Round the
Celsius value to the nearest degree.
See if you can find any errors in the following
instructions or groups of instructions. 11. An ASCII keyboard outputs parallel ASCII + pari-
a. CNTDOWN:
MOVE.B #-3,D0 ty to port $CO15 of an URDA board. The keyboard
DBEQ DO,CNTDOWN also outputs a strobe to the LSB (bit 0) of port
ADD.B #03402110,D0 $CO13 (see Figure 4-18). When you press a key,
JMP (DO) the keyboard outputs the ASCII code for the
ADDI.L DO,D2 pressed key on the 8 parallel lines and outputs a
S
eno
DIVS A2,DO strobe pulse high for 1 ms. You want to poll the
8 strobe over and over until you find it high. Then
Write an algorithm for a program that adds a
you want to read in the ASCII code, mask the
byte number from one memory location to a
parity bit (bit 7), and store the ASCII code in an
byte from the next memory location, puts the
array in memory. Next you want to poll the strobe
sum in a third memory location, and saves the
over and over again until you find it low. When you
state of the carry flag in the least significant
find the strobe has gone low, check to see if you
bit of a fourth memory location. Mask the
have read in ten characters yet. If not, then go
upper 7 bits of the memory location where the
carry is stored.
back and wait for the strobe to go high again. If 10
characters have been read in, stop.
b. Write a 68000 assembly language program
for this algorithm. (Hint: Use a rotate instruc- 12; a. Write a delay loop that produces a delay of
tion to get the carry flag state into the LSB of a 500 us on a 68000 with a 4.77-MHz clock.
register or memory location.) b. Write a short program that outputs a 1-kHz
c. What additional instructions would you have square wave on bit 0 of port $CO15. The basic
to add to this program so that it correctly adds principle here is to output a high, wait 500 us
2 BCD bytes? (0.5 ms), output a low, wait 500 us, output a
ASCII
$00
: }ERROR
$2F
$30
: }HEX 0-9
$39
$3A
: \ERROR
$40
$41)
: }HEX A-F
$46
ERROR
The last chapter showed you how quite a few of the each time we want it to execute in the program. To be
68000 instructions work and how jump instructions consistent with the Motorola literature, we use the
are used to implement IF-THEN-ELSE, WHILE-DO, term subroutine when referring to called subpro-
and REPEAT-UNTIL structures. The major point of grams. A subroutine is called using a jump to subrou-
this chapter, however, is to show you how to write and tine code and using a special type of jump that leaves a
use subroutines (sometimes called procedures or sub- return address and can be returned from. The transfer
programs). A final section of the chapter shows you of control to the subroutine is accomplished using a
how to write and use assembler MACROs. JSR (jump to subroutine) instruction, and the return
from the subroutine to the mainline program is accom-
plished using an RTS (return from subroutine) instruc-
tion.
OBJECTIVES
There is another major reason for using subroutines
At the conclusion of this chapter, you should be able to in programs. Recall from Chapter 2 the top-down-
design approach to solving a programming problem. In
1. Write a 68000 assembly language program that this approach the problem is carefully defined and
calls a subroutine. then the overall job is broken down into modules. Each
of these modules is broken down into smaller modules.
2. Describe how a stack is initialized and used in
The process is continued until the algorithm for each
68000 assembly language programs that call sub-
module is clearly obvious. Figure 5-1, p. 114, shows
routines.
how this hierarchy of modules can be represented in
3. Write and use an assembler MACRO. diagram form. A diagram such as this is often called a
hierarchy chart. The point of all this is to break a large
In many programs where we want to choose between problem down into manageable-sized pieces that can
two or more alternative series of actions, each of the be individually written, tested, and debugged. The
series of actions is quite lengthy. In many programs we individual modules are usually written as subroutines
want to perform some series of operations at several and called from a mainline program, which imple-
points in an algorithm. In these cases we write each ments the highest level of the hierarchy. An added
series of actions as a subroutine and call this subpro- advantage of this approach is that a person can read
gram when it is needed. The next major section of this the mainline program to get an overview of what the
chapter shows you how to write and use subroutines. program does and then work his or her way down into
Subroutines and coroutines are types of procedures; the subroutines to see the amount of detail needed at a
we will not discuss coroutines in this text, but the particular point. Now that you know what subroutines
reader is encouraged to investigate them once subrou- are used for, we will give you an overview of how they
tines are well understood. work.
Figure 5-2a, p. 114, shows in diagram form how
program execution goes from the mainline to a subrou-
tine and back to the mainline. A JSR instruction in the
WRITING AND USING SUBROUTINES mainline loads the program counter with the starting
Introduction address of the subroutine. The next instruction
fetched, then, is the first instruction of the subroutine.
Whenever we have a series of instructions that we At the end of the subroutine a return instruction, RTS,
want to execute several times in a program, we write sends execution back to the next instruction after the
the series of instructions as a separate subprogram. JSR in the mainline program. The RTS instruction
We can then call this subprogram each time we want to does this by loading the program counter with the
execute that series of instructions. This saves us from address of the next instruction after the RTS instruc-
having to write the series of instructions over and over tion. As shown in Figure 5-2b, p. 114, a subroutine can
113
UPDATE
Mat INVENTORY
PRINT PRINT
PR ee DEPARTMENT PARTS TO
LEVEL 2 INVENTORIES ORDER LIST
call another subroutine. This is called nesting subrou- able code because it uses displacements rather than
tines. Nested subroutines are used to implement the absolute addresses. The RTS instruction can be used
hierarchy of modules we described in the preceding to return from both BSR and JSR subroutine calls.
paragraph. In the case of nested subroutines, an RTS
instruction at the end of the lower level subroutine THE JSR INSTRUCTION
returns execution to the higher-level subroutine. A The 68000 JSR instruction performs two operations
second RTS instruction at the end of the higher-level when it executes. First, it stores the address of the
subroutine returns execution to the mainline program. instruction after the JSR instruction on the stack.
The question that may occur to you at this point is, If This address is called the return address because it is
a subroutine can be called from anywhere in a pro- the address to which execution will return after the
gram, how does the RTS instruction know where to subroutine executes.
return execution? The answer to this question is that The second operation of the JSR instruction is to
when a JSR instruction executes, it automatically change the contents of the program counter to contain
stores the return address in a special section of memo- the starting address of the subroutine. Figure 5-3, pp.
ry called the stack. A later section introduces you to 115-16, shows the coding formats for the 68000 JSR,
how 68000 stacks work. For now let’s take a closer BSR, and RTS instructions. The difference between
look at the 68000 JSR, RTS, and BSR instructions. the two subroutine calls is in the way they tell the
68000 to get the starting address for the subroutine.
The JSR instruction gets the starting address of the
The 68000 JSR, BSR, and RTS Instructions subroutine from the 32 bits following the instruction.
Jump to subroutine (JSR) and branch to subroutine
This is the 32-bit absolute address of the subroutine
(BSR) are the two forms of subroutine call instructions
and will be loaded into the program counter directly.
provided by the 68000. The BSR instruction can be
used only when the called subroutine is within the 64K
THE BSR INSTRUCTION
region of memory around the BSR instruction. This is The second form of subroutine call is branch to in-
because the BSR instruction uses an 8-bit or 16-bit struction (BSR). This form of subroutine call gets the
displacement. The JSR instruction uses an absolute starting address of the subroutine by adding the dis-
32-bit address. BSR can be used to construct relocat- placement in the last 8 bits of the instruction or from
MAINLINE OR MAINLINE
CALLING PROGRAM INSTRUCTIONS
(a)
FIGURE 5-2 Program flow to and from subroutines. (a) Single subroutines.
(b) Nested subroutines.
Assembler
Syntax: JSR (ea)
Attributes: Unsized
Condition Codes:
Not affected.
Instruction Format:
15 14 13 12 1 10 9 7 6 8) 4 3 2 1 0
EFFECTIVE ADDRESS
REGISTER
Instruction Fields:
Effective Address field — Specifies the address of the next instruction. Only
control addressing modes are allowed as shown:
rarensing
Mode|Mode|Rogier |
ace
ages ae Pa
es elen fre
ee ea,
(dg,An,Xn) reg. number:An
Assembler
Syntax: BSR (label)
Description: Pushes the long word address of the instruction immediately fol-
lowl ng the BSR instruction onto the system stack. The PC contains the address
of the instruction word plus two. Program execution then continues at location
(PC) + displacement. The displacement is a twos complement integer that
represents the relative distance in bytes from the current PC to the destination
PC. If the 8-bit displacement field in the instruction word is zero, a 16-bit dis-
placement (the word immediately following the instruction) is used. If the 8-
bit displacement field in the instruction word is all ones ($FF), the 32-bit dis-
placement (long word immediately following the instruction) is used.
Conditio n Codes:
Not affected.
Instruction Format:
15 14 13 12 1 10 ‘] 8 7 6 5 4 3 2 1 0
Instruction Fields:
8-Bit Displacement field — Twos complement integer specifying the number
of bytes between the branch instruction and the next instruction to be exe-
cuted.
16-Bit Displacement field — Used for a larger displacement when the 8-bit
di splacement is equal to $00.
32-Bit Displacement field — Used for a larger displacement when the 8-bit
di splacement is equal to $FF.
NOTE
A branch to the immediately following instruction automatically uses
the 16-bit displacement format because the 8-bit displacement field
(b) contains $00 (zero offset).
Attributes: Unsized
Description: Pulls the program counter value from the stack. The previous pro-
gram counter value is lost.
Condition Codes:
Not affected.
Instruction Format:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MASK UPPER
4 BITS
INITIALIZE POINTER TO ARRAY, A®O
INITIALIZE COUNTER, DO
REPEAT
READ PORT
MASK UPPER 4 BITS
PUT IN ARRAY, A®@
INCREMENT POINTER, AQ
CALL WAIT_1MS SUBROUTINE
WAIT 1 MS DECREMENT COUNTER, DO
UNTIL COUNTER = @
WAIT_1MS SUBROUTINE
LOAD COUNT VALUE
100 REPEAT
SAMPLES DECREMENT COUNT VALUE
? UNTIL COUNT = @
YES (c)
; alr 10-88
PRESSURE_PORT EQU $c@1l1 : PRESSURE_PORT is the symbolic name for
the address of the pressure port
; Mainline code
LEA STACK_TOP,A7 ; initialize user stack pointer to stack top
LEA PRESSURES, AQ ; initialize pressure reading array pointer
LEA PRESSURE_PORT,A2
MOVE.B #100,D1 ; initialize sample loop counter
NEXT_VALUE:
MOVE.W (A2),D@ read the pressure port
ANDI.W #SQOFFF,D® mask off upper 4 bits
MOVE.W D@, (AQ)+ store data word in array and increment
array pointer to point to next word
JSR WAIT_1MS delay of 1 ms
DBGT D1,NEXT_VALUE decrement counter and repeat if greater
than Q :
RTS return to whoever called me
; Procedure to wait 1 ms
WAIT_1MS:
MOVE.W #S$23F2,D2 ; load delay count
HERE:
DBGT D2,HERE ; decrement count until <= @
RTS ; return to whoever called -me
END
memory and label the address of the first word with the what values are initially in these locations, because the
name PRESSURES. In some cases we may also want to program is going to write values in them. However,
initialize all these 100 words to Os. In such cases we with later examples we may want to initialize arrays
could use a DC.W declaration. It really doesn’t matter such as this to all Os so that during debugging we can
i}
|
!
AFTER Push D2 —}—> BEFORE Pops
i
1
:
MULTO:
SUBROUTINE MULTO
!
MOVE.L D@,-(A7) ; push DO AFTER Push D1. —>—= |
AFTER Pop D2
MOVE.L D1,-(A7) ; push D1 i}
!
A 7SnmaS> (5) Bs
(a)
FIGURE 5-9 Using push and pop operations. (a) Instruction sequence.
(b) Effect on stack and stack pointer.
4596 = $11F4
FIGURE 5-10 BCD-to-HEX or BCD-to-binary algorithm.
REGISTERS USED: D@
PORTS USED : none
PROCEDURES : BCD_HEX
alr 1-89
RTS
END
; alr 1-89
RTS
7 — ee oe we oe oe oe em oe em oe oe oe oe om om oe om om om oe oe oe oe
i alr 1-89
RTS
we assume that previous instructions in the mainline have left the BCD number in DO. In the mainline
set up a stack segment, initialized the stack segment fragment in Figure 5-13a, we copy DO to the stack with
register, and initialized the stack pointer. We also the MOVE.W DO,-(A7) instruction. Here we are push-
assume that previous instructions in the mainline ing a full word to keep the stack aligned on even-word
fouls incest)
Se
se
“=e
Ne
Me
te
se
RTS
alr 7-88
ORG $4000 ; start the code at memory address $4000
In this case FACTO was called from a previous To see where we are returning, take another look at
execution of FACTO, so the return will be to the Figure 5-17b. We are returning with 2! in the stack, so
MOVE.L (A7)+,D0 instruction after JSR FACTO. This we still need one more computation to produce the
instruction copies the last computed (N — 1)! from the desired 3!. Therefore, the return is again to the
stack to DO so that we can multiply it by N. Restricting MOVE.L (A7)+,DO instruction after JSR in FACTO.
the allowed range of N for this example means that we The instructions after this will multiply 2! times 3 to
have to do only a 16-bit by 16-bit multiply. Since N is produce the desired 3! and copy 3! to the stack, as
presumed to be 9 or less, we know a 16-bit by 16-bit described in the preceding paragraph. Since we have
multiply will not overflow. We could increase the done all the required computations, this time the
allowed range of N by simply setting aside larger spaces return will be to the mainline program. The desired
in the stack for factorials and including instructions to result, 3!, will be in the memory location we reserved
multiply larger numbers. In this example the MULU for it in the stack, overwriting the original value of N
D1,D0 instruction multiplies the (N — 1)! in DO by the passed into FACTO on the JSR from the main program.
previous N from the stack. The 32-bit product is left in We can access this result with a normal pop addressing
DO. Execution then flows into the MOVE.L DO,#20(A7) mode (address register indirect with postincrement)
instruction, which copies this product to the stack when we need the value in the mainline.
locations where the incoming N (2 in this case) used to If you can work your way through the flow of the
be. Now take a look at the stack diagram in Figure stack and the stack pointer in this example program,
5-17b to see where this value gets put and where the you should have a good understanding of how the stack
stack pointer is at this time. The next operation we do is used.
in the subroutine is pop the registers and return.
Use (Seu
; Upon return from the subroutine the carry condition code will be set
; if some problem occurred during the division. In this case, go and
Stops thesCPUr If the division went OK (CC cleared) then get the
; parameters from the registers (the quotient and remainder) and place
; them into memory in the designated locations. The user can check these
; memory locations to see what the result of the division was.
SAVE_ALL:
MOVE.L DQ, (QUOTIENT ) save the quotient in memory
MOVE.L Di, (REMAINDER) save the remainder in memory
RTS return to the monitor program
This im the ‘normal’ program flow
back to the whoever called this main
we program.
(a)
FIGURE 5-19 Assembly language program to divide a 32-bit number by a
16-bit number and return a.32-bit quotient. (a) Mainline program module.
(b) Subroutine module.
der, which we move to D1 with a MOVE.L DO,D1 merge the upper 16 bits of the final quotient back with
instruction. We then shift this remainder right into the the lower 16 bits using an OR.L D3,D0 instruction,
lower 16 bits, creating the final remainder value to be leaving the result in DO to be passed back to the
passed back to the mainline program in D1. After the mainline program. We know the carry flag is clear
first DIVU operation, we saved the high word of our because the OR instruction always clears the carry
32-bit quotient in D3. We now use two shift-left in- flag.
structions to move this into the upper 16 bits of D3 and Back in the mainline we check the carry flag with
shift Os into the lower 16 bits. We mask off the the BCS instruction. If the carry flag is set, we know
remainder (upper 16 bits) in register DO. We then that the divisor was 0, no division was done, and there
subroutine: SMART_DIVIDE
; incoming parameters: D@ - dividend; D1 - divisor
; returning parameters: D@ - quotient; D1 - remainder
; cc - set if division failed
SMART_DIVIDE:
;Save registers
MOVE.L D2,-(A7) ; Save registers D2 and D3
MOVE.L D3,-(A7)
ERROR_EXIT:
MOVE.B #S01,CCR ; set the carry flag and clear the rest
EXIT: MOVE.L (A7)+,D3 ; restore registers D3 and D2
MOVE.L (A7)+,D2
RTS ; return to whoever called me
(b)
FIGURE 5-19 (continued)
is no result to put in memory. If the carry flag is not set, tines as stubs. If the structure of the mainline seems
then we know that a valid 32-bit quotient was returned reasonable, we then develop each subroutine and re-
in DO and a 16-bit remainder was returned in D1. place the dummy with it. The advantage of this ap-
Finally, we copy this quotient and this remainder to proach is that you have a structure on which to hang
some named memory locations we set aside for them. the subroutines. If you write the subroutines first, you
have the problem of trying to write a mainline to
connect all the pieces together. This can get messy.
Writing and Debugging Programs Containing
Now, suppose that you have approached a program
Subroutines
as we suggested, and the program doesn’t work. Proba-
The most important point in writing a program con- bly the best tools to help you localize a problem to a
taining subroutines is to approach the overall job very small area are breakpoints. Run the program to a
systematically. We carefully work out the overall struc- breakpoint just before a JSR instruction to see if the
ture of the program and break it down into modules correct parameters are being passed to the subroutine.
that can easily be written as subroutines. We then Put a breakpoint at the start of the subroutine to see if
write the mainline program so that we know what each execution ever gets to the subroutine. Move the
subroutine has to do and how parameters can be most breakpoint to a later point in the subroutine to deter-
easily passed to each subroutine. To test this mainline mine if the subroutine found the parameters passed
we simulate each subroutine with a few instructions from the mainline. Use a breakpoint just before the
that simply pass test values back to the mainline. RTS instruction to see if the subroutine produced the
Some programmers refer to these ‘‘dummy’’ subrou- correct results and put these results in the correct
a. Usea stack map to show the effect of each of b. Write a mainline program that uses this sub-
the following instructions on the stack point- routine to output a square wave on bit 0 ofa
er and on the contents of the stack. port at SCO15.
Write a subroutine that converts a 4-digit BCD
MOVEA.L 843FC, A7 number passed in DO to its binary equivalent. Use
MOVE.L D0O,-(A7) the algorithm in Figure 5-10. ;
JSR MULTO
MOVE.L_ (A7)+,DO The 68000 MULU instruction allows you to multi-
MULTO: ply a 16-bit number by a 16-bit binary number to
MOVE.L AO,-(A7) give a 32-bit result. In some cases, however, you
MOVE.LA1,-{A7) may need to multiply a 32-bit number by a 32-bit
number to give a 64-bit result. With the MULU
instruction and a little adding, you can easily do
this. Figure 5-20 shows in diagram form how to do
MOVE.L_ (A7)+,Al it. Each letter in the diagram represents a 16-bit
MOVE.L (A7)+,A0 number. The principle is to use MULU to form
RTS partial products and add these partial products
together as shown. Write an algorithm for this
b. What effect would it have on the execution multiplication and then write the 68000 assem-
of this program if the MOVE.L (A7)+,A0 bly language program for the algorithm.
instruction in the subroutine was
accidentally left out? Describe the steps you
would take in tracking down this problem if
you did not notice it in the program listing.
Zee Xe SZ. Bis
DECREMENT N
UNTIL N = O
This chapter consists of two major sections. The first ADDRESSING TERMINOLOGY
section is a dictionary of all of the 68000/68008/
68010 instructions. For each instruction we give a The 68000 family provides 14 different addressing
detailed description of its operation, the correct syntax modes. Of these, the implicit modes (usually referring
for the instruction, the condition codes affected by the to the status register, SR, or to the condition code
instruction, and the allowable addressing modes for register, CCR) are usually distinguished and described
each of the instruction’s operands. Also, numerical individually when they occur. As shown in Figure 3-8,
examples are shown for those instructions where ap- 12 addressing modes occur normally in many of the
propriate. The binary coding templates for the instruc- following instructions. These will commonly be called
tions are shown alphabetically in a table in Appendix all the addressing modes (or “‘any addressing mode is
B. Putting the codes together in a table makes it easier allowed’’). In the descriptions that follow, several other
to find codes if you are hand coding a program. terms will be used as shorthand for certain subsets of
The second major section of this chapter is a dictio- the addressing modes. In particular, there are four
nary of commonly used 68000 assembler directives. terms that can be combined to refer to subsets of the
The directives described here are a common subset of addressing modes. These terms are data, memory,
those defined by the Raven® cross assembler, which alterable, and control. The term data refers to modes
runs on the IBM PC, and those defined by the Consul- that can be used to name data operands. Address
air Corporation 68000 assembler, which runs on an register direct, for example, is not a data-addressing
Apple Macintosh®. If you are using some other assem- mode because it refers to an address register, not a
bler, it probably has similar capabilities, but the data register. The term memory refers to addressing
names may be different. modes that can address memory. Therefore, data regis-
You will probably use this chapter mostly as a refer- ter direct and address register direct are not memory-
ence to get the details of an instruction or directive as addressing modes. The term alterable refers to ad-
you write programs of your own or decipher someone dressing modes that address something that can be
else’s programs. However, you should skim through altered, or modified. So, for example, immediate data is
the chapter at least once to get an overview of ‘the not alterable, and immediate addressing is not an
material contained here. You should not try to absorb alterable addressing mode. Finally, the term control is
all the chapter at once. Most of the instructions de- used to refer to addressing modes that do not require a
scribed here are used and discussed in various exam- size to be associated with them. For example, address
ple programs throughout the book. register indirect, as used with the jump to subroutine
instruction, does not require a size to be associated
with it because it specifies an address to jump to rather
than a size of data to move. Thus address register
OBJECTIVES indirect can be a control addressing mode. Address
register indirect with postincrement does require a size
At the conclusion of this chapter, you should be able to because the instruction must know whether to incre-
ment by 1 (for a byte), by 2 (for a word), or by 4 (for a
1. Summarize the addressing modes available on the long). Hence, address register indirect with postincre-
Motorola 68000 CPU. ment is not a control addressing mode.
2. Describe the instruction set of the 68000.
These four terms are often combined in pairs to yield
common subsets of the 12 allowable addressing
3. Describe the assembler directives available for a modes. The usages that occur in the following descrip-
typical symbolic assembler program. tions are explained in a little more detail as they occur.
144
Data-alterable addressing modes refer to those BCD arithmetic. The extend bit is used during the
modes containing data that can be altered (immediate addition to allow carries into this addition from a
data, for example, cannot be altered). The data altera- lower-digit addition carry and to send a carry from this
ble addressing modes include data register direct (Dn), byte addition to the next-higher digit. The operation is
address register indirect ((An)), address register indi- a byte operation only. Both the source operand and the
rect with predecrement (—(An)), address register indi- destination operand must be data registers, or they
rect with postincrement ((An)+), address register indi- must both be memory locations accessed using the
rect with displacement ((d,,,An)), address register address register indirect with predecrement address-
indirect with index ((d,,An,Xn)), absolute word ing mode.
((xxx).W), and absolute long ((xxx).L). Another way to Following the operation, the carry bit is set if a
think of it is that data alterable addressing includes decimal carry was generated and is cleared if there was
any addressing mode except address register direct, no carry. The extend bit is set equal to the carry bit.
immediate, and PC relative modes. The zero bit is cleared if the result is nonzero and is
' Data-addressing modes include all 12 addressing unchanged otherwise. The zero bit is normally cleared
modes except address register direct. That is, data- via programming before a series of BCD additions (a
addressing modes include 11 of the 12 modes, with ad- multiple-precision operation) and tested once following
dress register direct being the one mode not included. all the additions. This allows convenient testing after
Control addressing modes include any of the 12 decimal additions of BCD values represented as several
modes except data register direct, address register BCD digits.
direct, postincrement, predecrement, and immediate
addressing modes. Thinking of this in the positive
sense, control addressing modes include address regis- EXAMPLES
ter indirect, address register indirect with displace-
ment, address register indirect with index, absolute ABCD DO,D1 ; Add the two BCD digits in DO
word, absolute long, program counter relative with ; to the two BCD digits in
displacement, and program counter relative with in- ; D1 and place the result
dex. The control modes are those allowed in the jump 3 aD.
to subroutine instruction (JSR), for example. In the ABCD -(A3),—(A2) ; Add the BCD digits in
JSR these modes are used to change the flow of control ; the memory pointed
in the program. ; at by A3 to the BCD
Control alterable addressing modes are similar ; digits pointed at by
to the control addressing modes except that the PC ; A2. Decrement each
relative modes are not included. So the control altera- ; pointer before
ble addressing modes include only address register ; accessing the BCD
indirect, address register indirect with displacement, ; digits. Store the
address register indirect with index, absolute word, ; result in the memory
and absolute long. In some sense the PC relative ; location pointed at
addressing modes are not alterable, so they are not DyeAZ.
included.
Memory alterable addressing modes include all
the modes except register direct (address or data regis-
ADD Instruction—Add: ADD Source,
ter), immediate, and PC relative (with displacement or
Destination
with index). That is, memory alterable addressing
modes include all the address register indirect modes The ADD instruction adds a number from some source
(normal, postincrement, predecrement, with displace- to a number from some destination and puts the result
ment, and with index) and the absolute modes (word in the specified destination. The source may be an
and long). immediate number, a register, or a memory location,
Last but not least, the memory addressing modes as specified by any of the 12 addressing modes shown
include all the modes that can be used to refer to in Figure 3-8. The destination may be a register or a
memory, or every mode except the register direct memory location specified by any one of the alterable
modes. addressing modes in Figure 3-8. Both the source and
the destination can be data registers, but at least one
must be a data register. Thus, the source and the
destination in an instruction cannot both be memory
INSTRUCTION DESCRIPTIONS locations. The source and the destination must be of
the same type. In other words, they must both be byte
ABCD Instruction—Add Decimal with Extend:
locations, they must both be word locations, or they
ABCD Dy,Dx or ABCD —(Ax),—(Ay)
must both be long locations. If you want to add a byte to
The ABCD instruction adds the source operand to the a word, you must copy the byte to a word location and
destination operand and places the result back in the fill the upper byte of the word with zeros before adding.
destination operand. The addition is performed using Flags affected are X, N, Z, V, C.
The BCHG instruction tests a bit in the destination BRA there _ ; Branch to there always
operand and changes the bit in one indivisible opera-
tion. The value of the old bit is saved in the Z condition
BSET Instruction—Bit Test and Set: BSET
code, and the bit is inverted. If the bit is a 1, it is set to
O, and if it is a O, it is set to 1. The source specifies the
Source, Destination
bit number to test and must be either an immediate bit The BSET instruction tests a bit in the destination
count or a data register. The bit numbering is modulo operand and sets the bit (= 1) in one indivisible
32, so that bit 32 = bit 64 = bit 96 and so on. The operation. The value of the old bit is saved in the Z
destination may be specified using any data-alterable condition code, and the bit is set (set = 1). The source
addressing mode. The Z bit is set if the bit tested is 1 specifies the bit number to test and must be either an
and is cleared otherwise. The other condition codes are immediate bit count or a data register. The bit number-
not affected. ing is modulo 32, so that bit 32 = bit 64 = bit 96 and so
EXAMPLES EXAMPLES
BCHG D2,(Al)_ ; Test the bit in CHK #4(A4),DO ; Check DO (the index register)
; memory pointed at by Al ; against the array boundary
; using the bit number in D2. ; pointed at by A4 offset by 4.
BCHG #7,D3 _ ; Test bit 7 of D3. ; If the test fails, then trap
; and let handler fix things.
CHK Instruction—Check Against Bounds: MOVE.B #0(A2,D0),D2
; Get the value from array
CHK Source, Destination
; element whose index is
The CHK instruction performs an operation similar to ; in DO and base address
the compare instruction, except that the instruction ; is in register A2.
The CLR instruction clears the destination operand to CMPA.L A3,A0 ; Compare A3 to AO.
all O bits. The operation size can be byte, word, or long. CMPA.W ($4200),A2 ; Compare the word value
The destination operand can be specified by any data- ; at memory address $4200
alterable addressing mode (that is, any mode except ; to the word address in
immediate, PC relative, and address register direct). As
The Z condition code bit is always set to 1. The N, V,
and C condition code bits are always cleared to 0. The
X bit is not affected. CMPI Instruction— Compare Immediate: CMPI
Source, Destination
CMPI.B #874,DO
CMP Instruction—Compare: CMP Source,
; Compare DO to the constant $74.
Destination
CMPI.L #$12345678,(A2)+
This instruction compares a byte from the specified ; Compare the
source with a byte from the specified destination, a ; immediate long value $12345678 to the long
word from a specified source with a word from a ; value pointed at by A2 and increment A2 (by 4)
specified destination, or a long word from a specified ; after the comparison.
source to a long word in a specified destination. The
source can be an immediate number, a register, or a
memory location specified by one of the 12 addressing
CMPM Instruction—Compare Memory: CMPM
modes shown in Figure 3-8. The destination must be a Source, Destination
data register. The comparison is actually done by The CMPM form of compare is used for memory-to-
subtracting the source byte, word, or long word from memory comparisons. Normally, the assembler will
the destination using temporary internal CPU regis- automatically convert a CMP to a CMPM if necessary.
ters. The destination data register is not changed. The Both operands must be specified using the address
X condition code is not affected. The N, Z, V, and C bits register indirect with postincrement addressing mode.
are affected according to the results of the comparison See the CMP instruction.
operation. That is, C is set if a borrow is generated by
the subtraction and cleared otherwise. N is set for a
negative result and cleared otherwise, Z is set if the EXAMPLE
result is zero (that is, the two operands were equal) and
cleared otherwise, and V is set if an overflow is gener- CMPM.L (Al1)+,(A2)+ ; Compare the long value
ated and cleared otherwise. ; pointed at by Al to the
; long value pointed at
; by A2. Increment both
EXAMPLES ; registers (by 4) after
; the comparison.
CMP.B D3,DO0 ; Compare the low byte of DO to
; the low byte of D3.
CMP.L ($4200),D2 ; Compare the long contents of DBcc Instruction—Decrement and Branch
; the memory at address Conditionally: DBcc Source, Destination
; $4200 to the long value in
The DBcc instruction is one of the basic looping primi-
D2:
tives of the 68000 family. It is normally used to
implement the REPEAT-UNTIL control structure. For
example, a count is decremented until it reaches 0
CMPA Instruction—Compare Address: CMPA
using DBGT, decrement and branch if greater than.
Source, Destination
For each count a series of instructions performs some
The CMPA form of compare is used when the destina- operation, such as adding an inflation factor to a data
tion is an address register. Normally, the assembler value in an array.
will automatically convert a CMP to a CMPA if neces- The lowercase c’s in DBcc are normally replaced by
sary. The operand size must be word or long. See the one of 14 different condition tests. For example, replac-
CMP instruction. ing cc with GT yields the DBGT instruction. Thus DBcc
DIVS Instruction—Divide Signed: DIVS EOR.W DO,D3 _ ; Exclusive-OR the low word of
Source, Destination ; register DO with D3 and
; put the result back in DO.
The DIVS instruction divides the destination operand
by the source operand and places the quotient in the
lower word of the destination. It places the remainder EORI Instruction—Exclusive-OR Immediate:
in the high word of the destination operand. The EORI Source, Destination
division is performed using 2’s complement signed
binary arithmetic. The operation presumes a 32-bit Each bit of the source operand is combined with the
dividend (destination operand) and a 16-bit divisor
corresponding bit of the destination operand using the
(Source operand). The result is a 16-bit quotient anda
exclusive-OR operation and the result is placed back
16-bit remainder. The destination must be a data into the corresponding bit of the destination. The
register. The source can be specified in any data- resulting bit is a 1 only when exactly one of the two
initial bits is 1 (that is, 1 and O or O and 1). If both bits
alterable addressing mode. The condition codes are set
according to the result of the division. The X bit is not are initially O or both are initially 1, then the resulting
affected. bit is a 0. The source must be immediate data and the
If the source operand (divisor) is 0, then a CPU trap is destination must use a data-alterable addressing
generated, and control is transferred to the zero divide mode. The immediate data follows the instruction
exception service routine, whose address is stored at opcode wordin memory. If the operand size is byte or
address $014. If overflow is detected and set before the word, then 1 additional word of immediate data is
completion of the instruction, the operands are not
required. If the operand size is long, then 2 additional
modified. words are required. If the operand size is byte, then the
lower byte of the immediate data word contains the
byte of immediate data. The operands can be of size
EXAMPLE byte, word, or long. The V and C condition codes are
both cleared. The X condition code is not affected. Z is
DIVS #-311,D0_ ; Divide DO by the constant set if the result has all bits equal O and cleared
5 = Sylil. otherwise. The N condition code is set equal to the MSB
of the result.
This instruction can also be used to exclusive-OR a
DIVU Instruction—Divide Unsigned: DIVU byte of immediate data with the condition-code register
Source, Destination (EORI to CCR), thereby affecting the condition codes, or
with the status register to set the CPU status. The
DIVU performs a division using unsigned binary divi-
EORI to SR instruction is a privileged instruction. It
sion. Otherwise, the instruction operates as described
can be executed only while in the supervisor state of
in the previous DIVS discussion.
the CPU (that is, when the supervisor bit of the status
register is equal to 1). If the CPU is in user state when
EXAMPLE the EORI to SR is attempted, a CPU trap will occur.
EORI to SR is always of size word, and EORI to CCR is
DIVS #311,D0_ ; Divide DO by the constant always of size byte.
sole
EXAMPLES
EOR Instruction—Exclusive OR Logical: EOR
Source, Destination EORI.W #FFFF,SR_ ; Change all the bits of the
; Status register. That is,
Each bit of the source operand is combined with the ;ifa bitis a0,
corresponding bit of the destination operand using the ; set it to 1; ifitisa1, setit to 0.
EXAMPLES EXAMPLES
EXG DO,D3_ ; Exchange DO and D3. JMP there ; Jump to the address
EXG AO,A3_ ; Exchange AO and A3. ; represented by the label
EXG AO,D3_ ; Exchange AO and D3. eLeRe, |
JMP (A3) _ ; Jump to the location pointed
; at by register A3.
EXT Instruction—Sign-Extend a Data Register:
EXT Destination
JSR Instruction—Jump to Subroutine: JSR
The EXT instruction sign-extends a data register from Destination
a byte to a word (size word) or from a word to a long (size
long). The sign bit of the operand is copied into the The JSR instruction jumps to a subroutine. It also
upper bits of the word (or long). The V and C condition saves the program counter on the A7 stack and loads
codes are always cleared. The X condition code is not the program counter with the destination value. The
affected. The N and Z condition codes are set according destination can be specified using any control address-
to the value of the sign-extended result. ing mode ((An), d(An,Xi), Abs.W, ABS.L, d(PC), or
d(PC,Xi)). The condition codes are not affected.
This instruction uses a 32-bit destination address so
EXAMPLES
it can jump to anywhere in memory. BSR can be used
when an 8- or 16-bit displacement is acceptable.
EXT.W D4 _; Sign extend D4 from a byte
; to a word.
EXT.L D3 __ ; Sign extend D3 from a word EXAMPLES
; toa long.
JSR ADD—CORRECTION
; Call the subroutine
Illegal Instruction— Cause an Illegal ; ADD—~CORRECTION. Save
Instruction Trap: ILLEGAL ; a 32-bit return address
; on the system stack.
The ILLEGAL instruction causes an illegal instruction JSR #$1200(PC)
trap. The current program counter value (which will be ; Call the subroutine that
pointing at the instruction following the ILLEGAL ; is $1200 bytes beyond the
instruction) is pushed on the supervisor system stack. ; Current program counter—
The status register is pushed on the supervisor stack, ; i.e., add $1200 to the PC.
and the program counter is loaded with the illegal
instruction vector. The illegal instruction vector is
found at memory address $010. This type of trap will LEA Instruction—Load Effective Address: LEA
occur if any illegal instruction pattern is encountered. Source, Destination
The ILLEGAL instruction is normally used to test the
trap-handling routine. Bit patterns other than the The LEA instruction computes an effective address
ILLEGAL instruction pattern (S8AFC) are normally and loads that address into a CPU address register. The
reserved for future instructions in future 680x0 CPUs. operand size is always long (32 bits). The condition
The condition codes are not affected. codes are not affected.
In most instructions the effective address would
automatically be used to access one of the operands
EXAMPLE from memory. The LEA instruction provides access to
the effective address itself rather than the operand at
ILLEGAL ; Cause an illegal instruction trap. which it points.
MOVEP Instruction—Move Peripheral Data: The MULS instruction multiplies the destination oper-
MOVEP Source, Destination and by the source operand and places the result in the
destination. The division is performed using 2’s com-
Move peripheral data performs a special kind of move, plement signed binary arithmetic. The operation pre-
in which alternate bytes in memory are moved rather sumes two 16-bit operands. The result is a 32-bit
than consecutive bytes. That is, every other byte is product. The destination must be a data register. The
moved from a data register to a series of memory- source can be specified in any data-alterable address-
mapped I/O ports (or to memory) or to a data register ing mode. The N and Z condition codes are set accord-
from every other memory byte. The operation can be ing to the result of the division. The X bit is not
either word or long. Bytes are transferred starting with affected. V and C are always cleared.
the MSB of the data register for long operands and
starting with the high-order byte of the low word of the
EXAMPLES
data register if the operand size is word.
The general idea is that many peripherals use 8-bit-
MULS #-311,D0O _ ; Multiply DO by the constant
wide I/O ports but use several of these ports. It is often
;=o3l 1.
easiest to implement these byte-wide ports using all
MULS D2,D1 ; Multiply the low word of D2
even bytes of the 68000 word-wide data bus. In this
; by the low word of D1 and
case the I/O ports appear at even addresses, which
; place the long result in D1.
alternate bytes in 68000 memory (only the even byte
addresses (or odd) are used). Using MOVEP, 2 or 4 bytes
can be moved to such an I/O device using a single MULU Instruction—Multiply Unsigned Bytes,
instruction. This can save time and instruction memo- Words, or Longs: MULU Source, Data Register
ry space.
The condition codes are not affected. Only the ad- MULU performs a multiply using unsigned binary
dress register indirect with displacement addressing division. Otherwise the instruction operates as de-
mode is allowed. Either the source or the destination scribed in the preceding MULS discussion.
must be a data register.
EXAMPLES
EXAMPLE
MULU #311,D0_; Divide DO by the constant
MOVEP.L DO, #$10(A3) 5 LIL.
; Move bytes of data from DO MULU D2,D1 ; Multiply the low word of D2
; to where A8 points plus $10. ; by the low word of D1 and
; First byte goes to A3+S10, ; place the long result in D1.
; second to A3+$12, etc. ; Use unsigned arithmetic.
EXAMPLES
EXAMPLES
RTR Instruction—Return and Restore
Condition Codes: RTR
ROXL.B D1,D2_ ; Rotate D2 left by
; the count in D1, including the RTR is a form of RTE in which only the condition-code
; extend bit in the rotation. portion of the status register is affected. RTR is, there-
ROXR.W #3,D7 ; Rotate D7 right 3 bit positions fore, not a privileged instruction. RTR is used to return
; using the extend bit as well. from an exception handler or interrupt-service routine
when in the user (or supervisor) state of the CPUS ine
condition codes are set according to the word popped
RTE Instruction—Return from Exception: RTE from the system stack. The upper byte of the status
register is not affected.
When an exception occurs, the address where the CPU
is currently operating is pushed onto the system stack.
The status register is also pushed onto the stack. This EXAMPLE
leaves one word more on the stack than is pushed
when a normal jump to subroutine is executed. The RTR_; Return and restore condition codes.
extra word is the status register. After the address and
status register are pushed, a new program counter
value is accessed from the low-memory area according RTS Instruction—Return from Subroutine: RTS
to what type of exception occurred (e.g., divide by O. or
privilege violation). This address is the address of an The RTS instruction is the most common method of
exception handler, often called an exception service returning to a calling mainline program. This instruc-
routine. The routine is like a subroutine except that it tion is a companion instruction to the JSR and BSR
is not called from some mainline program; it is called instructions. Control is passed to a subroutine using a
when a CPU exception occurs. This same type of JSR and control is returned to the mainline program
operation happens in response to a CPU interrupt from using an RTS instruction.
some external device. An interrupt is a kind of excep- The instruction operates by popping a long-word
tion in some sense. address off the system stack and placing that address
When the exception-handling routine has completed in the program counter. The address is presumed to
its operation, which normally involves ‘‘fixing’’ the have been pushed onto the stack by a JSR (or BSR)
problem which caused the exception, then control may instruction. The system stack pointer is postincre-
be transferred back to the code that was executing mented (by 4) after the return address is popped off.
when the exception (or interrupt) occurred. However, a The condition codes are not affected.
normal return from subroutine will not work properly
because the return from subroutine uses only a return EXAMPLE
address from the stack. The saved status register
would be left clogging up the stack. Therefore, the RTS; Return from this subroutine
68000 provides a special type of return instruction ; to the mainline program after the
TRAP #3 _ ; Cause a CPU trap and use UNLK A3_; Remove the link from the stack,
; exception vector number ; deallocating stack memory, load
; 3 (at address SO8C). ; a new stack pointer value from the
; address register A3, and load a
; new reserved memory base
TRAPV Instruction—Cause a CPU Trap on ; address from the stack into A3.
Overflow: TRAPV
The TRAPV instruction causes a CPU trap if the
overflow condition code is set. The current PC is ASSEMBLER DIRECTIVES
pushed on the system stack, followed by the status
register. The PC is loaded with the address from the The words defined in this section are directions to the
TRAPV location (SO1C). Also see the TRAP instruc- assembler; they are not instructions for the 68000.
tion. The condition codes are not affected. The assembler directives described here are a common
This instruction can be used to transfer control subset of those defined for the Raven® cross assembler,
to an overflow-handling routine if an overflow has which runs on the IBM PC, and the Consulair® Corpo-
occurred. ration 68000 assembler, which runs on an Apple
Macintosh. If you are using some other assembler, it
probably has similar capabilities, but the names may
EXAMPLE
be different.
TRAPV_ ; Cause a CPU trap if an
; overflow has occurred.
ABS_LONG, ABS_SHORT— Absolute Long,
Absolute Short: ABS_LONG; ABS_SHORT
TST Instruction—Test an Operand: TST The absolute long and absolute short directives, used
Destination only by the Raven cross assembler, tell the assembler
With the TST instruction, the destination operand is to use either 32-bit (long) or 16-bit (short) addresses
tested and the N and Z condition codes are set accord- when assembling instructions with absolute addresses
ing to its value. The V and C condition code bits are in them. The Consulair assembler for the Macintosh
always cleared, and X is not affected. Only data- uses .L and .S suffixes to indicate long or short absolute
alterable addressing modes are allowed. The operand addresses.
size can be byte, word, or long.
EXAMPLES
EXAMPLES
ABS—SHORT ; Use short addressing.
TST.W DO ; Test the low word of DO and BLT smaller _ ; Branch to location
; set the N and Z condition ; ‘smaller’
; codes according to their values. ; if less than; use a 16-bit
TST.L (A3)+ _ ; Test the long word pointed at ; address so smaller must be
; by A3 and increment A3 (by ; within this 64K area.
; 4) following the test. ABS—LONG __ =; Change to long addressing.
BGT larger ; If greater; branch to
; location “‘larger.’’ Use
UNLK Instruction—Unlink the Stack b ; 32-bit addressing so
Loading New Stack Pointer: UNLK Address ; larger can be anywhere in
Register ; this 4-Gbyte area.
ORG— Specify an Address of Origin for the CHECKLIST OF IMPORTANT TERMS AND
Program: ORG Address Constant
CONCEPTS IN THIS CHAPTER
The ORG statement is used during absolute assembly
Assembler directives
to tell the assembler what address to start assembling
the code into. When assembling code that will later be Addressing terminology
linked to specific addresses, ORG is not required. ORG
is used only in the Raven assembler.
Data-addressing modes
Memory-addressing modes
Alterable addressing modes
EXAMPLE Control-addressing modes
Data-alterable addressing modes
ORG $4000 _; Start assembling code at address
Instruction source
; $4000.
Instruction destination
3. What is the difference between the CMP and the 7. Show how you could combine several MOVE in-
CMPI instructions? structions to perform the same operation as the
SWAP instruction. What are the differences be-
4. Why does the CPU have an ILLEGAL instruction?
tween a single SWAP and the MOVE instruction
For what can the instruction be used?
sequence?
In Chapter 2 we showed that a microcomputer consists can show how a microcomputer system is built around
of a CPU, memory, and ports. We also showed in it. We also discuss the hardware connections for a
Chapter 2 that these parts are connected by three 68008. A later chapter shows the hardware connec-
major buses, the address bus, the control bus, and the tions for the 68020, 68030, and 68040 microproces-
data bus. For Chapters 3 through 6, however, we made sors.
little mention of the hardware of a microcomputer
because we were concerned in these chapters, for the
most part, with how a microcomputer is programmed. 68000 Input and Output Signals
In this chapter we come back to take a closer look at To get started, let’s take a look at the pin diagram for
the hardware of a microcomputer. the 68000 in Figure 7-1. Don’t be overwhelmed by all
those pins with strange mnemonics next to them. You
don’t need to learn the detailed functions of all these at
once. We describe and show the use of these different
OBJECTIVES
pins throughout the next few chapters as needed.
At the conclusion of this chapter, you should be able to When you need to refresh your memory of the function
of a particular pin, consult the index to find the section
1. Draw a diagram showing how RAMs, ROMs, and where that particular pin or signal is described in
I/O ports are added to a 68000 CPU to make a detail. For reference, the complete data sheet showing
simple microcomputer. all of the pin descriptions is shown in Appendix A.
Look first at the dual-in-line package, which is quite
2. Describe how addresses are sent out on the 68000
common in Figure 7-1. Notice that Vc, is on pins 14
data bus.
and 49, whereas ground is on pins 16 and 53. Next find
3. Describe the signal sequence on the buses as a the clock input labeled CLK on pin 15. A 68000
simple 68000-based microcomputer fetches and requires a clock signal from some external, crystal-
executes an instruction. controlled clock generator to synchronize internal op-
erations in the processor. Different versions of the
4. Describe how address-decoding circuitry gives a 68000 have maximum clock frequencies ranging from
specific address to each device in a system and
8 MHz to 12.5 MHz. Notice in Figure 7-1 that the 16-bit
makes sure only one device is enabled at a time. data bus is carried on pins DO—D15. Remember from
5. Calculate the required access time for a memory previous chapters that the 68000 has a 24-bit address
device or port to work correctly in a 68000 micro- bus. The astute reader will notice that only pins
computer system. A1—A23 exist. What happened to address line AO? The
lowest-order bit of the address is represented by the
6. List a series of steps you might take to troubleshoot UDS and LDS pins (upper and lower data strobes). The
a malfunctioning microcomputer system that once 23 bits can address 8 megawords of memory, which is
worked. equal to 16 Mbytes, since each word consists of 2
bytes.
Figure 7-2 shows the 68000 pins grouped into logical
68000 HARDWARE OVERVIEW collections, depending on the pin’s function. The data
and address buses are shown on the upper right. The
In previous chapters we worked with what is often actual pin locations and numbers were shown in Fig-
called the programmer’s model of the 68000. This ure 7-1. The directions of the arrows indicate whether
model shows features such as internal registers, num- the signals on the pins represent information moving
ber of address lines, and number of data lines that we into or out of the 68000 CPU. The address bus is
need in order to be able to program the device. Now we actually a three-state bus, where each bit can bea 0,a
will look at the hardware model of the 68000 so that we 1, or ‘‘floating,’’ where the CPU does not drive the
166
64-Pin Dual-in-Line Package 68-Terminal Chip Carrier
IS|QIB
pbcie
D3 2
WY 64/5
63
D5
D6 els] NAOrANYTHNORDD
Kya
ea ge Qe ae
ee Pee tore adalat ot
D2 6215 D7 1
D1 =h 61 D8 oO = > @ aA
po C15 601 D9 3
lee)G)
AS 6 591 D10
UDS 417 580 D114
LOS os 5719 D12
RW 9
DTACK 410
560
55
D13
p14 |
>S655
ZC
DDO
Ze OUOARS
DA TOP VIEW.
value of the bus. The data bus is also a tristate bus, but Figure 7-2 also shows the power lines (V,-), the
it can either send or receive data. The CPU can be the ground lines (GND), and the clock line (CLK). The
source of the data going out of it, or it can be the remaining pins are grouped into the processor state
destination for the data going into it. lines, the M6800 peripheral control lines, the system
control lines, the asynchronous bus control lines, the
bus arbitration control lines, and the interrupt control
ADDRESS BUS A1-A23
lines. Each of these groups of lines is discussed briefly
DATA BUS DO-D15
here. Most are revisited in later chapters in more
detail. During these discussions the term low is gener-
ally used to indicate the presence of a logical 0 on the
ASYNCHRONOUS line. The active state of a line is a high voltage for some
PROCESSOR
‘a BUS
CONTROL lines and a low voltage for other lines. Table 7-1, p.
STATUS
DTACK 168, shows the real active state for each line. In the
MC68000
discussion, however, the terms assert or assertion
M6800
PERIPHERAL
MICROPROCESSOR
BUS ARBITRATION (e.g., we can assert UDS by making it have a low
=== (i) CONTROL
CONTROL BGACK voltage) and negate or negation are often used. The
names actually carry the correct condition in them.
SYSTEM INTERRUPT
For example, the upper data strobe line is labeled UDS
CONTROL i CONTROL
(that is, ““‘UDS bar’’), not just UDS, because when we
assert the upper data strobe, we give it a low voltage
FIGURE 7-2 Input and output signals. (Reprinted with (i.e., a0). This makes UDS true and UDS false. Another
permission of Motorola Inc.) way to think of this is that if we want to access the
NOTES:
1. Open drain
2. Function codes are placed in high-impedance state during HALT for R9M, T6E, and BF4 mask sets
upper byte of a word, we want to assert the upper data in all 16 bits of the data bus. When the I/O device has
strobe signal. To do this we should place a 1 on the finished reading the word of data, it should set DTACK
upper data strobe control line, but that means we low. The 68000 can also provide a synchronous mode
should place a low voltage on the UDS pin of the of operation using its M6800 peripheral control lines.
68000. This is exactly what Table 7-1 tells us needs to
be done, because UDS is active low. M6800 PERIPHERAL CONTROL LINES
ASYNCHRONOUS BUS CONTROL Systems built using Motorola 6800 series peripheral
device controllers typically require synchronous oper-
The bus control lines include the address strobe line ation. In a synchronous system the CPU grinds on at
(AS), the read/write line (R/W), the upper and lower its own speed, and it is up to the rest of the devices to
data strobes (UDS and LDS), and the data transfer keep up. In such systems all chips are synchronized to
acknowledge line (DTACK). These lines are used to the system clock and must operate in fixed numbers of
synchronize and control the address bus and data bus clock cycles for the system to operate properly. Devices
operation. The 68000’s normal addressing mode is an of this type often cannot be conveniently configured to
asynchronous mode in that the bus timing is regular, use the DTACK line to indicate when a read is com-
but not fixed. For example, a bus read operation by the plete. The peripheral control lines, Enable (E), valid
CPU can take any number of clock cycles, depending peripheral address (VPA), and valid memory address
on how fast the system RAM or I/O devices are. The (VMA), provide synchronous control of the bus for
CPU will not go on processing following a read until the interfacing 68000 class CPUs to 6800 class peripheral
reader (which may be RAM or some I/O device) sends a devices. These lines are discussed in more detail in
transfer complete acknowledgment using the DTACK later examples.
line. Table 7-2 shows how the upper and lower data
strobes in combination with the read/write line indi-
cate when data is valid on which bits of the data bus. SYSTEM CONTROL LINES
DTACK is used to indicate that the appropriate data The system control lines, bus error (BERR), reset
bits have been successfully read. For example, when (RESET), and halt (HALT) are used to start and stop the
the UDS and LDS lines are both low and R/W is also system. Halt is a bidirectional line that will cause the
low, then a word write is occurring. There is valid data CPU to stop its operation at the completion of the
current bus cycle. When halted, the CPU asserts the priority level. Signals can be applied to these inputs to
halt line. The reset line is used by the CPU to reset cause the 68000 to interrupt the program it is execut-
external devices. The reset line can be used to reset the ing and go execute a specified interrupt-service rou-
CPU so that the CPU begins its start-up processing. If tine. We might, for example, connect a temperature
both the halt and reset lines are asserted, then an sensor from a steam boiler to the interrupt inputs ona
entire system reset is performed. When the CPU resets 68000. If the boiler gets too hot, then it will assert the
external devices as a result of executing a RESET interrupt inputs. This will cause the 68000 to stop
instruction, the CPU internal state is not affected. The executing its current program and execute a routine
bus error line can be used to cause a CPU bus error we wrote to turn off the fuel supply to the boiler. At the
exception and initiate error handling by the bus error end of the interrupt-service routine we can return to
service routine. Typically, this line is tied to external executing the interrupted program. Chapter 8 de-
time-out circuitry so that if an I/O device does not scribes in detail the operation and uses of interrupts.
respond within some reasonable length of time (deter- The CPU will not acknowledge an interrupt which is
mined by the hardware designer), the bus error line is of lower priority than its current interrupt mask level
asserted and the CPU can handle the error and contin- (specified in the CPU status register). If the CPU inter-
ue processing. Otherwise, with an asynchronous bus, rupt mask is set to.3, for example, then interrupts from
if some I/O device is unable to respond, then the entire devices with priority level 3 and lower will not be
system is stopped because the CPU cannot proceed recognized. Interrupts from devices with interrupt pri-
without a DTACK (or bus error). If a second bus error ority levels of 4, 5, 6, or 7 will be acknowledged as
occurs while the CPU is attempting to service the first quickly as possible. Interrupt level 7 is used for a
bus error, then the CPU will halt. This is called a nonmaskable interrupt, which is always acknowl-
double bus error condition. edged at the next instruction cycle. Since the boiler
will explode if it gets too hot, we had better connect the
PROCESSOR STATUS boiler sensor so that it sets IPLO, IPL1, and IPL2 toa 7
(i.e., to binary 111, all 1s) when the temperature gets
The processor status lines consist of three function critical. Interrupt level 7 will assure that the CPU finds
code lines (FCO, FC1, and FC2), which tell the outside time to call the interrupt-service routine and turn off
world what the CPU is doing. The function codes give the boiler fuel.
the CPU state and the type of bus cycle being per-
formed. Table 7-3, p. 170, shows the encoding used. BUS ARBITRATION CONTROL LINES
For example, if FC2 and FC1 are both low (0) and FCO is
high (1), then the CPU is in user state and the bus cycle In a simple 68000 system the 68000 CPU controls the
is accessing data. The read/write line indicates wheth- operation of the system buses using its various bus
er a read or a write is being performed. control lines. In some more complex systems, however,
there may be several 68000 family devices using the
same bus. Clearly, they cannot all control the bus at
INTERRUPT-CONTROL LINES once. In such systems one device controls the bus (the
The interrupt-control lines are three input lines (IPLO, system controller); however, there is a mechanism
IPL1, and IPL2) that encode the interrupting device’s whereby that device can give up control of the opera-
DTACK \ if \ if \ /
FIGURE 7-4 68000 word- and byte-read cycle timing diagram. (Reprinted with
permission of Motorola Inc.)
DTACK to indicate that the data has been placed on the read machine cycle, a 68000 first asserts the function
bus. The CPU then latches the data, recording it in code and address signals. This gives these lines time to
internal memory areas called buffers, or latches. The settle so that later uses of the lines will yield clean,
CPU negates UDS or LDS (whichever was used for the reproducible results. The FCO—FC2 and Al—A23 lines
transfer). The CPU negates AS, indicating that the are shown as two lines that cross. This is because the
address bus is no longer in use. The I/O device or signals may be going low or going high for the read
memory then stops driving the data bus; that is, it cycle. That is, the address bits may include both Os and
removes that data from the bus and negates DTACK. 1s. The point where the two waveforms cross indicates
The CPU then starts the next bus cycle. We can trace the time at which the signal becomes valid for this
this entire operation in another manner using the machine cycle. Note that the address line signals are
timing diagram of Figure 7-4. not guaranteed to be valid until the start of state S1.
The first line to look at in Figure 7-4 is the clock The function code lines, on the other hand, are valid
waveform at the top (CLK). This represents the crys- by the end of SO. Likewise, in the rest of the tim-
tal-controlled clock signal sent to the 68000 from an ing diagram, crossed lines are used to represent
external clock generator device, as shown at the top the time when information on a line or group of lines
left of Figure 7-2. One cycle of this clock is referred to is changed. Incidentally, the best way to analyze
as a state. A state is measured from the falling edge of a timing diagram such as this one is to think of
one clock pulse to the falling edge of the next clock time as a vertical line moving from left to right
pulse. SO in the figure is state 0, S1 is state 1, and so across the diagram. With this technique you can
on. The diagram shows the states numbered relative to easily see the sequence of activities on the signal lines
the start of the machine cycle. Three machine cycles as you move your imaginary time line across the
are shown: One word-read cycle is represented by the waveforms.
first seven states, SO—S7, in Figure 7-4; the next cycle During S1 the address lines become valid (stable
is an odd-byte read represented by the second group of enough for use). During S2 the AS, UDS, and LDS lines
states SO—S7; and the third group of states SO-S7 is are asserted, indicating a valid address and data de-
an even-byte-read bus cycle. As we discussed in Chap- sired on both the upper and lower bytes of the data bus.
ter 4, each instruction requires a certain number of Notice also that the read/write line (R/W) is assumed to
states to execute. The total time it takes the 68000 to be asserted throughout the entire operation. The buses
fetch and execute an instruction is called an instruc- are now ready, and the I/O device or memory (the slave
tion cycle. An instruction cycle consists of one or more device) should be preparing to provide the data. S3 is
machine cycles. A machine cycle represents a basic the first opportunity that the device has to provide the
bus operation, such as reading a byte from memory or data. If the device is fast, then it can provide the data
writing a word to a port. To summarize, then, an immediately. When the data is on the bus and valid,
instruction cycle is made up of machine cycles, and a the slave device will assert DTACK, telling the CPU that
machine cycle is made up of states. Here we examine the data is valid. The CPU latches the data during S5
the activities that occur on the buses during a read and S6, remembering it internally to the CPU. During
machine cycle. S7 the CPU negates AS, UDS, and LDS, the device
Let’s start at the left of the diagram by examining the negates DTACK, and the cycle is completed. If the
activities during a word-read operation. During SO of a device were very slow, then additional states would be
FIGURE 7-5 68000-byte write-cycle flowchart. (Reprinted with permission of Motorola Inc.)
latched by the device (e.g., by the RAM) and DTACK is from the bus. Therefore, if we have a memory or port
asserted during S3, stabilizing by S4. The CPU negates device which needs more time to absorb the data from
AS during S6 and negates LDS during S6. The device the data bus, we can use some external hardware to
negates DTACK during S6; by S7 these control lines hold off DTACK until the device has gotten the data off
have stabilized and the machine cycle is complete. The the data bus and saved it. Delaying DTACK will cause
bus is then ready to begin another machine cycle. the 68000 to insert one or more WAIT states in the
If the device is slow and requires several cycles to machine cycle, thus giving the addressed device more
read the data bus, then wait states will be introduced time to absorb the data.
between S3 and S4. The device will not assert DTACK Work your way across the timing diagrams for the
during S4 but will wait until it has successfully latched read and write machine cycles in Figures 7-4 and 7-6
the data before asserting DTACK. The CPU will wait until you feel that you understand the sequence of
until DTACK is asserted before it begins the process of activities that occur. Understanding them well will
terminating the data transfer and removing the data make later sections easier to understand.
FIGURE 7-7 68000 read-modify-write cycle flowchart. (Reprinted with permission of Motorola Inc.)
nn ae nN |
DTACK \ / \ /
ce INVISIBLE CYCLE - =|
FIGURE 7-8 68000 read-modify-write cycle timing diagram. (Reprinted with permission of Motorola Inc.)
Whenever you are approaching a system that is new There is no difference between the internal 68000 CPU
to you, it is a good idea to study the detailed block buses and the external PC board-level buses. The
diagram of the system carefully before you start dig- 68000 CPU is by far the largest IC in physical dimen-
ging into the actual schematics. The schematics for sions, being more than 3 in. long and 2 in. wide in its
even a small system such as this are sometimes spread most common dual-in-line package (see Figure 7-1).
over many pages. Without the overview that the block The RAMs and ROMs in the block diagram connect
diagram gives, it is very difficult for you to see how all to all three buses and are each composed of two
the schematic pieces fit together. physical ICs. There may be more RAM and ROM ICs in
The first parts to look at in Figure 7-10 are the 68000 more complex systems. The URDA MDS can have
CPU and the clock generator. Note that the MDS hasa additional RAM added to it by means of an external PC
3.579545-MHz crystal connected to it. The crystal is board connected to the two connectors at the right side
connected to a 74LS14 IC, which is in turn connected of the diagram. The two connectors in the block dia-
to the 68000 CPU. gram represent a general ability to expand the MDS.
Notice also that there are no bus drivers or bus URDA makes other add-on boards, including a serial
latches other than those on the CPU chip. The CPU interface and a floating-point coprocessor card. Most
chip itself can drive several other ICs to build a small systems need a serial port so they can communicate
system such as this. If we had a bigger system with with CRT terminals, MODEMS, PCs, and other devices
more ICs, we might need to include separate, higher- that require data to be sent and received in serial form.
power bus driver ICs. In this system the internal 68000 The URDA MDS product family uses a Motorola
buses are actually the same ‘‘wires’’ as used on the MC68681 as a serial port. The 68681 is a type of
main PC board external to the CPU IC itself. This USART, or universal synchronous/asynchronous re-
makes the system very easy to deal with conceptually. ceiver transmitter. Chapter 14 discusses the initiali-
zation and use of the 68681. For now, just think of this
device as two registers. One is a shift register, which
accepts a parallel byte you give it and sends it out, bit
by bit, on a single data line. The other register is a
control register, to which you send bytes of data to
configure and command the USART. For example, to
select the desired frequency from the available speeds,
one sends the control register commands to select a
specific baud rate, which is the way of specifying the
rate at which data bits are shifted in or out of a serial
device. Baud rate for a device such as the 68681 is
defined as 1 over the time per bit (in seconds). If the
time per bit is 3.33 ms, for example, then the baud rate
is 300 baud. Common baud rates for serial data trans-
mission are 300, 600, 1200, 2400, 9600, and 19,200.
The I/O ports on the URDA MDS are used to control
the LED display and the keyboard. The URDA MDS
system port is one of two I/O ports in the block
diagram in Figure 7-10. The system port is used to
control the display and the keyboard. On the URDA
MDS, two PIAs (programmable interface adapters) at
FIGURE 7-9 The URDA MDS. the top right give the system programmable parallel
RAM
Clock
Generator
Address
Bus
Data Bus
| Control Bus |
JOJOQUUOD
ports, one the system port and the other the user port. 68000 CPU. Recall that the address space on a 68000
The term programmable in this case means that as is 16 Mbytes (or 8 megawords) and uses addresses 0 to
part of your program, you can send the port a control SFFFFFF. Normally, ROMs are used in the lowest
byte, as described for the serial device. The user ports absolute addresses, starting at address 0, because the
are for the experimenter to use in any way desired. On devices at the low 256 addresses must provide excep-
the upper right of the PC board itself are two 6821 tion vectors and the power-on stack location for the
PIAs, which act as the two primary I/O ports in the 68000 CPU. ROMs are some of the most common and
URDA MDS. reliable devices that can be implemented by low-cost
One of the most important things not shown in ROM ICs or by user-programmable EPROM or EEPROM
Figure 7-10 is exactly how all these devices are con- ICs. Two EPROMs, 2732s, are used on the URDA MDS.
nected on the PC board itself. Which pins are connect- They can be programmed to point back into the expect-
ed by PC board traces to which other pins, and why? ed RAM address space; where the code for the actual
Figure 7-11, the schematic for the URDA MDS, an- exception handling and start-up routines would reside.
swers the first part of the question. The schematic The URDA 2732s are located at absolute addresses
shows exactly which pins are to be connected. The ICs $000000 to SOOOIFFF, a range of 4 Kbytes. However,
shown on the schematic are labeled to correspond to they are connected such that one of the 2-Kbyte 2732s
labeling on the PC board itself. Also, the schematic hold all the upper (even) bytes and the other 2732
indicates the expected IC part numbers for most of the holds all the lower (odd) bytes. Since the 68000 has a
ICs. The schematic does not show exactly where the 16-bit data bus, the two 8-bit EPROMs can work in
ICs are placed on the PC board. The actual location parallel to provide all 16 bits of data as quickly as
information is normally shown on a layout diagram, possible.
which shows exactly how the physical ICs are ‘“‘laid The URDA MDS does not use the upper 8 bits of the
out’’ on the PC board so that they can all be intercon- address bus. Address pins Al6-—A23 are not used.
nected. Additionally, a loading diagram can be used to Therefore, we will normally use only 16 bits, or 4 hex
indicate how ICs are to be loaded into specific sets of digits, to describe URDA MDS addresses. Thus the
holes or sockets on the PC board. EPROMs are said to be located at addresses $0000 to
The second part of the question is much more diffi- S1FFF.
cult to explain. In the remainder of this and the next The RAMs represent the changeable,storage for the
section we examine the question of why we should computer where programs will be placed and executed.
connect the system in a particular way. The RAMs occupy addresses $4000 to S4FFF, 4 Kbytes
Perhaps the first key piece of information needed in of address space. In the URDA MDS, two 6116 ICs are
answering the question Why? is the expected place- used, each providing 2 Kbytes of RAM (16 Kbits). The
ment of the various devices in the address space of the RAMs are also used in pairs in a typical 68000 system
BEISrL
gl
[on [nsw | v
pealas
,
Lal Bard
siton
Si)
358) Ane" I
391430
riswe
annows
ast | ast | ast | ast | ast | ag
iL
eee ee MC
Li
s+
|
1a
|
; !|) ‘| ania’ ania- =
an
@°S-%BVEWT
I
st)
Ae) €1) z13 I
1nd) 4.
'
zene
7 WHY
Wow
9 Wee
CONNECTIONS,
elf
Tl
S
1
8
z
xba
¢nd
INT wash
2 Geeel |
| Q8b084 3
68000 SYSTEM
43SN
ips
=
A3x
H
es
ES
: Ty ya
Qa EN
By LPNI
10
a (2-3)
a OSI WHO
er 8u viswe
8/7 WHO
vy
ASZ
+ ANe
qd
€)
ary LPNI.
QP m
vise ee vist vISTrL
AS+ O
so that they can operate in parallel and each provide 1 IC. Usually IC numbers are sequential and start from
byte of a full word of data. the upper left corner of the component side of a board.
Finally, we have already mentioned the connectors There may be several ROMs on the board, but only one
on the right side of the block diagram in Figure 7-10. will be labeled IC7. Notice that several logic gates on
On the URDA MDS, there are actually only sets of posts the board may have the same IC number, since often a
to which a connector can be attached (i.e., the ‘‘male”’ single IC will provide more than one gate. For example,
portions of the connector pair). These connectors can IC5 provides four NAND gates, two shown in zone B3
be used for add-on boards from URDA or for experi- and two in zone C4.
mentation by the owner or student. Other devices often found on microprocessor boards
are resistor packs. You can find an example in zone C4
of the schematic, labeled N2. As you can see from the
schematic, this device contains seven 10-KQ resistors.
A Look at the URDA MDS Schematic
Resistor packs may physically be thin vertical, rectan-
Now that you have seen an overview of the URDA MDS, gular wafers, or they may be in packages similar to
the next step is to take a close look at Figure 7-11, small ICs. The advantages of resistor packs are that
which shows the actual schematic for the board. At they take up less PC board space and are easier to
first this maze of lines may seem overwhelming to you, install than individual resistors. The function of this
but if you use the 5-minute rule and then approach the resistor pack connection is to assert the lines to which
schematic one part at a time, you should have no they are tied. For example, notice that BGACK is tied to
trouble understanding it. The schematic simply shows +5 V through a resistor in the resistor pack. What this
greater detail for each of the parts of the block diagram means is that BGACK is always asserted. The same is
that we discussed in the preceding sections of the true for RES, and the rest of the lines tied to the
chapter. resistor pack without additional circuitry.
At this point we want to make clear that it is not the Some other symbols to look at in the schematics are
purpose of this chapter to make you an expert on the the structures with labels such as J2 and P1. You can
circuit connections of an URDA MDS board. We use find examples of these in zones C7 and B7 of schematic
parts of this schematic to demonstrate some major sheet 1. These symbols are used to indicate connec-
concepts such as address decoding and to show how tors. The number in the rectangular box specifies the
the parts are connected together to form a small, but pin number on the connector to which a signal goes.
real, system. Even if you do not have an URDA MDS The letter P stands for plug. A connector is considered
board, you can learn a great deal about how a 68000 a plug if it plugs into something else. In the case of the
system functions from these schematics. This sche- URDA MDS, the connector labeled P1 is the printed
matic is actually quite simple as the industry goes. One circuit board edge connector. The letter J next to a
often encounters multipage schematics, such as those connector stands for jack. A connector is considered a
typical for any PC or sophisticated microprocessor- jack if something else plugs into it. On the URDA MDS
based board or product. board, the jacks J1 and J2 are 50-pin connectors into
Before getting started on the next major concept, we which you can plug ribbon cable connectors. These
discuss some of the symbols used on most micro- jacks allow the address bus, data bus, control bus, and
processor system schematics. The first thing that we parallel ports to be connected to additional circuitry.
want to look at in the schematics is the numbers One more point to notice on the URDA MDS sche-
across the top and bottom and the letters along the matic is the capacitors on the power supply inputs
sides. These are called zone coordinates. You use shown in zone A3. As you can see there, the schematic
these coordinates to identify the location of a part or shows a large number of 0.01-yF capacitors in parallel
connection on the schematic just as you might.use with a 1.2-uF capacitor. Most systems have filtering
similar coordinates on a road map to help you locate such as this on their power lines. You may wonder
Bowers Avenue. what is the use of putting all these small capacitors in
For example, on the schematic find the CPU IC, parallel with one that is obviously many times larger.
which is in zone B3. To find the CPU IC, first move The point of this is that the large capacitor filters out,
across the row of the schematic labeled B until you or bypasses, low-frequency noise on the power lines,
come to the column labeled 3. This zone is small and the small capacitors, spread around the board,
enough that you should easily be able to find where the bypass high-frequency noise on the power supply
CPU IC is. It is the largest IC on the schematic and is lines. Noise is produced on the power supply lines by
labeled IC2, then MC68000, and then MPU (micropro- devices switching from one logic state to another. If
cessing unit). For practice, try finding the RAMs in this noise is not filtered out with bypass capacitors, it
zones B2 and B3 and the clock crystal in zone D2. may become large enough to disturb system operation.
The next point to look at on the schematic is the Glance through the URDA MDS schematic to get an
numbers on the ICs. In addition to a part number such idea of where various parts are located and to see what
as MC68000, each IC has a number of the form ICn additional information you can pick up from the notes
where n is a number. For example the CPU is labeled on them. In the next section of this chapter we discuss
IC2. This second number is used to help locate the IC how microcomputer systems address memory and
on the printed circuit board. The number is usually ports. As part of the discussion, we cycle back to the
silk-screened on the board next to the corresponding schematic to see how the URDA MDS does it.
ap
<8
ee
| ae
eal
7432 Al4
Al—-A12
Address Bus
D8-D15
ice A1-A12
ROM
U
ROMU |CE
indication of how many bytes are stored in it. Each is enabled when the address strobe and the lower data
EPROM has 12 address lines (Al—A12) connected to it. strobe are both asserted. Hence, this decoder is used to
Therefore, the number of bytes stored in the device is enable the lower byte ROM. The upper bytes of ROM
2'*, or 4096. If you have trouble with this, think of how are enabled by a decoder whose E input is connected to
many bits a counter must have to count the 4096 the AND combination of AS and UDS (the upper data
states from 0 to 4095 decimal, or S$OO00 to S3FFF. strobe).
Note that each 2732 in Figure 7-12 has a chip select To determine the addresses of ROMs, RAMs, and
(CS) input. When this input is asserted low, the ad- ports in a system, a good approach in many cases is to
dressed byte in a device will be output on the data bus. use a worksheet such as that in Figure 7-13, p. 182. To
To get meaningful data from the EPROMs, we need to make one of these worksheets, write the address bits
make sure that the CS input of only one device at a time and the binary weight of each address bit across the
is low. In the circuit in Figure 7-12, this is done by the top of the paper, as shown in the figure. To make it
74LS139. easier to convert binary addresses to hex, it helps if
The 74LS139 contains two 1-of-4 decoders. These you mark off the address lines in groups of four, as
are shown in separate boxes in Figure 7-12 even shown. Next, draw vertical lines that mark off the two
though the actual IC uses only one package. The two address lines that connect to the decoder-select inputs
boxes representing the two decoders are distinguished (AO and Al). For the decoding shown in Figure 7-12,
from each other by the pin numbers written on the address lines Al5 and Al4 are connected to the Al
schematic. If the first decoder in the 74LS139 is ena- and AO inputs of the decoder, respectively, so mark off
bled asserting its enable input (E), then only one columns A15 and A14. Since we are using Al15 and
output of the decoder will be asserted at a time. The A14 only to decode for the EPROMs, we show the four
output that will be asserted is determined by the 2-bit possible combinations of these 2 bits as the four
address applied to the Al and AO select inputs. For possible memory blocks.
example, if the address is 00, then the O output will be Now, under each address bit write the logic level that
asserted, and all the other outputs will be high. If the must be on that line to address the first location in the
address is 10, then only the 2 output will be asserted. first EPROM. To address the first location in any of the
Examining the line connected to the enable input EPROMs, the Al through A12 address lines must all be
should reveal that the input is connected to the output low, so put a O under each of these address bits on the
of an OR gate (in a 7432 IC), which combines the LDS worksheet. To enable the EPROM 0, the select inputs of
(lower data strobe) and AS (address strobe) control the decoder must be all Os. Since address lines A15
lines coming out of the 68000 MPU. Thus, the decoder and Al4 are connected to the inputs of the decoder and
FIGURE 7-13 Address decoder worksheet showing address decoding for two
2732s in Figure 7-12.
the EPROM-enable input is connected to output line 0, are all 1s. If you put a 1 under each of these bits, as
the EPROM will be enabled only when both A15 and shown on the worksheet, you can see that the ending
Al4 are O. Write Os under address bits A15 and Al4. address for the EPROMs is S3FFF. Remember that A15
We are left with Al3 and AO not yet filled in. and A14 have to be low to select the EPROMs. A15 has
AO tells whether a byte is even or odd. In terms of to be low to enable the decoder. The address range of
memory organized into words, AO determines whether EPROM 0 is said to be $0000 to S3FFF, a 16-Kbyte
the byte is a low byte or a high byte. Notice that the block. Draw a horizontal line below the highest EPROM
UDS and LDS lines from the CPU are used in conjunc- address, S3FFF, to indicate the end of the EPROM
tion with the AS line to enable the EPROM decoders. memory block. We explain shortly why the RAMs are
The UDS and LDS lines encode the value of AO. So, if shown in the second memory block.
UDS is asserted, then the “‘high’’ decoder will be These EPROMs are put at the low address in memory
enabled, which will, in turn, enable the high-byte on the URDA MDS board because, after a RESET, the
EPROM. If both UDS and LDS are asserted (a full word 68000 goes to address $0000 to get the address of its
operation), then both decoders will be enabled and first instruction. Since we want the URDA MDS to
both EPROMs will, in turn, be enabled. If only LDS is execute its monitor program after we press the RESET
asserted, then only the low-byte EPROM will be ena- button, we put the address of the monitor routine in
bled. For our address decoder worksheet, we will con- location SO000 of the EPROM. We also normally put
sider the two EPROMs to be in one memory block, since the monitor routine itself in EPROM.
they both work in lockstep providing alternate bytes in Some people like to think of address lines Al4 and
memory—one the high bytes and one the low bytes. A15 as ‘‘counting off’ 16-Kbyte blocks of memory. If
Notice, finally that data lines DO to D7 come from the you think of the address lines as the outputs of a 16-bit
low-byte EPROM and data lines D8 to D15 come from counter, you can see how this works. The end address
the high-byte EPROM. for each EPROM has all Is in address bits Al—A13.
A13 is not used in connection with the EPROMs. When you increment the address to access the next
What this means is that the EPROMs will be addressed byte in memory, these bits all go to O, anda 1 rolls over
when A13 is a O and when it is a 1. What this has the into bits Al4 and A15. This increments the count in
effect of doing is duplicating the ROM address space, these 3 bits by 1 and enables the next highest 16-
with one copy occurring where A13 is O and the other Kbyte memory block. The count in these bits goes from
where Al3isa 1. The 2732 bits are used twice and can binary 00 to 11.
be accessed with an A13 value of either 1 or 0. Looking
at the completed worksheet, then, the 2732 EPROMs THE URDA SYSTEM RAM DECODER
are said to be overlapped, occupying both the space The system in Figure 7-7 contains only ROM. In most
$0000 to S1FFF and the space $2000 to S3FFF. systems we want to have ROM, RAM, and ports. To give
2764 EPROMs provide 8 Kbytes each of memory (64 you more practice with basic address decoding, we will
Kbits) instead of the 4 Kbytes (32 Kbits) that 2732s now show you how the same decoders work with the
provide. If the system used 2764 EPROMs instead of RAM in the system.
2732 EPROMs, then A13 would be an input to the Suppose that we want to add two 2K X 8 RAMs to the
EPROMs and there would not be this duplication of system, and we want the first RAM to start at address
EPROM memory space. $4000, just above the EPROMs, which end at address
You can now read the starting address of EPROMs S3FFF. The URDA board uses 6116 static RAMs. The
directly from the worksheet as $0000. The highest R/W line from the 68000 will be connected to the write
address in the EPROMs is that address where AO-A13 enable (WE) input of the 6116s to tell the RAMs
FIGURE 7-14 Address decoder worksheet for two 2-Kbyte RAMs starting at
address $4000.
pa 2 PIANO)
OUTPUT ——$$$ DAN
REGISTER A Ne
PERIPHERAL
(ORA) © PAS
INTERFACE
0) PAG
— =f, PAS
BUS INPUT poh PNG)
REGISTER pa 8) PANY
(BIR)
BUS
INPUT
————— @) Pex)
OUTPUT eee el rl8)il
REGISTER B eZ
(ORB) PERIPHERAL pees 13 PB3
INTERFACE
B B
poe I) IRM!
——— ON BO
a he [elate)
poe BY
CONTROL
DATA DIRECTION
CONTROL REGISTER B
REGISTERE |e (DDRB)
(CRB)
FIGURE 7-15 MC6821 internal block diagram. (From Motorola Inc. datasheet)
tied high so that they are always asserted. Figure 7-17 register B. Table 7-1 shows why the particular I/O port
shows the entire URDA memory map as a collection of initialization used in previous chapters’ examples
the EPROM, RAM, and I/O port memory blocks. A works.
memory map such as the one in Figure 7-17 is a Completing the worksheet of Figure 7-18, for address
convenient way to summarize where each device is lines A2 and Al fill in Os for the low address of the I/O
located in the system address space. memory block and 1s for the high address. Address
Figure 7-18, p. 186, shows an address decoder work- line AO is used implicitly, as with the ROM and RAM
sheet for the I/O ports similar to those for the EPROMs decoding, because UDS and LDS are used to enable the
(Figure 7-13) and RAMs (Figure 7-14). Address bits decoders. The low-byte decoder enables the low PIA
A15 and Al14 must both be Is to assert decoder line 3 and the high-byte decoder enables the high PIA. The
and enable the I/O port PIAs. Fill in 1s in the columns two PIAs can also be used in parallel, as can the RAMs
for Al5 and Al14. Examine Figure 7-16 and notice that and ROMs. This style of connection means that all
the only other address lines connected to the PIAs are even addresses refer to one PIA (the high one) and all
A2 and Al. Further notice that A2 and A1 are connect- odd addresses all refer to the other PIA (the low one).
ed to the register select lines of the PIAs (RS1 and RSO). The remaining address lines, A3—A13, are not con-
Table 7-4, p. 185, shows which PIA register is selected nected during I/O space decoding. The values used on
by each combination of register select lines. If both A2 these lines do not matter. They can be either Os or 1s
and Al are Os when RS1 and RSO are Os, then and have the same effect. For example, to access the
peripheral register A or data direction register A will be control register for the upper PIA port A, the address
selected. The data register will be selected if bit 2 of $CO12 could be used as well as SDF 12 or SDF 12. Fillin
control register A is 0; otherwise the peripheral regis- Os for the low address used to access the PIAs and 1s
ter will be set. If A2 and Al are binary 01, then control for the highest address. Keep in mind that the PIA
register A will be selected. If A2 and Al are 11, then memory map will be folded over throughout this space.
control register B will be selected. If A2 and Al are 10, The 6821 connection also involved using the special
then RS1 and RSO will be 10 and either the data capabilities of the 6800 to provide MC6800 peripheral
direction register or the peripheral data register will be control using the valid peripheral address (VPA) and
selected, depending on the value of bit 2 of control valid memory address (VMA) lines instead of the nor-
mal DTACK. The VPA input to the 68000 is asserted
184 CHAPTER SEVEN
10 k DTACK
HD68000
MPU DO-D15
IC11
DO-D7 HD6821
Al
AIA?
Address Bus
ee haa )>
HEX
FIGURE 7-17 Memory map for BLOGK anmeres Block FUNCTION
URDA MDS board.
1 START $0000
END $3FFF ROM
2 START $4000
END $7FFF RAM
3. START $8000
END $BFFF (not used)
4 START $C000
END $FFFF SS
Control
TABLE 7-4 Register Bit
6821 INTERNAL ADDRESSING
(From Motorola Inc. datasheet) RSO CRA-2 CRB-2 Location Selected
Peripheral Register A
Data Direction Register A
Control Register A
Peripheral Register B
Data Direction Register B
-eonoe/B
cool
B on Control Register B
X = Don’t Care
whenever Al5 and A14 are both 1s—‘in other words, decoded system each memory block is fully used or is
whenever an I/O port memory reference is made. The available for future use.
CPU then uses VMA to control timing for synchronous Using incomplete decoding as we have, there are few
MC6800 family devices such as the MC6821. VMA is memory blocks and each memory block is consumed,
used in conjunction with the 74LS139 decoder output even though the entire block may not have been need-
3 to enable the PIA ICs. ed. Remember that two 6116 RAMs required only 4
Recall that a decoder that translates memory ad- Kbytes of address space, but we gave them 16 Kbytes
dresses to chip select signals for port devices is called and simply wasted 12 Kbytes as additional addresses
memory-mapped I/O. In this system a port will be to which the RAMs respond. The RAM memory space
written to or read from in the same way as any other of 16 Kbytes was folded into four identical 4-Kbyte
memory location. The advantage of memory-mapped chunks. Incomplete decoding is, however, the easiest
I/O is that any instruction that references memory can to implement in real hardware. On the URDA MDS we
be used to input data from or output data to ports. Ina did not have to connect Al3 to the RAM, ROM, I/O
system such as this, for example, the single instruc- ports, or to the address decoder. This saves expense
tion ADD.B DO,(SCO14) could be used to input a byte of and time in construction of the URDA MDS and dollars
data from the port at address $CO14 and add the byte in its cost to the student.
to register DO. The disadvantage of memory-mapped
I/O is that some of the system memory address space is How the 68008 Microprocessor Accesses
used up for ports and is therefore not available for Memory and Ports
memory.
You can use memory-mapped I/O with any micro- Now that we have shown in detail how the 68000
processor, but some microprocessors—such as those accesses memory and port devices, we can show you
of the Intel 8086 family— allow you to set up separate how the 68008 does it.
address spaces for input ports and for output ports. The instruction set of the 68008 is identical to that
You access ports in these separate address spaces of the 68000, and the registers of the two are the same.
directly with the IN and OUT instructions. Having There are two major differences between the two devic-
separate address spaces for input and output ports is es. First, the 68008 provides only 20 address lines,
called direct I/O. The advantage of direct I/O is that whereas the 68000 provides 24 lines. Thus the 68008
none of the system memory space is used for ports. The can address only 2”, or 1,048,576, bytes. Second, and
disadvantage is that only the specialized IN and OUT most important, the 68008 memory is not divided into
instructions can be used to input or output data. Since two banks as the 68000 memory is. The 68008 has
68000 family processors all use memory-mapped I/O, only an 8-bit data bus, DO—D7. All the memory devices
we do not mention direct I/O again. and ports in a 68008 system are connected onto these
Notice that in several of the preceding discussions we eight lines. The 68008 memory then functions as a
indicated that some address lines were not used. This single bank of up to 1,048,576 bytes. Figure 7-19
is sometimes called incomplete decoding. In contrast, shows this structure. This single-bank structure
URDA could have built a system using complete de- means that a 68008 cannot read a word from or write a
coding, in which all the address lines played a part in word to memory in one machine cycle, as the 68000
selecting a device and one of its internal ports or can. The 68008 can read or write only bytes, so the
registers. Complete decoding often creates a system 68008 must always do two machine cycles to read or
with better expansion capabilities because more write a word. Address lines AO—A19 are used with
smaller memory blocks are provided. In a completely some decoders to select a desired byte in memory.
BERR/BR
(Note 2)
HALT/RESET
Asynchronous
Inputs
(Note 1)
FIGURE 7-20 (a) 68000 read-cycle timing diagram. (b) Simplified version of
68000 read-cycle timing diagram. (Reprinted with permission of Motorola Inc.)
(continued)
which stands for time data in must be valid before simplified diagram form.
clock goes low. The data sheet gives a value of 15 ns Now, as we told you in a previous paragraph, the
for this parameter as a minimum. Converting to the 2732 has a maximum ty; of 450 ns. Since this 450 ns
time for a 3.579-MHz clock yields 34 ns. is less than the 647 ns available, you know that the tacc¢
The time between the end of the tg,a,interval and the of the 2732 is acceptable for the URDA MDS operating
start of the tp;~, interval is the time available for getting with a 3.579-MHz clock. You still, however, must
the address to the memory and for the taco of the check if the values of t,, and to, for the 2732 are
memory device. You can determine this time by sub- acceptable.
tracting ty,y and tp, from the time for three clock If you look at the URDA MDS schematic, you should
cycles (end of SO to end of S6). With a 3.579-MHz clock, see that the CE inputs of the 2732s are connected to
each clock cycle is 279 ns. Three clock cycles then either ROM U or to ROM L. ROM L and ROM U are
total 837 ns. Subtracting a tq.ayof 156 ns and a ty, of generated from the AS, UDS, and LDS lines. The
34 ns leaves 647 ns available for getting the address to timing for these signals is similar to that for the
the 2732 and for its ty... To help you visualize these addresses in the preceding section. There are two main
times, Figure 7-23a, p. 193, shows this operation in differences. First, the AS and UDS lines are asserted
CLK
A1-A23
LDS/UDS
Data In
low in the middle of S2 and continue to be asserted for output data to the bus. This is fine for EPROMs and
a time labeled ‘‘14’’ (t,,). Looking at Figure 7-20 you ROMs. If you accidentally try to write to the EPROMs
can tell that the data must be ready (data—in starts) because of a programming error, the EPROMs will not
two full clock cycles after the AS and UDS/LDS signals change. If you accidentally write to the EPROMs, both
are asserted. This gives a starting time window of the EPROMs and the CPU will try to put data on the
558 ns. The second difference is that the AS and data bus. The data on the bus will be garbage, but
UDS/LDS signals are passed through gates and an neither the CPU nor the EPROMs will be harmed. Since
address decoder. If you look at the URDA MDS sche- no other device will be using the bus, there will be no
matic, you should see that the address decoding cir- harm done and the operation will be one big NOP,
cuitry that enables the 2732 passes the AS signal and except for the effect on the CPU status bits.
the Al4—A15 address information from the 68000 The output buffer-enabling line will normally be
through a 7432 NAND gate, through a 74LS139 decod- connected to the R/W CPU line. Since the EPROMs
er, and through another 7432 NAND gate. Looking should be read from but are not normally written to,
these up in a data catalog, you should find that the the connection is not necessary. However, if we look at
74LS139 causes a maximum delay of 40 ns and the the RAM, then the direction of the I/O buffers is very
7432 causes a maximum propagation delay of 15 ns important. A write will change the RAM contents.
before the enable signal gets to the 2732s. The propa- You have now checked all three 2732 parameters
gation delay of the 74LS139s and 7432s must be and found that all three are acceptable for an URDA
subtracted from 558 ns to determine how much time is MDS operating on a 3.579-MHz clock. No wait states
actually available for the t,, of the 2732. Subtracting need to be inserted when these devices are accessed, so
70 ns (15 ns + 40 ns + 15 ns) from 558 ns leaves 488 extra circuitry connected to DTACK is not necessary.
ns for the t,, of the 2732. Since the maximum tc, of the No additional wait states need to be introduced to slow
2732 is 450 ns, you know that this parameter is also the CPU while the memory devices catch up. Thus,
acceptable for an URDA MDS operating with a 3.579- from the EPROM’s point of view, DTACK can be assert-
MHz clock. Figure 7-23b shows this diagramatically. ed constantly.
The final parameter to check is to, of the 2732. Look up the 6116 in a data book and perform a
According to the URDA MDS schematics, the G (output timing analysis like the one just given to verify that the
enable) signal is tied low. This means that the output 6116 is fast enough to operate in the URDA MDS witha
buffers are always enabled on the 2732s. Therefore, we 3.579-Mhz clock. Use the timing diagram from Figure
know that to, will not hinder the 2732 operation. 7-21 to find the necessary write cycle times.
When the system power is turned on, G will be assert-
ed, which implies the output buffers will be powered up
and enabled. The buffers will be configured to drive the TROUBLESHOOTING A SIMPLE
data bus 120 ns after power on and will stay enabled 68000-BASED MICROCOMPUTER
until the system is powered down. The 2732s will
operate only when the main E is asserted. Whenever Now that you have some knowledge of the software and
the chip is enabled, however, the 2732s will attempt to the hardware of a microcomputer system, we can start
BERR/BR
(Note 2)
HALT/RESET
sahon
Asynchronous
Inputs
(Note 1)
teaching you how to troubleshoot a simple microcom- effective than random poking, probing, and hoping.
puter system such as an URDA MDS board. For this You don’t, for example, want to spend 2 h troubleshoot-
section assume that the microcomputer- or micro- ing a system and finally discover the problem is that
processor-based instrument previously worked. Later the power supply is putting out only 3 V instead of 5 V.
sections of this book will describe how the prototype of’ Use the following list of steps or a list of your own each
a microprocessor-based instrument is developed. time you have to troubleshoot a microcomputer.
The following sections describe a series of steps that
we have found effective in troubleshooting various 1. Identifying the Symptoms. Make a list of the
microcomputer systems. The first point to impress on symptoms that you find or those that a customer
your mind about troubleshooting a microcomputer is describes to you. Find out, for example, whether
that a systematic approach is almost always more the symptom is present immediately or whether
<= 5)
Clock Period ine)a wo
E
Clock Width Low
Clock Width High = nmoa
Lasa
14A? a) idth Low (Write)
espns — [os | |
52 |=
AS,lockDSHighWicthto Control
>I
9 High [sx [150 [ — [05 |— |
oy 16 i?) Bus High Impedance | ‘CHCZ | — | 80 | — | 70
| 177
Ue _|AS,DS
AS, DS High toR/W
High to RW High
High (Read)
(Read) Psern [4 [— [2% |— || —| os|
} 18" [Clock Highito RAVHigh |
18' Clock High to R/W High Pvonne [0 [70 [0 [| 0 | 0 | ns|
| 20" [Clock Highto
Clock High R/WLow
to R/W Low(Write)
(Write) | cnet — [70 |—|
|20A®
20a" |[AS LowtotoR/W
AS Low R/WValid (Write)
Valid (Write) Pasay [ — [20 |— |2 [=| 2 |[irsns|
EE21? Address Valid to R/W Low (Write) PACAVRL 6 |! 200] Sie) O pale OMe
2inT [FOVaidio RAWLow (rie) ____—_—_~+|
Ea ovat | 0 |— |60|— |3 |—| ns
22! [R/WLow ioDSLow (write) «sy
eee ast_| 0 | — | 0 |— | | —| ns
‘cLopo | — | 70 |ae Dee Ca een
23 | Clock Low to Data Out Valid (Write) ee
25% [AS,DSHightoDataOutvatawrte) | “SHDOT | | — |2 |— || —| ns
Data OutValdtoDSLow(write) | “Bost | wof— |e |— [i |—| rs
AS, DSHigh toDTACKHigh__—=—SS*; SHAH |0 |ea| 0 | 700|
AS, DS High to DTACK High
AS, DS High to Data in Invalid
(Hold Time on Read)
FIGURE 7-22 68000 system timing requirements: Vcc = 5.0 V dc + 5%; GND
= 0 V dc; T, = T, to T,, (continued on p. 192). (Reprinted with permission of
Motorola Inc.)
the system must operate for a while before it shows hot, do it gently, because a bad IC can get hot
up. If someone else describes the symptoms to you, enough to give a nasty burn if you keep your finger
check them yourself or have that person demon- on it too long.
strate the symptoms to you. This allows you to Check to see that all ICs are firmly seated in their
check if the problem is with the machine or with sockets and that the ICs have no bent pins. Vibra-
how the person is attempting to use the machine. tion can cause ICs to work loose in their sockets. A
bent pin may make contact for a while, but after
Making a Careful Visual and Tactile Inspection.
heating, cooling, and vibration, it may no longer
This step is good for preventive maintenance as
make contact. Also, inexpensive IC sockets may
well as for finding a current problem. Check for
oxidize with age and no longer make good contact.
components that have been or are excessively hot.
Check for broken wires and loose connectors. A
When touching components to see if any are too
40
39_| BG Wiath High
Clock Low to VMA Low
- ew pas [— [is [— [is [— fe
| ‘CLVML | — |
41 Clock Low to E Transition | ‘CLET | — |
42 =
mi 4 leat E)
46
a
ie)Oo =) n
4a
50
51 700
53 fo)ae S) 2)
54
56
56% s)e|e
ie)
= vu
is} ooO
seh
NOTES
1 For a loading capacitance of less than or equal to 50 picofarads, subtract 5 nanoseconds from the value given in the
maximum columns.
2 Actual value depends on clock period.
3 If #47 is satisfied for both DIACK and BERR, #48 may be 0 nanoseconds.
4 For power up, the MPU must be held in RESET state for 100 ms to allow stabilization of on-chip circuitry. After the
system is powered up, #56 refers to the minimum pulse width required to reset the system.
5 #14, #14A, and #28 are one clock period less than the given number for T6E, BF4, and R9M mask sets.
6 If the asynchronous setup time (#47) requirements are satisfied, the DTACK low-to-data setup time (#31)
requirement can be ignored. The data must only satisfy the date-in clock-low setup time (#27) for the following
cycle.
7 For T6E, BF4, and R9M mask set #11A timing equals #11, and #21A equals #21. #20A may be 0 for T6E, BF4, and
R9M mask sets.
8 When AS and R/W are equally loaded (+20%), subtract 10 nanoseconds from the values given in these columns.
9 The processor will negate BG and begin driving the bus again if external arbitration logic negates BR before asserting
BGACK.
10 The minimum value must be met to guarantee proper operation. If the maximum value is exceeded, BG may be
reasserted.
11 The falling edge of S6 triggers both the negation of the strobes (AS and xDS) and the falling edge of E. Either of these
events can occur first depending upon the loading on each signal. Specification #49 indicates the absolute maximum
skew that will occur between the rising edge of the strobes and the falling edge of the E clock.
thin film of dust may form on printed circuit board the appropriate pins of some ICs to make sure the
edge connectors and prevent them from making voltage is actually getting there. Check with a
dependable contact. The film can be removed by scope to make sure the power supplies do not have
gently rubbing the edge connector fingers with a excessive noise or ripple. One microcomputer that
clean, nonabrasive pencil eraser. If the microcom- we were called on to troubleshoot had very strange
puter has ribbon cables, check to see if they have symptoms caused by 2-V,,, ripple on the 5-V sup-
been moved around or stressed. Ribbon cables ply.
usually have small wires that are easily broken. If
you suspect a broken conductor in a ribbon cable, Making a Signal Roll Call. The next step is to make
you can later make an electrical check to verify a quick check of some key signals around the CPU
your suspicions. of the microcomputer. If the problem is a bad IC,
this can help point you toward the one that is bad.
3. Checking the Power Supply. From the manual for First, check if the clock signal is present and at the
the microcomputer, determine the power supply right frequency. If it is not, perhaps the clock
voltages. Check the supply voltage(s) directly on generator IC is bad. If the microcomputer has a
[Pt
works, then probably the CPU is good. Turn off the
power and put the CPU back in the bad system. If
the good system does not work with the CPU from
7432 delay 74LS139
max 15 ns delay
the bad system, then the CPU is probably bad.
max 40\ns TIME AVAILABLE FOR 2732 Remove it from the good system and bend the pins
CHIP ENABLE TIME so that you know it is bad. If the CPU seems bad,
toe = 558 ns — 15 ns — 40 ns —-15 ns = 488 ns you can try replacing it with the CPU you removed
(b) from the good system. If you do this, however, it is
important to keep track of where each IC came
FIGURE 7-23 Calculations of 68000 times available for from. To do this mark each IC from the good system
2732 EPROM access. (a) Time for tcc. (b) Time for te. with a wide-tip, water-soluble marking pen. The
good system can then be rebuilt by simply putting
clock but doesn’t seem to be doing anything, use an
back all the marked ICs. The marks on the ICs can
oscilloscope to check if the CPU is putting out
easily be removed with a damp cloth.
control signals such as R/W, UDS, and AS. Also,
The procedure from here on is to keep testing ICs
check the least significant data bus lines to see if
from the bad system until you find all the bad ICs.
there is any activity on the buses. If there is no
Make sure to turn the power off before you remove
activity on these lines, a common cause is that the
or insert any ICs. Be aware that more than one IC
CPU is stuck in a wait, hold, halt, or reset condition
may be bad. It is not unusual, for example, that an
by the failure of some TTL devices. To check this
ac power surge will wipe out several devices in a
out, use the manual to help you predict what logic
system. You can work your way out from the CPU to
level should be on each of the CPU input control
address latches, buffers, decoders, and memory
signals for normal operation. The RES input of the
devices. Often the specific symptoms point you to
68000, for example, should be high for normal
the problem group of ICs without your having to
operation. If an external logic gate fails and holds
test every IC in the system. If, for example, the
RES low, the 68000 will constantly be reset, and
system accesses ROM but doesn’t access RAM,
the buses will be held constant. If the 68000 HALT
suspect the RAM decoder. If a system uses buffers
input is held high, the 68000 bus activity will stop.
on the buses, suspect these devices. Buffers are
Connecting a scope probe to these lines will pull
high-current devices and they often fail.
them to ground, so you will see them as lows.
If there is activity on the buses, use an oscillo- Troubleshooting a System with Soldered-in ICs.
scope to see if the CPU is putting out control signals The approach described in the preceding para-
such as R/W and AS. Also check with your oscillo- graphs works well if the system ICs are all in
scope to see if select signals are being generated on sockets and you have two identical systems. How-
the outputs of the ROM, RAM, and port decoders as ever, since sockets add to the cost and unreliability
the system attempts to run its monitor or basic of a system, many small systems put only the CPU
program. If no select signals are being produced, and ROMs in sockets. This makes your trouble-
then the address-decoding circuitry may be bad or shooting work harder, but not impossible.
the CPU may not be sending out the correct ad- Again, if you
have two identical systems, one that
dresses. works and one that doesn’t work, you can attempt
After a little practice you should be able to work to run the monitor or basic system program on
through the previously described steps quite quick- each and compare signals on the two. A missing or
ly. If you have not located the problem at this point, wrong signal may point you to the bad IC or ICs.
the next step for a system with its ICs in sockets is If the system works enough to read some instruc-
ADJUSTABLE
THRESHOLD DISPLAY voi a|
COMPARATORS MEMORY SCAN
CIRCUIT
D! spUAY
TRIGGER
WORD
COMPARATOR
AND
TRIGGER WORD TRIGGER
SELECTION CIRCUITRY
SWITCHES
each time a pulse from an internal clock oscillator seeing the actual pattern of 1s and Os on signal
occurs. If, for example, you set the frequency of the lines, but a hexadecimal listing such as that in
internal clock to 50 MHz, the analyzer will take a Figure 7-26c makes it easier to recognize if a
sample every 20 ns. microcomputer is putting out addresses in the right
If the analyzer is receiving either an internal or sequence. Some analyzers, such as the Tektronix
an external clock, it will be continuously taking 318, allow you take a series of samples from a
samples of the input data and storing these sam- functioning system, store these samples in a sec-
ples in the internal RAM. A trigger signal tells the ond memory in the analyzer, and then compare
analyzer when to display the samples stored in the these samples with a series taken from a nonfunc-
RAM. As shown by the block diagram in Figure tioning system. The dual listing in Figure 7-26c is
7-25, some external signal can be used to trigger an example of this. This feature is quite helpful.
the analyzer, or the trigger signal can come from a Now that you have an overview of how a logic
word recognizer in the analyzer. The word recog- analyzer works, here’s a few hints on how to use
nizer compares the binary word on the input signal one for troubleshooting a 68000 microcomputer.
lines with a word you set with switches or a Connect the analyzer data inputs to the address
keyboard. When the two words match, the word and data bus lines from the CPU. For a 68000,
recognizer sends out a trigger signal. Since the connect the external clock input of the analyzer to
analyzer is continuously taking samples, you can the 68000 DTACK pin. Look at a 68000 timing
set the analyzer for a pretrigger display, a center- diagram such as the one in Figure 7-20 to see at
trigger display, or a posttrigger display. For an which edge of the DTACK signal valid addresses are
analyzer that displays 256 samples, pretrigger present on the buses. Set the analyzer to clock on
means that the display will show the 256 samples this edge. Set the analyzer to trigger on address
that were taken just before the trigger occurred. For $0000, the first address output by the 68000 after
center-trigger mode, 128 samples taken before the a reset. Set the analyzer display format for pretrig-
trigger and 128 samples taken after the trigger will ger display. Tell the analyzer to doa trace and press
be displayed. Posttrigger mode means that the the 68000 system reset button. The display on the
analyzer will take 256 more samples after the analyzer should show you the sequence of address-
trigger and display them. es output after a reset. Use the system monitor
Figure 7-26, p. 196, shows some of the formats in listing to see if the displayed sequence is correct. If
which a logic analyzer can display the samples it is not, look for address bits that should change
stored in its RAM. The series of displayed data but don’t. A common failure mode for buffers is
samples is often called a trace. The timing diagram that an input or an output will short to V,, or to
format in Figure 7-26a is most useful when making ground, which prevents that line from changing.
time measurements with an internal clock. A bina- If the address sequence seems reasonable, con-
ry listing such as that in Figure 7-26b is useful for nect the analyzer external clock input to the 68000
ay
:
TT
7
6)
occa
ced
nent
Sali
oe
Iee
a
What is the purpose of the DTACK signal in a 16. Briefly describe the function of the 6821,
68000 system? The BERR signal? 74LS139, and 6116 devices in the URDA MDS.
Describe the sequence of events on the 68000 17. A group of signal lines on a schematic is said to be
data/address bus, the AS line, the UDS/LDS line, in zone C4. What is the meaning of this?
and the R/W line as the 68000 fetches an instruc-
18. What is the difference between a connector identi-
tion word.
fied with a J and a connector identified with a P?
What logic levels will be on the 68000 R/W and AS
19. Describe the purpose of the many small capaci-
lines when the 68000 is doing a write to a memory
tors connected between V,, and ground on micro-
location? A read from a port?
computer printed circuit boards.
What is the major difference between a 68000
20. A 74LS139 decoder has its two SELECT inputs
operating synchronously and a 68000 operating
connected to Al4 and A13 of the system address
asynchronously?
bus. It does not use A15 (presume that A15 is 0).
Describe the response a 68000 will make when its AS and UDS/LDS are combined using a NAND
RESET (RES) input is asserted low. gate, then combined with R/W using and AND
gate, and then connected to the enable line (E).
Why are buffers often needed on the address,
Use an address decoder worksheet to determine
data, and control buses in a microcomputer sys-
what four ROM address blocks the decoder out-
tem?
puts will select. Why would R/W be used as one of
a. How is a 68000 forced to add a wait state? the enables on the ROM decoder?
b. At what point in a machine cycle does a
21; Show a memory map for the ROMs in problem 20.
68000 enter a wait state?
c. How long is a wait state? 22. Use an address decoder worksheet to help you
d. How many wait states can be inserted? draw a circuit to show how another 74LS139 can
e. Why would you want the 68000 to insert a be connected to select one of four 1-Kbyte RAMs
wait state? starting at address $8000.
10. What is the function of the 68000 R/W signal? 23. Why are there actually many addresses that will
select one of the port devices connected to the
11. What does an arrow labeled with a number (often
address decoder in Figure 7-16?
going from a transition on one signal waveform to
another transition) tell you? 24. Describe memory-mapped I/O and direct I/O. Give
the main advantage and main disadvantage of
12. What are the functions of the UDS and LDS lines
each.
of the 68000 CPU?
255 a. Why is the 68000 memory set up as two
13. How does a register pack look on a schematic?
byte-wide banks?
Most microprocessors allow normal program execution pick up the hammer again, and continue your con-
to be interrupted by some external signal or by a struction where you left off. The phone interrupted
special instruction in the program. When a micro- your task, you serviced the interrupt (i.e., answered
processor is interrupted, it stops executing its current the phone), and then you went back to your task,
program and calls a routine that “‘services”’ the inter- resuming it at just the point where you left it, even in
rupt. At the end of the interrupt-service routine, exe-
the middle of hammering in a nail.
cution is usually returned to the interrupted program. As a different example, suppose the mail arrives
This chapter shows you how the 68000 family mem- while you are building your bookshelf. Normally you
bers respond to interrupts, how to write interrupt- won't leave things immediately but will wait until you
service routines, and how interrupts are used in a come to a normal break in your work, possibly when
variety of applications. the bookshelf is finished. Then you go get the mail. The
mail arrival does not generate an interrupt because it
does not require immediate attention. It can wait in the
mailbox until you are ready to get it. This latter case
OBJECTIVES corresponds to a polled I/O, where you check the
At the conclusion of this chapter, you should be able to mailbox for mail at your convenience. The phone
corresponds to an interrupt I/O, where you have to
1. Describe the interrupt response of a 68000 family answer the phone within a short amount of time or the
processor. calling party will hang up and you won't get the phone
call. With a computer, polled I/O can be used when the
2. Initialize a 68000 interrupt-vector (pointer) table. 1/O events do not require immediate attention—that
3. Write interrupt-service routines. is, when you can afford to wait for the event, doing
nothing but watching for it. Interrupt I/O services
4. Describe the operation of an 8254 programmable higher-priority events that require the CPU’s immedi-
counter/timer and write the instructions neces- ate attention. :
sary to initialize an 8254 for a specified applica- A 68000 exception happens when some abnormal
tion. condition occurs that requires the CPU’s immediate
processing attention. An exception causes the CPU to
5. Describe the operation of an 8259A priority-inter-
stop executing the program from which it is currently
rupt controller and write the instructions needed
operating and to begin executing an exception-
to initialize an 8259A for a specified application.
handling routine. 68000 exceptions can be generated
by either internal or external causes. An exception
caused externally is usually termed a hardware inter-
68000 INTERRUPTS AND INTERRUPT rupt. An exception caused internally is sometimes
RESPONSES called a software interrupt. We will frequently use the
terms interchangeably. When they need to be distin-
Overview guished, the differences will be explicitly noted.
Interrupts provide a mechanism whereby the CPU can The externally generated interrupts can occur be-
stop what it is currently doing (executing the mainline cause of bus errors (asserting BERR), because of reset
program) and do some processing required by a special requests, or because a device asserts a combination of
external or internal event. As an analogy, suppose you the IPLO, IPL1, and IPL2 lines. The third case, in which
are in the basement building a bookcase and the phone some external device attempts to cause a CPU excep-
rings. Typically, you put down your hammer or saw tion by asserting an interrupt line, is often used as the
and run up the stairs, trying to get to the telephone “restricted’’ definition of an interrupt.
before the person who is calling hangs up. Once you At the end of each instruction cycle, the 68000
finish talking on the phone, you go back downstairs, checks to see if any interrupts have been requested. If
200
an interrupt has been requested, the 68000 responds Soe =
to the interrupt by stepping through the following
Higher
series of major actions. Addresses
Vector Assignment
Number(s)
24 Spurious Interrupt
25 Level 1 Interrupt Autovector
26 Level 2 Interrupt Autovector
D7 Level 3 Interrupt Autovector
28 Level 4 Interrupt Autovector
jm) Level 5 Interrupt Autovector
30 Level 6 Interrupt Autovector
31 Level 7 Interrupt Autovector
32-47 TRAP Instruction Vectors
*Vector numbers 12, 13, 14, 16 through 23, and 48 through 63 are
reserved for future enhancements by Motorola. No user peripher-
al devices should be assigned these numbers.
REPEAT
get INPUT VALUE
divide by scale factor
IF result valid THEN
store result as scaled value
ELSE store zero
UNTIL all values scaled
Save registers
Set error flag
Restore registers For the example program here, we have four word-
Return to mainline sized hexadecimal values stored in memory. We want
to divide each of these values by a word-type scale
(b) factor to give a word-type scaled value. If the result of
FIGURE 8-3 Algorithm for divide by zero program the division is valid, we want to put the scaled value in
example. (a) Mainline program. (b) Interrupt-service an array in memory. If the result of the division is
routine. invalid (too large to fit in the 16-bit result register), we
want to put the unscaled value in the array for that
scaled value. If the division fails (i.e., division by zero)
we want to put the best approximation to infinity we
register to the stack. The 68000 then gets the starting can in the array of scaled values. We will use SFFFF as
address of the exception-handling routine from the the closest we can find to infinity. Figure 8-3 shows the
type 5 locations in the exception vector table. As you algorithm for this program in pseudocode. As shown in
can see in Figure 8-2, it gets the new value for PC from Figure 8-3a, the mainline part of this program gets
addresses $0020 through $0023. After the starting each 16-bit value from memory in turn and divides
address of the routine is loaded into the PC, the 68000 that value by the scale factor. If the result of the
fetches and executes the first instruction of the service division is too large to fit in the 16-bit quotient area of
routine. the destination data register, then the 68000 will leave
At the end of the interrupt-service routine, an RTE the destination operand unaffected. If the divisor is 0,
instruction will be used to return execution to the then the 68000 will do a type 5 trap immediately after
interrupted program, restoring the status register in the divide instruction finishes.
the process. The RTE instruction pops the stored value Figure 8-3b shows the algorithm for our type 5
of the status register off the stack and increments the exception service routine. The main function of this
stack pointer by 2. This restores the status register of routine is to set a flag that will be checked by the
the interrupted mainline program, including the con- mainline program. The flag in this case is not one of
dition codes, as they were before the exception oc- the flags in the 68000 status register. The flag here isa
curred. It then pops the stored value of the PC off the bit in a memory location we set aside for this purpose.
stack and increments the stack pointer by 4. To sum- In the actual program we give this memory location the
marize, then, RTE returns execution to the interrupted name BAD—DIV—FLAG. At the end of the exception
program and restores the status register to the state it service routine, we return to the interrupted mainline
was in before the interrupt. Now that we have de- program.
scribed the type 5 response, we can show you how to After the division in the mainline program, we check
write a program to handle this interrupt. to see if the result of the division is valid. If the result is
good, we store it in the correct place in the scaled
values array in memory. If the result is bad, we leave
A 68000 Interrupt Program Example SFFFF (our approximation of infinity) in that place in
the scaled values array. To decide if a result is valid or
DEFINING THE PROBLEM AND WRITING THE
not, we check the BAD_DIV_—FLAG. If the division had
ALGORITHM
a zero divisor, then the 68000 will have done a type 5
Instead of jumping directly into the program, let’s use trap, and our exception service routine will have set
this example to review how you go about writing any the BAD_DIV—FLAG to a 1. If the result of the division
program. is valid, then the 68000 will not do the trap, and the
As described in Chapter 3, you start by carefully BAD—DIV—FLAG will be 0.
defining the problem that you want it to perform. Part The sequence of operations is repeated until all the
of this step is to determine the amount and types of values have been scaled. We use a register to keep track
data with which the program is to work. of which input value is being operated on at a particu-
4
ZERO_ DIV_VEC: .
8 MOVE.L ZERO_DIV_PTR,-(A7) \
RTS #
ROM 12
16
"hard"
vectors 20 ZERO_ DIV_VEC
a
4
“Ne
4
4
7
4
Indirection
Routines
Service
Routines ita
‘e MOVE.L (A7)+,D0 —/
ZERO_ DIV_PTR: BAD_DIV Se RTE ee
68000 Program
ABSTRACT This program scales some data values by division.
7
PeRHGISTERS USED: AQ ... pointer to array of data values
? = Al eee pointer to array of scaled data values
; DO ... one value
; Dl ... sample loop counter
; PORTS USED : none
; PROCEDURES : BAD_DIV, a division by 0 exception handler
;
, alr 3-89
Mainline code
INITIALIZATION LIST
se
we
so
EXT_VALUE:
Zr
we
~e
=e get INPUT VALUE
CLR.L DO
MOVE.W (A0)+,D0
: divide by scale factor
DIVU D1,D0O
; IF result valid THEN
CMPI.B #$01,(BAD_DIV_FLAG)
BEQ BAD
; store result as scaled value
MOVE.W DO, (Al)+
JMP SKIP1
; ELSE store zero
MOVE.W #SFFFF, (Al) +
i UNTIL all values scaled
MOVE.B #0,(BAD
DIV FLAG) + reset the division by 0 flag
DBGT D1,NEXT_VALUE ; dec counter and loop if > 0
(a) (continued)
FIGURE 8-5 68000 assembly language program for divide by zero example.
(a) Mainline. (6) Exception service routine, p. 206.
205
» Division by 0 exception handling routine
BAD DIV:
4 Save registers
MOVE.L DO0O,-(A7)
; Set error flag
MOVEQ #1,D0
MOVE.B DO, (BAD _DIV_FLAG)
= Restore registers
MOVEM.L (A7)+,D0
: Return to mainline
RTE H return to the interrupted program
END
(b)
FIGURE 8-5 (continued)
Once you have the algorithm and the initialization then declare the program starting address as $4000.
list for a program, the next step is to start writing the Part of the 68000 exception response is essentially a
instructions for the program, so now let’s look at the call to the exception service routine. In any program
assembly language program for this problem. that calls a subroutine (or causes one to be called by
causing a trap), we have to set up a stack to store the
return address and parameters passed to and from the
ASSEMBLY LANGUAGE PROGRAM AND routine. The next section of the main program initial-
EXCEPTION HANDLING ROUTINE izes a stack segment called STACK—HERE. It also
Figure 8-5 shows our 68000 assembly language pro- initializes the stack pointer to the next location above
gram for the mainline and for the type 5 interrupt- the stack with the statement LEA STACK—TOP,A7.
service routine. You can use many of the parts of these Remember from the examples in Chapter 5 that this
when you write your own interrupt programs. label is used to initialize the stack pointer to the next
First, examine the data declarations at the end of the location after the top of the stack.
program. The input values are words, so we use a The rest of the program initialization involves setting
DC.W directive to declare these four values. The scaled up an address register to point to the input array (AO)
values will also be words, so we use the DS.W directive and a second address register to point to the scaled
to set aside four locations for these. As the program value array (Al). The last part of the initialization loads
executes, the results will be written into these loca- the initial value of our loop counter to its starting
tions. We will be using the loop counter as our scale value, 3. We will count this value down to O and scale
factor for this example. It will be held in a data register each input value accordingly, so the last scaling opera-
and counted down from 3 to 0. We don’t need a memory tion will cause a zero-divide exception.
location for this. This means that the scaling will use a The next three instructions are needed to place the
different scale factor for each input value. We reserve a address of the BAD_DIV routine in the type 5 location
byte for the bad division flag using a DC.B directive. in the soft exception vector table. Recall from the
Finally, the stack area is reserved in the normal previous discussion that we cannot change the low
fashion using a DS.W 40 directive to declare the memo- memory EPROM hard vector values, but we can
ry area of 40 words and a DS.W 0 directive to associate change the high-memory RAM vector values. First we
a label with the top of the stack. load up the address of the bad division exception-
At the start of the mainline program in Figure 8-5, handling routine using an LEA BAD_DIV,AO instruc-
we use an EQU declaration to define the address of the tion. We then move the address into a data register so
soft exception vector for the zero-divide exception. This that we can store it back into memory at the soft
will be used later in the program when we set up the zero-divide exception vector location. The type 5 trap
vector to point to our exception-handling routine. We soft vector is at location $7FC4. Since we have declared
NEXT: DBGE D1,AGAIN ; go send next char if not done with string
ANDI.W #S$FFFE,SR ; clear carry flag to indicate char sent
EXIT?
NOP ; continue with mainline program
NOP
RTS
END
the correct result for the sum of unsigned binary 2’s complement form. The result then actually repre-
numbers, but it is not the correct signed result. For sents —67 decimal, which is obviously not the correct
signed operations, the 1 in the most significant bit of result of adding +108 and +89.
the result indicates that the result is negative and in There are two major ways to detect and respond to an
* Although a vector number is one byte, both data strobes are asserted due to the microcode used for exception processing
The processor does not recognize anything on data lines D8 through D15 at this time
A On aid aat/a
Sa
IPLO-IPL2
ean
wo, oe inn
LAST BUS CYCLE OF INSTRUCTION STACK IACK CYCLE STACK AND
(READ OR WRITE) l=—— PCL —>|-—— (VECTOR NUMBER ——+|=—— VECTOR |
(SSP) ACQUISITION) FETCH
ed (the 68000 can’t do it during normal operation). A may be any valid combination of register values, mem-
bus error indicates that some I/O device or memory is ory values, and instruction code displacements or
simply not responding. These are serious problems addresses. The instruction register contains the code
from the CPU’s viewpoint, and help from an exception- word on which the CPU was operating internally when
handling routine is required. the exception occurred. The R/W bit indicates whether
During group O-—type exceptions, the CPU pushes a read or a write was occurring. A 1 implies a read. The
more information onto the system stack than it does I/N bit indicates whether or not the CPU was process-
for group 1 and 2 exceptions. This additional informa- ing an instruction. A 1 indicates that it was not, which
tion consists of four additional words of data, including typically means the CPU was fetching a new instruc-
the relevant access address, the instruction register, tion to execute. The function code bits indicate the
and some status bits describing the operation that was state of the FCO, FC1, and FC2 CPU status lines when
occurring when the exception occurred (R/W, I/N, and the exception occurred. This information is not suffi-
function code). Figure 8-9 shows the organization and cient to restart the interrupted operation, but it is very
order of information pushed during a group O excep- useful in debugging the situation.
tion. The program counter and status register are the When a type O trap occurs, the CPU will begin
same as we saw during the group 1 and 2 exceptions. exception processing within two clock cycles, termi-
The access address was the effective address being nating the operation currently in process if necessary.
used by the CPU when the exception occurred. De- The status register is copied internally, the supervisor
pending on the addressing mode in use by the particu- state is entered, and tracing is suppressed (S bit assert-
lar instruction being executed, the effective address ed, T bit off). The appropriate vector number is gener-
15, 14 1) 2 ail 10 9 8 ve 6 5) 4 3 2 1 0
SSP
STATUS REGISTER
One of the most common uses of interrupts is to relieve FIGURE 8-10 Circuit modifications for URDA MDS
a CPU of the burden of polling. In Chapter 4 we showed interrupt input.
you how ASCII characters can be read in from an
encoded keyboard on a polled basis. Figure 4-18 shows
the circuit connections, and Figure 4-19 shows the
algorithm and program for this. To refresh your memo- by the CPU. Instead we have connected the key strobe
ry, polling works as follows. output to the 74148 I1 input. The 74148 output is, in
The strobe, or data-ready, signal from some external turn, connected to the CPU IPLO line (as well as other
device is connected to an input port line on the micro- lines). When a key on the ASCII keyboard is pressed,
computer. The microcomputer uses a program loop to the keyboard circuitry sends out the ASCII code for the
read and test this port line over and over until the pressed key on its eight parallel data lines, and it
data-ready signal is found to be asserted. The micro- asserts the key-pressed strobe line. The key-pressed
computer then exits the polling loop and reads in the strobe assertion causes the I] input of the 74148 to be
data from the external device. Data can also be output asserted, which causes the CPU’s IPLO line to be
on a polled basis. asserted. This causes the 68000 to do a group 1
The disadvantage of polled input or output is that interrupt. Now let’s look at the hardware and software
while the microcomputer is polling the strobe or data- considerations for this interrupt example.
ready signal, it cannot easily be doing other tasks. In The hardware considerations for this example are
systems where the microcomputer must be doing quite simple. The IPLO input requires a sustained low
many tasks, polling is a waste of time, so interrupt signal for assertion; with the circuit connections
input and output is used. In this case the data-ready, or shown in Figure 8-10, this will be produced when a key
strobe, signal is connected to an interrupt input on the on the ASCII keyboard is pressed. Since we are using
microcomputer. The microcomputer then goes about only one interrupt here, we are not concerned about
doing its other tasks until it is interrupted by a data- priorities. In response to its IPLO input being asserted
ready signal from the external device. An interrupt- and if the CPU priority level is 0 (i.e., the CPU interrupt
service routine can read in or send out the desired data priority mask in the status register is 000), the 68000
and, when finished, return execution to the interrupt- automatically does a group 1 interrupt response. No
ed program. external hardware is needed to insert the interrupt
For our example here we will connect the key- type.
pressed strobe to the interrupt inputs of the 68000 on The software considerations require a little more
an URDA MDS. We will use autovectoring because it thought, but their answers are very similar to those for
does not require an external hardware device to insert the divide by 0 example in a previous section. At the
the exception vector number. start of the mainline we need to load address $7FF4
Refer to the 68000 schematic (Figure 7-11), which with the soft vector table address of the level 1 inter-
shows a 74148 multiplexer IC (IC3 in C3) connected to rupt-service routine. Since any interrupt response
the IPL inputs to the CPU. The inputs IO-I7 of the uses the stack, we need to set up a stack. Assuming
74148 can be used to cause autovectored interrupts on that we are going to read in the ASCII characters from
the 68000. Interrupt autovectors 2—5 are used by the the keyboard and put them in an array in memory, we
two 6821s on the MDS, so we will use interrupt need to set up a data area for the array. In the actual
autovector 1 for this example. When only input I1 of code section of the mainline, we need to initialize the
the 74148 is asserted, the multiplexer IC in turn stack pointer. Figure 8-11, pp. 216-17, shows the
asserts IPLO and does not assert IPL1 and IPL2. instructions for doing all this. Another important thing
Figure 8-10 shows how we modified the circuitry of to do in the start of the mainline program is to initialize
Figure 4-18 for our example here. We have no longer a pointer to the start of the array, where the ASCII
connected the key strobe line to a status bit to be polled characters will be put as they are read in. The state-
ce
Ne
Me
Te
he
Se
te
~e alr 3-89
ORG $4000 ; start the code at $4000
; INITIALIZATION
LEA STACK_ TOP ,A7 iH initialize user stack pointer to top of stack
ment ASCII-POINTER DC.L ASCII_-STRING in the Figure 8-11 also shows the interrupt-service routine
data segment in Figure 8-11 sets aside a long-word for this example. The comments for the ISR express its
location in memory and initializes that location with algorithm fairly clearly. After saving AO, DO, and D1 on
the address of the start of the array we declared to put the stack, we check to see if all characters have been
the ASCII characters in. In the interrupt-service rou- read. If CHARCNT is zero, then we do not read in any
tine we get this pointer, use it to store a character, and characters. If CHARCNT is not zero, we copy the array
increment it to point to the next location in the array. pointer from its named memory location, ASCII_
Since this pointer is stored in a named memory loca- POINTER, to AO. We then read in the ASCII character
tion, it can be accessed easily by the ISR, no matter from the port to which the keyboard is connected and
when the interrupt occurs in the mainline program. mask the parity bit of the ASCII character. The
Next we enable interrupts by setting the CPU priority MOVE.B D1,(AO)+ instruction next copies the ASCII
to 0 using an AND to SR instruction. Finally, the character to the memory location pointed to by AO and
HERE: BRA HERE instruction at the end of the main- increments AO to point to the next available location.
line program simulates a complex mainline program To get the pointer ready for the read and store opera-
that the 68000 might be executing. The 68000 will tion, we store the incremented pointer back into mem-
execute this instruction over and over until an inter- ory at the ASCII_- POINTER location. Finally, our work
rupt occurs. When an interrupt occurs, the 68000 will done, we restore D1, DO, and AO and return to the
service the interrupt and then return to execute the mainline program.
HERE: JMP HERE instruction over and over again Sitting in a HERE: JMP HERE loop waiting for an
until the next interrupt. interrupt signal may not seem like much of an im-
MOVE.B (CHARCNT)
,DO ; get character count
LEA (ASCII POINTER) ,AO ; get the current string pointer
MOVE.B D1, ($7FF4) ; read in a character
ANDI.B #$7F,D1 ; mask off the parity bit
MOVE.B D1, (A0O)+ ; move character to buffer and increment
; pointer
MOVE.L AO,(ASCII_POINTER) ; save incremented pointer in memory
SUBQ.B #1,D0 ; decrement counter
MOVE.B- DO, (CHARCNT) ; save decremented counter in memory
BNE NOTDONE “i fe (readvalle 100 chars)
MOVE.B' #$01, (KEYDONE) ; set last character flag
JMP Jay, Oey ; else
NOTDONE:
MOVE.B #$00, (KEYDONE) ; clear flag (not done)
Jap cacges
MOVEM.L (A7)+,DO0-D1/A0O_ j; restore DO,D1, and Al
END
provement over polling the key-pressed strobe. Howev- the 68000. The interrupt-service routine for that input
er, in a more realistic program the 68000 would be can simply increment the board count stored in a
doing many other tasks between keyboard interrupts. named memory location.
With polling, the 68000 would not easily be able to do To detect a board coming out of the machine, we use
these other tasks. an infrared LED, a phototransistor, and two condition-
ing gates, as shown in Figure 8-12, p. 218. The LED is
USING INTERRUPTS FOR COUNTING AND positioned over the track where the boards come out,
TIMING COUNTING and the phototransistor is positioned below the track.
Asa simple example of the use of an interrupt input for When no board is between the LED and the phototran-
counting, suppose that we are using a 68000 to control sistor, the light from the LED will strike the phototran-
a printed-circuit-board-making machine in our com- sistor and turn it on. The collector of the phototransis-
puterized electronics factory. Further suppose that we tor will then be low, as will the interrupt input to the
want to detect each finished board as it comes out of 74148, and the IPL lines on the 68000 will not be
the machine and to keep a count of finished boards so asserted. When a board passes between the LED and
that we can compare this count with the number of the phototransistor, the light will not reach the photo-
boards fed in. This way we can determine if any boards transistor, and it will turn off. Its collector will go high,
were lost in the machine. as will the signal to the 74148; in turn, the IPLO input
To do this count on an interrupt basis, all we have to to the 68000 will be asserted. The 74LS14 Schmitt
do is detect when a board passes out of the machine trigger inverters are necessary to turn the slow rise-
and send an interrupt signal to an interrupt input on time signal from the phototransistor collector into a
Dp
N 4LS14 {74L$14
INFRARED LED v
.
ae
= BOARD PHOTOTRANSISTOR
signal that meets the risetime requirements of the interrupts that occur, we will then know how many
74148 input. When the 68000 senses that the IPLO seconds have passed.
line is being asserted, it automatically does an inter- Here’s how the programming is done for this applica-
rupt response. As we mentioned before, all the inter- tion. In the mainline we set aside a memory location for
rupt-service routine has to do in this case is increment the seconds’ count and initialize that location to the
the board count in a named memory location and number of seconds that we want to count off. In this
return to running the machine. This same technique case we want 4 min, which is 240 decimal, or SFO,
can be used to count people going into a stadium, cows seconds. Each time the 68000 receives an interrupt
coming in from the pasture, or just about anything else from the 555 timer, it executes the interrupt service
you might want to count. routine for the level 1 interrupt. In this ISR we decre-
ment the seconds’ count in the named memory loca-
TIMING tion and test to see if the count is down to zero yet. If
In Chapter 4 we showed how a delay loop could be used the count is zero, we know that 4 min have elapsed, so
to set the time between microcomputer operations. In we reload the seconds’ count memory location with
that example we used a delay loop to let us take in data SFO and call the routine that reads the pH of the
samples at 1-ms intervals. The obvious disadvantage solution and takes appropriate action if the pH is not
of a delay loop is that while the microcomputer is stuck correct. If the seconds’ count is not zero, execution
in the delay loop, it cannot easily be doing other useful
work. In many cases a delay loop would be waste of the
microcomputer’s valuable time. For most microcom-
puter timing, an interrupt approach is much more
efficient.
Suppose, for example, that in our 68000-controlled +5 V +5 V from 6821
printed-circuit-board machine we need to check the
PH of a solution approximately every 4 min. If we used 100 KOhm pe
a delay loop to count off the 4 min, either the 68000
wouldn't be able to do much else, or we would have to
do some difficult calculations to figure out at what
points in the program to check the pH. 470 kOhm
To solve this problem, all we have to do is connect a
simple 1-Hz pulse source to an interrupt input, as
shown in Figure 8-13. This 555 timer circuit is not
very accurate, but it is inexpensive, and it is good
5
enough for this application. We connected the timer 1 microF T 0.01 microF T
output to the 68000 interrupt input (through the
74148), as you might do to demonstrate this concept
on an URDA MDS board. The 555 timer will send an
interrupt signal to the 68000 IPLO input approximate- FIGURE 8-13 Inexpensive 1-Hz pulse source for
ly once every second. If we simply count the number of interrupt timing.
INITIALIZE
INTERRUPT POINTER TABLE
STACK AND STACK SEGMENT POINTER
DATA SEGMENT
SECONDS COUNT TO 240 DECIMAL
WAIT FOR INTERRUPT
SAVE REGISTERS
DECREMENT SECONDS COUNT
IF SECONDS COUNT = O THEN
RELOAD SECONDS COUNT WITH 240 DECIMAL
CALL pH READ PROCEDURE
RESTORESREOTSP ERS
RETURN TO MAINLINE
ELSE RESTORE BREGTSHERS
RETURN TO MAINLINE
OUT 0
A Software Programmable Timer/Counter: the
Intel 8253 and 8254
Because of the many tasks for which they can be used
n CEA
in microcomputer systems, it is very important that RP
ma
REGISTER
these discussions when you have a specific problem to OUT 2
solve.
Another important point to make to you here is that
the discussions of various devices throughout the rest
of this book are not intended to replace the manufac- FIGURE 8-15 8254 internal block diagram. (Intel
turers’ data sheets for the devices. Many of the pro- Corporation)
grammable peripheral devices we discuss are So versa-
tile that each requires almost a small book to describe
all the details of its operations. The discussions here
are intended to introduce you to the devices, show you
what they can be used for, and show you enough to be software programmable. To program the device
details about them so that you can do some real jobs you send count bytes and control words to the device,
with them. After you become familiar with using a just as you would send data to a port device.
device in some simple applications, you can read the If you look along the left side of the block diagram in
data sheets to learn about further features of the Figure 8-15, you will see the signal lines used to
devices. interface the device to the system buses. A little later
we show how these are actually connected in a real
system. The main points for you to note about the 8254
Basic 8253 and 8254 Operation at the moment are that it has an 8-bit interface to the
data bus, it has a CS input, which is asserted by an
The Intel 8253 and 8254 each contain three 16-bit address decoder when the device is addressed, and it
counters, which can be programmed to operate in has two address inputs, AO and Al, to allow you to
several different modes. The 8253 and 8254 devices address one of the three counters or the control word
are pin-for-pin compatible, and they are nearly identi- register in the device.
cal in function. The major differences are as follows: The right side of the 8254 block diagram in Figure
8-15 shows the counter inputs and outputs. You can
1. The maximum input clock frequency for the 8253 apply a signal of any frequency from dc to 8 MHz (2.6
is 2.6 MHz, and the maximum clock frequency for MHz for the 8253) to the counter clock inputs, labeled
the 8254 is 8 MHz (10 MHz for the 8254-2). CLK in the diagram. The GATE inputs on each counter
2. The 8254 has a read-back feature, which allows allow you to start or stop that counter with an external
you to latch the count in a counter and the status of hardware signal. If the GATE input of a counter is high
the counter at any point. The 8253 does not have (1), then the counter is enabled for counting. If the
this read-back feature. GATE input is low, the counter is disabled. The resul-
tant frequency or pulse from each counter appears on
To simplify reading of this section, we refer only to its OUT pin. Now let’s see how a programmable periph-
the 8254. However, you can assume that the discus- eral device such as the 8254 is connected in a system.
sion also applies to the 8253 except where we specifi-
cally state otherwise. SYSTEM CONNECTIONS FOR AN 8254
As shown by the block diagram of the 8254 in Figure TIMER/COUNTER
8-15, the device contains three 16-bit counters. In An 8254 is a very useful device to have in a microcom-
some ways these counters are similar to the TTL puter system, but, in order to keep the cost down, the
presettable counters we reviewed in Chapter 1. The big URDA MDS was not designed with one on the board.
advantage of these counters, however, is that you can For an actual example of how an 8254 is connected ina
load a count in them, start them, and stop them with system, we show you here how to add one to an URDA
instructions in your program. The device is then said MDS board. If you use wire-wrap headers for connec-
N
aS
im
IC4A 748139 n
= 8259A #1
IC4B 748139 ty | G2B oo
@
A7
Ab
54
LDS
A4
A3
At
DO—D7
RW
AS
FCO
FC1 || pulse
FC2 | ]generate
Al d
A2 pulse
8259 INT
A2
D8—D15
FIGURE 8-16 Circuit showing how to add an 8254 and 8259A(s) to an URDA
MDS board.
8259A #1
BFO8 8259A #2
~N
FIGURE 8-17 Truth table for 74LS138 address decoder in Figure 8-16.
4. Inthe data sheet for the device, look up the format COUNTER LATCH COMMAND (SEE READ
OPERATIONS)
of the control word(s) that you have to send to the
device to initialize it. For different devices, inciden-
SELECTS
0 0 COUNTER O
Fo [0 [1 |Mooe1=HAROWAREONE-sHoT
COUNTER 2
Px [1 [0 |wooe2—Puise GeneraToR
1 ~@y
=) CONTROL WORD REGISTER
FIGURE 8-18 8254 internal addresses and system FIGURE 8-19 8254 control word format. (/nte/
addresses. (a) Internal. (b) System. Corporation)
Inte tufofutslolslolel
stl 8254 OUT pin will then go high and interrupt the
68000.
To determine the counter value for this application,
CW=12 LSB=3 just calculate the number of input clock pulses re-
quired to produce a countdown time longer than 16.66
ms, such as 18 ms. If we use the 3.579-MHz CLK signal
on an URDA MDS board, 20 ms requires 64,776 cycles
of CLK, so this is the number we would load in the
8254 counter. Since this number is too large to load in
as a BCD count, we load it in as SFDO8, and in the
control word we tell the 8254 to count the number
down in binary.
OO! 160.) 0! | 0-1 Orfeo
jodie (1) fe pe [ePaper ie
MODE 2—TIMED INTERRUPT GENERATOR
CW=12 LSB=2 LSB=4 In a previous section we described how a real-time
clock of seconds, minutes, and hours could be kept in
three memory locations by counting interrupts from a
1-Hz pulse source. We also described how the 1-Hz
interrupts could be used to measure off other time
intervals. The difficulty with using a 1-Hz interrupt
signal is that the maximum resolution of any time
measurement is 1 s. In other words, if you use a 1-Hz
signal, you can measure times only to the nearest
Colson) OPER LER] LOomO second. To improve the resolution of time measure-
[ott Cideb 8 PE se es ealpi Be ipa ments, most microcomputer systems use a higher-
frequency signal, such as 1 kHz for a real-time clock
MODE 1 interrupt. With a 1-kHz interrupt signal, the time
resolution is then 1 ms. An 8254 counter operating in
FIGURE 8-21 8254 mode 1 example timing diagrams.
mode 2 can be used to produce a stable 1-kHz signal by
(Intel Corporation)
dividing down the processor clock signal.
Figure 8-23 shows the waveforms for an 8254 count-
countdown will then start over and continue until er operating in mode 2. Let’s look at the top set of
another trigger occurs or until the count reaches zero. waveforms first. The two dips in the WR waveform
If trigger pulses continue to come before the count is represent a control word and the LSB of a count being
decremented to zero, the OUT pin will remain low. written to the count register. The next clock pulse after
The bottom set of waveforms in Figure 8-21 shows the count is written will transfer the count from the
that if you write a new count to a count register while count register to the actual counter. Since the GATE
the OUT pin is low, the new count will not be loaded input is high, succeeding clock pulses will count down
into the counter and counted down until the next this value until it reaches 1. When the count reaches 1,
trigger pulse occurs. the OUT pin, which was previously high, will go low.
For an example of the use of mode 1, we will show The falling edge of the next clock pulse will cause the
you how to make a circuit that produces an interrupt OUT pin to go high again and the original count to
signal if the ac power fails. This circuit could be again be loaded into the counter. Successive clock
connected to the IPLO input of a 68000 to vector to an pulses will cause the countdown and load cycle to
ISR that saves parameters in battery-backed RAM repeat over and over. If the counter is loaded with a
when the ac power fails. Figure 8-22, p. 228, shows a number N, the OUT pin will go low for one clock cycle
circuit that uses an optical coupler (LED and a photo- every N input clock pulses. The frequency of the output
transistor packaged together) to produce logic-level waveform then will be equal to the input clock frequen-
pulses at power line frequency. The 74LS14 inverters cy divided by N.
sharpen the edges of these pulses so that they can be For a specific example, suppose that we want to
applied to the GATE/trigger input of an 8254. For a produce a 1-kHz signal for a real-time clock from an
OPTICAL
COUREER
8-MHz processor clock signal. To do this we connect written to a counter programmed for mode 3, the
the processor clock signal to the CLK input on one of output waveform will be high for one more clock cycle
the 8254 counters and tie the GATE input of that than it is low, so the waveform will not be quite
counter high. We initialize that counter for BCD count- symmetrical. Figure 8-24 shows some example wave-
ing, mode 2, and read/write LSB and then MSB. Since forms for mode 3. By now these waveforms should look
we want to divide the 8 MHz by 8000 decimal to get 1 quite familiar to you.
kHz, we then write $00 to the counter as the LSB and The top set of waveforms shows that after a control
$80 to the counter as the MSB. word is written to the control register and a count is
A question that may occur to you at this point is, How written to the count register, the count is transferred
do I count seconds if the interrupts are coming in every to the counter on the next clock pulse. As shown by the
millisecond? The answer is that you set aside a memo- count sequence under the OUT waveform, each addi-
ry location as a milliseconds’ counter and initialize tional clock pulse decrements the counter by 2. When
that location with 1000 decimal (S3E8). The interrupt- the count is down to 2, the OUT pin goes low and the
service routine decrements this count each time an original count is reloaded. The OUT pin stays low while
interrupt occurs and checks to see if the count is down the loaded count is again counted down by 2s. When
to zero yet. If the count is not zero, then execution is the count is down to 2, the OUT pin goes high again
simply returned to the mainline. If the count is down to and the original count is again loaded into the counter.
zero, 1000 interrupts (1 s) have passed. Therefore, the The cycle then repeats.
milliseconds’ counter location is reloaded with $3E8, The center set of waveforms in Figure 8-24 shows
and the seconds-minutes-hours procedure is called to what happens if an odd number is written to the count
update the count of seconds. In a similar way the 1-kHz register. As you can see from this waveform, the num-
interrupt-service routine can measure off several dif- ber of clock cycles for each waveform is still equal to
ferent time intervals that are multiples of 1 ms. the number loaded into the count register. However, as
The middle set of mode 2 waveforms in Figure 8-23 we mentioned before, the clock is high for one more
demonstrates that if the GATE input is made low while clock cycle than it is low.
the counter is counting, counting will stop. If the GATE The bottom set of waveforms in Figure 8-24 shows
input is made high again, the original count will be that counting stops if the gate is made low at any time.
reloaded into the counter by the next clock pulse. After the GATE input is made high again, the original
Succeeding clock pulses will decrement the loaded count will be loaded by the next clock pulse.
count. Mode 3 can be used for any case where you want a
The bottom set of mode 2 waveforms in Figure 8-23 repetitive square-wave-type signal. In a previous sec-
shows that if a new count is written to the count tion we showed how an 8254 counter operating in
register, this new count will not be transferred to the mode 3 can be used to generate the baud-rate clock for
counter until the previously loaded count has been a USART such as the 8251A. Mode 3 can also be used
decremented to 1. to generate interrupt pulses for a real-time clock, as we
described for mode 2.
MODE 3—SQUARE-WAVE MODE Another use of 8254 counters operating in mode 3 is
If an 8254 counter is programmed for mode 3 and an as programmable audio tone generators. For this appli-
even number is written to its count register, the wave- cation a high-frequency clock such as the 3.579-MHz
form on the OUT pin will be a square wave. The CLK signal on an URDA MDS board is connected to the
frequency of the square wave will be equal to the counter CLK input, the GATE input is tied high, and
frequency of the input clock divided by the number the OUT pin is connected to an audio buffer such as
written to the count register. If an odd number is that shown in Figure 8-25. This simple buffer allows
CW=14 LSB=3
0| 0] 0
21014
Iytulw|yfstolotstelstsl
CW=14 LSB=4 LSB=5
"WJ Loi el a
InPytm[ufelotalotototaletale|
NOTE: A GATE TRANSITION SHOULD NOT OCCUR ONE CLOCK
PRIOR TO TERMINAL COUNT.
Isfutw|n[olslolotstals| MODE 3
NOTE: A GATE TRANSITION SHOULD NOT OCCUR ONE CLOCK FIGURE 8-24 8254 mode 3 example timing waveforms.
PRIOR TO TERMINAL COUNT. (Intel Corporation)
MODE 2
produce a low-going pulse that is N clock pulses wide.
FIGURE 8-23 8254 mode 2 example timing waveforms.
If you look at the top set of waveforms for mode 4 in
(Intel Corporation)
Figure 8-26, p. 230, you should see that mode 4
produces a low-going pulse after N + 1 clock pulses.
For mode 4 the output pulse is low for the time of one
the outputs of several counters to be added together if input clock pulse and then returns high. In other
desired and supplies the current required to drive a words, in mode 4 a counter produces a low-going strobe
small speaker. pulse N + 1 clock cycles after a count is written to the
As an example of this application, suppose that you
want to produce a 440-Hz tone that is a musical A from
the 3.579-MHz CLK signal. Dividing the CLK signal by sete)W/
Rumi
CW=18 LSB=3
FF |FF
Puixfu |w
[Sl olsl oleeleeles 01/01/00 1FF 0
|» |N |N |N |N || Oil | lea 41
7/710 Cf
CW=18 LSB=3 CW=1A_ LSB=3
\lf |esFesaeas| ee
MODE 4 MODE 5
FIGURE 8-26 8254 mode 4 example timing waveforms. FIGURE 8-27 8254 mode 5 example timing waveforms.
(Intel Corporation) (Intel Corporation)
count register. Mode 4 is referred to as software- the count is not transferred to the counter until the
triggered because it is the writing of the count to the GATE (trigger) input is made high. When the trigger
count register that starts the process. Note that after input is made high, the count will be transferred to the
the loaded count is counted down, the counter decre- counter on the next clock pulse. Succeeding clock
ments to SFFFF and then continues to decrement from pulses will decrement the counter. When the counter
there. reaches zero, the OUT pin will go low for one clock
Mode 4 can be used in a case where you want to send pulse time. The OUT pin will go low N + 1 clock pulses
out some parallel data on a port and then, after some after the trigger input goes high.
delay, send out a strobe signal to let the receiving The second set of waveforms in Figure 8-27 shows
system know that the data is available. that if another trigger pulse occurs during the count-
down time, the original count will be reloaded on the
MODE 5—HARDWARE-TRIGGERED STROBE next clock pulse and the countdown will start over.
Mode 5 is used where we want to produce a low-going The OUT pin will remain high until the count is finally
strobe pulse some programmable time interval after a counted down. If trigger pulses continue to come before
rising-edge trigger signal is applied to the GATE input. the countdown is completed, the OUT pin will continue
This mode is very useful when we want to delay a to stay high. Therefore you can use a counter in mode 5
rising-edge signal by some amount of time. to produce a power-fail signal, as we showed in the
Figure 8-27 shows some example waveforms for a discussion of mode 1. Note that for mode 5, however,
counter operating in mode 5. For a start let’s look at the the OUT pin will be high if the power is on and will go
top set of waveforms. As usual we write a control word low when the power fails.
and the desired count to a counter. As shown by the The bottom set of waveforms in Figure 8-27 shows
count sequence under the OUT waveform, however, that if a new count is written to a counter, the new
BUFFER
i CONTROL LOGIC
RD IRO
WR cx IR1
Ay
a
4 IN INTERRUPT IR2
S SERVICE PRIORITY eee ors IR3
cc REG RESOLVER am IR4
cs ee (ISR)
cs
IRS
IR6
IR7
CAS0
CASCADE
CAS 1 BUFFER/
COMPARATOR << INTERRUPT MASK REG
CAS 2 (MR)
SP/EN
edge from the 68000 function codes, the 8259A out- The IRR keeps track of which interrupt inputs are
puts an interrupt vector on the 8-bit data bus, as asking for service. If an interrupt input is unmasked
shown in Figures 8-7 and 8-8. The interrupt vector and has an interrupt signal on it, then the correspond-
that it sends to the 68000 is determined by the IR input ing bit in the interrupt request register will be set.
that received an interrupt signal and by a number you The ISReg keeps track of which interrupt inputs are
send the 8259A when you initialize it. The point here currently being serviced. For each input that is cur-
is that the 82594 ‘‘funnels”’ interrupt signals from up rently being serviced, the corresponding bit will be set
to eight different sources into a single 68000 interrupt in the ISReg. An example will show how the priority
level, and it sends the 68000 a specified interrupt- resolver acts as a judge in the middle of all this.
vector number for each of the eight interrupt inputs. Suppose that IR2 and IR4 are unmasked and that an
At this point you might wonder what would happen if interrupt signal comes in on the IR4 input. Since IR4 is
interrupt signals appear at, for example, IR2 and IR4 unmasked, bit 4 of the IRR will be set. The priority
at the same time. In the fixed-priority mode in which resolver will detect that this bit is set and see if any
the 8259A is usually operated, the answer to this action needs to be taken. To do this it checks the bits in
question is quite simple. In this mode the IRO input has the ISReg to see if a higher-priority input is being
the highest priority (most importance), the IR1 input serviced. If a higher-priority input is being serviced, as
the next highest, and so on down to IR7, which has the indicated by a bit being set for that input in the ISReg,
lowest priority. What this means is that if two inter- then the priority resolver will take no action. If no
rupt signals occur at the same time, the 8259A will higher-priority interrupt is being serviced, then the
service the one with the highest priority first assuming priority resolver will activate the circuitry that sends
that both inputs are unmasked (enabled). an interrupt signal to the 68000. When the 68000
Now let’s look again at the block diagram of the responds with an interrupt acknowledge, the 8259A
8259A in Figure 8-29 so we can explain in more detail will send the interrupt type that we specified for the
how the device will respond to multiple interrupt IR4 input when we initialized the device. The 68000
signals. In the block diagram, note the four boxes will use the vector number it receives to find and
labeled interrupt request register (IRR), interrupt execute the interrupt-service routine we wrote for the
mask register (IMR), in-service register (ISReg), and IR4 interrupt.
priority resolver. The operation of these four functional Now, suppose that an interrupt signal arrives at the
blocks is quite logical. IR2 input of the 8259A while the 68000 is executing
The interrupt mask register is used to disable (mask) the IR4 service routine. Since we assumed for this
or enable (unmask) individual interrupt inputs. Each example that IR2 was unmasked, bit 2 of the IRR will
bit in this register corresponds to the interrupt input be set. The priority resolver will detect that this bit in
with the same number. You unmask an interrupt the IRR is set and make a decision whether to send
input by sending a command word with a 0 in the bit another interrupt signal to the 68000. To make the
position that corresponds to that input. decision, the priority resolver looks at the ISReg. If a
bea
paTs +
Ds D, Ds Ds D, Do
Ao D; De
1 = |CW4 NEEDED
0 = NO ICW4 NEEDED
1 = SINGLE
0 = CASCADE MODE
A,-As OF INTERRUPT
VECTOR ADDRESS
(MCS-80/85 MODE ONLY)
A,5-Ag OF INTERRUPT
VECTOR ADDRESS
(MCS80/85 MODE)
T,-T; OF INTERRUPT
VECTOR ADDRESS
(8086/8088 MODE) NO
YiES
1 =1R INPUT HAS
A SLAVE (SNGL=0)
0 =1R INPUT DOES NOT HAVE
A SLAVE
|CW3 (SLAVE DEVICE)
MEDS DeemDen D, LO nn O2t Ogee Op
Se eee
icw4
Ao Degiip Dee eDeeu! 0; D3
Doel Ona 05
Fe a
1 = AUTO EO!
0 = NORMAL EO! READY TO
ACCEPT
INTERRUPT
REQUESTS
Lnka NON BUFFERED MODE
a Pom BUFFERED MODE/SLAVE
BUFFERED MODE/MASTER
(a)
FIGURE 8-31 8259A initialization command word formats and sending order.
(a) Formats. (b) Sending order and requirements. (Intel Corporation)
ocw1
eee OD. 2,eeotete Ds wD 3 Dz D1 Da
+
VU
1 M7 M5 | M 4 m3 | M2 | M1 | MO
INTERRUPT MASK
1 = MASK SET
0 = MASK RESET
ocw2
Ao D; De Ds D, Ds D, D, Do
OCW3
BWM Dei (Deg EO, De, Doe DilanDs
CS na ed
Ez arcane Perea
Paez de
READ
IR REG ON |READ IS REG ON
NO ACTION NEXT
RD PULSE |NEXT RD PULSE
peed aa eee
1
yn ae eee
RESET SET
NO ACTION SPECIAL MASK | SPECIAL MASK
; alr 8-89
ORG $4000 ; start the code at $4000
; INITIALIZATION
; Subroutine: KEYBOARD
KEYBOARD: instructions
keyboard subroutine
; Subroutine: CLOCK
CLOCK:
clock subroutine instructions
SECONDS: Dc.B 0
MINUTES: DcC.B 0
HOURS : Dc.B 0
END
Describe the purpose of the 68000 exception vec- Saves all registers on the stack.
tor table. Saves the stack pointer value for the last entry at
What addresses in the exception vector table are location $8000.
used for a type 5 exception? Saves the contents of memory locations $0400—
O5FF after the saved stack pointer value at the
The starting address for a type 5 exception service
start of the battery-backed memory. (A string-
routine is $4178. Show where this address should
move-type operation might be useful for this.)
be placed in the hard exception vector table. Show
where it should be placed in the soft exception Halts.
table.
When the power comes back on, the startup
Address $0108 in the interrupt jump table con- routine can check the power fail flip-flop. If the
tains $4224, and address $010C contains $0440. flip-flop is set, the start-up routine can copy the
To what exception types do these locations corre- saved data back into its operating locations and
spond? What are the starting addresses for the initialize the stack pointer value from address
interrupt-service routines? $8000. Using this value it can restore the pushed
registers and return execution to where the power
Briefly describe the condition or conditions that
fail interrupt occurred. This is called a warm
cause the 68000 to perform each of the following
start. If we don’t want it to do a warm start, we
types of exceptions: TRAPV, CHK, zero divide,
can reset the flip-flop with an external RESET key
trace, and user interrupt.
so the system does a start from scratch, or a cold
Why is it necessary, at the start of an interrupt- start.
service routine, to push all registers used in the
12. Why is the 68000 interrupt mask (CPU priority
routine and to pop them at the end of the routine?
level) automatically set to level 7 when the 68000
Why must you use an RTE instruction rather than is RESET? How are the 68000 interrupt inputs
the regular RTS instruction at the end of an enabled to respond to interrupts? What instruc-
interrupt-service routine? tion can be used to disable (mask) the interrupt
inputs? Why is the interrupt mask (CPU priority
Show the assembler directives and instructions level) automatically set to the level of the current
you would use to initialize the soft exception interrupt as part of the response to an interrupt?
vector table for a type 5 routine called DIV-O_- How are the interrupts automatically reenabled at
ERROR and a type 15 routine called POWER— the end of an interrupt-service routine?
FAIL.
13. Describe the response a 68000 will make if it
10. Describe the main use of the 68000 type 9 (trace) receives a level 7 interrupt signal during a division
trap. Show the assembly language instructions operation that produces a divide by O trap.
necessary to set the 68000 T bit in the status
register. 14. The data outputs of an 8-bit A/D converter are
connected to bits DO—D7 of port SBFF9 and the
11. In a system that has battery-backed RAM for end-of-conversion signal from the A/D converter
saving data in case of a power failure, the stack is is connected to the IPLO, IPL1, and IPL2 inputs of
often put in the battery-backed RAM. This makes a 68000 (i.e., to interrupt level 7). Write a simple
it easy to save registers and critical program data. mainline program and an interrupt-service rou-
Assume that the battery-backed RAM is in the tine that reads in a byte of data from the convert-
address range of $S8000-S8FFF. Write a 68000 er. If the MSB of the data is a O, indicating the
power failure interrupt-service routine that value is in range, add the byte to a running total
Sets an external battery-backed flip-flop connect- kept in two successive memory locations. If the
The major goal of this chapter and the next is to show PROGRAMMABLE PARALLEL PORTS AND
you much of the interface circuitry and software need- HANDSHAKE INPUT/OUTPUT
ed to control a complex machine such as our printed-
circuit-board-making machine or a medical instru- Throughout the program examples in the preceding
ment with a microprocessor. We try to show enough chapters, we have used port devices to input parallel
detail in each topic so that you can build and experi- data to the microprocessor and to output parallel data
ment with some real circuits and programs. Perhaps from the microprocessor. Most of the available port
you can use some of this to control appliances around devices such as the 6821 on the URDA® MDS board
your house or solve some problems at work. contain two or three ports that can be programmed to
operate in one of several different modes. The different
modes allow you to use the device for many common
OBJECTIVES types of parallel data transfer. First, we discuss some
of these common methods of transferring parallel data,
At the conclusion of this chapter, you should be able to and then we show how the 6821 is initialized and used
in a variety of I/O operations.
1. Describe simple input and output, strobed input
and output, and handshake input and output.
Methods of Parallel Data Transfer
2. Initialize a programmable parallel port device
such as the 6821 for simple input or output and SIMPLE INPUT AND OUTPUT
for handshake input or output. When you need to get digital data from some simple
3. Interpret the timing waveforms for handshake switch such as a thermostat into a microprocessor, all
input and output operations. you have to do is connect the switch to an input port
line and read the port. The thermostat data is always
4. Describe how phonemes are sent to a speech present and ready, so you can read it at any time.
synthesizer on a handshake basis. Likewise, when you need to output data to a simple
5. Describe how parallel data is sent toa printer ona display device such as an LED, all you have to do is
handshake basis. connect the input of the LED buffer on an output port
pin and output the logic level required to turn on the
6. Show the hardware connections and the pro- light. The LED is always there and ready, so you can
grams that can be used to interface keyboards toa send data to it at any time. The timing waveform in
microcomputer. Figure 9-la, p. 244, represents this situation. The
7. Show the hardware connections and the pro- crossed lines on the waveform represent the time at
grams that can be used to interface alphanumeric which a new data byte becomes valid on the output
displays to a microcomputer. lines of the port. The absence of other waveforms
indicates that this output operation is not directly
8. Describe how an 8279 can be used to refresh a dependent on any other signals.
multiplexed LED display and scan a matrix key-
board. SIMPLE STROBE 1/O
9. Initialize an 8279 for a given display and keyboard In many applications valid data is present on an
format. external device only at a certain time, and it must be
read in at that time. An example of this is the ASCII-
10. Show the circuitry used to interface high-power
encoded keyboard shown in Figure 4-13. When a key is
devices to microcomputer ports. pressed on the keyboard, circuitry on the keyboard
11. Describe the hardware and software needed to sends out the ASCII code for the pressed key on eight
control a stepper motor. parallel data lines. The keyboard circuitry then sends
243
SINGLE-HANDSHAKE 1I/O
Figure 9-1c shows some example timing waveforms for
a handshake data transfer from a peripheral device to
a microprocessor. The peripheral outputs some paral-
lel data and sends an STB signal to the microprocessor.
The microprocessor detects the asserted STB signal on
a polled or interrupt basis and reads in the byte of data.
The microprocessor then sends an acknowledge sig-
nal, ACK, to the peripheral to indicate that the periph-
eral can send the next byte of data. From the viewpoint
of the microprocessor, this operation is referred to asa
handshake, or strobed, input.
STB
These same waveforms might represent a hand-
shake output from a microprocessor to a parallel print-
er. In this case, the microprocessor outputs a character
to the printer and asserts an STB signal to the printer
to tell the printer, ‘‘Here is a character for you.”” When
the printer is ready, it answers back with the ACK
signal to tell the microprocessor, ‘‘] got that one, send
me another.’’ We show you much more about printer
interfacing in a later section.
The point of this handshake scheme is that the
STB
sending device or system cannot send the next data
byte until the receiving device or system indicates with
an ACK signal that it is ready to receive the next byte.
fORA) iphera |
Periph ae
PA3
Interface
PA4
5
Voc = Pin 20
Vv = Pind
rf Output —<—e 11 PBI
RegisterB
(ORB) Peripheral a 12 PB2
CSO 22
Interface <——e 13 PB3
CS1 24 4 B —a—e 14 PB4
Ran i : 15 PBS
CS2 23 Pp Tri State
Select ae
RSO 36
and —<——e16 PB6
RS1 35 R/W <——e 17 PB7
RWW 21 Control
Enable 25
IRQA(B) 1 Interrupt Flag (bit b7) CA1 (CB1) Interrupt Request Enable/Disable
Goes high on active transition of CA1 (CB1); Automatically cleared by MPU bO = 0: Disables IRQA(B) MPU Interrupt by CA1 (CB1) active transition. |
bO = 1: Enable IRQA(B) MPU Interrupt by CA1 (CB1) active transition
Read of Output Register A(B). May also be cleared by hardware Reset
1. IRQA(B) will occur on next (MPU generated) positive transition of bO if
CA‘ (CB1) active transition occurred while interrupt was disabled
CA2(CB2) CA1(CB1)
Control Control
IRQA(B) 2 Interrupt Flag (bit b6) Determines Whether Data Direction Register Or Output
Register is Addressed
CA2 (CB2) Established as Input (b5= 0): Goes high on active transition of
CA2 (CB2); Automatically cleared by MPU Read of Output Register A(B) b2 = 0: Data Direction Register selected
May also be cleared by hardware Reset.
b2 = 1: Output Register selected.
CA2 (CB2) Established as Output (b5 = 1): IRQA(B)2 = 0, not affected by
CA2 (CB2) transitions.
(a)
FIGURE 9-5 Control word examples for 6821. (a) Mode-set control word.
(b) Control register bit-set control word to set bit 3.
BE Ro ee aie
[eta eat te OS PONSee ee
(a)
MOVE.B #$00,(SC@16) ; Bit D2=0 implies access
data direction register
interrupts disabled
MOVE.B #SFF, (A2) ; Make all bits of port outputs
MOVE.B #504, (A3) ; Bit D2=1 implies access data reg,
interrupts disabled
(b)
FIGURE 9-7. (a) Control word to initialize the 6821 for interface with tape
reader and lathe. (b) 68000 code to initialize and start the tape reader.
DO to go high (i.e., to be set to a 1 by the tape reader); instruction and output the appropriate control byte to
then the 68000 can read the data from port A. When the lathe on the upper 6821 port B. The tape reader
the R/W signal from the microprocessor goes low for then sends the next instruction byte. If the instruction
this read of port A, the 6821 will automatically reset its tape is made into a continuous loop, the lathe will keep
interrupt request signal on IRQB. This is done so that a making the specified parts until it runs out of material.
second interrupt cannot be caused by the same data The unused bits of the lower 6821 port B could be
byte transfer. When the processor raises its R/W connected to a mechanism that loads in more material
signal high again at the end of the read operation, the so the lathe can continue.
lower 6821 drops its acknowledge signal on port B, bit Figure 9-9 shows the 68000 code for this type of
D1, low again. The acknowledge going low again is the handshaking operation. In this application the 68000
signal to the tape reader that the data transfer is actually performs the handshaking itself and is re-
complete and that it can send the next byte of data. sponsible for manipulating all the handshake signals
The time between when the lower 6821 sends the itself, by writing to the appropriate 6821 port data
interrupt request signal and when the processor reads register bits. It is also possible to connect the 6821
the data byte from port A depends on when the proces- using the IRQA and CAI lines such that part of the
sor gets around to servicing that interrupt. The point handshaking is done automatically by the 6821. In the
here is that this time doesn’t matter. The tape reader next example we show how this is done. The 68000
will not send the next byte of data until it detects that direct handshake method is slower and does not use
the acknowledge signal has gone low again. The trans- the full functionality of the 6821. However, it is con-
fer cycle will then repeat for the next data byte. ceptually simpler and is more flexible in terms of
After the processor reads in the lathe-control in- timing requirements. When following through the next
struction byte from the tape reader, it will decode this example, try to map the 68000 handshake operations
STROBE FROM
TAPE READER TO CA1 NS ET
Ee ey
Fw
TRO FROM 6821
E SIGNAL (DBE)
INTO 6821 NA Nd No Noe
RD a ee, ae aoe
CA2 OUTPUT
|
ee een pr
I
FIGURE 9-8 Timing waveforms for 6821 handshake data input from a tape
reader.
Sos kQ
4.7kQ VOTRAX
SC-01A
ya 34 10 kQ +12 V
a3} 16
42 15 = 150 pF ONPG
i 20 => 100 mF
as fF 3.3k2 10k2 = a
open 48
es He aE WW
44 HK 22 |0.022 uF SPEAKER
+12 V 10 kQ 220 uF x
0.1 uF Boge
NZ
aacsos
6
#2 1K == 001F sll
=
> 18 =>
40 +12 V ale
574C906 4.7 k2 a ap Oe
=> 8 9
)
=~6 74C906
HOV =
—_ 3 47kQ
WR 2
FROM CPU 32 ATkQ 45 13
6
74C906
Voc = PIN 14
100 pF
at
GND = PIN 7, 10
(a)
BFFROM
6821
DELAYED AND
INVERTED OBF
SC-01A A/R
TO 6821
6821|INTR
TO CPU
CPU WR
TO 6821
DATA OUT
FROM PORT
Tice
SIGNAL RETURN
PIN NO. PIN NO. SIGNAL DIRECTION DESCRIPTION
STROBE pulse to read data in. Pulse width must be more than 0.5 us at receiving terminal. The
IN signal level is normally ‘‘high’’; read-in of data is performed at the “‘low”’ level of this signal.
mls |
IN
4 IN
IN These signals represent information of the 1st to 8th bits of paralle! data respectively. Each
signal is at ‘‘high’’ level when data is logical ‘’1’ and ‘‘low’’ when logical ‘’0.”’
DATA 5 IN
DATA 6 IN
DATA7 |N
DATA 8 IN
Approximately 5 us pulse; ‘‘low’’ indicates that data has been received and the printer is
OUT
ready to accept other data.
A “high” signal indicates that the printer cannot receive data. The signal becomes “‘high’’
in the following cases:
BUSY OUT 1. During data entry. 3. In “offline” state.
2. During printing operation. 4. During printer error status.
A “high” signal indicates that the printer is out of paper.
SLCT OUT This signal indicates that the printer is in the selected state.
AUTO With this signal being at ‘‘low”’ level, the paper is automatically fed one line after printing. (The
IN signal level can be fixed to “‘low’’ with DIP SW pin 2-3 provided on the control circuit board.)
REEDIXT
CHASIS- Printer chasis GND. In the printer, the chassis GND and the logic GND are isolated from
17
GND each other.
18 NC Not used,
“Twisted-Pair Return’”’ signal; GND level.
When the level of this signal becomes ‘‘low”’ the printer controller is reset to its initial state
31 IN Me IN and the ‘print buffer is cleared. This signal is normally at ‘‘high”’ level, and its pulse width
must be more than 50 us at the receiving terminal.
ERROR The level of this signal becomes “‘low’’ when the printer is in ‘‘Paper End” state, ‘‘Offline’’
32 OUT state and ‘’Error’’ state.
33
gS ad
en
34 ee
35 dhs thoes Pulled up to +5 Vdc through 4.7 k-ohms resistance.
Data entry to the printer is possible only when the level of this signal is ‘‘low.”’ (Internal
36 SLCT IN fixing can be carried out with DIP SW 1-8. The condition at the time of shipment is set
“Now” for this signal.)
Notes: 1. ‘’Direction’”’ refers to the direction of signal flow as viewed from the printer.
“Return” denotes ‘’Twisted-Pair Return” and is to be connected at signal-ground level.
When wiring the interface, be sure to use a twisted-pair cable for each signal and never fail to complete connection on the return side. To prevent
noise effectively, these cables should be shielded and connected to the chassis of the system unit.
3. All interface conditions are based on TTL level. Both the rise and fall times of each signal must be less than 0.2 us.
4. Data transfer must not be carried out by ignoring the ACKNLG or BUSY signal. (Data transfer to this printer can be carried out only after
confirming the ACKNLG signal or when the level of the BUSY signal is ‘‘low.’’)
FIGURE 9-13. Timing waveforms for transfer of a data Routines that input data from or output data to periph-
character to a Centronics-type parallel printer such as eral devices such as disc drives, MODEMs, and print-
the IBM-PC or Epson printer. (IBM Corporation) ers are often called I/O drivers. Here we show you one
Upper
6821
Port A
474LS07
>
1A 3 4
pe
Cro
11 10
JE Sis) 12
a |8 |DATA7
LOGIC GND
CHASSIS GND
way to write the driver routine for our parallel printer between transfers. If characters are sent on an inter-
interface. rupt basis, many other program instructions can be
The first point to consider when writing any 1/O executed while waiting for the interrupt request to
driver is whether to do it on a polled or on an interrupt send the next character. Also, when the printer buffer
basis. For the parallel Centronics interface here, the gets full, there will be an even longer time during
maximum data transfer rate is about 1000 characters/ which the processor can be working on some other job
second. This means that there is a little less than 1 ms while waiting for the next interrupt. This is another
illustration of how interrupts allow the computer to do
several tasks “‘at the same time.”’ For our example
D7 D6 D5 D4 D3 D2 D1 DO here, assume that the interrupt request from IRQB of
ee re ee the 8255A is connected to the interrupt input of the
68000, as shown in Figure 7-15 (the URDA MDS
oak Te ey
———————
a eia a]
sy | ees
schematic), so that a clock interrupt, a keyboard inter-
rupt, and the printer interrupt can all be serviced in
Interrupt flags Mode control Interrupt Control turn.
input to 68000 DDR Access a , a
(qetussdron Suto 1 ee. Figure 9- 16a shows the steps youriced in the main
register line to initialize everything and ‘‘call’’ the printer
driver to send a string of ASCII characters to the
printer.
FIGURE 9-15 6821 control words for printer interface. At the start of the mainline, some named memory
Initialization
if error then
exit
FIGURE 9-16 Algorithm for printer mainline and interrupt-based printer driver
routine. (a) Mainline steps. (b) Printer driver routine steps, p. 258.
locations are set aside to store parameters needed for sentinel method we described for handshake output to
transfer of data to the printer. The memory locations the SC-01A in Figure 9-10 could have been used. With
set aside for passing information between the mainline the sentinel approach you put a sentinel character in
and the driver routine are often called a control block. memory after the last character to be sent out. MS-
In the control block a named location is set aside for a DOS, for example, uses a $ character ($24) as a senti-
pointer to the address of the ASCII character that is nel character for some of its drivers. As you read each
currently being sent. Another memory location is set character in from memory, you compare it with the
aside to store the number of characters to be sent. The sentinel value. If it matches, you know all the charac-
number in this location will function as a counter so ters have been sent. The sentinel approach and the
you know when you have sent all the characters in the counter approach are both widely used, so you should
buffer. Instead of using this counter approach to keep be familiar with both.
track of how many characters have been sent, the To get the hardware ready to go, you need to initialize
save registers
wait 1 microsecond
wait 1 microsecond
restore registers
the 68000 by unmasking its interrupt inputs. This characters to be sent in the reserved location in the
enables 68000 interrupts. Next the 6821 must be control block. Finally, you enable the interrupt request
initialized by sending it the control word sequence pin on the 6821. Note that you do not enable this
shown earlier. A bit write to the control word of the interrupt until you are actually ready to send data. A
6821 then makes the STB signal to the printer high high on the ACKNLG line from the printer causes the
because this is its unasserted level. To make sure the 6821 to output an interrupt request signal to the
printer is internally initialized, you pulse the INIT line 68000. This interrupt request signal goes to the pro-
to the printer low for a few microseconds. cessor and causes it to go to the interrupt-service
When you are actually ready to print some charac- routine.
ters in a program, you first read the printer status from Figure 9-16b shows the algorithm for the interrupt-
port A and check if the printer is selected, not out of service routine (ISR) that services this interrupt and
paper, and not busy. In a more complete program you actually sends the characters to the printer. After
could send a specific error message to the display pushing some registers, the 68000 interrupts are ena-
indicating the type of error found. The program here bled so that higher-priority interrupts can interrupt
just sends a general error message. If no printer error this ISR. The string address pointer is then read in
condition is found, you load the starting address of the from the control block and used to read a character in
string of ASCII characters into the control block loca- from the buffer to DO. The character in DO is then
tion you set aside for this and load the number of output to port B of the 6821. From here on the program
ORS meUSiEo 2 UR DAR MID S =piottsitc Uipipe amr6) 8:2 aa prolta lean, C1Onl4 mmcremtercs
: wt ©.O)
1 Om G OlnMieionl
; : UD PieiigmeOlS 2a >)Ollaitems Bens GlOlLIO mG litre
5 : eG Ole / me OenaOnL
sO CEDURES See REN ae Cie Se Om UIE
D Ulta Ciiicmdl
cre elms
alr 9-89
B INITIALIZATION
LEA STACK_TOP,A7 Fein tra lize is el uesitealckw pionuinit: eliuat:On 0: Dano. temesitrayer
FIGURE 9-17 68000 assembly language mainline instructions for printer driver
example. (continued)
"Se GML pl Pol m ter to message storage and say print not done yet
SENDIT: MOVEA.L MESSAGE_1,A1
MOVE.L fa)itg [al
MOVE.L Deleon Ge Oba NIT EIR)
MOVE.B #$0@@, (PRINT_DONE )
MOVE.B #MESSAGE_LENGTH, (COUNTER )
mechanical contacts to become oxidized or dirty. A Keyboard Circuit Connections and Interfacing
small disadvantage is the specialized circuitry needed
to detect the change in capacitance. Capacitive key-
In most keyboards the keyswitches are connected in a
switches typically have a rated lifetime of about 20 matrix of rows and columns, as shown in Figure
9-20a, p. 264. We will use simple mechanical switches
million keystrokes.
for our examples here, but the principle is the same for
other types of switches. Getting meaningful data from
HALL EFFECT KEYSWITCHES
a keyboard such as this requires doing three major
A Hall effect keyswitch is another type of switch that tasks:
has no mechanical contact. It takes advantage of the
deflection of a moving charge by a magnetic field.
Figure 9-19c, p. 263, attempts to show you how this
1. Detect a key-press.
works. A reference current is passed through a semi-
conductor crystal between two opposing faces. When a 2. Debounce the key-press.
key is pressed, the crystal is moved through a magnetic
3. Encode it (produce a standard code for the
field that has its flux lines perpendicular to the direc-
pressed key).
tion of the current flow in the crystal. (Actually, it is
easier to move a small magnet past the crystal.) Moving
the crystal through the magnetic field causes a small
voltage to be developed between two of the other The three tasks can be done with hardware, soft-
opposing faces of the crystal. This voltage is amplified ware, or a combination of the two, depending on the
and used to indicate that a key is pressed. Hall effect application. We will first show you how they can be
keyboards are more expensive because of the more done with software, as might be done in a microproces-
complex switch mechanisms, but they are very de- sor-based grocery scale, where the microprocessor is
pendable and have typical rated lifetimes of 100 million not pressed for time. Later we describe some hardware
or more keystrokes. devices that do these tasks.
PRINT_IT:
MOVEM.L [A1-A2,D@-—-D1],-(A7) 3; save registers
MOVEA.L #$C013,A1 ; pointer to lower A data register
MOVEA.L #$C014,A3 ; pointer to upper B data register
MOVEA.L (POINTER) ,A2 ; pointer to message
MOVE<B (A2)-r, Oe ; get a character
; send printer a strobe on upper PA4 (low then high)
BCLR #4, (A3) sce airam Gnome mnOn)
BSEn #4,(A3) 5 Se Chatela e- ab)
3. increment pointer and decrement counter
MOM Eee CE OLNTEER Ok Ah GENE POI MBe tr
ADDI.L #1,0D1 ; one byte increment
MOVE .L Dene Orc NiIERs) Ste SCCU teieeGOm meno tay
MOVE .B (COUNTER) ,0O1 ; get counter
SU Baler inte elren
ele 3; decrement
MOVE.B Or eC OW NaERe) ; return to memory
BGE NEXT 3; Wait for next character? -
Nise
MOVEM.L (A7)+,[A1—-A2,D0-D1] ; restore registers
RTE ;
END
Software Keyboard Interfacing key and can be detected on the input port. If you know
the row and the column of the pressed key, you then
CIRCUIT CONNECTIONS AND ALGORITHM know which key was pressed and can make up any
Figure 9-20a, p. 264, shows how a hexadecimal code you want to represent that key. Figure 9-20b, p.
keypad can be connected to a couple of microcomputer 264, shows a flowchart for a subroutine to detect,
ports so the three tasks can be done as part of a debounce, and produce the hex code for a pressed key.
program. The rows of the matrix are connected to four The first step is to output Os to all the rows. Next the
output port lines. The column lines of the matrix are columns are read and checked over and over until the
connected to four input port lines. When no keys are columns are all high. This is done to make sure a
pressed, the column lines are held high by the pull-up previous key has been released before looking for the
resistors to +5 V. The main principle here is that next one. In standard keyboard terminology this is
pressing a key connects a row to a column. If a low is called two-key lockout. Once the columns are found to
output on a row and a key in that row is pressed, then be all high, the program enters another loop, which
the low will appear on the column that contains that waits until a low appears on one of the columns,
OUTPUT
PORT 01
READ
DO COLUMNS
D1
D2
READ
COLUMNS
D3
10 kQ
INPUT
PORT 02
OUTPUT
ZERO TO
ONE ROW
(a)
PORTS USED URDA MDS ports upper 6821 port A - $C@14 data output
- §C016 control
UPPeELrMOS lle pPOLteBe= SCO LS edatas input
aS OMe CONG ro) |
PROCEDURES : Calls KEYBRD to scan and decode 16-switch keypad
REGISTERS Uses D@ and Al (and status register condition codes)
alr 9-89
; INITIALIZATION
; initialize ports
MOVE.B #5S
JSR KEYBRD
NOP
NOP
_Raeeeeeteraeeeeeeteeeeeeeneaeeneeneaeeeneeeeeennkenekeeene
ew eee ee ee ee ee ee ee ee eee
SUBROUTINE KEYBRD
ABSTRACT: Subroutine gets a code from a 16-switch keypad and decodes
te It returns the code for the keypress in D@ and D1=S$900.
If there is an error in the keypress then it returns D1=S$01.
SUBROUTINES: None
PORTS USED URDA MDS ports upper 6821 port A - $CQ@14 data output
- §C016 control
upper 6821 port B - $CQ@15 data input
- §C@17 control
INPUTS Keypress from port
OUTPUTS keypress code in D@ and error message in Dl
KEYBRD:
MOVEM.L [A1-A2,D2],-(A7) ; Save registers
MOVEA.L #UPPERA_DATA,A1 ; pointer to lower A data register
MOVEA.L #UPPERB_DATA,A2 3; pointer to upper B data register
MOVE.B #SQQ, (Al) ; send @’s to all rows
; read columns
WAIT_OPEN:
MOVE.B (A2),D2
AND.B #SOF ,D@ ; mask row bits
CMP.B #SQOF,D@ ; wait until no keys pressed
JINZ WAIT _OPEN
; Debounce keypress
MOVE.W #S16EA,D1 delay of 20 ms
DELAY: DBGE D1,DELAY
MOVE.B (A2) ,D@ read columns
AND.B #SOF,D@
CMP.B #SQOF,D9O see if key still pressed
JEQ WAIT_PRESS
NEXT_ROW:
MOVE.B D2,(A1) °
. put a low on one row
MOVE.B (A2),D@ .
° read columns and check for low bit
AND.B #SQF,DO ry
® mask out row code
CMP.B #SOF,DO e
» check for low in a column
BNE ENCODE ® found column, now encode it
ROL.B #1,D2 .
° rotate mask
BRA NEXT_ROW °
. look at next row
END
ERROR TRAPPING
CONVERTING ONE KEYBOARD CODE TO
The concept of detecting some error condition such as ANOTHER
“no match found’’ is called error trapping. Error
trapping is a very important part of real programs. Suppose that you are building up a simple microcom-
Even in this simple program, think what might happen puter to control the heating, watering, lighting, and
with no error trap if two keys in the same row were ventilation of your greenhouse. As part of the hard-
pressed at exactly the same time. A column code with ware, you buy a high-quality, fully encoded keyboard at
two lows in it would be produced. This would not the local electronics surplus store for a few dollars.
mateh any of the row and column codes in the table. When you get the keyboard home you find that it works
After all the values in the table were checked, D1 perfectly but that it outputs EBCDIC codes instead of
would be decremented to SFFFF and DO would then be the ASCII codes that you want. Here’s how you use
compared with a value in memory at offset SFFFF. The the 68000 looping instructions to solve this problem
cycle would continue until, by chance, the value ina easily.
memory location matched the row and column code in First look at Table 1-2, which shows the ASCII and
AL. The contents of D1 at that point would be passed EBCDIC codes. The job you have to do here is convert
back to the calling routine. The chances are 1 in 256 each input EBCDIC code to the corresponding ASCII
that this would be the correct value. Since these are code. One way to do this is to use the compare tech-
not very good odds, it is advisable to put error traps in nique described previously for the hex-keyboard exam-
your programs whenever there is a chance for the ple. For that method you first put the EBCDIC codes in
program to go off to ‘‘never-never land”’ in this way. a table in memory in the order shown in Table 1-2 and
The error/no-error code can be passed back to the set up a register as a counter and pointer to the end of
calling program in a register as shown, in a dedicated the table. Then enter a loop that compares the EBCDIC
memory location, or on the stack. character in DO with each of the EBCDIC codes in the
table until a match is found. The counter is decre-
mented after each compare so that when a match is
found, the count register contains the desired ASCII
Keyboard Interfacing with Hardware
code. This compare technique works well, but for this
The previous section described how you can connect a conversion it will, on the average, have to do 64
keyboard matrix to a couple of microprocessor ports compares before a match is found. Thus the compare
and perform the three interfacing tasks with program technique is often too time-consuming for long tables.
instructions. For systems where the CPU is too busy to There is another method that is much faster: using a
be bothered doing these tasks in software, an external hash table.
device is used to do them. One example of an MOS The first step in the new method is to make up in
device that can do this is the General Instruments memory a table that contains all the ASCII codes. You
AY-5-2376, which can be connected to the rows and can use the DC.B assembler directive to do this. Since
columns of a keyboard switch matrix. The AY-5-2376 EBCDIC code is an 8-bit code, the table will require 256
independently detects a key-press by cycling a low memory locations. The trick here is to put each ASCII
down through the rows and checking the columns, just code in the table at a displacement equal to the value of
as we did in software. When it finds a key pressed, it the EBCDIC character from the start of the table. For
waits a debounce time. If the key is still pressed after example, the EBCDIC code for uppercase A is SC1, so at
the debounce time, the AY-5-2376 produces the 8-bit offset SCl in the table you put the ASCII code for
code for the pressed key and sends it out to, for uppercase A, $41, as shown in Figure 9-22, p. 268.
example, a microcomputer port on eight parallel lines. To do the actual conversion, you simply load the D1
To let the microcomputer know that a valid ASCII code register with the address of the start of the table, load
is on the data lines, the AY-5-2376 outputs a strobe the EBCDIC character to be converted in the AO regis-
pulse. The microcomputer can detect this strobe pulse ter, and do an indexed MOVE indirect instruction.
and read in the ASCII code on a polled basis, as we When the 68000 executes the MOVE.B (AO,D1),DO
showed in Figure 4-14, or it can detect the strobe pulse instruction, it internally adds the EBCDIC value in D1
on an interrupt basis, as we showed in Figure 8-9. to the starting address of the table in AO. Because of
With the interrupt method the microcomputer doesn’t the way the table is made up, the result of this addition
have to pay any attention to the keyboard until it will be a pointer to the desired ASCII value in the table.
receives an interrupt signal, so this method uses very The 68000 uses this pointer to copy the desired ASCII
little of the microcomputer’s time. The AY-5-2376 has character from the table to DO. D1 is called the hash
a feature called two-key rollover. This means that if code for the desired ASCII character.
two keys are pressed at nearly the same time, each key The advantage of this technique is that, no matter
will be detected, debounced, and converted to ASCII. where in the table the desired ASCII value is, the
The ASCII code for the first key and a strobe signal for it conversion requires only execution of two loads and
IN D1
INTERFACING TO ALPHANUMERIC
+— START OF TABLE, AG DISPLAYS
FIGURE 9-22 Memory table setup for converting Many microprocessor-controlled instruments and ma-
chines need to display letters of the alphabet and
EBCDIC keycodes to ASCII equivalent.
numbers to give directions or data values to users. In
systems where a large amount of data needs to be
displayed, a CRT is usually used to display the data. In
a later chapter we show you how to interface a micro-
computer to a CRT. In systems where only a small
one move-indexed indirect instruction. It may occur to
amount of data needs to be displayed, simple digit-type
you at this point to wonder why, if this method is so
displays are often utilized. There are several technolo-
fast, we didn’t use it for the hex keypad conversion
gies used to make these digit-oriented displays, but we
described earlier. The answer is that since the row and
have space here to discuss only the two major types.
column code from the hex keypad is an 8-bit code, the
These are light-emitting diodes (LEDs) and liquid-
lookup table for the hash code method would require
crystal displays (LCDs). LCD displays use very low
256 memory locations. Of these 256 memory loca-
power, so they are often used in portable, battery-
tions, only 16 would actually be used. This would be a
powered instruments. LCDs however, do not emit their
waste of memory, so the compare method is a better
own light; they simply change the reflection of avail-
choice. It is important for you to become familiar with
able light. Therefore, for an instrument that is to be
both code conversion methods so that you can use the
one that best fits a particular application.
used in dim light conditions, you have to include a light
source for the LCDs or use LEDs, which emit their own
DEDICATED MICROPROCESSOR KEYBOARD light. Starting with LEDs, the following sections show
ENCODERS you how to interface these two types of displays to
microcomputers.
Most computers and computer terminals now use
detached keyboards with built-in encoders. Instead of
using a hardware encoder device such as the AY-5- Interfacing LED Displays to Microcomputers
2376, these keyboards use a dedicated microprocessor.
Figure 9-23 shows the encoder circuitry for the IBM PC Alphanumeric LED displays are available in three com-
mon formats. For displaying only numbers and hexa-
capacitive-switch matrix keyboard. The 8048 micro-
processor used here contains an 8-bit CPU, a ROM, decimal letters, simple seven-segment displays such as
some RAM, three ports, and a programmable timer/ that shown in Figure 1-6a are used. To display num-
counter. A program stored in the on-chip ROM per- bers and the entire alphabet, 18-segment displays,
forms the three keyboard tasks and sends the code for such as that shown in Figure 9-24a, p. 270, or 5 x 7
a pressed key out to the computer. To cut down the dot-matrix displays, such as that shown in Figure
number of connecting wires, the key code is sent out in 9-24b, p. 270, can be used. The seven-segment type is
serial form rather than in parallel form. Some key- the least expensive, most commonly used, and easiest
boards send data to the computer in serial form using a to interface, so we will concentrate first on how to
beam of infrared light instead of a wire. interface this type. Later we will show the modifica-
Note in Figure 9-23 the sense amplifier to detect the tions needed to interface to the other types.
change in capacitance produced when a key is pressed.
Also note that the 8048 uses a tuned LC circuit rather STATIC AND MULTIPLEXED DISPLAYS CIRCUITS
than a more expensive crystal to determine its opera- Figure 9-25, p. 270, shows a circuit you might use to
ting clock frequency. drive a single seven-segment, common-anode display.
One of the major advantages of using a dedicated For a common-anode display, a low is applied to a
microprocessor to do the three keyboard tasks is pro- segment to turn it on. When a BCD code is sent to the
27 MbO0 SENSEA C7
28 MD01 SENSEB AQ
= 29 MDO2 SENSEC A7
20.7 pF 30 MDO3 SENSED AS
31 MD04 SENSEE A3
32 MDOS KEYBOARD SENSEF
33 MDO6 CAPACITIVE
sear SENSEG
34M DO7 SENSEH
cD 1 (aos) <GND
- SENSE
AMPLIFIER
+5 VDC
+SERIAL
DATA CD1 (A07)
a
10 kQ PR
Caley DATAIN
D
fa]
or —REQUEST/
—REQOUT CLOCK
D> CD1 (A039)
inputs of the 7447, it outputs lows on the segments exceed its maximum rating. Therefore, a standard
required to display the number represented by the BCD value of 150 1) is reasonable.
code. This circuit connection is referred to as a static The circuit in Figure 9-25, p. 270, works well for
display because current is being passed through the driving just one or two LED digits. However, there are
display at all times. Note that current-limiting resistors problems if you want to drive, for example, eight digits.
are required in series with each segment. Here’s how The first problem is power consumption. For worst-
you calculate the value of these resistors. case calculations, assume that all eight digits are
Each segment requires a current of between 5 and displaying the digit 8 so all seven segments are lit.
30 mA to light. Let’s assume you want a current of 20 Seven segments times 20 mA per segment gives a
mA. The voltage drop across the LED when it is lit is current of 140 mA per digit. Multiplying this by eight
about 1.5 V. The output low voltage for the 7447 isa digits gives a total current of 1120 mA, or 1.12 A for
maximum of 0.4 V at 40 mA, so assume that it is about the eight digits! A second problem of the static ap-
0.2 V at 20 mA. Subtracting these two voltage drops proach is that each display digit requires a separate
from the supply voltage of 5 V leaves 3.3 V across the 7447 decoder; each uses perhaps another 13 mA. The
current-limiting resistor. Dividing 3.3 V by 20 mA current required by the decoders and the LED displays
gives a value of 168 © for the current-limiting resistor. might be several times the current required by the rest
The voltage drops across the LED and the output of the of the circuitry in the instrument.
7447 are not exactly predictable, and the exact current To solve the problems of the static display approach,
through the LED is not critical as long as we don’t we use a multiplex method. A circuit example is the
i i 7
D
c COMMON ANODE
DISPLAYS = DL 707
eateries ot R1-7 = 1kQ
Q1-7 = 2N3906
to check the data sheet for the maximum current and a hex keypad to an URDA MDS. The displays here
rating for the displays you are using. are common anode, and each digit has a PNP transistor
switch between its anode and the +5-V supply. A logic
A disadvantage of the software multiplexing ap- low is required to turn on one of these switches. Note
proach shown here is that it puts an additional burden the 22-uF capacitor between +5 V and ground at the
on the CPU. Also, if the CPU gets involved in doing top of the schematic. This is necessary to filter out
some lengthy task that cannot be interrupted to re- transients caused by switching the large currents to
fresh the display, only one digit of the display will be the LEDs off and on. The segments of each digit are all
left lit. An alternative approach to interfacing multi- connected on a common bus. Since these are common-
plexed displays to a microcomputer is to use a dedicat- anode displays, a low is needed to turn on a segment.
ed display controller, such as the Intel 8279, which The drive for the digit-switch transistors comes from
independently keeps displays refreshed and scans a a 7445 BCD-to-decimal decoder. This device is also
matrix keyboard. In the next section we show you how known as a one-of-ten-low decoder. When a 4-bit BCD
an 8279 is connected in a circuit, discuss how the code is applied to the inputs of this device, the output
8279 operates, and show you how to initialize an 8279. corresponding to that BCD number will go low. For
example, when the 8279 outputs 0100 or BCD 4, the
7445 output labeled 04 will go low. In the mode used
Display and Keyboard Interfacing with the for this circuit, the 8279 outputs a continuous BCD
8279 count sequence from 0000 to 1111 over and over. This
causes a low to be stepped from output to output of the
8279 CIRCUIT CONNECTIONS AND OPERATION 7445 in ring-counter fashion, turning on each LED
OVERVIEW digit in turn. Only one output of the 7445 will ever be
Figure 9-27a, p. 272, shows how an 8279 can be used low at a time, so only one LED digit will be turned on at
to connect two multiplexed seven-segment displays a time.
Shift
Cnt
8 COLUMNS
RETURN LINES
8 ROWS
3-8 DECODER
SCAN LINES
BLANK DISPLAY
4-16 DECODER
ADDRESSES
(DECODED)
DISPLAY
FROM CHARACTERS
ADDRESS
DECODER
DATA
DISPLAY
FIGURE 9-27 (a) Circuit connections for two seven-segment displays and a hex
keypad connected to an URDA MDS. (6) 8279 display refresh timing and
keyboard scan timing. (/nte! Corporation)
The segment bus lines for the displays are connected transistors. The lines SO and S1 in Figure 9-27 repre-
to the A3—AO and B3—B0 outputs of the 8279 through sent the SLO and SL1 lines. The 8279 then outputs the
some high-current buffers in the ULN2003A. Note that seven-segment code for the first digit on the A83-—AO
the 22-0, current-limiting resistors in series with the and B3-Bo0 lines. This lights the first digit with the
segment lines are much smaller in value than those we desired pattern. After 490 us the 8279 outputs a code
calculated for the static circuit in Figure 9-25. There on the A and B lines that turns off all the segments. For
are two reasons for this. First, there is a drop of an the circuit in Figure 7-6, sheet 7, this blanking code
additional few tenths of a volt across the transistor will be all 1s (SFF). The display is blanked here to
switch on each anode. Second, when multiplexing prevent ‘ghosting’ of information from one digit to the
displays we pass a higher current through the displays next when the digit strobe is switched to the next digit.
so that they appear as bright as they would if not While the displays are blanked, the 8279 sends out the
multiplexed. Here’s how the 8279 keeps these displays BCD code for the next digit to the 7445 to enable the
refreshed. digit-2 driver transistor. It then sends out the seven-
When you want to display some letters or numbers, segment code for digit 2 on the A and B lines. This then
you write the seven-segment codes for the letters or lights the desired pattern on digit 2. After 490 us the
numbers that you want displayed to a 16-byte RAM 8279 blanks the display again and goes on to digit 3.
inside the 8279. The 8279 then automatically cycles The 8279 steps through all the digits and then returns
through the process we described previously for send- to digit 1 and repeats the cycle. Since each digit
ing these codes in sequence to the displays. Figure requires about 640 ys, the 8279 gets back to digit 1
9-27b shows the operation in timing diagram form. after about 5.1 ms for an 8-digit display and back to
The 8279 first outputs the BCD number for the first digit 1 after about 10.3 ms for a 16-digit display. The
digit to the 7445 on the SLO-SL3 lines (Figure 7-6, time it takes to get back to a digit again is referred to as
sheet 7) to turn on the first one of the digit driver the scan time.
us
RLo-RL,
60 us =v H— CONDITIONAL WRITE TO FIFO RETURN LINES ARE SAMPLED ONE AT A TIME AS SHOWN
40 us RLg SELECTED, LATCHED
The point is that once you load the seven-segment The 74LS156 then puts a low on one row of the
codes into the internal RAM in the 8279, it automati- keyboard at a time.
cally keeps the displays refreshed without your having The column lines of the keyboard are connected to
to do anything else in the program. As we will show the return lines, RLO—RL7, of the 8279. Asa low is put
later, the 8279 can be connected and initialized to on each row by the scan-line count and the 74LS156,
refresh a wide variety of displays. the 8279 checks these return lines one at a time to see
The 8279 can also automatically perform the three if any of them are low. The bottom line of the timing
tasks for interfacing to a matrix keyboard. Remember waveforms in Figure 9-27 shows when the return lines
from previous discussions that the three tasks involve are checked. If the 8279 finds any of the return lines
putting a low on a row of the keyboard matrix and low, indicating a key-press, it waits a debounce time of
checking the columns of the matrix. If any keys are about 10.3 ms and checks again. If the key-press is still
pressed in that row, a low will be present on the present, the 8279 produces an 8-bit code that repre-
column that contains the key because pressing a key sents the key pressed. Figure 9-28, p. 274, shows the
shorts a row to a column. If no low is found on the format for the code produced. Three bits of this code
columns, the low is stepped to the next row and the represent the number of the row in which it found the
columns are checked again. If a low is found on a pressed key, and another 3 bits represent the column
column, then after a debounce time, the column is of the pressed key. For interfacing to full typewriter
checked again. If the keypress was valid, a compact keyboards, the shift and control keys are connected to
code representing the key is constructed. Take a look at pins 36 and 37, respectively, of the 8279. The upper 2
the circuit in Figure 9-27a to see how an 8279 can be bits of the code produced represent the status of these
connected to do this. two keys.
When connected as shown in Figure 9-27a, the After the 8279 produces the 8-bit code for the
74LS156 functions as a one-of-eight-low decoder. In pressed key, it stores the word in an internal 8-byte
other words, if you apply 011, the binary code for 3, to FIFO (first in, first out) RAM. When you start reading
its inputs, the 74LS156 will output a low on its 2Y3 codes from the FIFO, the first code you read out will be
output. Remember from the discussion of 8279 display that for the first key pressed. The FIFO can store the
refreshing that the 8279 is outputting a continuous codes for up to eight keys before overflowing.
counting sequence from 0000 to 1111 on its SLO—SL3 When the 8279 finds a valid key-press, it does two
lines. This count sequence applied to the inputs of the things to let you know about it. It asserts its interrupt
74LS156 will cause it to step a low along its outputs. request pin, IRQ, high, and it increments a FIFO count
MSB LSB
code: [1]0]0]aijalala]al
coe [o[o]o [oo] x [kK], The CPU sets up the 8279 for a write to the Display RAM
by first writing this command. After writing the com-
Where DD is the Display Mode and KKK is the Keyboard mand with Ag= 1, all subsequent writes with Ag=0 will
Mode. be to the Display RAM. The addressing and Auto-
Increment functions are identical to those for the Read
DD Display RAM. However, this command does not affect
0 0 8 8-bit character display — Left entry the source of subsequent Data Reads; the CPU will read
from whichever RAM (Display or FiFO/Sensor) which
Om 16 8-bit character display — Left entry’
was last specified. If, indeed, the Display RAM was last
1 0 88-bit character display — Right entry specified, the Write Display RAM will, nevertheless,
1 1. 16 8-bit character display — Right entry change the next Read location.
For description of right and left entry, see Interface Display Write Inhibit/Blanking
Considerations. Note that when decoded scan is set in
keyboard mode, the display is reduced to 4 characters A B A B
independent of display mode set.
code: [iJo]+]x]w] w]e] a]
0 0 O- Encoded Scan Keyboard — 2 Key Lockout* The IW Bits can be used to mask nibble A and nibble 8B
in applications requiring separate 4-bit display ports. By
0 0 1 Decoded Scan Keyboard — 2-Key Lockout setting the IW flag (IW= 1) for one of the ports, the port
0 1 0 Encoded Scan Keyboard — N-Key Rollover becomes marked so that entries to the Display RAM
from the CPU do not affect that port. Thus, if each nibble
0 1 1 Decoded Scan Keyboard — N-Key Rollover
is input to a BCD decoder, the CPU may write a digit to
0 Encoded Scan Sensor Matrix the Display RAM without affecting the other digit being
1 Decoded Scan Sensor Matrix displayed. It is important to note that bit By corresponds
to bit Dp on the CPU bus, and that bit Az corresponds to
1 1 0 Strobed Input, Encoded Display Scan
bit D7.
1 1 1 Strobed Input, Decoded Display Scan
If the user wishes to blank the display, the BL flags are
Program Clock available for each nibble. The last Clear command issued
determines the code to be used as a “blank.” This code
code: [olo|1|p|rip
le|r| defaults to all zeros after a reset. Note that both BL
flags must be set to blank a display formatted with a
All timing and multiplexing signals for the 8279 are single 8-bit port.
generated by an internal prescaler. This prescaler
divides the external clock (pin 3) by a programmable Clear
code [ols{ifatfalalala
the internal timing chain.
End Interrupt/Error Mode Set
The CPU sets up the 8279 for a read of the Display RAM
by first writing this command. The address bits AAAA Code: fa]a]afe[x]x |x|x] X = Don't care.
select one of the 16 rows of the Display RAM. If the Al
flag is set (Al=1), this row address will be incremented
after each following read or write to the Display RAM. For the sensor matrix modes this command lowers the
Since the same counter is used for both reading and IRQ line and enables further writing into RAM. (The IRQ
writing, this command sets the next read or write line would have been raised upon the detection of a
address and the sense of the Auto-Increment mode for change in a sensor value. This would have also inhibited
both operations. further writing into the RAM until reset).
FIGURE 9-29 8279 command word formats and bit descriptions. (Intel
Corporation)
DIGITAL INTERFACING 275
RAM For the URDA MDS, a high from the 8279 turns on a
LOCATION segment, so the required blanking code is all Os.
DISPLAY POSITION Therefore you can put Os in the two Cp bits. The
'
2
BARE resultant control word is 1100 0000.
The three control words described so far take care of
the basic initialization. However, before you can send
3 codes to the internal display RAM, you have to send the
(F{) REPRESENTS 8279 a write display RAM control word. This word
5 7 SEGMENT tells the 8279 that data later sent to the data address
6 CODE FORA should be put in the display RAM, and it tells the 8279
7 where in the display RAM to put the data byte sent in.
8 Refer to Figure 9-29 for the format of this word. The
8279 has an internal 4-bit pointer to the display RAM.
You use the lower 4 bits of this control word to initialize
the pointer to the location where you want to write a
RAM data byte in the RAM. If you want to write a data byte
LOCATION
to the first location in the display RAM, you put 0000 in
DISPLAY POSITION these bits. If you put a 1 in the autoincrement bit,
wo
we SEND SEVEN SEGMENT CODE TOSDISPLAYS RAM
END
FIGURE 9-31 68000 instructions to initialize an URDA MDS connected to an
8279, write to display RAM, and read FIFO RAM.
error-overrun bit, labeled 0 in the status word, will be the first location in the display RAM. Since the 8279 is
set to tell you characters have been lost. initialized for left entry, the first location should corre-
Characters can be read from the 8279 on a polled spond to the leftmost display digit. However, if you look
basis as well as on an interrupt basis. To do this you at Figure 9-27a you will see that digit 1 (leftmost as far
simply read and test the status word over and over as the 8279 is concerned) is actually the rightmost on
again until bit 0 of the status word becomes a 1. The the board. This means that, for the URDA MDS, the
URDA MDS uses this method to tell when the FIFO position of a seven-segment code in the display RAM
holds a key-pressed code. corresponds to its position in the display starting from
the right! All you have to do is send the seven-segment
code for a number you want to display in a particular
URDA MDS Display Driver Routine digit position to the corresponding location in the
display RAM.
Figure 9-33, p. 278, shows a 68000 assembly language
routine to display the contents of register DO on the
FIFO STATUS WORD
new LED display connected to the MDS using an 8279.
This routine assumes the 8279 has already been
initialized, as shown in the first part of Figure 9-31. If eRe
eT TT A—_,—_
DO is zero when this routine is called, the contents of
D1 will be displayed on the data field LEDs. If DO is not
| (ae NUMBER OF CHARACTERS IN FIFO
zero, then the contents of D1 will be displayed on the FIFO FULL
address field LEDs. There are two main points for you ERROR-UNDERRUN
to see in this routine. The first is the sending of the ERROR-OVERRUN
write display RAM control word to the 8279 so we can SENSOR CLOSURE/ERROR FLAG
FOR MULTIPLE CLOSURES
write to the desired locations in the display RAM. Note DISPLAY UNAVAILABLE
that, for the data field, we write a control word of $90,
which tells the 8279 to put the next data word sent into FIGURE 9-32 8279 status word format.
ORG $4100
MOVEM.L D2/A2-A3,-(A7) ; Save registers
MOVEA.L CONTROL_ADDR,A2 ; point at 8279 control register
CMPI.B #S00,D9 ; see if data field requested
BEQ DATFLD ; yes, go load control word for data
MOVE.B #S94,D90 ; no. load address field control word
BRA SEND ; go send control word
DATFLD: MOVE.B #S90,D@ ; control word for data field
SEND: MOVE.B D@,(A2) ; send to 8279
MOVEA.L SEVEN_SEG,A3 ; point at seven_seg table
MOVEA.L DATA_ADDR,A2 ypoInt atedatasregiastve 5
MOVE.B DO,D2 ; get copy of low nibble to display
ANDI.B #SQF,D2 ; mask upper nibble
MOVE.B 0(A3,D2),D2 ; translate lower nibble to 7-seg code
MOVE.B 2,(A2) ; send to 8279 display RAM
MOVE.B D@,D2 ; get another copy of low nibble
ROL.B #4,D2 ; rotate high nibble into low position
ANDI.B #S@F,D2 ; mask nibble
MOVE.B Q(A3,D2),D2 ; translate upper nibble to 7-seg code
MOVE.B D2, (A2) ; send to 8279 display RAM
ROR.W #8,D90 ; rotate bytes to get at upper 2 digits
MOVE.B D@,D2 3; get copy of upper byte
ANDI.B #SOF,D2 ; mask upper nibble
MOVE.B 0(A3,D2),D2 ; translate lower nibble to 7-seg code
MOVE.B OD2,(A2) ; send to 8279 display RAM
MOVE.B D@,D2 3; get another copy of upper byte
ROL.B #4,D2 ; rotate high nibble into low position
ANDI.B #S@OF,D2 ; mask nibble
MOVE.B 90(A3,D2),D2 ; translate upper nibble to 7-seg code
MOVE.B AA N72 }) ; send to 8279 display RAM
MOVEM.L (A7)+,D2/A2-A3 ; restore registers
RTS ; return to caller
END
D4 D3 D2 D1
SEGMENT OUTPUTS SEGMENT OUTPUTS SEGMENT OUTPUTS SEGMENT OUTPUTS
LATCH DECODER
ENABLE
ENABLE
74LS138 aT
oo 2 OSCILLATOR BACK-
Y2 C82 ES. : aie 16 KHZ PLANE BACKPLANE
my afFe FREE- DRIVER OUTPUT
RUNNING
ENABLE
+5 V OSC ENABLE
ENABLE DETECTOR
FIGURE 9-35 Circuit for interfacing four LCD digits to an URDA MDS bus
using Intersil |CM7211M.
and the high-power device. This section shows you a we show using 74LS07 buffers on the lines from ports
few of the commonly used devices and techniques. to a printer. In an actual circuit the 6821 outputs to the
computer-controlled lathe in Figure 9-6 should also
have buffers of this type. The 74LS06 and 74LS07 have
INTEGRATED CIRCUIT BUFFERS open-collector outputs, so you have to connect a pull-
One approach to buffering the outputs of port devices is up resistor from each output to +5 V. Each of the
with TTL buffers, such as the 7406 hex inverting and buffers in a 74LS06 or 74LS07 can sink as much as 40
7407 hex noninverting. In Figure 9-14, for example, mA to ground. You could then drive an LED with each
D.C. CHARACTERISTICS
Ty, = 0°C to 70°C, Vog = +5 V £5%; GND = OV
Rel WinNT,
|i=06!|Foas ivefase ee |
Pie.PERT] OUTPUTLOWVOLTAGE PERIPHERALPORT
|_| 046
Rey = 750 2 Vey, = 15V
ERS 9 ae 8 4.7K
(a)
FIGURE 9-41 Four-phase stepper motor interface circuit and stepping
waveforms. (a) Circuit. (b) Full-step drive signal order. (c) Half-step drive signal
order.
ZW(B)
4 In the Rhino robot arm each motor drives its section
7
INNER
(UV Co
== ME of the arm through a series of gears. Gearing the motor
WL are | down reduces the force that the motor has to exert and
oe a = | HI makes the exact position of the motor shaft less criti-
A | | : cal. Therefore, for the Rhino, six sets of slots in the
| | | | encoder disk are sufficient. However, for applications
| | LO
] | | | | | where a much more accurate indication of shaft posi-
|
Cai
: || | |
|
tion is needed, a self-contained shaft encoder such as
the Hewlett-Packard HEDS-5000 is attached to the
! | LO motor shaft. These encoders have two track-encoder
| | disks with 500 tiny radial slits per track. The wave-
NO~ oO
°
Ww oO
©
© 0” 180" 270° »3607 forms produced are the same as those shown for the
| | | |
oo | 10 1 11:1 01 1 00 Ee
ery
SS
| | 11 | 01 1 00 | Rhino encoder in Figure 9-44, but at a much higher
frequency for the same motor speed.
0.004 SEC. |
ONE CYCLE Optical encoders, in their many different forms, are
an important part of a large number of microcompu-
FIGURE 9-44 Optical-encoder disk slot pattern and ter-controlled machines.
output waveforms.
b. Show the bit writes needed to enable the port 11. Modify the printer driver procedure in Figure 9-17
A interrupt request and the port B interrupt so that it stops sending characters to the printer
request. when it finds a sentinel character of $03, instead
c. Show the assembly language instructions you of using the counter approach.
would use to send these control words to the
6821 in problem 4. 2: Would the software method of generating the
d. Show the additional instruction you need if STROBE signal to the printer in Figure 9-17 still
you want the handshake to be done on an work if you try to run the program with an 8-MHz
interrupt basis through the IRQA output of 68000? A 50-MHz 68030?
the lower 6821 in Figure 7-6. 13. Show the instructions you would use to read the
Describe the exchange of signals between the tape status byte from the 6821 in problem 5.
reader, 6821, and 68000 in Figure 9-6 as a byte of 14. Describe the three major tasks needed to get
data is transferred from the tape reader to the meaningful information from a matrix keyboard.
microprocessor.
15. Describe how the ‘‘compare’”’ method of code con-
Why is it more efficient to send phonemes to the version in Figure 9-21 works.
SC-01A speech synthesizer in Figure 9-10a on an
interrupt basis than on a polled basis? 16. Why is error trapping necessary in real programs?
17. Assume the rows of the circuit shown in Figure 18. a. Calculate the value of the current-limiting
9-45 are connected to ports $C0O14 and the 74148 resistor needed in series with each segment of
is connected to port $CO15 of an URDA MDS a seven-segment display driven by a 7447 if
board. The 74148 will output a low on its GS we want 40 mA per segment.
output if a low is applied to any of its inputs. The Approximately how much current is being
way the keyboard is wired, the A2, Al, and AO pulsed through each LED segment on the
outputs will have a 3-bit binary code for the URDA MDS board?
column in which a low appears. Use the algorithm
and discussion of Figure 9-21 to help you write a 19. Write the algorithm for a subroutine that
routine that detects a key-press, debounces the refreshes the multiplexed LED displays
key-press, and determines the row number and shown in Figure 9-26. Assume the routine
column number of the pressed key. The routine will be called every 2 ms by an interrupt
should then combine the row code, column code, signal to the 68000.
shift bit and control bit into a single byte in the Write the assembly language instructions
form control, shift, row code, column code. The for the display refresh subroutine. Since
MOVE indexed indirect instruction can then be this routine is called on an interrupt basis,
used to convert this code byte to ASCII to return to all display parameters should be kept in named
the calling program. (Hint: Use DC.B directive to memory locations. If you have time, you can
make up table of ASCII codes.) Why is the hash add the circuitry shown in Figure 9-26 to
code approach more efficient than the compare your microcomputer so you can test your
technique for this case? program.
2N2907
15022 1502
aN nN
+5V
2N2907
2N3904
1502
1kQ
2N2222 2N2222
FIGURE 9-46 Eight by eight LED matrix circuitry for problem 20.
16 character display, left entry, encoded-scan status register on the URDA MDS board until it
keyboard, N-key rollover. finds a key pressed and then reads the key-
pressed code from the FIFO RAM to DO and
1-MHz input clock divided to 100 kHz
returns.
Blanking character SFF
24. Why must the backplane and segment-line sig-
nals be pulsed for LCD displays?
b. Show the 8279 instructions necessary to
write $99 to the first location in the display 25; Draw a circuit you could attach to a 6821 port B
RAM and autoincrement the display RAM pin to drive a 1-A solenoid valve from a +12-V
pointer. supply. You want a high on the port pin to turn on
c. Show the assembly language instructions the solenoid.
necessary to read the first byte from the 8279
FIFO RAM. 26. Why must reverse-biased diodes always be placed
d. Determine the seven-segment codes you across inductive devices when you are driving
would have to send to the URDA MDS 8279 to them with a transistor?
display the word HELP on the data field dis-
play. Remember that DO of the byte sent 27. What are the major advantages and disadvantag-
equals BO and D7 of the byte sent equals A3. es of mechanical relays and solid-state relays?
e. Show the sequence of instructions you can
28. a. Howis electrical isolation between the control
send to the 8279 of the URDA MDS board to
output and the output circuitry achieved ina
blank the entire display.
solid-state relay?
23. Write a subroutine that polls the LSB of the 8279 b. Describe the function of the zero-crossing
In order to control the machines in our electronics Write programs to control A/D and D/A converters.
factory, medical instruments, or automobiles with a
Describe how feedback is used to control variables
microcomputer, we need to determine the values of
such as pressure, temperature, flow, and motor
variables such as pressure, temperature, and flow.
speed.
There are usually several steps in getting an electrical
signal that represents the values of these variables and 9. Describe the operation of a time-slice factory con-
converting the electrical signals to a digital form that trol system.
the microcomputer understands.
The first step involves a sensor, which converts the
physical pressure, temperature, or other variable to a
proportional voltage or current. The signals from most REVIEW OF OPERATIONAL-AMPLIFIER
sensors are quite small, so they must next be amplified CHARACTERISTICS AND CIRCUITS
and perhaps filtered. This is usually done with some Basic Operational Amplifier Characteristics
type of operational-amplifier (op-amp) circuit. The final
step is to convert the signal to digital form with an A/D Figure 10-la, p. 294, shows the schematic symbol for
converter. In this chapter we review some op-amp an operational amplifier commonly called an op amp.
circuits commonly used in these steps, show the inter- Here are the important points for you to remember
face circuitry for some common sensors, and discuss about the basic op amp. First, the pins labeled +V and
the operation and interfacing of A/D converters. We —V represent the power supply connections. The volt-
also discuss the interfacing of D/A converters and ages applied to these pins will usually be +15 V and
show how all these pieces are put together in a micro- —15 V or +12 V and —12 V. The op amp also has two
computer-based scale and a machine-control system. signal inputs. The amplifier amplifies the difference in
voltage between these two inputs by 100,000 or more.
The input labeled with a — sign is called the inverting
OBJECTIVES input and the one labeled with the + sign is called the
noninverting input. The + and — on these inputs have
At the conclusion of this chapter, you should be able to nothing to do with the power supply voltages. These
signs indicate the phase relationship between a signal
1. Recognize several common op-amp circuits, de- applied to that input and the result that the signal
scribe their operations, and predict the voltages at produces on the output. If, for example, the noninvert-
key points in each. ing input is made more positive than the inverting
input, the output will move in a positive direction,
2. Describe the operation and interfacing of several
which is in phase with the applied input signal. Now
common sensors used to measure temperature,
let’s see how far the output changes for a given input
pressure, flow, etc.
signal and see how an op amp is used as a comparator.
3. Draw circuits showing how to interface D/A con-
verters with any number of bits to a microcom-
puter. Op-amp Circuits and Applications
4. Define D/A data sheet parameters such as resolu- OP AMPS AS COMPARATORS
tion, settling time, accuracy, and linearity. We said previously that the op amp amplifies the
difference in voltage between its inputs by 100,000 or
5. Describe briefly the operation of flash, successive
more. (The number is variable with temperature and
approximation, and ramp A/D converters.
from device to device.) Suppose that you power an op
6. Draw circuits showing how A/D converters of vari- amp with +15 V and —15 V, tie the inverting input of
ous types can be interfaced to a microcomputer. the op amp to ground, and apply a signal of +0.01 V de
JasJas
COMMON OP AMP COMPARATOR COMPARATOR WITH HYSTERESIS
pe OUTPUT
~ +V—1 V
+V
OUTPUT ~+V —1 V IF Viv < Veer
IF Vin > Veererence
Vin
OUTPUT ~-V +1V
OUTPUT ~—V + 1V IF Vin > Vaer .
;
Vy, IF Vin < Vaee Vuysteresis = Vour * R,+R5
Avo. > 100,000 VREF
Veer
R1+R2 Vout
Ave. ~~ Ry V5
(d) (f)
DIFFERENTIAL AMP INSTRUMENTATION AMP
Vout
AW
(g) (h)
INTEGRATOR (RAMP GENERATOR) DIFFERENTIATOR
i)
2ND ORDER LOW PASS FILTER
Vout
(k) (I)
FIGURE 10-1 Overview of commonly used op-amp circuits. (2) Common op
amp. (b) Comparator. (c) Comparator with hysteresis. (d) Noninverting amp.
(e) Inverting amp. (f) Adder (mixer). (g) Differential amp. (h) Instrumentation
amp. (i) Integrator (ramp generator). (j) Differentiator. (k) Second-order
low-pass filter. (/) Second-order high-pass filter.
294 -CHAPTER TEN
to the noninverting input. The op amp will attempt to To determine the amount of hysteresis in a circuit
amplify this signal by 100,000 and produce the result such as that in Figure 10-lc, assume Vr = O V and
on its output. An input signal of 0.01 V times a gain of Vour = 13 V. A simple voltage-divider calculation will
100,000 predicts an output voltage of 100 V. The tell you that the noninverting input is at about 13 mV.
op-amp output, however, can go positive only to a The voltage on the inverting input of the amplifier will
voltage that is a volt or two less than the positive have to go more positive than this before the compara-
supply voltage, perhaps 13 V, so this is as far as it goes. tor will change states. Likewise, if you assume Voy; is
Now suppose that you apply a signal of —0.01 V to the -13 V, the noninverting input will be at about
noninverting input. The output will now try to go to —13 mV, so the voltage on the inverting input of the
—100 V as fast as it can. The output, however, can go amplifier will have to go below this to change the state
only to about —13 V, so this is where it stops. of the output. The hysteresis of this comparator is then
In this circuit the op amp effectively compares the +13 mV to -—13 mV, or a total of 26 mV.
input voltage with the voltage on the inverting input
and gives a high or low output depending on the result
of the comparison. If the input is more than a few NONINVERTING AMPLIFIER OP-AMP. CIRCUIT
microvolts above the reference voltage on the inverting When operating in open-loop mode (no feedback to the
input, the output will be high (+13 V). If the input inverting input), an op amp has a very high, but
voltage is a few microvolts more negative than the unpredictable, gain. This is acceptable for use as a
reference voltage, the output will be low (—13 V). An op comparator but not for use as a predictable amplifier.
amp used in this way is called a comparator. Figure Figure 10-ld shows one way negative feedback is
10-1b shows how a comparator is usually labeled. The added to an op amp to produce an amplifier with stable,
reference voltage applied to the inverting input does predictable gain. First of all, notice that the input
not have to be ground (0 V). An input voltage can be signal in this circuit is applied to the noninverting
compared to any voltage within the input range speci- input, so the output will be in phase with the input.
fied for the particular op amp. Second, note that a fraction of the output signal is fed
As you will see throughout this chapter, comparators back to the inverting input. Now, here’s how this
have many applications. We might, for example, con- works.
nect a comparator to a temperature sensor on the To start, assume that V,, is O V, Voyr is O V, and the
boiler in our electronics factory. When the voltage voltage on the inverting input is 0. Now, suppose that
from the temperature sensor goes above the voltage you apply a +0.01-V dc signal to the noninverting
on the reference input of the comparator, the output input. Since the 0.1-V difference between the two
of the comparator will change state and send an inputs will be amplified by 100,000, the output will
interrupt signal to the microprocessor controlling the head toward 100 V as fast as it can. However, as the
boiler. Commonly available comparators, such as the output goes positive, some of the output voltage will be
LM319, have TTL-compatible outputs, which can be fed back to the inverting input through the resistor
connected directly to microcomputer port or inter- divider. This feedback to the inverting input will de-
rupt inputs. crease the difference in voltage between the two in-
Figure 10-1c shows another commonly used compa- puts. To make a long story short, the circuit quickly
rator circuit. Note in this circuit that the reference reaches a predictable balance point, at which the
signal is applied to the noninverting input, and the voltage on the inverting input (Vy) is very, very close to
input voltage is applied to the inverting input. This the voltage on the noninverting input (V,). For a 1.0-V
connection simply inverts the output state from those de output, this equilibrium voltage difference might be
in the previous circuit. Note also in Figure 10-1c the about 10 wV. If you assume that the voltages on the two
positive-feedback resistors from the output to the non- inputs are equal, then predicting the output voltage for
inverting input. This feedback gives the comparator a a given input voltage is simply a voltage-divider prob-
characteristic called hysteresis. Hysteresis means lem: Voyr = Vin (R1 + R2)/R1. If R2is 99 kO andR1 is 1
that the output voltage changes at a different input kQ, then Voyr = Viy X 100. For a 0.01-V input signal,
voltage when the input is going in the positive direction the output voltage will be 1.00 V. The closed-loop gain,
than it does when the input voltage is going in a Aycr, for this circuit is equal to the simple resistor ratio,
negative direction. If you have a thermostatically con- (Rl + R2)/R1.
trolled furnace in your house, you have seen hysteresis To see another advantage in feeding some of the
in action. The furnace, for example, may turn on when output signal back to the inverting input, let’s see what
the room temperature drops to 65°F and then not turn happens when the load connected to the output of the
off until the temperature reaches 68°F. Hysteresis is op amp changes and draws more current from the
the difference between the two temperatures. Without output. The output voltage will temporarily drop be-
hysteresis, the furnace would rapidly be turning on cause of the increased load. Part of this drop will be fed
and off if the room temperature were near 68°F. Anoth- back to the inverting input, increasing the difference
er situation where hysteresis saves the day is the case in voltage between the two inputs. This increased
in which you have a slowly changing signal with noise difference will cause the op amp to drive its output to
on it. Hysteresis prevents the noise from causing the correct for the increased load. Feedback that causes an
comparator output to oscillate as the input signal gets amplifier to oppose a change on its output is called
close to the reference voltage. negative feedback. Because of the negative feedback,
PHOTORESISTOR
Temperature Sensors
V
PHOTODIODE um
HP5082-4203 Again, there are many types of temperature sensors.
The two types we discuss here are semiconductor
PN (2 devices, which are inexpensive and can be used to
FIGURE 10-5 Photodiode circuit to measure infrared measure temperatures over the range of —55°C to
light intensity. 100°C, and thermocouples, which can be used to mea-
sure very low temperatures and very high tempera-
tures.
MEASURED TEMP
P2 15K
+V 0 TO 100°C
TRIM 100°C
4-30 V
AD590J
LM35 Vout = +1500 mV AT 150°C
+250 mV AT 25°C
—550 mV AT —55°C
R, REMOTE
TEMPERATURE-
pena TO-CURRENT
= =VE 1 50 pA TRANSDUCER, R1
1 pA/K 1KQ. 0.1% INSTRUMENTATION
LOW TCR AMPLIFIER,
AD590 IC IS METERING GAIN OF 10,
AVAILABLE IN RESISTOR, 0.00 V TO 1.00 FS
PROBE AS AC2626J ImV/pA = 1mV/K 10 mV/°C
(a) (b)
FIGURE 10-6 Semiconductor temperature-sensor circuits. (a) LM35
temperature-dependent voltage source. (b) AD590 temperature-dependent
current source. (Analog Devices Incorporated)
to about 1600°C. Thermocouples can be made small, from the measuring junction. This is done so that the
rugged, and stable; however, they have three major output connecting wires are both constant. The ther-
problems that must be overcome. mocouples formed by connecting these wires to the
First of these is the fact that the output is very small copper wires going to the amplifier will then cancel out.
and must be amplified a great deal to bring it up into The resultant output voltage will be the difference
the range where it can, for example, drive an A/D between the voltages across the two thermocouples. If
converter. Second, in order to make accurate measure- we simply amplify the output of the two thermocou-
ments, a second junction made of the same metals ples, however, there is a problem if the temperature of
must be included in the circuit as a reference. Adding both thermocouples is changing. The problem is that it
this second junction is referred to as a cold-junction is impossible to tell which thermocouple caused a
compensation. Figure 10-7 shows a circuit to amplify change in output voltage. One cure for this is to put
the output of a thermocouple and provide cold-junction the reference junction in an ice bath or a small oven
compensation for a type J thermocouple. to hold it at a constant temperature. This solution is
The first thing to notice in the circuit is that the usually inconvenient, so instead a circuit such as
reference junction is connected in the reverse direction that in Figure 10-7 is used to compensate elec-
tronically for changes in the temperature of the refer-
ence junction.
As we discussed in a previous section, the AD590
REFERENCE shown here produces a current proportional to its
JUNCTION iy temperature. The AD590 is attached to the reference
15°C <1, < 35°C
thermocouple so that they are both at the same temp-
OUTPUT erature. The current from the AD590, when passed
AMPLIFIER through the resistor network, produces a voltage that
MEASURING OR METER
JUNCTION GHon compensates for changes in the reference thermocou-
ple with temperature. The output amplifier for this
circuit is a differential amplifier such as that shown in
Figure 10-lg or the instrumentation amplifier shown
—_—_—— =O ©
WIDE
POWER SUPPLY
OPTIONS
WIDE VARIETY OF SENSOR AND
ANALOG SIGNAL INPUTS
An LVDT can be used directly in this form to mea- to create some resistance. Flow through this resistance
sure displacement or position. If you add a spring so produces a difference in pressure between the two
that a force is required to move the core, then the sides of the resistance. The pressure transducer gives
voltage out of the LVDT will be proportional to the force an output proportional to the difference in pressure
applied to the core. In this form the LVDT can be used between the two sides of the resistance. In the same
in a load cell for an electronic scale. Likewise, if a way that the voltage across an electrical resistor is
spring is added and the core of the LVDT is attached to proportional to the flow of current through the resistor,
a diaphragm in a threaded housing, the output from the output of the pressure transducer is proportional to
the LVDT will be proportional to the pressure exerted the flow of a liquid or gas through the pipe.
on the diaphragm. We do not have space here to show
the ac interface circuitry required for an LVDT.
Other Sensors
Flow Sensors
As we mentioned previously, the number of different
If we are going to control the flow rate of some material types of sensors is very large. In addition to the types
in our electronics factory, we need to be able to mea- we have discussed, there are sensors to measure pH,
sure it. Depending on the material, flow rate, and concentration of various gases, thickness of materials,
temperature, we use different methods. and just about any thing else you might want to
One method used is to put a paddle wheel in the flow, measure. Often you can use commonly available trans-
as shown in Figure 10-13a, p. 304. The rate at which ducers in creative ways to solve a particular applica-
the paddle wheel turns is proportional to the rate of tion problem you have. Suppose, for example, that you
flow of a liquid or gas. An optical encoder can be need to determine accurately the level of a liquid in a
attached to the shaft of the paddle wheel to produce large tank. To do this you could install a pressure
digital information as to how fast the paddle wheel is transducer at the bottom of the tank. The pressure ina
turning. liquid is proportional to the height of the liquid in the
A second common method of measuring flow is with tank, so you could easily convert a pressure reading to
a differential-pressure transducer, as shown in Figure the desired liquid height. The point here is to check out
10-13b, p. 304. A wire mesh or screen is put in the pipe what is available and then be creative.
WEIGHT
(a)
PRIMARY SECONDARIES
AC
EXCITATION
SIGNAL
20 KHZ
oy
~ a
SreeleenEcerenn- verre i
©
17
microprocessor. Interfacing an 8-bit converter in- O
18
volves simply connecting the inputs of the converter to ©
19
an output port; for some D/As, it means simply con- 20
16-BIT ss i
necting it to the buses, as you would a port device. DATA BUS 0 TO
Now, suppose that for some application you need 12 5 CURRENT
| SWITCHES
bits of resolution, so you need to interface a 12-bit
converter. If you are working with a system that has an
8-bit data bus, your first thought might be to connect y O 6 Q
the lower 8 inputs of the 12-bit converter to one output DBO DB4 gut Q
port and the upper 4 inputs to another port. You could 98 Q
send the lower 8 bits with one write operation and the oe a
Ee
upper 4 bits with another write operation. However,
there is a potential problem with this approach that is
caused by the time between the two writes. Suppose,
Veco 9-7 By TE 1/ | G)
for example, that you want to change the output of a BYTE2
12-bit converter from 0000 1111 1111 to 0001 0000 SIGNAL mea,
FROM CS. O
0000. When you write the lower 8 bits, the output will ADDRESS Trach ee)
DECODER lilo e
go from 0000 1111 1111 to 0000 0000 0000. When
XFER. 4
you write the upper 4 bits, the output will then go back SYSTEM ——
WR WR2, ie)
up to the desired 0001 0000 OOOO. The point here is STROBE ak ee
ee eee eee
that for the time between the two writes, the output
will go to an unwanted value. In many systems this
could be disastrous. The cure for this problem is to put
latches on the input lines. The latches can be loaded
separately and then strobed together to pass all 12 bits
to the D/A converter at the same time.
Many currently available D/A converters contain
built-in latches to make this easier. Figure 10-17a
shows a block diagram of the National DAC1230- and
DAC1208-type 12-bit converters. Note the internal
latches and the register. The DAC1230 series of parts
has the upper 4 input bits connected to the lower 4 bits Vos ADJUST
so that the 12 bits can be written with two write (ZERO
ADJUSTMENT)
operations from an 8-bit port or data bus, such as that
of the 68008 microprocessor. The DAC1208 series of e —Vrer (0)
Vout = (lout: X Rep) = 4096 FOR O<D < 4095
parts has the upper 4 data inputs available separately
so they can be connected directly to the bus in a system (b)
that has a 16-bit data bus, as shown in Figure 10-17a.
FIGURE 10-17 (a) National DAC1208 12-bit D/A input
If, for example, you want to connect up a DAC1208
converter to an URDA® MDS board, you can simply
block diagram showing internal latches. (b) Analog
circuit connections.
connect the DAC1208 data inputs to the lower 12 data
bus lines, connect the CS input to an address decoder
output, connect the WR1 input to the system RD/WR
line, and tie the WR2 and XFER inputs to ground. The the output current to a proportional voltage. An FET-
BYTE1/BYTE2 input is tied high. You then write words input amplifier is used, because the input-bias current
to the converter just as if it were a 16-bit port. The of a bipolar input amp might affect the accuracy of the
timing parameters for the DAC1208 are acceptable for output. The DAC1208 and DAC1230 have built-in
a 68000 operating with a clock frequency of 4 MHz or feedback resistors, which match the temperature
less. For higher 68000 clock frequencies, you would characteristics of the internal current-divider resis-
have to add a one-shot or other circuitry that inserts tors, so all you have to add externally is a 50-0 resistor
a wait state each time you write to the D/A. Here are for ‘‘tweaking’’ purposes. With a —10.000-V reference,
a few notes about the analog connections for these as shown, the output voltage will be equal to (the
devices. digital-input word/4096) x (+10.000 V). Note that the
These D/A converters require a precision voltage D/A has both a digital ground and an analog ground.
reference. The circuit in Figure 10-17b uses a To avoid getting digital noise in the analog portions of
-10.000-V reference. The D/A converters have a cur- the circuit, these two should be connected together
rent output, so we use an op amp, as shown, to convert only at the power supply.
LATCHES | DATA
74LS374 f OUTPUTS
WE
MC1408
Voc Ve Ei
(2)] (13)] (3)} (16)} (14)] (15) (1)
LM741
NC
50 pF 2.5kQ
: 2.5kQ
—15V <5 Viidrat- 6) 2d — O
converter is going to drive a display, then it is conve- of the buses and allows data to be transferred directly
nient to have the output coded in BCD. For applications from the A/D converter to successive memory loca-
where the input range of the converter has both a tions. We discuss DMA in detail in the next chapter.
negative and a positive range (bipolar), we usually use
offset binary coding. As you can see in Figure 10-21
INTERFACING TO SLOPE-TYPE A/D CONVERTERS
the values of 0000 0000 to 1111 1111 are simply
shifted downward so that 0000 0000 represents the Most of the commonly available slope-type converters
most negative input value and 1000 0000 represents were designed to drive seven-segment displays in, for
an input value of zero. This coding scheme has the example, a digital voltmeter. Therefore, they usually
advantage that the 2’s complement representation can output data in a multiplexed BCD or seven-segment
be produced by simply inverting the most significant form. Figure 10-22 shows how you can SETS: the
bit. Some bipolar converters output the digital value multiplexed BCD outputs of an inexpensive 35-digit
directly in 2’s complement form. slope converter, the MC14433, to a microprocessor
port. In the section of the chapter where Figure 10-22
is located, we use this converter as part of a microcom-
Interfacing Different Types of A/D Converters puter-based scale. The BCD data is output from the
to Microcomputers converter on lines QO—Q3. A logic high is output on one
of the digit strobe lines, DS1—DS4, to indicate when
INTERFACING TO PARALLEL COMPARATOR A/D
the BCD code for the corresponding digit is on the Q
CONVERTERS
outputs. The MC14433 converter shown in Figure
In any application where a parallel comparator con- 10-23 outputs the BCD code for the most significant
verter is used, the converter is most likely going to be digit and then outputs the BCD code for the most
producing digital output values much faster than a significant digit and then outputs a high on the DS1
microcomputer could possibly read them in. Therefore, pin. After a period of time it outputs the BCD code for
separate circuitry is used to bypass the microprocessor the next most significant digit and outputs a high on
and load a set of samples from the converter directly the DS2 pin. After all 4 digits have been put out, the
into a series of memory locations. The microprocessor cycle repeats.
can later perform the desired operation on the sam- To read in the data from this converter, the principle
ples. Bypassing the microprocessor in this way is is simply to poll the bit corresponding to a strobe line
called direct memory access, or DMA. The basic prin- until you find it high, read in the data for that digit, and
ciple of DMA is that an external controller IC tells the put the data in a reserved memory location for future
microprocessor to float its buses. When the micro- reference. After you have read the BCD code for one
processor does this, the DMA controller takes control digit, you poll the bit that corresponds to the strobe line
FIGURE 10-21 Common A/D output codes. Figure 10-22 shows a block diagram of our smart
scale. A load cell converts the applied weight of, for
example, a bunch of carrots, to a proportional electri-
cal signal. This small signal is amplified and converted
for the next digit until you find it high, read the code for
to a digital value, which can be read in by the micro-
that digit, and put it in memory. Repeat the process
processor and sent to the attached display. The user
until you have the data for all the digits. The A/D
then enters the price per pound with the keyboard and
converter in Figure 10-23 is connected to do continu-
this price per pound is shown on the display. When the
ous conversions, so you can call the procedure to read
user presses the compute key on the keyboard, the
in the value from the A/D converter at any time.
microprocessor multiplies the weight times the price
Frequency counters, digital voltmeters, and other
per pound and shows the result on the display. After
test instruments often have multiplexed BCD outputs
holding the price display long enough for the user to
available on their back panels. With the connections
read it, the scale goes back to reading in the weight
and procedure we have just described, you can use
value and displaying it. To save the user from having to
these instruments to input data to your microcom-
type the computed price into the cash register, an
puter.
output from the scale could be connected directly into
the cash register circuitry. A speech synthesizer, such
INTERFACING A SUCCESSIVE-APPROXIMATION as the Votrax SC-01A we described in Chapter 9, could
A/D CONVERTER
be attached to tell the customer the weight, price per
Successive-approximation A/D converters usually pound, and total price.
have outputs for each bit. The code output on these Smart scales such as this have many applications
lines is usually straight binary or offset binary. You other than weighing carrots. A modified version of this
can simply connect the parallel outputs of the convert- scale is used in company mail rooms to weigh packages
er to the required number of input port pins and read and calculate the postage required to send them to
the converter output in under program control. In different postal zones. The output of the scale can be
addition to the data lines, there are two other succes- connected to a postage meter, which then automatical-
sive-approximation A/D converter signal lines you ly prints out the required postage sticker. Another
need to interface to the microcomputer for the data application of smart scales is to count coins in a bank
transfer. The first of these is a START CONVERT or gambling casino. For this application the user sim-
signal, which you output from the microcomputer to ply enters the type of coin being weighed. A conversion
DISPLAY
KEYBOARD
POWER
SUPPIEY.
factor in the program then computes the total number maximum signal from the load cell will give a maxi-
of coins and the total dollar amount. Still another mum voltage of 2.00 V to the A/D converter input. A
application of a scale such as this is in packaging items precision voltage divider on the output of the amplifier
for sale. Suppose, for example, that we are manufac- divides this signal in half so that a weight of 10.00 Ib
turing wood screws and that we want to package 100 of produces an output voltage of 1.000 V. This scaling
them per box. We can pass the boxes over the load cell simplifies the display of the weight after it is read into
on a conveyer belt and fill them from a chute until the the microprocessor. The 0.1-yuF capacitor between
weight—and therefore the count—reaches some en- pins 15 and 16 of the amplifier reduces the bandwidth
tered value. The point here is that the combination of of the amplifier to about 7.5 Hz. This removes 60 Hz
intelligence and some simple interface circuitry gives and any high-frequency noise that might have been
you an instrument with as many uses as you can induced in the signal lines.
imagine. The MC14433 A/D converter used here is an inex-
pensive dual-slope device intended for use in 35-digit
digital voltmeters, etc. Because the load cell changes
Smart-Scale Input Circuitry slowly, a fast converter isn’t needed here. The voltage
Figure 10-10 shows a picture of the Transducers, Inc. across an LM329, 6.9-V precision reference diode is
Model C462-10#-10P1 strain-gage load cell we used amplified by IC4 to produce the 10.00-V excitation
when we built this scale. We added a piece of plywood voltage for the load cell and a 2.000-V reference for the
to the top of the load cell to keep the carrots from falling A/D. With a 2.000-V reference voltage, the full-scale
off. This load cell has an accuracy of about 1 part in input voltage for the A/D is 2.000 V. Conversion rate
1000, or 0.01 lb over the O- to 10-lb range for which it and multiplexing frequency for the converter are deter-
was designed. mined by an internal oscillator and R11. An R11 of
As shown in Figure 10-23, p. 312, the load cell 300 k0Q gives a clock frequency of 66 kHz, a multiplex
consists of four 350-( resistors connected in a bridge frequency of 0.8 kHz, and about four conversions per
configuration. A stable 10.00-V excitation voltage is second. Accuracy of the converter is +0.05% and +1
applied to the top of the bridge. With no load on the cell, count, which is comparable to the accuracy of the load
the outputs from the bridge are at about the same cell. In other words, the last digit of the displayed
voltage, 5 V. When a load is applied to the bridge, the weight may be off by 1 or 2 counts. As we described ina
resistance of one of the lower resistors will be changed. previous section, the output from this converter is in
This produces a small differential output voltage from multiplexed BCD form.
the bridge. The maximum differential output voltage
for this 10-lb load cell is 2 mV per volt of excitation. An Algorithm for the Smart Scale
With a 10.00-V excitation, as shown, the maximum
differential-output voltage is then 20 mV. Figure 10-24, p. 312, shows the flowchart for our
To amplify this small differential signal, we use a smart scale. Note that, as indicated by the double-
National LM363 instrumentation amplifier. This de- ended boxes in the flowchart, most major parts of the
vice contains all the circuitry shown for the instru- program are written as procedures. The output of the
mentation amplifier in Figure 10-1h. The closed-loop A/D is in multiplexed BCD form, as we described in
gain of the amplifier is programmable for fixed values the section on slope-converter interfacing. Therefore,
of 5, 100, and 500 with jumpers on pins 2, 3, and 4. We each strobe has to be polled until it goes high, and then
have jumpered it for a gain of 100 so that the 20-mV the BCD code for that digit can be read in.
2N2222
ace
INITIALIZE
LOAD CELL |+15 V
BALANCE
ADJUST
50 KQ
GET WEIGHT
0.1 uF
REL =15 V FROM A/D CONVERT
PRICE/LB
| TO BINARY
| DUMB DISPLAY
|
| SCALE ©
seri WEIGHT AND LB CONVERT
|
| WEIGHT
| TO BINARY
350 Q |
DISREAY SSP
FOR
SELLING PRICE CONVERT
TOTAL PRICE
8255 TO BCD
1.3 KQ |
O (12)
SZ
The BCD values read in from the converter are stored _is pressed, it is assumed that the entered price per
in four memory locations. A display procedure accesses pound is correct, and the program goes on to compute
these values and sends them to the address field the total price.
display of the URDA MDS. The letters LB are displayed Computing the price involves multiplying the
in the data field. After the weight is displayed, a check weight in BCD form times the price per pound in
is made to see if any keys have been pressed by the BCD form. It is not easy to do a BCD x BCD multiply
user. If a key has been pressed, the letters SP, which directly, so we took an alternate route to get there.
represent selling price, are displayed in the address Both the weight and the price per pound are convert-
field. Keycodes are read from the 8279 as entered and ed to binary. The two binary numbers are then mul-
displayed on the data field display. Keys can be pressed tiplied. The binary result of the multiplication is con-
until the desired price per pound shows on the display. verted to BCD, rounded to the nearest cent, and
The price per pound entered by a user is assembled in displayed in the data field. The letters PR are dis-
a series of memory locations. When a nonnumeric key played in the address field. After a few seconds the
STACK HERE; DS.W 200 ; veserve 200 words for the stack
STACK TOP: DS.W 0 ; stack top is high address
WEIGHT BUFFER: DS.B 4 ; Space for unpacked BCD weight
SELL PRICE: DS.B 4 ; Space for unpacked price/pound
PRICE TOTAL: Ses 4 7) Space Lom totally price toudi splay,
BINARY WIEGHT: DC.W 0 ; Space for converted wieght
iS DC.B S0B7 910,014,514 >" by Gye blank miblank
S.i28 E413} SLAs
Sul sli! 2 32 S. douheval<. loiteiale
PR: DC.B $13, S127614)
S14 te ery lanka blank
SEVEN_SEG: DC.B Sir, S06, Sas, SG", S66, SGD, SID, SOT
5 0 ul 2 3 4 5 6 7
DC.B Sr, S69, S77, SIC. S89, Sas, STO, Sl
q 8 9 A b e da E F
DESB Sasi; SED, S73, SSO, SOO, S76
L S Pp ie Isllevole — 19
Ss Stantecode
g ORG $4000 ; for the Consulair Cross-assembler
START: LEA STACK _TOP,A7 ; initialize user stack pointer
; Tinitialize 8279
LEA SBF10,A1 ; point to 8279 control address
MOVE.B #500, (Al) ; configure 8279 for 8 character display
f left entry encoded scan, 2-key lockout
MOVE.B #538, (Al) clock word for divide by 24
MOVE.B #5SCO, (Al) fi clear display character is all 0's
DSSr (#$C014)
,DO read A/D to check MSD bit
#6,D0 test digit 3 strobe bit
DS3 loop and read A/D again if
MSD strobe bit not set
MOVE .B (#$C014), read A/D to get digit
AND .B #S0F,DO mask out strobe bits
NXTCHR: * MOVE .B DO, (Al) - save digit 3 code in weight buffer
and decrement pointer to point to
next lower digit
PRAKKKKKRKKKKK KKK KKK KKK KK KKK KKK KKK KKK KKK KK KKK KKK KKK KKK KK KKK KKK KK KKK RK KK KK KKK
j XXKKKKKAKKKKAKE* Subroutines use in smart scale program **KK KARR KR KKK KKH
; SUBROUTINE READ KEY
; ABSTRACT reads the URDA Keyboard attached via an 8279 - subroutine
polls the status register until it finds a key pressed.
It then reads the keypressed code from the FIFO RAM into
DO and returns.
; REGISTERS USED: Destroys DO - returns character read in DO
PRKKKKKKAKKKK KKK KKK KKK KK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK KEKKKKKKK KKK KKK AK KK A KK
; SUBROUTINE DISPLAY
, ABSTRACT This subroutine displays characters on the display
connected to the URDA MDS via an 8279. The data is sent
to this subroutine in the following manner:
INCOMING Parameters:
Al -- pointer to buffer containing the 7-seg
codes of the 4 characters to be displayed
DO = 0 implies use data field
DO = 1 implies use address field
D1 = 0 implies no decimal point
Dl = 1 implies decimal point between second
and third digit
; REGISTER USAGE (all saved and restored)
A2 - 8279 control/data register pointer
A3 - pointer to seven-seg table
D25—wealgisen OOpmeount er
D3 - temporary index for BCD to seven seg translation
DISPLAY:
(A2,A3,D2,D3],-(A7) save working registers on stack
#SBF10,A2 point at 8279 control register
#$00,D0 see if data field required
DATFLD yes, load cntl wd for data field
#594,D0 no, load cntl wd for addr field
SEND go send control word to 8279
DATFLD: #$90,D0 load control word for data field
SEND: DO, (A2) send control word to 8279
#SBF09,A2 point to 8279 display RAM
#4,D2 counter for number of characters
#SEVEN_SEG, A3 pointer to seven seg codes
AGAIN: (Al) +,D3 get character to be displayed
(A3;,/D3) ,DO get seven seg code to display
#$02,D2 see if digit that gets decimal pt
no go send digit
yes, see if decimal pt specified
no, go send character
yes, OR in decimal point
MORE: send seven-seg code to 8279
display RAM
D2, AGAIN decrement digit counter and loop
to send another if > 0 (continued)
ANALOG INTERFACING AND INDUSTRIAL CONTROL 317
MOVEME = (Ay) (AZ WAS) DZD ol 7 restore saved registers from stack
RTS 7 return to calling routine
; SUBROUTINE PACK
; ABSTRACT This subroutine converts four unpacked BCD digits pointed
; to by Al to four packed BCD digits in DO
7 DESTROYS mb 0
CONVERT2BIN:
MOVEM.L [D1-D5],-(A7) ; save working registers D1-D5
KKKKKKKKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK KKK KK KK KKK
; SUBROUTINE BINCVT
; ABSTRACT This subroutine converts a 24-bit binary number in DO
; to a packed BCD equivalent in DO
PUNE UL: DO - 24-bit binary number
OU DEW Tes DO - packed BCD equivalent
; USES and SAVE/RESTORES: D1 - number of bits in value for CNVT1
f D2
, D3 -
. D4 -
, DS =
BINCVT:
MOVEM.L [D1-D6],-(A7) ; save working registers D1-D6
PRKA K K KKK KKK KK KKK KK KKK KKK KKK KKK KK KKK KKK KKK KK KKK KKK KKK KEKKKEKEKKEKEK
‘
; SUBROUTINE CNVT1
; ABSTRACT Extract two BCD digits from the incoming binary number in
DO, leave DO as the new value less the BCD equivalent.
; On incoming D1 indicates the number of bits in the incoming
; value, return the two digits in the low byte of Dl
CNVT1:
CNVEZ RG lie 15 D6 ; clear D as workspace and clear carry
DBGT D1, CONTINUE : decrement bit count and return if 0
RTS 5 return to calling routine
CONTINUE:
ROL. L #1,D0 5 rotate left 1 bit
ASLX.B #1,D6 2 double BCD digit being built and add
extend bit (carry)
; decimal adjust here
END
The subroutine in Figure 10-25 produces two BCD produced by the compare instruction and the next two
digits of the result at a time by calling the subroutine higher BCD digits in D2 are added to D1. This must be
CNVT1. Figure 10-26 shows a flowchart for the opera- done in a data register, because the decimal-adjust
tion of CNVT1. The main principle here is to shift the operations, used to keep the result in BCD format, work
24-bit number left 1 bit position so the MSB goes into only on an operand in a data register. Any carry from
the carry flip-flop and then add this bit to twice the these two BCD digits is propagated on to the upper two
previous result. We use a decimal-adjust operation to digits of the result in D2. After this rounding, the
keep the result of the addition in BCD format. If the packed BCD for the total price is left in D1.
decimal-adjust produces a carry, we add this carry In order for the display subroutine to be able to
back into the shifted 24-bit number in D2 so that it will display this price, it must be converted to unpacked
be propagated into higher BCD digits. After each run of BCD form and put in four successive memory loca-
CNVT1 (24 runs of CNVT2), D2 will be left with a tions. Another ‘‘mask and move nibbles’’ subroutine
binary number that is equal to the original binary called EXPAND does this. The DISPLAY subroutine is
number minus the value of the two BCD digits pro- then called to display the total price on the data field.
duced. You can adapt this subroutine to work with a The DISPLAY subroutine is called again to display the
different number of bits by simply calling CNVT1 letters PR in the address field.
more or fewer times and by adjusting the count load- Finally, after delaying a few seconds to give the
ed into D1 to be 1 more than the number of binary operator time to read the price, execution returns to
bits in the number to be converted. The count has the ‘‘dumb-scale’’ portion of the program and starts
to be 1 greater because of the position of the decre- over.
ment in the loop. The temperature-controller routine A question that may occur to you when reading a
in Figure 10-25 shows another example of this long program such as this is, How do you decide which
conversion. parts of the program to keep in the mainline and which
The least significant two digits of the BCD value for parts to write as subroutines? There is no universal
the total price returned by BINCVT in D1 represent agreement on the answer to this question. The general
tenths and hundredths of a cent. If the value of these guidelines we follow are to write a program section asa
two BCD digits is greater than $49, then the carry subroutine if it is going to be used more than once in
ADD OVERFLOW
CARRY TO DO & D1
FOR NEXT BCD
BYTE CALCULATION
+V
SETPOINT
FIGURE 10-26 Flowchart for CNVT1 subroutine.
POWER
AMPLIFER
POWER
= AMP f
iD
9 }moToR
4+
DERIVATIVE = |
De
LJ} TACHOMETER
PROPORTIONAL
feedback is a signal proportional to the rate of change A programmable timer in the system determines the
of the error signal. If the load on the system is suddenly rate at which control loops get serviced.
changed, the derivative amplifier circuit will give a Microcomputer-based process-control systems
quick shot of feedback to try and correct the error. range from a small programmable controller such as
When the error signal is first applied to the differentia- the one shown in Figure 10-31, p. 324, which might be
tor circuit, the capacitor in series with the input is not used to control one or two machines on a factory floor,
charged, soit acts as a short circuit. This initially letsa to a large minicomputer used to control an entire
large current flow, so the amplifier has a sizable out- fractionating column in an oil refinery. To show you
put. As the capacitor charges, the current decreases, how these microcomputer-based control systems
so the feedback from the differentiator decreases. Too work, here’s an example system you can build and
much derivative feedback can cause the system to experiment with.
overshoot and oscillate.
The point here is that by using a combination of
some or all of these types of feedback, a given feedback- A 68000-BASED PROCESS-CONTROL
controlled system can be adjusted for optimum re- SYSTEM
sponse to changes in load or set point. Process-control Program Overview
loops that use all three types of feedback are called
proportional-integral-derivative- (PID-) control loops. Figure 10-32, p. 325, shows in flowchart form one way
Because process variables change much more slowly in which the program for a microcomputer-based con-
than the microsecond operation of a microcomputer, a trol system with eight PID loops can operate. After
microcomputer with some simple input and output power is turned on, a mainline or executive program
circuitry can perform all the functions of the analog initializes ports, initializes the timer, and initializes
circuitry in Figure 10-29 for several PID loops. process variables to some starting values. The execu-
Figure 10-30, p. 324, shows a block diagram of a tive program then sits in a loop waiting for a user
microcomputer-based process-control system. DASs command from the keyboard or a clock “‘tick’’ from the
convert the analog signals from various sensors to timer. Both the keyboard and the clock are connected
digital values that can be read in and processed by the to interrupt inputs.
microcomputer. A keyboard and display in the system When the microcomputer receives an interrupt from
allow the user to enter set-point values and to read the the timer, it goes to a subroutine that determines
current values of process variables. Relays, D/A con- whether it is time to service the next control loop. The
verters, solenoid valves, and other actuators are used interrupt-service routine does this by counting inter-
to control process variables under program direction. rupts in the same way as the real time clock we
TEMPERATURE SENSORS
FLOW METERS
MICRO-
COMPUTER
PORTS
INPUT SOLENOID
OUTPUT
PORTS VALVES
LOAD CELLS
LIQUID—LEVEL SENSORS
PH METERS KEYBOARD } N
CONTROL
SIGNALS
TO DAS
described in Chapter 8. For example, if you program other loops. This system is one type of time-slice
the timer to produce a pulse every 1 ms and you want system, because each loop gets a 20-ms ‘‘slice”’ of time.
the controller to service another loop every 20 ms, you The routines that actually update each control loop
can simply have the interrupt-service routine count 20 are independent of each other. For our example system
interrupts before going on to update the next loop. here, we have space to show the implementation of
Once you have counted down 20 interrupts, the pro- only one loop, the control of the temperature of a tank
gram then falls into a decision structure that deter- of liquid in our PC-board-making machine, for in-
mines which loop is to be updated next. Every 20 ms, a stance. You could write other, similar control-loop
new loop is updated in turn, so with eight loops, each procedures to control pH, flow, light-exposure timing,
loop gets updated every 160 ms. Note that each loop is motor speed, etc. Figure 10-32c shows the flowchart
serviced at a regular interval instead of simply updat- for our temperature-controller loop. We explain how
ing all eight loops, one loop right after another. This is this works after we have a look at the hardware for the
done so that the timing for each loop is independent of system.
the timing for the other loops. A change in the internal
timing for one loop then will not affect the timing in the
Hardware for Control System and
Temperature Controller
To build the hardware for this project, we started with
an URDA MDS board and added an 8254 programma-
ble timer and an 8259A priority interrupt controller,
as shown in Figure 8-14. The timer is initialized to
produce 1-kHz clock ticks. The 8259A provides inter-
rupt inputs for the clock-tick interrupts and for key-
board interrupts. We built the actual temperature-
sensing and detecting circuitry on a separate prototyp-
ing board and connected it to some ports on the URDA
MDS with a ribbon cable. Figure 10-33, p. 326, shows
the added circuitry.
The temperature-sensing element in the circuit is an
LM35 precision Celsius temperature sensor. The volt-
age between the output pin and the ground pin of this
device will be O V at 0°C and will increase by 10 mV for
each increase of 1°C above that. The 300-kO resistor
connecting the output of the LM35 to —15 V allows the
output to go negative for temperatures below 0°C. (If
you are operating with +12-V supplies, use a 240-k0
FIGURE 10-31 Photograph of Texas Instrument’s resistor.) This makes the circuit able to measure tem-
programmable controller for up to eight PID loops. peratures over the range of —55°C to +150°C. For our
INITIALIZE
TURN HEATER
OFF
TIMER
INITIALIZE
PROCESS
VARIABLES
GET NEW
UNMASK AND TEMPERATURE
READING
ENABLE
INTERRUPTS
CONVERT TO
BCD FOR
DISPLAY
FIND AT
SERVICE
USER
COMMAND
COMPUTE
HEATER
DUTY CYCLE
(a)
SET DUTY
CYCLE FOR ON
TURN HEATER
ON
SET DUTY
CYCLE FOR
OFF
RETURN
ENABLE TO INTR
INTERRUPTS
(c)
RETURN TO
MAINLINE PROGRAM
(b)
FIGURE 10-32 Flowchart for microcomputer-based process-control system.
(a) Mainline or executive. (b) Loop selector. (c) Temperature-control loop.
ANALOG INTERFACING AND INDUSTRIAL CONTROL 325
UPPER
6821
RELAY 120V AC PORT A
+5 V
; OUTPUT END OF CONVERSION
1k 0.1 microF ENABLE START OF CONVERSION
ie 14 Mine
= 3 4 o
= NPUT 4 ADC
ie O
INPUT 5
a ‘outs DATA 7
f& DATA 6
INPUT 7 a
ana DATA 5
{ ‘4 DATA 4
1 Pa Vee DATA 3
LM329 A eer ae
a —REF DATA 1
0.1 microF GND DATA 0
Bes) 10 microF
SOLID
TANTALUM
REFERENCE
FOR A/D =
application here, we use only the positive part of the temperature change will produce an output change of
output range, but we thought you might find this 20 mV, or one step on the A/D converter. This gives us
circuit useful for some of your other projects. An a resolution of 1°C, which is about equal to the typical
LM308 amplifies the signal from the sensor by 2 so accuracy of the sensor. The advantage of using Vppp
that the signal uses a greater part of the input range of as the V,, for the device is that this voltage will not
the A/D converter. This improves the noise immunity have the switching noise that the digital V,, line has.
and resolution. The control inputs and data outputs of the A/D con-
The ADCO808 A/D converter used here is an eight- verter are simply connected to URDA MDS ports, as
input DAS. You tell the device which input signal you shown.
want digitized with a 3-bit address you send to the Figure 10-34 shows the timing waveforms and pa-
ADC, ADB, and ADA inputs. This eight-input device rameters for the ADCO808. Note the sequence in which
was chosen so that other control loops could be added control signals must be sent to the device. The 3-bit
later. Some Schmitt-trigger inverters in a 74C14 are address of the desired input channel is first sent to the
connected as an oscillator to produce a 300-kHz clock multiplexer inputs. After at least 50 ns, the ALE input
for the DAS. The voltage drop across an LM329 low- is sent high. After another 2.5 us the START CONVER-
drift zener is buffered by an LM308 amplifier to pro- SION input is sent high and then low. Then the ALE
duce a V¢_ and a Varp of 5.12 V for the A/D converter. input is brought low again. When you detect the
With this reference voltage, the A/D converter will END-OF-CONVERSION signal from the A/D converter
have 256 steps of 20 mV each. Since the temperature going high, you can then read in the 8-bit data value
sensor signal is amplified by 2, each degree Celsius of which represents the temperature. _
326 CHAPTER TEN
lie al
WALe
STABLE ADDRESS
en ea NN
ADDRESS 50% 50%
oo
Heal ss
a SS
COMPARATOR
INPUT
Pal
ise 1/2 LSB
(INTERNAL
NODE)
o
TRI-STATE
CONTROL
EOC
leoc
fos
TRI-STATE
OUTPUTS = eee
FIGURE 10-34 Timing waveforms for the ADC0808 data acquisition system.
To control the power delivered to the heater, we used on. Port pins, remember, are in a floating state after a
a 25-A, O-V turn-on, solid-state relay such as the reset. Now that you know how the hardware is con-
Potter and Brumfield unit described in Chapter 9. With nected, we can explain how the program for this
this relay we can control a 120- or 240-V-ac-powered system works.
hot plate or immersion heater. The heater is pulsed on
and off under program control. The duty cycle of the
pulses determines the amount of heat put out by the The Controller System Program
heater.
For very low power applications, a D/A converter and THE MAINLINE OR EXECUTIVE SECTION
a power amplifier could be used to drive the heater. Figure 10-35, pp. 328-33, shows the assembly lan-
However, in high-power applications this is not very guage program for our controller system. Refer to the
practical, because the power amplifier dissipates as flowchart in Figure 10-32 as you work your way
much or more power than the load. For example, when through this program. The mainline or executive part
driving a 5000-W heater, the amplifier will dissipate of the program starts by initializing port $CO14 for
5000 W or more. The D/A converter approach has the output, the 8259A to receive interrupt inputs from the
added disadvantage that it cannot directly use the timer and the keyboard, and the 8254 to produce a
available ac line voltage. 1-kHz square wave from its counter 0. We have de-
The driver transistor on the input of the solid-state scribed these operations in detail previously, so we
relay serves three purposes: It supplies the drive for the won’t dwell on them here. We also initialize some
relay, isolates the port pin from the relay, and holds the process variables, which we explain later when they
relay in the off position when the power is first turned will have more meaning. After enabling the 68000
LOOP_ADDR_TABLE:
(a)
initialize ports
MOVE.B #S00, (UPPERA_CNTL) address data direction register
MOVE.B #$00, (UPPERA_DATA) all bits output
MOVE.B #$00, (UPPERB_CNTL) address data direction register
MOVE.B #SFF,(UPPERB_DATA) all bits input
MOVE.B #$0@, (LOWERB_CNTL) address data direction register
MOVE.B #SFF, (LOWERB_DATA) all bits input
; initialize 8259A
MOVE.B #%@0010011, (CONTROL_ADDR) ; edge triggered, single, ICW4
MOVE.B #%01000000, (CONTROL2_ ADDR) ; type 64 is first 8259 type (IRQ)
MOVE.B #%0Q0000001, (CONTROL2_ ADDR) ; ICW4, 8086 mode
MOVE.B #%11111110, (CONTROL2_ADDR) ; ICW4, 8@86 mode
; initialize variables
MOVE.B #S3C, (SETPOINT) initialize final temp of 6@ deg
MOVE.B #514, (COUNTER) initialize time counter
MOVE .B #S@0, (LOOPNUM) we start at first loop
MOVE.B #$@1, (TIMELO)
MOVE.B #501, (TIMEHT )
MOVE.B #S0@, (CURTEMP )
HERE:
return to caller
CLOCK_TICK: (b)
(continued)
KEYBOARD:
5 aaeee ; keyboard routine instructions
RTE
LOOP@:
MOVEM.L D@-D3,-(A7) ; Save registers
(c)
DISPLAY:
D2/A2-A3,-(A7) save registers
CONTROL_ADDR,A2 point at 8279 control register
#$20,D0 see if data field requested
DATFLD yes, go load control word for data
#$94,D0 no. load address field control word
SEND go send control word
DATFLD: #$90,D0 control word for data field
SEND: D@, (A2) send to 8279
MOVEA.L SEVEN_SEG,A3 point at seven_seg table
MOVEA.L DATA_ADDR,A2 point at data register
MOVE. D1,D2 get copy of low nibble to display
#SOF ,D2 mask upper nibble
@(A3,D2),D2 translate lower nibble to 7-seg code
D2, (A2) send to 8279 display RAM
D1,D2 get another copy of low nibble
#4,D2 rotate high nibble into low position
#SQF,D2 mask nibble
@(A3,D2),D2 translate upper nibble to 7-seg code
D2, (A2) send to 8279 display RAM
#8,D0 rotate bytes to get at upper 2 digits
D1,D2 get copy of upper byte
#SOF ,D2 mask upper nibble
@(A3,D2),D2 translate lower nibble to 7-seg code
D2, (A2) send to 8279 display RAM
D1,D2 get another copy of upper byte
#4,D2 rotate high nibble into low position
#SQF,D2 mask nibble
@(A3,D2),D2 translate upper nibble to 7-seg code
MOVE.B D2, (A2) send to 8279 display RAM
MOVEM.L (A7)+,D2/A2-A3 restore registers
RTS return to caller
A_D_READ:
MOVEM.L D1-D2,-(A7) we save registers
(d)
RTS
instructions for this loop
instructions
6800@ SUBROUTINE TO DISPLAY DATA ON LEDs CONNECTED TO URDA MDS USING 8279
ABSTRACT This subroutine displays characters on the display
connected to the URDA MDS via an 8279. The data is sent
to this subroutine in the following manner:
: D@ = 00 implies use data field
: D@ = Q1 implies use address field
(e)
BINCVT:
MOVEM.L D2-D3,-(A7) ; save registers and flags
RTS
END
interrupt input with an AND to SR instruction, the tation of the keyboard interrupt-service routine that
program then enters a loop and waits for an interrupt allows the user to change set points, stop a process, or
from the user via the keyboard or from the timer. The examine the value of process variables at any time.
keyboard interrupt-service routine would normally
contain a command recognizer and subroutines to
implement each of the commands, similar to the way THE CLOCK-TICK INTERRUPT HANDLER
the URDA MDS monitor program is structured. Due to The next part of the program to discuss is the inter-
space limitations, we do not show here the implemen- rupt-service routine that counts clock ticks and de-
Computer-Aided-Design Approach
Another approach to creating the needed hardware for
the prototype is with a computer-aided-design, or
CAD, system. This system may be a large and powerful
engineering workstation such as those made by Men-
real° tor Graphics Corporation or simply an IBM PC-—type
MICROCOMPUTER CONTROL computer with programs such as the PCAD system
——-— THERMOSTAT CONTROL
SONNY from Personal CAD Systems, Inc., Electronic Design
°C
TEMPERATURE
Automation Division. The programs on these systems
allow you, first of all, easily to design and draw a
15 30 45 1H 2H 3H
schematic for your hardware. You can just select the
MIN MIN MIN TIME
schematic symbol for a part you want to use by num-
FIGURE 10-36 Temperature versus time response for a ber from a large library of common devices in a disk file
thermostat-controlled and a microcomputer-controlled and bring it on to your CRT screen. You can use a
heater. mouse to move the symbol into position and to draw
DIGITAL FILTERS
A section at the start of this chapter showed how op
amps can be used to build high-pass and low-pass
filter circuits. Filtering of a signal can also be done by (b)
taking samples of the signal with an A/D converter,
performing mathematical operations on the samples FIGURE 10-37 FIR and IIR digital filter principles.
from the A/D converter, and outputting the result toa (a) FIR. (b) IIR.
Switched-capacitor filter
Computer-aided design
Simulation
is: The data sheet for an A/D converter indicates that 21. What is the major advantage of a microcomputer-
its output is in offset binary code. If the converter controlled loop over the analog approach shown in
is set up for a range of —5 V to +5 V and the output Figure 10-29?
code is 01011011, what input voltage does this Suppose that you want to control the speed of a
Zhe
represent? How could you convert this code to small de motor, such as the one in Figure 10-27,
2’s-complement form after you read the code into
with LOOP 1 of our microcomputer-based process
your microcomputer?
controller.
16. Write a subroutine to round a 32-bit BCD number a. Show how you would connect the output from
in DO to a 16-bit BCD number in D1. the motor’s tachometer to the system in Fig-
ure 10-33. Also show how you would connect
17. For the scale circuitry in Figure 10-23, what an 8-bit D/A to control the current to the
voltage should you measure on the inverting input motor.
of the LM308 amplifier? What voltages should you b. Write a flowchart for the LOOP 1 subroutine
measure on the two inputs of the LM363 amplifier to control the speed of the motor.
with no load on the scale? What voltage should c. Describe how a lookup table could be used to
you measure on the output of the LM363 with no determine the feedback value.
load on the scale?
23; Describe the major difference in how the feedback
18. The section of the scale program following the is produced in an FIR digital filter and how it is
label NXTKEY in Figure 10-35 moves some bytes produced in an IIR filter.
around in memory. Rewrite this section of the
program using the 68000 MOVEM instruction to 24. When developing a prototype, why is it very im-
do the move operations. Which version seems portant to build, test, and debug both software
more efficient in this case? and hardware in small modules?
The major objective of the first six chapters of this book OBJECTIVES
was to introduce you to structured programming and to
writing 68000 assembly language programs. Chapters At the conclusion of this chapter, you should be able to
7 through 10 introduced you to the hardware of a
minimal 68000 system, showed you how to interface a 1. Show how a 68020 is connected with a controller
microcomputer to a wide variety of input and output device for operation in a large system.
devices, and finally demonstrated how all these pieces 2. Show how a direct-memory-access (DMA) control-
are put together to build a simple microcomputer- ler device can be connected in a 68020 system, and
based instrument or control system. The major goal of describe how a DMA data transfer takes place.
the remaining chapters in the book is to show you the
hardware and software of larger microcomputer sys- 3. Describe how large banks of dynamic RAM can be
tems. connected in a system.
As an example of what we mean by a larger system,
4. Describe how a cache memory is used to reduce the
look at Figure 11-1, which shows the component side
number of wait states required in a system that has
of the main microprocessor board, or motherboard, for
a large dynamic RAM main memory.
an Apple Macintosh® II. As you can see, the board
contains a 68020 microprocessor, ROM, and a large 5. Describe how automatic error-detecting and cor-
block of dynamic RAM. The 68020 is a newer member recting circuitry works with memories.
of the 68000 family that is compatible with the 68000
6. Show how a coprocessor can be connected to a
but also includes some additional capabilities. We have
68020.
chosen the Mac II for discussions in this chapter
because it represents a large 68000 family system, 7. Describe how a 68020 and a 68881 cooperate
which includes a 68881 floating-point processor. Fi- during the execution of a program that contains
nally, note the system-expansion connectors in the instructions for each.
upper left corner of Figure 11-1. These connectors
8. Write a simple assembly language program for a
allow you to plug in additional boards that give the
system the specific interface functions you need. For
68881.
example, you may want to add a disk-controller board, 9. Describe how schematic capture programs, simu-
a serial-port board, a CRT-controller board, a board lator programs, and other computer-based tools
with additional memory, an A/D-D/A board, or a board are now used to develop a microcomputer system.
that allows your MAC to function as a logic analyzer.
This ‘‘open-system”’ approach lets you easily custom- INTRODUCTION
ize the system for your application and your financial
state. The Apple Macintosh family of computers has three
In later chapters we discuss the operation of pe- form factors. The original Macintosh had a compact
ripheral boards such as CRT-controller boards, disk form factor. This Mac had a relatively small ‘‘foot-
drive—controller boards, and serial communication print’’—about 12 in. by 9 in.—and was about 15 in.
boards, which plug into these expansion connectors. tall. It had a relatively small (9-in. diagonal) black and
The first goal of this chapter is to show you how the white screen. Several years ago Apple introduced Mac-
circuitry on a microcomputer motherboard such as the intosh computers in an ‘‘open’’ form factor, similar to
one in Figure 11-1 works. A second goal of this chapter that of the IBM PC. These open Macs, consisting of a
is to show you how computer-based tools are used to main box containing the Mac electronics and a sepa-
design, test, debug, and produce the hardware and rate monitor and keyboard, look very much like IBM
software for a board such as this. PCs. The new Macs have I/O slots for expansion cards
341
buffers, and the custom bus-controller chip. As we
explain later, a bus-controller chip is required to gen-
erate control bus signals when the 68020 is operated
in a large-scale system. The buses from these devices
go across the drawing and connect to the NuBus
peripheral board connectors so the 68020 can commu-
Witte
With (LMI
Li Witt
ttthY
Ui
UWiLtttthlY, Witte, nicate with the boards in the peripheral expansion
slots as well as with the ROM, RAM, and ports on
board. Incidentally, the layout of the newer Macintosh
Pi coed models is very similar to this layout.
eeah yea) Now find the ROM in the lower center, the keyboard
a] SS
cm)
Aee logic and other features in the middle, and the dynamic
ad
RAM in the middle right. Finally, take a look at the
Pea a Re
column of devices that contains the DMA controller.
The major parts of this circuit that are new to you are
the DMA section, the dynamic RAM section and its
associated parity check/generator logic, and the auxil-
iary processor. In the following sections of the chapter,
we discuss each of these types of circuitry in detail.
First, however we explain what we mean when we
FIGURE 11-1 Component layout diagram for Apple say that a 68020 is operating in multimaster mode,
Macintosh. because many of the circuits shown in this chapter and
the following chapters use the devices in this mode.
of
= t— NuBus AD31-0
A4-1 xt trans-
ceivers
FPU s)
0
MC68882 | p31-0 a
$9 $A $B $C pines
$D
peatene,—
DERM Fs ame Es
A7-0
Address
Address bus |: MUXs
RAM
CPU A31-8
1 to 8 MB
D31-0
MC68030
Data bus
D31-0
Apple Desktop
eee ROM Bus ports
256 KB
NIATIRQ
RTC
Slot
interrupts
22, 20, VIA2
16-13, 1, 0 esee
‘ | eB
Be = LOTS int GLUE
SCSIIRQ
Internal hard disk
SCSI connector External
A6-4
SCSI port
\CEREEREEEEDY,
Internal floppy
Internal floppy disk connector External
A12-9 SWIM disk connector (Macintosh IIx only) floppy disk port
ERRRRREEA IEERRRRRERA (Macintosh IIcx only)
ACRE |
Serial ports
/SCCIRQ Channel A Port A
Drivers C2)
Channel B and ope)
A2,1 See receivers aol 3 C)
(printer)
Internal External
I speaker sound jack
/SND Sony
ASC
sound IC
access (DMA) controller to manage the data transfer. ry-to-memory transfers to implement fast block trans-
The DMA controller temporarily borrows the address fers. Here’s an example of how a common DMA con-
bus, data bus, and control bus from the microproces- troller is connected and used in a 68020 system.
sor and transfers the data bytes directly from the disk
controller to a series of memory locations. Because the Circuit Connections and Operation of the
data transfer is handled totally in hardware, it is much Intel 8237 DMA Controller
faster than it would be if done by program instructions.
A DMA controller can also transfer data from memory We chose the 8237 DMA controller as the example for
to an I/O port. Some DMA devices can even do memo- this section because it is a commonly used device.
WE DI/O WE DI/O
74LS74
8288
BUS AO
pen CTRLR
D
DT/R
ALE
74LS74
/O
PORT
OE
8286
TRANSCEIVER
(2)
(b)
FIGURE 11-3 68000 revisited. (a) 68000 pin diagram. (b) Circuit showing 68000
connections for a complete system. (c) FCO, FC1, and FC2 codes for 68000
machine cycles.
ADDRESS
LATCHES
Ad@-Ad15
ADDRESS BUS
ALE
MEMORY
DATA BUS
DATA BUS
CONTROL BUS
CONTROL BUS
HRQ
DMA CONTROL BUS
CONTROLLER 1OR, IOW SMART
PERIPHERAL (eg DISK
DREO MEMW, MEMR DEVICE CONTROLLER)
DACK®O
8286
B BIDIRECTIONAL
ADDRESS STB
STROBE
ae | ee eT ons
Es A7-0 i OCTAL
2 © © EN LATCH
MPXER [©
RD 8272
WR DISK DISK DRIVE
AQ CONTROL CONTROL AND
cs CHIP DATA SIGNALS
DACK
FROM PORT DECODER
+5 V
FIGURE 11-5 Schematic for 68000 system with DMA controller and floppy-disk controller.
to show you a complete initialization, but here is an 11-5, the 8237 has four DMA request inputs, or chan-
overview. nels, as they are commonly called. For each channel
The 8237 is connected in a system as a port device, you need to send a command word that specifies the
so you write initialization words to it just as you would general operation, mode words, the starting memory
to any other port device. Incidentally, several 8237s address, and the number of bytes to be transferred.
can be cascaded in a master-slave arrangement to give Each channel of the 8237 can be programmed to
more input channels, and each device must be initial- transfer a single byte for each request, to transfer a
ized. block of bytes for each request, or to keep transferring
As shown by the pin labels on the 8237 in Figure bytes until it receives a wait signal on the EOP input/
y =a GS
RIE ES SES SETS ITE FN
HRQ 8237
TO 68000 a /
BGACK
i
VntOwNA| @ls{OlOLO), en IEE AAA
AEN
0 el
ADSTB
SY)
FROM 8237
AO-A7 ADDRESS VALID ADDRESS VALID
FROM 8237
DACK 8237
T0027 2een = et oS
iOR, MEMR a 6 ee a ee
FROM 8237
low, MEMW ee eer / ne oe
FROM 8237 —
_
INT EOP \ /
output. Consult the data sheet in an Intel data book to stored on the tiny capacitors tends to change due to
get the details of each command word. leakage. When activated by an external signal, the
Now that you know how DMA works in a microcom- refresh circuitry in the device checks the voltage level
puter, the next block of circuitry to talk about is the stored on each capacitor. If the voltage is greater than
RAM section. Vec/2, then that location is charged to Vc. If the
voltage is less than V,,/2, then that location is dis-
charged to O V. Let’s take a look at a typical DRAM to
see how we read, write, and refresh it. Figure 11-7(a)
INTERFACING AND REFRESHING DYNAMIC and (b) shows the pins on a Macintosh used to control
RAMs : the RAMs. Refer back to this figure while reading the
following discussion.
Review of Dynamic RAM Characteristics
Figure 11-8a, p. 349, shows an internal block dia-
For small systems such as the URDA® MDS, where we gram for a Texas Instruments TMS44C256 CMOS
only need a few kilobytes of RAM, we usually use static DRAM. This device is a 256K x 4 device, so it stores
RAM devices because they are very easy to interface to. 262,144 words of 4 bits each in its 20-pin package. You
For larger systems where we want several hundred can connect two of these in parallel to store bytes or
kilobytes or megabytes of memory, we use dynamic four in parallel to store 16-bit words. Since DRAMS are
RAMs, often called DRAMs. Here’s why. almost always connected in parallel, several compa-
Static RAMs store each bit in an internal flip-flop, nies now produce DRAM modules such as the TI
which requires four to six transistors. In DRAMs a data TM4256FL8 256K x 8 device shown in Figure 11-8b.
bit is stored as a charge or no charge on a tiny The 30-pin single-in-line package (SIP) takes much
capacitor. All that is needed in addition to the capacitor less PC board space than the equivalent DIPs.
is a single transistor switch to access the capacitor According to the basic rules of address decoding, 18
when a bit is written to it or read from it. The result of address lines should be required to address one of the
this is that DRAMs require much less power per bit, 256K, or 2'8, words stored in the MT44C256 DRAM.
and many more bits can be stored in a given-size chip. The diagram in Figure 11-8a, however, shows only
This makes the cost per bit of storage much less. The nine address inputs, AO—A8. The trick here is that to
disadvantage of DRAMs is that each stored data bit save pins, DRAMs usually multiplex in the address
must be refreshed every 2 to 8 ms because the charge one-half at a time. A look at the timing diagram for a
(a) (b)
FIGURE 11-7 Pin names and numbers for peripheral slots. (a) On Apple Macintosh
Plus motherboard. (b) On Apple Macintosh SE motherboard.
pai o0a4
PARSER
pulsed with a RAS strobe, one right after the other
every 8 ms. In the distributed mode a row is addressed
and pulsed after every 8/512 ms, or 15.6 ws. Ina
Sule particular system you use the mode that will least
interfere with the operation of the system. Now that
the operation of dynamic RAMs is fresh in your mind,
ODO
CO
=
OMAN
OAAFRWBN
we will show you how you interface banks of DRAMs to
a 68020.
read operation in Figure 11-8c should help you to see Using an 82C08 DRAM Controller IC
how this works.
To read a word from a bank of dynamic RAMs, a In high-performance systems where we want DRAM
DRAM-controller device or other circuitry asserts the refreshing to take up a minimum amount of the proces-
write-enable (W) pin of the DRAMs high to enable them sor’s time, we usually use a dedicated device that
for a read operation. It then sends the upper half of the handles all the refreshing chores without tying up the
address, called the row address, or page address, to microprocessor or its buses, as the DMA approach
the nine address inputs of the DRAMs. The controller does. An example of this type of device is the Intel
then asserts the row-address-strobe (RAS) input of the 82C08. Figure 11-9, p. 352, shows, in block diagram
DRAM low to latch the row address in the DRAM. After form, how an 82C08 can be connected with a 68000 in
the proper timing interval, the controller removes the maximum mode to refresh and control 512 Kbytes of
row address and outputs the lower half of the address, dynamic RAM. The 82C08 takes care of all the ad-
called the column address, to the nine address inputs dressing and refresh tasks.
of the DRAMs. The controller then asserts the column- The memories here are the 256K x 4 devices shown
address-strobe (CAS) inputs of the DRAMs low to latch in Figure 11-8a. As usual for a 68000 system, the
the column address in the DRAMs. After a propagation memory is set up as two byte-wide banks. In this
delay, the data word from the addressed memory cells system each bank has two DRAM devices, so each
will appear on the data outputs of the DRAMs. bank has 256 Kbytes.
‘:-——— A tg) Aa
| |
Vin
\ /\ '\
| | Vit
rae
td(CLRH) ki —— twin) —=4
Ly tg(RLCL) ——el
bo—_——— td(RLCH)
ViH
eeoe ViL
Cy nD = (2)2
tsu(CA)
|
thiRA)—el be ft taicact ——4 |
SI Fe tsu(RA) | 1 ta(CARH)
|
TYVUYYVVYVYVYVYY ¥Y
LAAALAA 8 vi
| |
t talC) -=+— tdisicH) ———&4
| |
1
| |
|
| Te tdis(G)
pe CL $a
NOTE 18: Output may go from high impedance to an invalid data state prior to the specified access time.
(c)
One important point to observe here is that the DRAMs, nine at a time. Address line AO is used along
status signals from the 68000, FCO—FC2, are connect- with the BHE signal to select the desired bank(s). This
ed directly to the control inputs of the 82C08. The leaves only the Al9 system address line unaccounted
82C08 decodes these status signals to produce the read for. If we connect the Al9 address line directly to the
and write signals needed for the DRAMs. This ad- PE input of the 82C08, then PE will be asserted
vanced decoding means that, except when a refresh whenever the 68000 outputs a memory address with
cycle is in progress, the 68000 will be able to read a A19 low. In other words, the PE input will be asserted
byte or word from the DRAMs without WAIT states. when the 68000 outputs any address between S00000
If you look closely at the 82C08 in Figure 11-9, you and S7FFFF.
should find the port enable input, PE. This input is
asserted low to request access to the DRAM. If the
82C08 is not involved in a refresh operation when PE is NOTE: The status signals from the 68000 are
asserted low, the 82C08 will multiplex the address decoded in the 82C08, so it knows whether an
from the address bus into the DRAMs with the appro- address is intended for memory or an I/O port.
priate RAS and CAS strobes. The 82C08 will also send
out an AACK signal, which clocks the 74LS74 flip- The address decoder here is simply an inverter that
flops to transfer the AO and BHE signals to the two connects Al9 to the PE input. This connection puts
memory banks. For a read operation, the addressed the RAM in the upper part of the 68000 address range,
byte or word will then be output on the data bus to the which is appropriate because for a 68000, we want
68000. For a write operation, the byte or word on the ROMs containing the startup program to be at the
data bus will be written to the addressed locations in bottom of the address range.
the DRAMs. The next point to consider in the system in Figure
The output of an address decoder is connected to the 11-9 is how the. controller arbitrates the dispute that
PE input to assert it for the desired range of addresses. occurs if the CPU tries to read from or write to memory
Because the DRAM banks in the circuit in Figure 11-9 while the controller is doing a refresh cycle. If the
are so large, the address decoding is very simple. Each 82C08 in Figure 11-9 happens to be in the middle of a
bank in the circuit contains 256 Kbytes. Since 256K = refresh cycle when the 68000 tries to read a DRAM
2'8 18 address lines are required to address one of the location, the 82C08 will hold its AACK high until it is
bytes in a bank. In most systems we connect system finished with the refresh cycle. With the connections
address lines Al—A18 to the 82C08 address inputs, shown in Figure 11-9, this will cause the 68000 to
and the 82C08 multiplexes these signals into the insert one or more WAIT states while the 82C08 finish-
INTERRUPT
ACKNOWLEDGE
4-MEGABYTE
ADDRESS BUS
8286 16-BIT
TRANSCEIVER DATA BUS
(2)
es its refresh cycle. In this system, then, the occasional 82C08 to perform refresh operations. Also, by using
access conflict is arbitrated by the DRAM controller. the CMOS oscillator, the high-current 8284 system
Inserting a wait state now and then slows the 68000 clock generator does not need to be kept running.
down less than the other DMA approaches. When the power returns, the MAX691 generates a
Another interesting feature of the system in Figure power-on-reset signal, RESET, with the correct timing
11-9 is the battery backup circuitry. In Chapter 8 we for the 68000. If a low is output to the PDD input of the
discussed the use of a 68000 interrupt-service routine 82C08 as part of the startup sequence, the 82C08 will
to save program data in the case of a power failure. In automatically switch to using the system clock and
the few milliseconds between the time the ac power operate normally for read, write, and refresh opera-
goes off and the time the de power drops below opera- tions.
ting levels, an interrupt-service routine copies pro- For the backup battery we use nickel-cadmium or
gram data to a block of CMOS static RAM, which hasa some other type that can stand the continuous re-
battery backup power supply. When the system is charging and supply the needed current. The diodes in
repowered, the saved data is copied back into the main the circuit prevent the power supply output and the
RAM, and processing takes up where it left off. In battery from fighting with each other.
larger systems there may not be time enough to copy In applications where the entire system must be kept
all the important data to another RAM, so we simply running during an ac power outage, we use a noninter-
use a battery backup for the entire DRAM array. ruptible power supply, or NPS. These power supplies
In this circuit we used CMOS DRAMs because when contain large batteries, charging circuitry, and circuit-
these devices are not being accessed for reading, writ- ry needed to convert the battery voltage to the voltages
ing, or refreshing, they take only microwatts of power. needed by the microcomputer.
During battery backup of the DRAMs, they must still
be refreshed, so the 82C08 DRAM controller is also
connected to the battery power.
Dynamic RAM Timing in Microcomputer
When the power supply voltage drops below a speci-
Systems
fied level, the PFO pin on the MAXIM 691 supervisor
device sends a signal to the 68000. The interrupt- In Chapter 7 we showed you how to determine if a
service routine saves parameters so the program can memory device such as a ROM or RAM is fast enough
restart correctly when power returns and then sends a to operate in a synchronous 68000 system with a given
signal to the power down detect (PDD) input of the clock frequency. To make these calculations for a ROM
82C08. In response to this signal the 82C08 switches or for an SRAM, you use its access times. For DRAMs,
from the high-frequency system clock to a lower- however, the limiting time is the read cycle time, tgp.
frequency clock signal from the CMOS crystal oscilla- Here’s why.
tor. Reducing the clock frequency decreases the If you take a close look at the read cycle timing
amount of current required by the DRAMs and by the diagram for the TMS44C256 in Figure 11-8c, you
3 |
'
|
| | fhe
. i] ear
|
ie EE d(RLCL) ——_—_—_—_p | nae k=— tqiCHRL)
ie —™
| apr riers | ai
fl t ol
a twicl) TT | eal Kee *(CLRN) Tees i
| 1H
ae |
CAS by VE |
pines) wrsews|omy ea eae ore
1 | | | 1 | ViL
ee | jp td(CACH) | |
1 | thi(RLCA)
fmo-omt} t su(RA) Rage t su(CA) i | |
pee CREAR | ~| |
| rm-thray 4; | et = tica) | |
PIV (SKYY YY YVVVYXX VIH
A0-A8 (XXX DON'T CARE (X)
LVANLVZAZANLANLY OXKKABADABADKAX ViL
|
ee, oar a | | |
genius coneidt | | | = Weer
ree tsu(rd) —t—™ | | th(RHrd) <=> |
VIH
wW | | | | |
| ' ima Vit
| I| tac) tay TE 20
Seabees ae!
| -— ta(ca) fine Sabie i TE tdis(CH)
(eg) NOTE 20 | i d
Da1- NOTE 18 NOTE 19 OH
Da4 | VALID OUT |
i | | VoL
ae (a(G\ =a ae tdis(G)
| ViH
G Rain PANES’ Niort Lane mae olen ernie ean
ViL
NOTES: 18. Output may go from high impedance to an invalid data state prior to the specified access time.
19. A write cycle or read-modify-write cycle can be mixed with the read cycles as long as the write and read-modify-write timing
specifications are not violated.
20. Access time is ta(cp) or ta(ca) dependent.
(a)
static column decode mode read cycle timing
twiRH) 4
Dp Us twiRL)P + ! |
}=»——— th(RLca) ———4 | VIH
RAS \l | : |
| | VIL
|
|
ViH
feet th(RHCA)
Vit
od)
SC ot
may bet tsuira) || | | tsu(CAR)
ro
A0-A8 | COLUMN |
NOTE 18: Output may go from high impedance to an invalid data state prior to the specified access time.
(b)
FIGURE 11-10 TMS44C256 DRAM. (a) Page mode read cycle operation.
(b) Static column read cycle operation. (Texas Instruments Inc.)
354 ~ CHAPTER ELEVEN
Cache Mode DRAM Systems states. However, when a word is read from main memo-
ry, it not only goes to the microprocessor, it is also
INTRODUCTION written to the cache. If the processor needs to access
Traditionally the term cache, which is pronounced this data word again, it can then read the data directly
“‘cash,”’ refers to a hiding place where you put provi- from the cache with no wait states. The percentage of
sions for future use. As we describe how a cache accesses where the microprocessor finds the code or
memory system is implemented in a microcomputer, data word it needs in the cache is called the hit rate.
perhaps you can see why the term is used here. Current systems have average hit rates greater than 90
Figure 11-11 shows in block diagram form how a percent.
simple cache memory system is implemented in a For write-to-memory operations most cache systems
68020-based microcomputer system. In Chapter 15 we use a posted-write-through method. If the cache con-
discuss the details of the 68020 microprocessor, but troller determines that the addressed word is present
for this discussion all you need to know is that the in the cache, the controller will write the new word to
68020 has a 32-bit data bus and a 32-bit address bus. the cache with no wait states and signal the 68020
A 32-bit address bus allows the 68020 to address up to that the write is complete. The controller will then
4 Gbytes of memory, and a 32-bit data bus allows the write the data word to main memory. This write to the
68020 to read or write 4 bytes in parallel. main memory is transparent to the main processor
The cache in a system such as this consists of unless the main memory is still involved in a previous
perhaps 32 or 64 Kbytes of high-speed SRAM. The write operation.
main memory consists of a few megabytes or more of To keep track of which main memory locations are
slower but cheaper DRAM. The general principal of a currently present in the SRAM cache, the cache con-
cache system is that code and data sections currently troller uses a cache directory. For the Intel 82385
being used are copied from the DRAM to the high- cache controller shown in Figure 11-11, the cache
speed SRAM cache, where they can be accessed by the directory RAM is contained in the controller. Each
processor with no wait states. A cache system takes location in the cache is represented by an entry in the
advantage of the fact that most microcomputer pro- directory. The exact format for the directory entry
grams work with only small sections of code and data depends on the particular cache scheme used. The
at a particular time. The fancy term for this is locality three basic cache schemes are direct mapped, two-way
of reference. Here’s how the system works. set associative, and fully associative. We don’t have
When the microprocessor outputs an address, the time here to do a detailed discussion of these three
cache controller checks to see if the contents of that caching schemes, but we give you an introduction to
address have previously been transferred to the cache. each so you will understand the terms if you see them
If the addressed code or data word is present in the in a computer magazine article or advertisement. We
cache, the cache controller enables the cache memory discuss cache systems further in Chapter 15.
to output the addressed word on the data bus. Since
this access is to the fast SRAM, no wait states are
A DIRECT-MAPPED CACHE
required.
If the addressed word is not in the cache, the cache Figure 11-12a shows a block diagram of how a direct-
controller enables the DRAM controller. The DRAM mapped 32-Kbyte cache can be implemented in a
controller then sends the address on to the main 68020 system with an 82385 controller. As we said
memory to get the data word. Since the DRAM main before, a 68020 has a 32-bit address bus, so it can
memory is slower, this access requires one or two wait address 2°? bytes, or about 4 Gbytes, of memory. The
DRAM
MAIN
82385 CAS MEMORY
CACHE SRAM
CONTROLLER CACHE
AND TAG 32 KBYTES ENABLE
RAM
PAGE SIZE
=32 KB
(8K DOUBLE
WORDS)
CACHE ADDRESS
[oF 8K DOUBLE WORDS) |
A31 A15 A14 A5 A4 A2
(b)
FIGURE 11-12 Cache organization for 32-Kbyte direct-mapped cache.
(a) Block diagram. (b) Use of 32-bit address by cache controller.
68020 also has a 32-bit data bus, so it can read up to 4 directory entry identifies the main memory page that a
bytes at a time from memory. A group of 4 parallel line or set of lines in the cache duplicate. Each directo-
bytes is commonly referred to as a line. ry entry also contains a tag valid bit and eight line valid
The cache memory for the 68020 system in Figure bits (one for each line in the set). Here’s how the 82385
11-12a is set up to hold 8K 4-byte lines, or a total of 32 uses this directory during a read operation.
Kbytes. The 8K lines in the cache are organized as When the 68020 sends out a 32-bit address to reada
1024 sets of 8 lines each. The cache controller treats word from memory, address lines A15—A31 represent
the 4 Gbytes of main memory as 2”, or 131,072, pages a main memory page, address lines A5—A14 identify
of 32 Kbytes each. Each page in main memory then is the set containing a desired line, and address lines
the same size as the cache. A2-A4 identify the number of the line in the set
The term direct mapped here means that a particu- containing the desired word. Figure 11-2b shows this
lar numbered line from a page in main memory will in diagram form. The cache controller first uses ad-
always be copied to that same numbered line in the dress bits A5—A14 to select the directory entry for the
cache. For example, if line 1 from page O is in the set that contains the addressed line. Then it compares
cache, it will be stored in line 1 of the cache. If line 1 the upper 17 bits of the address from the 68020 with
from page 131,070 is in the cache, it will be stored in the 17-bit tag stored in the directory entry. If the two
line 1 of the cache. The cache directory on the left side are equal, the controller checks the tag valid bit to see
of Figure 11-12a is used to keep track of which lines if the tag is current. If the tag valid bit is set, the
from the main memory currently have copies in the controller checks the line valid bit for the line ad-
cache. As you can see, the directory contains a 26-bit dressed by address 4. If the tag matches and is valid
entry for each set of 8 lines in the cache. The upper 17 and the line is valid, the line is in the cache. This is a
bits of a directory entry are called a tag. The tagina cache hit. In this case the controller will apply address
CACHE ADDRESS
(1 OF 4K DOUBLE WORDS) |
A31 A14 A13 AS A4 A2
FIGURE 11-13 Two-way set-associative cache for 32-bit address bus system.
(a) Block diagram. (b) Use of 32-bit address by cache controller.
high-speed SRAM cache, the processor can use rela- where a data bit is stored. As the size of a RAM array
tively inexpensive DRAM for its large main memory increases, the chance of a hard or a soft error increases
and still operate with few wait states. A cache control- sharply. This increases the probability that the entire
ler device such as the 82385 automatically keeps the system will fail. It seems unreasonable that one fleet-
cache and the cache directory updated, so the process ing alpha particle could cause an entire system to fail.
is essentially invisible to the microprocessor and to an To prevent or at least reduce the chances of this kind of
executing program. failure, we add circuitry that detects and in some cases
corrects errors in the data read out from DRAMSs.
There are several ways to do this, depending on the
Error Detecting and Correcting in DRAM amount of detection and correction needed.
Arrays The simplest method for detecting an error is to usea
parity bit. This is the method used in the IBM PC. In
PARITY GENERATION AND CHECKING this type of system and in many others, each DRAM
Data read from DRAMs is subject to two types of errors, memory bank is 9 bits wide. Eight of these bits make
hard errors and soft errors. Hard errors are caused by up the data byte being stored, and the ninth bit isa
permanent device failure. This may be caused by a parity bit that is used to detect errors in the stored
manufacturing defect or simply random breakdown in data. A 74LS280 parity generator-checker circuit gen-
the chip. Soft errors are one-time errors caused by a erates a parity bit for each byte and stores it in the
noise pulse in the system or, in the case of dynamic ninth location as each byte is written to memory.
RAMs, perhaps an alpha particle or some other radia- When the 9 bits are read out, the overall parity is
tion causing the charge to change on the tiny capacitor checked by the parity generator-checker circuit. If the
8K
TAGS
00088014
DA ee ev 00088010
0008800C
00201238 AAAABBBB
00000008
A31 A2 AO OlOlOIO
Te alate 00000004
00000000
30-BIT TAG ee
BYTE
ENABLES BEO-BE3
FIGURE 11-14 Fully associative 32-Kbyte cache for 32-bit address bus system.
parity is not correct, an error signal is sent to the NMI generated and written in memory, along with the data
logic to interrupt the processor. When you first turn on word. As shown in Figure 11-15b, the number of
the power to the microcomputer or warm boot it by encoding bits required, K, is determined by the size
pressing keys, one of the self-tests that it performs is to of the data word, M, and the degree of detection or
write byte patterns to all the RAM locations and check correction desired. The total number of bits required
if the byte read back and the parity of that byte are for a data word, N, is equal to M + K. For example, 5
correct. If any error is found, an error message is encoding bits are required to detect and correct a
displayed on the screen so you don’t try to load and run single-bit error in a 16-bit data word, so a total of 21
programs in defective RAM. bits have to be stored for each 16-bit word. To detect or
correct a 1-bit error and detect 2 wrong bits in a 32-bit
word requires 7 encoding bits, or a total of 39 bits. The
encoding bits, incidentally, are not just tacked on to
Detecting Errors and Correcting Circuits
one end of the data word as a parity bit is. They are
One difficulty with a simple parity check is that two interspersed in the data word.
errors in a data word may cancel each other. A second When the processor reads a data word from memory,
problem with the simple parity method is that it does the data word and the check bits from memory go to
not tell you which bit in a word is wrong so that you can the EDAC. The EDAC calculates the check bits for the
correct the error. More complex error detecting-cor- data word read out from memory and XORs these
recting codes (ECCs), often called Hamming codes check bits with the check bits that were stored in
(after the man who did some of the original work in this memory with the data word. The result of this XOR
area), permit you to detect multiple-bit errors in a word operation is called a syndrome word. The syndrome
and to correct at least one bit error. word is decoded to determine if the data word has no
Special ICs can be used to implement this. For ex- errors, a single-bit error, or multiple-bit errors.
ample, a TI 74AS632 error-detecting and -correcting If the data word contains no errors, the 74AS632
(EDAC) device can be connected in the data path EDAC will simply output the data word to the processor
between a 32-bit microprocessor and 16-Mbyte DRAM on the data bus. If the data word contains a single-bit
main memory. The EDAC is connected in parallel with error, the EDAC device uses the syndrome word to
the DRAM refresh controller and in series with the determine which bit is incorrect and simply inverts
SRAM cache. Here’s how the EDAC device works. that bit to correct the bit. The EDAC then outputs the
When a data word is sent from the microprocessor to corrected data word to the processor on the data bus. If
memory, it also goes to the EDAC. As the data word is the data word contains multiple-bit errors, the EDAC
read in by the EDAC, several encoding or check bits are device asserts a signal, which is usually connected to
BYTE INTEGER
8-BIT 23-BIT
SINGLE REAL
EXP. FRACTION
SIGN OF FRACTION
62 $1 0
11-BIT 52-BIT DOUBLE REAL
EXP. FRACTION
SIGN OF FRACTION
Data (A0-A5)
Address
(D0-032)
Shifter
Shifter
Barrel
RO
Constant
Aap
Temporary
Data
Registers
Floating-Point
;
weasssencccecevccceecccesscensecsncenenenrancccessssassrcesseccscordbocsenssenenes ees:
we have chosen to use as an example here is the FADD Motorola data book, you will see this instruction repre-
instruction. sented as FADD.f <ea>,FPn and FADD.X FPm,Pn.
All the 68881 mnemonics start with an F, which This cryptic representation means that the instruction
stands for floating point, the form in which the 68881 can be written in two different ways.
works with numbers internally. If you look in the As an example, the instruction FADD.f CORREC-
TION—FACTOR,FPO will add a real number from the
memory location named CORRECTION —FACTOR to
15 14 qe: 12 11 10 9 8 the number in floating-point register FPO. Another
example, the instruction FADD FPO,FP1 will add the
BSUN OVFL DZ |INEX2|INEX1
number in register FPO to the number in FP1 and store
the result in FP1.
Inexact Decimal Input
Inexact Operation
Divide By Zero
Coding 68881 Instructions
Underflow Common 68000 family assemblers accept 68881 mne-
Overflow monics and an assembler is the only practical way to
Operand Error
produce codes for 68881 programs. However, to give
you a feeling for how they are coded, we show a simple
Signalling NAN
example.
Branch Set on Unordered
Figure 11-21, p. 366, shows the coding template for
the FADD instruction as well as the binary code for the
(a)
example instruction FADD FPO,FP1. The R/M bit indi-
cates whether the operation is register to register or (=
16 6 5 4 3 2 1 0
0) or memory to register (= 1). In this case the operation
fee pes oaB72) is register to register, so the R/M bit is set to 0. Since
R/M is 0, the effective address mode and register (first
Inexact
word bits 6-0) are all set to 0. The source floating-point
register is FPO (i.e., 000) and the destination is floating-
Divide By Zero
point register FP1 (i.e., 001). This yields a final encod-
Underflow
ing of SF20000A2. .
Overflow
Invalid Operation
68881 Instruction Descriptions
(b) The 68881 instruction mnemonics all begin with the
FIGURE 11-19 68881 control and status word formats. letter F, which stands for floating point and distin-
(a) Control. (b) Status. guishes the 68881 instructions from 68020 instruc-
FIGURE 11-20 (a) 68881 data register and control FCOS—Floating cosine function.
diagram. (b) 68881 exception condition enable register.
FCOSH—Floating hyperbolic cosine function.
FDBcc—Test floating-point condition, decrement, and
branch.
tions. If you mentally remove the F as you read the
FDIV—Floating-point divide.
mnemonic, it makes it easier to connect the mnemonic
and the operation performed by the instruction. Here FETOX—e* function.
we briefly describe each of the 68881 instructions so
that you can use some of them to write simple pro-
FETOXM1—e* — 1 function.
grams. As you read through these instructions the first FGETEXP—Get exponent.
time, don’t try to absorb them all, or you probably
won’t remember any of them. Concentrate first on the FGETMAN—Get mantissa.
instructions you need to get operands from memory FINT—Get integer part.
into the 68881, simple arithmetic instructions, and
the instructions you need to get results copied back FINTRZ—Get integer part, round to zero.
from the 68881 to memory where you can use them. FLOG10—Logarithm, base 10.
Then work your way through the example program in
the next section. After that, read through the instruc- FLOG2—Logarithm, base 2.
tions again and pay special attention to the transcen-
FLOGN—Logarithm, base e (natural log).
dental instructions, which allow you to perform trigo-
nometric and logarithmic operations. FLOGNP!|I—Logarithm (x + 1), base e.
Only a brief description of each instruction is shown
FMOD—Modulo remainder.
here. The MC68881 data book provides more detail
and shows the coding templates and clock cycles for FMOVE (control register)—Move floating-point control
each instruction. register.
Numerical Results
36 +0.0 0.0
Zero Add + infinity — infinity
= 0.0 —0.0
2 + infinity + infinity + infinity NAN(OPERR)
Infinity
= — infinity — infinity NAN(OPERR) — infinity
FMOVEM (data register—Move multiple floating-point FScc—Test floating-point condition and set condition
data registers. code.
FMUL—Floating-point multiply. FSGLDIV—Floating-point divide (single precision).
(d16,An) (d16,PC)
(d8,PC, Xn)
(bd,PC,Xn)
({bd,
PC,Xn],0d)
(
Instruction Format
14 11 10
Fe epee od od 0 BB BS]
[Ibe oP erears een Iborole Ie
Bit 14 (R/M) of the extension word determines whether the
operation is register to register (R/M=O) or memory to register
(R/M=1). The effective address field (bits 5—O of the first
instruction word) is valid only if the R/M bit is a 1. For the
register-to-register form (R/M=0), the effective address field
should be zeros.
The Source Spec field (bits 12—10 of the extension word)
indicates the register number for the register-to-register form
(R/M=0) or the operand format for the memory-to-register
form (R/M= 1). The encoding for this field is
368881 PROGRAM
;ABSTRACT: FLOATING POINT COPROCESSOR EXAMPLE PROGRAM
; This program calculates the hypotenuse of a right
; Pevancgie vmeg 1 VenomD evAmeancum orl Ee Eie
;INPUT: Incoming 96-bit values in SIDE_A and SIDE_B
;OUTPUT: Result (hypotenuse) in HYP as 96-bit value
LEA HYP,A®@
FMOVE.X FP1, (AQ) ; Store hypotenuse back into
: memory at location HYP
RTS
END
FIGURE 11-22 68881 program to compute the hypotenuse of a right triangle.
NuChip
D31-0
wm
=)
a
oN a
i} &
oc} <
Z
i ie A25-2 (10, 11, 12)
A7-0 =
Be ASieO, a(n)
CPU
MC68020
AMU/
PMMU
(2) PLO IPLO ROM
(2) IPL1 IPL1 256KB
(2) IPL2 IPL2
DATA
BUS
D31-0
D31-O (10, 11, 12)
ELEVEN
CHAPTER
372
output should be scheduled to change to a 1 after For simulating microprocessors, there are two types
15 ns. If the inputs change to a case where they are not of behavioral models available. One type is called a
all 1s, the output should be scheduled to change to a 0 hardware verification model. This type model is es-
after 10 ns. sentially a ‘‘black box,’’ which will, for example, pro-
The smallest increment of time used by a simulator duce the correctly timed address and control bus sig-
is called its time step. You can think of the time step as nals for a memory-read cycle when given the proper
the time resolution of the simulator. For simulating processor control language (PCL) file. Hardware verifi-
TTL and CMOS circuits, simulators usually use a time cation models are easy to use for checking system
step of 1 ns or 0.1 ns because the delay times for these timing because all they need is a simple PCL file as a
devices are a few nanoseconds. An important point stimulus. However, hardware verification models do
here is that the 0.1-ns time step is simulator time, not not allow simulation of actual microprocessor instruc-
real time. The simulator may take 20 min to determine tions. If we need this level of simulation, we use full
the effects that some input-signal changes produce on functional models, which do allow the execution of
the outputs of a complex circuit. The physical circuit instructions. The disadvantages of full functional
would respond to the same input changes in a real time models are that they operate more slowly than hard-
of just a few nanoseconds. The simulator essentially ware verification models and you have to develop a file
exercises the circuit ‘‘in slow motion’’ and generates containing the actual object codes for the microproces-
an output that represents, or simulates, the real-time sor instructions you want to execute.
operation of the circuit. In cases where a behavioral model of a device is not
Now that you have an overview of how a simulator available and it is not practical to write a model or in
uses models, we need to talk briefly about some of the cases where the simulation must interface with exter-
commonly used types of models. Three of these types nal circuitry at real time speeds, we use hardware
are modeling. In this approach the devices to be simulated
are plugged into an external unit such as the Mentor
Graphics Hardware Modeling System (HML) shown in
Gate-level models
Figure 11-26. When using a unit such as this, the
Behavioral models simulator program sends stimulus signals to the exter-
nal devices, reads back the responses of the external
Hardware models devices, and includes these responses in the simula-
tion.
As you may remember from a basic logic course, any To develop complex systems such as the engineering
digital circuit can be implemented with just basic workstation shown in Figure 11-24, we use multilevel
gates. We didn’t bother to show you, but even a com- simulators. An example of a multilevel simulator is
plex device such as a 68020 or 68030 microprocessor Mentor Graphics QuickSim, which can simulate com-
can be modeled at the basic gate level for simulation. binations of gate, behavioral, and hardware models.
The difficulty with using gate-level models for complex Quicksim runs on engineering workstations such as
devices is that simulation using these models requires the one in Figure 11-24. Another useful, but somewhat
a very long time. The reason for this is that the less powerful, multilevel simulator is SUSIE from Aldec
simulator must evaluate the effects of each signal Corp. SUSIE runs on PC-type computers and is avail-
change on all the intermediate circuit points (nodes) in able to schools at a generous discount. Multilevel
the device.
If the complex device is a standard part, we usually
know that all the internal circuitry works correctly, so
we don’t need to resimulate at the gate level of detail.
To speed up the simulation of circuits containing
complex devices, we often use behavioral models.
Behavioral models simply describe the effects that
input signals will have on the output signals and the
signal delays between inputs and outputs. A behavior-
al model of a D flip-flop, for example, will indicate that
20 ns after a positive clock edge, the logic level on the D
input will be transferred to the Q output if neither the
preset nor the clear input is asserted. Behavioral mod-
els also contain properties such as setup times, hold
times, and minimum pulse widths so the simulator can
check for violations of these times by the signals
propagating through the circuit. Sophisticated behav-
ioral models such as the Smartmodels from Logic
Automation Inc. give detailed error messages to pin-
point a timing problem instead of making you work
your way through a logic-analyzer-type display to find
the problem. FIGURE 11-26 Mentor Graphics HML box.
see in the figure, the circuit uses SN74AS373s as IROMF_EVEN = A19 & A18 & A17 & A16 & !A0 & M10;
address latches and SN74AS245s as data bus buffers. {ROMF_COD = A19 & A18 & A17 & Al6 & IBHE & MIO;
The ROM in this system consists of two 127256 !ROME_EVEN = A19 & A18 & A17 & !A16 & !A0 & M10;
EPROMS, one for the even bank and one for the odd !ROME_ OOD = A19 & A18 & Ai7 & !A16 & !BHE & MIO;
bank. A lattice GAL16V8 EPLD is used as an address END rompal
decoder for the ROMS. The RAM in this basic system
(a)
consists of two MCM6164 static RAM devices, one for
the. even bank and one for the odd bank. A second
lattice GAL16V8 EPLD is used as an address decoder 0:100/88;
for the RAMS. Off-page connectors go to a second
sheet, which contains the ports, timers, etc. For this (b)
example we are interested only in the basic micro-
processor and memory section of the system.
#include <i8086min.cmd>
The Logic Automation Smartmodel for the 8086 int i,addr;
processor in Figure 11-25 is a hardware verification main( )
type. As we said before, this type model allows us to cg
verify that the signal connections, address decoding, trace_on( );
set_trace_level(1);
and timing of the system are correct. To refresh your
addr = 0x0000;
memory as to what is involved in the timing of a system
such as this, look again at Figure 7-13. for (i=0; 1<=16; i++)
As you can see in Figure 7-13a, the 68000 and C
memories essentially form a loop. To read a word from write(1,addr,i);
read(1,addr);
memory, the 68000 sends out address and control
idle(5);
signals, and after some propagation delay the memory addr++;
sends the data word back to the 68000. In order for the 2)
data word to be accepted by the 68000, it has to get addr = 0xf0000;
os.0;
back to the 68000 within a certain time period. In i
Figure 7-20 and the accompanying discussion, for for (i=0; i<=16; i++)
{
example, we showed you how to determine if the read(2,addr);
address access time of a 2716 EPROM was fast enough addr++;
for the device to work in a 3.57-MHz 68000 system. addr++;
When you use Smartmodels to simulate a system )
such as that in Figure 11-25, the simulator will auto-
matically perform all the memory timing computations
and give you an error message if it finds any timing
violations. You can then redesign the circuit and re-
simulate until you do not get error messages. CLOCK PERIOO 125
To simulate the circuit you have to give the simulator FORCE CLOCK 0 0 -R
FORCE CLOCK 1 62.5 -R
several types of information in addition to the basic FORCE RESET 0 0
netlist produced from the schematic. These additional FORCE RESET 1 1000
parts are put in files, which the simulator will read out
as it needs them. The process is really quite simple.
(d)
Here is a list of the parts you need. FIGURE 11-27 Files required for simulating
microcomputer circuit in Figure 11-25. (a) ABEL source
1. A fuse map or JEDEC file for each of the GAL1I6V8 file for PAL address decoder. (b) Memory image file.
EPLD address decoders. These can be produced (c) Processor control file. (d) Simulator stimulus file.
LrEAce-mehUmstatem rz
Instance I$4(U2:18086-2), sheetl of micro2 at time 5312.5
Trace: eCPUTStatesrs
Instance I$4(U2:1I8086-2), sheetl of micro2 at time 5687.5
DMA channel
Developing the System Software
DRAM
In addition to designing the hardware of a microcom- RAS and CAS strobes
puter, you also have to develop the BIOS software that Refresh: burst and distributed modes
allows programs to interact with the hardware. As we 82C08 DRAM controller IC
said earlier, the Logic Automation Hardware Verifica- Error detecting and correcting
tion model for a processor such as the 68000 allows Hard and soft errors
you to include statements in a PCL file to initialize the Parity check
programmable peripheral device models, write data to Hamming codes and syndrome word
them, and read data from them. This, then, is a way to Page mode read/write access
verify the address, operation, and timing of these Static column read/write access
380
/* COMPUTE THE SELLING PRICE OF 10 ITEMS */
#include <stdio.h>
#define PROFIT 15
#define MAX PRICES 10
mre Ostia =mi 20s 2a, 26,019527,16,29,39,42}3; /* array of 10 costs */
int prices[10]; /* array to hold 10 prices */
int index; /* variable to use as index */
main()
{
for (index=0; index <MAX PRICES; indext++) /* for loop to compute */
prices{index] = cost[index] + PROFIT; /* 10 prices */
}
(a)
(b)
FIGURE 12-1 (a) Simple C program to add profit of 15 to each of 10 items.
(b) Printout of program results.
point to observe in this program is that any text example. As we pointed out in our earlier discussions
enclosed between /* and */ is a comment, not part of of assembly language programming techniques, it is
the actual program. The next parts to look at in this very important to define constants at the start of a
program are the statements that define the data with program in this way rather than using “‘hard’’ num-
which the program is going to work. The statement int bers directly in the program. Then if you have to
cost[ ] = {20,28,15,26,19,27,16,29,39,42}; declares an change a number, you simply have to change the value
array of 10 integers called cost and initializes the 10 in the equ or the #define instead of finding and chang-
elements of the array with the specified values. This ing the value each place it occurs in the program. Note
corresponds to the COST DC.B 20, ... statement in that we always use uppercase letters for constants
the program of Figure 4-23. The statement int pric- such as PROFIT so that we can tell them from varia-
es[10]; declares an array of 10 integers called prices. bles, which we put in lowercase letters.
Since no values are given, the elements of this array The int index; statement in Figure 12-la declares a
are not initialized. Note that the C program statements variable called index. The int at the start of the state-
are terminated with semicolons. ment indicates that the variable can have only integer
Program lines that begin with a # are preprocessor values. This index will be used to point to the array
directives. These lines do not generate any code; in- element being processed at a particular time and to
stead, they give instructions to the compiler. The keep track of how many elements have been processed.
#define PROFIT 15 line in Figure 12-la, for example, Now that you have an overview of the data, let’s take a
tells the compiler to replace the name PROFIT with the look at the action part of the program.
constant 15 each time it finds PROFIT in the program. All the action statements in C programs, even those
This is equivalent to the PROFIT EQU 15 line in the in the mainline part of a program, are written in
assembly language version in Figure 4-23. The #de- functions. In Pascal and some other languages, a
fine MAX—PRICES 10 line in Figure 12-1a is another function is the name given to a subroutine that returns
WS THINK C Folder
OC Libraries
(© cdew stuff
Ose stuff
© for QuickKeys users Page Setup... Io}
© Mac #includes
© Mac Libraries
|
> |e
[<p] ae © oops Libraries Transfer
...
New
Quit 96
Cancel
(a) (b)
QJ Hello Folder |
osce ge gE > HARD OISK
hello.c
es
(c)
FIGURE 12-2 Apple Think C® integrated program-development screen
displays. (a) Main menu and edit window 2. (b) Options submenu.
(c) Directories submenu of options submenu.
menus, you first move the mouse onto the menu (new file) menu item by keeping the mouse button
banner button and press the mouse button. Then you depressed and sliding the pointer down to the Open file
select the desired menu item from the menu that menu item. This item will highlight. Release the mouse
appears by using the arrow keys to move the highlight- button to select Open (new) file. This is the familiar
ed box to the desired menu name and press the Enter Macintosh menu-selection paradigm.
key. The next step in developing a program is to use the
The first thing you have to do when you create a editor to enter the source text for the program. The
program is to tell the compiler, linker, etc., where to large window in the center of the screen is the edit
put the object and executable files they create. You can window where you enter text. If the blinking cursor is
use a command in the menu to do this. If you prefer, not already in this window, move the mouse into the
you can allow the tools to create object and executable window and press the mouse button to get the cursor
files using the standard, or ‘‘default,’’ names. These there. Now type in your program as you would with
names are created by adding standard suffixes to the any text editor. Note that—as in Figure 12-la—we
name of the source code file in which your C code use spaces instead of tabs to format our programs.
program resides. If you decide to use the default names The reason for this is that the default tab setting of
(do so for this example), all you need to do is give your most printers is 8, and at this setting C programs
source code file a name. Use the File menu to do this. do not usually fit easily on 8.5-in.-wide paper be-
Figure 12-2b shows the menu that appears when you cause too many tabs would be used, even in a simple
move to the File button and press the mouse key. The program.
file pull-down menu will appear. Since we will be After you type in the source file, you need to save it on
creating a new file for this example, select the Open your work disk. To do this, you again use the File
v |_|
In the following sections we lead you through the C > main IS] Ss ral YY
char
enum 16 -32,768->+32,767
int
float
float 32 3.4E-38->3.4E+38
double 64 1.7E-308->1.7E+308
long double 80 3.4BE-4932->1.1E+4932
pointer
short 16 -32,768->+32,767
long 32 -2,147,483,648->+2,147,483,647
DC.L, and DS statements. The example program in variable with the same name as one in the main
Figure 12-la showed you a few examples of how you module. Now, let’s take a closer look at the syntax of
declare and initialize simple variables and arrays ina C declaring and initializing char type variables.
program. In this and the following sections we show As shown in Figure 12-5, a single char-type variable
how to declare and initialize variables of all the differ- uses 1 byte of memory. A declaration such as char key
ent C types. To start, Figure 12-6 shows some exam- declares a variable named key and reserves 1 byte of
ples of how you declare and initialize char-type varia- storage for it. If the declaration is outside of main, the
bles. , variable will be initialized with a default value of 0.
The first five variable declarations in Figure 12-6 are The second char example in Figure 12-6 shows how
all extern, which means that they are outside of any you can declare a variable named yes and initialize the
function. Variables declared outside any function are variable with the ASCII code for a lowercase y. Note
““global,’’ so they can be accessed by any function in a that the ASCII character is enclosed in single quotes.
program. If you declare a variable within a function, If you want to initialize a char variable with the
the variable is by default automatic, which means that ASCII code for a nonprinting character, you can enter a
it is “‘local’’ and can be accessed only within that \, followed by the hex code for the character. The \x07
function. For example, the declaration char com- in the third char example initializes the variable bell
mand[15]; in Figure 12-6 is in function main, so the with the ASCII code, which will sound a ‘‘bell’’ on your
variable command is automatic and can be accessed computer.
only within main. When we show you how to declare A char variable declaration such as one of the first
and use functions, we will discuss in more detail how three examples reserves space for just 1 byte, but the
you decide whether to make a variable extern or auto- char message [20] example shows how you can declare
matic. The general rule is to declare variables inside of an array of characters. In this case all 20 locations in
main unless they need to be accessible to other pro- the array are initialized with the default value of 0.
gram modules. This avoids a conflict if a module The char message|[ ] = ‘‘Turn off the power’’; state-
written by some other programmer has a different ment in Figure 12-6 declares an array of characters
}
FIGURE 12-6 Declaring and initializing char variables in C.
and initializes the locations in the array with the ASCII count, reserves a 16-bit word in memory for it, and
codes for the characters enclosed in double quotes. leaves the location initialized with a default value of 0.
Note that you use single quotes to initialize a single Headcount is declared outside of main, so it is extern.
character variable, but you use double quotes to ini- The second int example shows you how to initialize a
tialize the elements in an array of characters. We did variable to 10 decimal, and the third int example
not need to put a number in the [ ], because the shows you how to initialize a declared variable with
compiler automatically counts the number of charac- SFFFF. The Ox in front of the ffff tells the compiler that
ters enclosed in the double quotes and allocates the the ffff represents a hexadecimal number. Note that
required memory bytes. The array actually contains 1 since type int represents a signed value, Sffff is actual-
more byte than the number of characters in the string ly equal to —1. If you want to declare a variable and
because the compiler automatically inserts an ASCII initialize it with a value of +Sffff, you can use a
null character, SOO, as a sentinel after the last byte of statement such as “unsigned int hex—value = Oxffff;.”’
the string. This sentinel character is used by many The inti = 10, j= 20, k = 30; example in Figure 12-7
functions to identify the end of the string. shows how you can declare and initialize three or more
The declaration char command[15] in main in Figure variables of the same type in a single statement to
12-6 declares a 15-byte array of type char. As we said make your program more compact.
before, the declaration is in the routine main, so this The following two examples declare arrays. These
array is automatic and can be accessed only in main. examples should be very familiar to you from the
We did not initialize the array, so the locations in the program in Figure 12-1la. The int prices[10]; statement
command array will contain whatever random garbage declares an array of 10 words and leaves the 10 loca-
happens to be in the memory locations set aside for the tions uninitialized. The int cost[ ] = {20,28,15,26,19,
array. In some cases zeros get put in these locations, 27,16,29,39,42}; declares an array of 10 words and
but you can’t count on it, so you might tuck in a back initializes the 10 locations with the specified values.
corner of your mind that the default initialization for Note that you do not have to include the length of the
external arrays is O and the default inétialization for array in the [ ] for the cost declaration, because the
automatic arrays is garbage. compiler counts the number of specified values and
makes the array long enough to hold that number.
The last two int examples in Figure 12-7 show how
to declare two- and three-dimensional arrays. A two-
INT VARIABLES dimensional array consists of rows and columns. An
As shown in Figure 12-5, a simple INT variable uses 16 instructor’s grade roster is an example of a two-dimen-
bits and can represent integers in the range —32,768 sional array. The rows represent the names of the
to +32,767. The example declarations in Figure 12-7 students, and the columns represent the scores on
are all declared as simple int type, but you can replace tests, quizzes, and labs. The statement int test—
the int at the start of any of these with one of the other scores[25][4]; declares a two-dimensional array that
int types shown in Figure 12-5 to get the range you might be used to store four test scores for each of 25
need for a specific application. students. The 25 in this declaration represents the
As indicated by its comment, the first int example in number of rows and the 4 represents the number of
Figure 12-7 declares an int-type variable named head- columns. We did not initialize this array, because a
main()
int test_scores[25]
[4];
/* 2 dimensional array with 25 rows and 4 columns */
int av temp] 5] (121 (3845 /* Three dimensional array- pages, rows, columns*/
program that uses this array would probably prompt The program that uses this array would probably
the instructor to enter the values for the array from the compute the value for each element in the array using
keyboard. To see how to initialize a two-dimensional maximum and minimum values entered by a friendly
array as part of the declaration, see the array declara- weatherperson. Later we show you how to access
tions under the float type in Figure 12-8. elements in multidimensional arrays such as this.
You can think of the three-dimensional array de-
clared by the int av—temp[5][12][31]; statement in
Figure 12-7 as consisting of 5 ‘‘pages’’ with 12 hori- FLOAT VARIABLES
zontal rows and 31 vertical columns on each page. As shown in Figure 12-5, the three floating-point
This array represents the form in which the average number types available in C are float, double, and long
temperature values for a 5-y period might be stored. double. The basic format of float-type declarations is
#include <stdio.h>
main
()
{
int headcount S55 fe tele declare variable and initialize to 5 mil
int *present &headcount;
/* declare pointer named present and initialize
the pointer with the address of headcount */
(a)
FIGURE 12-9 (a) Declaring and initializing a simple int pointer. (b) Assembly
language example of initializing and using int pointer. (c) Results produced by
printf statement in Figure 12-9. (continued)
LINK A6,#SFFFA
BG;
UNLK A6é
RTS
(b)
(a)
FIGURE 12-10 (a) C program that uses pointers to compute selling prices.
(b) 68000 assembly language equivalent of program in a. (continued)
RTS
END
the value, and write the result at the location pointed cpntr and *ppntr to represent the contents of the
to by ppntr. In the initial declarations we initialized memory location pointed to by ppntr. We didn’t
cpntr with the address of the first element in cost and bother to show you, but this second method
ppntr with the address of the first element in prices. produces the same printout as that shown in
Therefore, the first execution of the for loop will read Figure 12-1b.
the first element in cost, perform the specified compu-
tation, and write the result in the first element of
prices. The cpntr and ppntr pointers are variables, so To help you further understand how this pointer
they can be, for example, incremented, decremented, version of the program works, Figure 12-10b shows
added to, or subtracted from, to access other elements how you could write it in 68000 assembly language.
in the arrays. The cpntr++; statement increments The program in Figure 12-10b actually generates ma-
cpntr to point to the next element in cost, and the chine code very close to that generated by the compiler
ppntr++; statement increments ppntr to point to the for the C pointer example we have just discussed,
next element in prices. except that it works with bytes instead of words and it
obviously does not produce the code for the printf
NOTE: Cpntr and ppntr were declared as point- function.
ers to int type variables, so the compiler automat- In this assembly language example you can see that
ically generates instructions that increment the we first use a DC.L statement to declare and initialize a
pointers as needed to access the next elements in pointer to the first element in cost and another DC.L
the two arrays. Since int variables take 2 bytes, statement to declare and initialize a pointer to the first
the compiler will generate instructions that add 2 element in prices. Then in the code section of the
to the value of cpntr and add 2 to the value of program, we load CPNTR into A2 and PPNTR into A3
ppntr. The next time through the for loop, then, so we can use them to access the arrays. We use
cpntr will point to the second element in cost and MOVE.B (A2)+,D0 to read in an element from cost and
ppntr will point to the second element in prices. MOVE.B DO,(A3)+ to copy the result to prices. These
With this pointer method you do not need [index] instructions also increment the pointers so they point
to identify the desired elements in the arrays, to the next elements in the arrays. We then decrement
because the pointers are incremented to point to the loop counter in D1 and loop back to do the next add
the desired elements. The printf( ) statement in and store operations.
the pointer method example in Figure 12-10a The third method of accessing the elements in the
also uses the *cpntr notation to represent the two arrays is the pointer arithmetic method shown in
contents of the memory location(s) pointed to by Figure 12-10a. As we said before, the name of an array
should use these last two methods in your programs so FIGURE 12-11 C format specifiers for use in printf,
that you can easily follow them in other people’s scanf, and other library functions.
programs.
Another point we want briefly to make about the
program in Figure 12-10a is the format in which the
data is stored and manipulated. Cost is declared as the program to declare a constant called MAX—
type int, so according to Figure 12-5, 2 bytes are set PRICES and then use MAX—PRICES in the for loops
aside for each element in cost. The compiler converts and every time we refer to the number of elements in
the decimal value supplied for each element to a 16-bit the arrays. If we want to change the number of ele-
signed equivalent. When the program is loaded into ments in the arrays, all we have to do is change the
memory to be run, these 16-bit signed values are value of MAX—PRICES in the #define and recompile
loaded in the memory locations allocated for cost. the program. The compiler will automatically replace
When the program is run, the binary equivalent of 15 each occurrence of MAX—PRICES with the new value.
is added to each value from cost and the 16-bit signed This shows the advantage of using defined constants
result is put in the appropriate location in prices. The instead of hard numbers in a program.
%d format specifiers in the printf() statement cause the A third improvement in the program is to add a
printf function to convert the *cpntr and *ppntr values section that allows us to enter any desired values
to their decimal equivalents before sending the values instead of using just the fixed values we put in cost for
to the screen. The result is the decimal printout shown the previous examples. To do this we declare the array
in Figure 12-1b. For reference, Figure 12-11 shows the cost as shown, but we do not initialize the array with
formats for some of the specifiers you can use with fixed values. After using the predefined function printf
printf, scanf, and other predefined functions. to send a prompt message to the user, we use another
predefined function called scanf and a for loop to read
in 10 values entered on the keyboard.
A FLOAT POINTER EXAMPLE The actual code for the scanf function is contained in
By now you are probably getting tired of the cost-price the library file. The #include <stdio.h> preprocessor
example, but we will use it one more time to show youa directive at the start of the program tells the compiler
few useful techniques that make the program more to look in the file stdio.h for the prototype of the scanf{()
realistic. function. When the program is linked, the code for
Figure 12-12 shows the new, “‘improved’’ version. scanf( ) and printf( ) functions will be linked with the
The first improvement is to make the program able to code for the rest of our program to generate the execut-
work with floating-point numbers instead of just inte- able file.
gers. We did this by declaring the two arrays as type The scanf(‘‘%f’’, cpntr) statement in the program
float instead of type int. calls the function and passes the parameters needed
The second improvement is to make it easy to change by the function. The scanf function needs to know
the program so it can work with some number of what type of data we want it to read and where we
values other than 10. Note how we use the preproces- want it to put the data. As with the printf function we
sor directive #define MAX—PRICES 10 at the start of used before, we use a format specifier to indicate the
type of data we want it to read. In this program we want In the previous examples we added a fixed profit of 15
scanf to read floating-point values, so we pass a %f to each cost, but this is not very realistic. A more
to scanf by putting it first in the ( ). As we said earlier, realistic approach is to compute profit as a percentage
the scanf function requires that you pass it a pointer to of the cost and add the computed profit to the initial
tell it where to put the data read. We want the data cost for each item. The statement *ppntr = *cpntr +
values to be put in the cost array, so we pass the 0.25*(*cpntr); does this. This statement says, ‘‘Get the
pointer cpntr, which we initialized with the starting cost pointed to by cpntr, multiply that value by 0.25,
address of the cost array. Each time through the for add the value pointed to by cpnir to the result, and
loop, cpntr will be incremented so that it points to the write the result to the memory locations pointed to by
next element in cost. ppntr. Note that the * symbol is used to represent the
This is a good time to show you why the type of each multiplication operation as well as to represent the con-
variable is important. According to Figure 12-5, a tents of the memory location pointed to by a pointer.
float-type variable uses 4 bytes of memory, so the The meaning of an * in a statement is usually clear
elements of cost are at intervals of four in memory. from its use.
Since cost is an array of floats, we declared cpntr as a After we compute each selling price, we call printf to
type float pointer. When the compiler translates the display the entered costs and the computed prices on
cpntr++ statement, it automatically generates a the screen. Since we want to print floating-point val-
68000 instruction that adds 4 to the value of cpntr so it ues, we use %f format specifiers. The 2 between the %
points to the next element in cost. and the f indicates that we want the values rounded to
When this first section of the program runs, it sends two digits to the right of the decimal point. This is
the ‘“‘Enter 10 costs .. .’’ message to the screen and appropriate for money values. The 6 between the %
waits for you to enter a value. After we enter a value and the f indicates that the values will have a maxi-
and press the space bar or the Enter key, the program mum of six digits, including the two to the right of the
will put the value in the array and wait for us to enter decimal point. This number is optional. Note that we
the next value. use *cpntr to pass the current cost value to printf and
After all 10 values are read in, the cpntr pointer is *ppntr to pass the current price value to printf. We
reset to point at the start cu” the cost array with the then increment the two pointers, cpntr and ppntr, so
cpntr = cost; statement, so we can process the 10 they point to the next locations in their arrays.
values read. To process the 10 values we use a for loop, Now that you have some experience with int and float
as in the previous examples. Now let’s see how we pointers, let’s take a look at some char pointers, which
compute each cost. work just a little bit differently.
main()
{ "
char *greeting = "Good morning, :
/* pointer to type char location, initialized with string */
printf("%s\n", exitmess);
ap a+b /* addition */
OPERATOR PRECEDENCE = aD /* subtraction */
In the preceding sections we have shown you most of
the C operators. We show you the few remaining << a<<4 /* shift bits of a left 4 bit
operators in later program examples, where they may positions */
#include <stdio.h>
main()
{
char™ch;
Start. “printi( Game over. \n");
printf("Enter y to play another game, Nevo ga.
tay ne
ifs( (ch = getchn@)) = WN a Cn e=:= tni?4)
t
printf("Goodbye.\n");
6x12
Q
else
printf("Here we go again.\n");
goto start;
;
}
FIGURE 12-14 Basic if-else example.
#include <stdio.h>
main()
{
char ch;
printf("Game over.\n");
prompt: printf("Enter y to play another game, n to quit.\n");
if... Gch = getch(),) s=seoN oaeneech) c= =menin)
f
printf("Goodbye.\n");
exit();
}
elser if eC che——re-Y 7. =i Aen)
{
printf("Here we go again.\n");
/* goto start; */
}
else
i
ch = getchar(); /* clear buffer */
goto prompt;
}
}
FIGURE 12-15 Nested if-else example.
E, R, C, P, O, D, and B. Each of these options brings up As you can see, in the while loop in Figure 12-17a,
a lower-level menu or carries out a command. the condition is evaluated before any statements are
In the program in Figure 12-16 we use our new executed. If the condition expression initially evalu-
friend getch( ) to read a character from the keyboard. ates to O, execution will simply bypass the block of
We then use a switch structure to evaluate the charac- statements under while and go on with the rest of the
ter and decide what action to take. To simplify the basic program. In this case none of the statements in the
structure of this example, we call a function to imple- while block will be executed. If the condition expres-
ment each of the desired actions. Actually, for this sion initially evaluates to a nonzero value, the state-
example we show the function calls as comments, ments in the while block will be executed once. Then
because we did not want to declare and define all these the condition expression will be evaluated again, and if
functions. When execution returns from the called the result of the evaluation is still nonzero, the state-
function, the break statement at the end of that line ments in the while block will be executed again.
will cause execution to skip to the next statement after Looping will continue until the condition expression
the switch structure. If the key pressed by the user evaluates to O.
does not match any of the choices, the default: edit The key point of a while loop is that the condition is
window( ); statement at the end of the block sends
execution back to the edit operation. You can have only
one value in each case evaluation, so if you want the
program to accept lower- or uppercase letters, you have
/* while format */
to put case lines in for each. The line case ‘F’: followed
by the line case ‘f’: file( ); break;, for example, will call while(condition)
the file function if the user enters either a lower- or {
uppercase f. A more versatile alternative is to write a statement(s);
small function that converts all entered characters to ;
lowercase before entering the switch structure. We
leave this for you to do as an exercise at the end of the (a)
chapter.
/* do-while format */
do
THE WHILE AND DO-WHILE IMPLEMENTATIONS {
statement(s);
In Chapter 3 we showed you how the while-do and the
repeat-until structures are used to loop through a
series of statements. In C these two structures are while(condition);
called the while and the do-while, respectively. The
(b)
major difference between the two structures occurs
when the exit test is done. For comparison, Figure FIGURE 12-17 (a) Basic format of C while structure.
12-17 shows how the two are implemented in C. (b) Basic format of C do-while structure.
/* while example */
#include <stdio.h>
main()
{
char. ch = 0x00; /* assign initial value to ch */
while(ch!='’n’&& ch!=’N’&& ch!=’y’&& ch!=’Y’)
printf("Enter y to play another game, Duy (OLGA Tt aN Teme
ch=getch();
}
if (ch=='’n’i! ch==’N’)
{
printf("Goodbye.\n");
exit();
}
else
printf("Here we go again.\n");
/* goto start */
}
(a)
FIGURE 12-18 (a) Example of C while structure. (b) Example of C do-while
structure. (continued)
(b)
FIGURE 12-18 (continued)
tion here. You might, for example, include two initiali- variable initialization and loop variable modification in
zation statements such as count=0; b=23; to initialize the for parentheses.
a variable called b with a value of 23 as well as To give you a little more challenging example of a for
initialize the loop variable count. loop and teach you more about arrays, the first part of
The test part of this example compares the value of the program in Figure 12-20a shows how you can use
count with the terminal value. If the value of count is nested for loops to read maximum and minimum temp-
not equal to the terminal value, the statements in the erature values from the keyboard and put the values in
loop will be repeated. a two-dimensional array. The last section of the pro-
The count++ in our example represents the “‘modi- gram uses another for loop to compute the average
fy’’ part of the for. This is where you specify what you temperature for each day and display all the results.
want to change each time around the loop so that the The int temps[7][3]; statement at the start of the
loop eventually terminates. In some C programs you program declares an array of seven rows and three
may see more than one action statement in the modify columns. To help you visualize this, Figure 12-20b
section of the for( ). You might, for example, see some- shows this array in diagram form. As you can see,
thing such as ‘‘count++, index=index+4;’’ in the there is one row for each of the seven days of the week.
modify section. These two statements will increment Also, there is one column for the daily maximum
count by 1 and increment index by 4 each time temperatures, one column for the daily minimum tem-
through the loop. The authors’ personal feeling is that peratures, and one column for the averages that will be
the program is more readable if you put only the loop calculated. The arrow looping through the array shows
the sequence in which the array values are stored in
memory. As you can see, the three elements in the first
row are stored in the three lowest memory locations,
#include<stdio.h> the three elements in the next row are stored in the
Pie count; next three memory locations, etc.
main() The elements of the array are stored in sequence in
{ memory, so you could access the elements in this array
Lit count: as if it were a one-dimensional array of 21 elements. In
hoOnmMCCOlunesL0F mCOUunt>
OW coun t——) other words, you could set up a pointer to the first
{ element in the array and then keep incrementing the
Digi nit GL ieee COU ts),
pointer to access the other elements in the array. The
} problem with this method is that you lose the row and
printt blastoff!");
column information.
}
A much more versatile way to access the elements in
FIGURE 12-19 Example of simple count-down for loop. this array is with row and column index values. The
#include <stdio.h>
int temps
(7? fiisls
main()
{
jis Ihe ge
for (i=0> i167. itt), 9%, read Values venteredat],
{
printf("Enter max temp for day %d,”
"then mini temp ane. Glen
for (9 =0°y 62a ey eee ademas, then min */
scanfieGucd Ck Utemps41.) cao,
}
for(i=0; 1¢7; i++) /* compute averages and print all values */
{
*(*(temps+i)+2) = (x(x(temps+i)+0) + *(*(tempst+i)+1))/2;
printf("For day %d max = %d min = %d av = %d Nias
(itl), *(*(tempst+i)+j), *(*(tempsti)+1), k(k(tempst+i)+2));
}
}
#include <stdio.h>
int temps[7][3]; /* extern so other modules can access */
main()
{
rea Ualeg. She
£OT MiteO te cs tt)
{
printf("Enter max temp for day %d,"
rthen min temp. \n",\i+)):
formslne <2 ttoe sy* read max, ,-then min */
scant 'Xdierktemps (1 | fs);
}
j=0; /* reset column index */
FOC =U; melee ts)
{
temps[{i][j+2] = (temps[i][j] + temps[i][j+1])/2:;
printf("For day %d max = %d min = %d av = %d \n",
(i+1), temps(i][{j], temps{i][j+1], temps[i][Jj+2]);
}
}
(d)
the inner loop will then terminate and execution will go the appropriate locations in the array, we use a single
back to the outer for loop. for loop to compute the average temperature for each
The outer for loop uses i to access the desired row in day and put the computed results in the appropriate
the array. The first time through the outer loop i = 0, so row of the third column in the array. The temps[i][j+2]
the first row in the array will be accessed. The next = (temps[i][j] + tempsfi][j+1])/2 statement shows how
time through the loop i has been incremented to 1, so to add a constant to the j index value to access the
the second row in the array will be accessed. This different elements in a row. Likewise, in the last printf
process is essentially the same as the nested delay statement in Figure 12-20a, we add constants to the j
loops that you met in earlier chapters. index to access the three elements in a row. Textbooks
The scanf function requires that you pass it a format often refer to this as pointer arithmetic.
specifier to tell it what type of data it will be reading Now that you know the array index method of acces-
and that you pass it the address of the location where sing the elements in a two-dimensional array such as
you want the data put. You use the %d specifier to this, we briefly show you the direct pointer method,
indicate that you want the data treated as a decimal which is very commonly used by experienced C pro-
value, and you use the term &temps{i][j] to pass the grammers. Even if you don’t choose to use this pointer
address of the desired element in the array to scanf. method yourself, you should understand it well enough
Remember that temps{i][j] is a way to refer to the value to follow it in other people’s programs.
of an element in the array, so &temps{[i][j] is a simple As we said before, one way of thinking about the
way to refer to the address of that element. Note that we array temps[7][3] is as a two-dimensional array with
use i + 1 for the value of the day instead of just i. An seven rows and three columns. Another common way
array index starts from zero, but we want the days to be of thinking of the array named temps is as seven
numbered 1-7. one-dimensional arrays of three elements each. In this
After all 14 temperature values are read in and put in view, shown in Figure 12-20c, temps[O] is the name of
DECLARATION (PROTOTYPE)
CALL
main()
function_name(actual arguments) ;
note: no ;
{
statements;
return(variable);
(a) (continued)
program. If the function does not directly return a As an example of a function header, the function
value to the calling program, you give the function a header int c2f(int c) in Figure 12-21b declares a func-
type void. tion called c2f, which returns an int value and requires
After the function name you enclose in parentheses an int value to be passed to it. The int value passed to
the type and name for each function variable that will the function will be automatically assigned to the int
receive values passed from the calling program. These variable called c in the function. Also in Figure 12-21b,
variables declared in the function header are often the function header void get_temp(int*ptr) defines a
called formal arguments or formal parameters. The function called get_temp that does not return a value
trick here is that you usually use different names for but requires that a pointer to an int-type variable be
particular variables in the calling program and in the passed to it. Note that function header lines do not
function. This makes the function ‘“‘generic,’’ because have semicolons after them.
you can then pass any variables of the same types to After you write the function definition, the next step
the function in place of the ‘‘local’’ variables declared is to declare the function by writing a prototype for the
in the function definition header. Later when we dis- function. This declaration is equivalent to declaring a
cuss the details of the example program in Figure variable at the start of your program. Note in Figure
12-21b, you will better see how this works. 12-21a that the function prototype declaration at the
#include<stdio.h>
int tempc, tempf; /* external (global) variables */
start of the program has the same format as the value of the variable—or, in other words, just a copy of
function definition header, but it is followed by a the variable. If you want the function to be able to
semicolon. This prototype lets the compiler know the access and change the actual value of a variable, you
name of the function and the types of data to be passed must pass the function a pointer to the variable. Now
to the function. The compiler uses this information to that you have an overview of the three tasks, let’s look
make sure that the correct data types are passed to the a little closer at the example program in Figure 12-21b.
function when it is called. In large programs the In this example program we first declare an int
function prototypes are put in a separate header file variable named tempc that will hold the value of a
and pulled into the program at compile time with a Celsius temperature entered by the user and an int
#include<> directive. This reduces the “‘clutter’’ at variable called tempf that will hold the value of a
the start of the main program. Fahrenheit temperature calculated by a function in the
As shown in the CALL section of Figure 12-21a, you program.
call a function with its name and a set of parentheses The int c2f(int c); statement next in the program is
that enclose the name(s) of the variables being passed the function prototype declaration for the c2f function.
to the function. If no variables are passed to the As you should be able to tell from the statement, the
function, you put the term void in the parentheses c2f function returns an int value and expects to receive
after the function name. a single int value from the calling program. Before we
The variables named in the function call are com- look at the next function prototype, let’s work our way
monly called actual arguments, or actual parame- through the call and execution of the c2f function.
ters. Remember from a previous discussion that when We call the c2f function with the statement tempf =
you pass a variable to a function in C, you pass just the c2f(tempc); statement. This statement will pass the
void main ()
{
int count; block block and sub blocks
after declared
static int interrupt cnt; program block and sub blocks
after declared
register int index block block and sub blocks
after declared
void main ()
{
int i;
int number=10;
printf("Enter %d costs. After each cost press enter.\n",number);
/* function definition */
The second for loop in main computes the average with an expression such as float hrs—worked| ][12]
temperature for each day and writes the result in the [31]. The trick here is to simply leave empty the first set
third column of the appropriate row in the array. of brackets after the array name.
Once all the Celsius values are in place, we call the Another method of declaring the formal argument
function c2f to convert each Celsius value to its Fahr- for passing the ctemps pointer to the function is with
enheit equivalent and put the results in an array called the expression int (*ct)[3]. This expression likewise
ftemps. As with the previous example, we want to pass declares ct as a pointer to a three-element array. The
pointers to the two arrays and pass the length of the parentheses around *ct are required to indicate that
arrays so that the function is as versatile as possible. you are declaring a pointer to an array. The expression
The expression int ct ][3] in the c2f function header int *ct[3] declares an array of three pointers, which
in Figure 12-24 shows one way to declare the pointer each point to int-type variables.
needed to receive a pointer to a two-dimensional array. To summarize the operation of all this, the
The empty brackets between ct and [3] indicate that ct c2f(ctemps, ftemps, days) statement in Figure 12-24
is a pointer to an array of three elements. When we call calls the function. The ctemps in the function call
the c2f function, we pass ctemps as the actual argu- passes a pointer to the ctemps array to the function
ment. As shown in Figure 12-20c, the name ctemps is pointer variable ct. The ftemps in the function call
a pointer to the first three-element array, temps[0], so passes a pointer to the ftemps array to the function
the call gives the c2f access to the first three-element pointer variable ft. The days in the function call pass
array. In the c2f function, a nested for loop is used the value of the variable days to the function variable
to access the elements in ctemps[O], ctemps[1], called rows. The procedure uses these passed values
ctemps[2], etc. and a nested for loop to read an element from ctemps,
In the same way the int ft[ ][3] expression in the c2f compute the Fahrenheit equivalent, and write the
function header declares another pointer to an array of result to the same element in ftemps. Note that since
three elements. This formal parameter is used to re- the number of rows is a variable in the function, the
ceive a pointer to ftemps during the call. Incidentally, function can be called to process any number of three
you can declare a pointer to a three-dimensional array element arrays.
#include <stdio.h>
int ctemps [7] [3];
int ftemps [7] [3];
void c2f(int ct{][3], int ft] [3], int rows); /* function declaration */
void main()
{
int days = 7;
ike a, ie /* note i and j separate variables in main and c2f */
for (i=0; i<days; i++)
{
printf("Enter max Celsius temp for day %d,"
"then min Celsius temp for day %d.\n", i+1,1+1);
fOGG)=O5 a < canta) /* read max, then min */
scanf ("%d", &ctemps[i][j]);
}
DECLARING AND USING POINTERS TO int (*convert)(int c); /* declare a pointer toa
FUNCTIONS function */
convert = c2f; /* initialize the pointer to point to
In the preceding sections we have shown you how to
PAE ey)
declare pointers to simple variables and pointers to
tempf = (*convert)(tempc); /* call c2f with pointer
arrays. You can also declare and initialize a pointer toa
and pass value of tempc
function. This is an advanced technique and it is
to the function */
unlikely that you will use pointers to functions in your
int c2f(int c) /* c2f function definition header */
initial programs. However, we want to show you a
couple of examples so that you will recognize them in
someone else’s programs. Here is how you could de- The basic function declaration and definition here
clare a pointer to the c2f function in Figure 12-21c and are the same as those in Figure 12-21b. The second
call the function using the pointer instead of using a statement declares a pointer called convert that points
direct call. to a function. The key to recognizing that convert is a
pointer to a function is the double set of parentheses in
the declaration. The int at the start of the declaration
int c2f(int c); /* declare the function c2f */ indicates that the function pointed to returns an int
#include <stdio.h>
#include <fcntl.h>
void main()
{
int index;
setmode(0004, O_TEXT);
for (index=0; index <10; index++) /* for loop to compute */
prices[index] = cost[index] + 15; /AM\ONDIACeSE=/,
We don’t have space here to discuss the prototypes program in Figure 12-27 we call the predefined func-
for the many 68881 type math functions found in tion sqrt() to take the square root. We pass sqrt a value
math.h. However, to keep a promise we made earlier, equal to side_a squared + side—b squared. Sqrt re-
Figure 12-27 shows how the Pythagoras program from turns the square root of the sum and assigns it to
Chapter 11 can be written in C. side_c. Note that we wrote a # include<math.h>
Remember, this program calculates the value of the directive at the start of the program to tell the compiler
hypotenuse of a right triangle by taking the square root where to look for the prototype of the sqrt( ) function.
of the sum of the squares of the two legs. In the When the compiler compiles this program, it will use
#include<stdio.h>
#include<string.h>
void main()
{
char password[] = "failsafe";
char input_word[8];
int try = 0;
printf("Please enter your password.\n");
gets(input_word);
while(stricmp(password, input_word) != 0 && try++ <2)
{
printf("Entered password is incorrect,try again.\n");
gets(input_word);
d
if(stricmp(password, input_word) != 0)
{
printf("This computer does not know you!");
/* alarm() *//* call ASM function to sound alarm */
exit);
>
printf("Welcome, what can I do for you?");
>
#include <stdio.h>
#include <math.h>
void main ( )
{
float side_a, side_b, side_c;
side_a = 3.0;
side_b = 4.0;
the default mode of ‘“‘emulator’’ for the instructions THE ASSEMBLY LANGUAGE EQUIVALENT OF A C
that act on floating-point numbers. When you run the PROGRAM
program, a predefined function determines if your
Figure 12-28a shows a simplified version of the temp-
system contains a 68881. If a 68881 is present, the
erature conversion program in Figure 12-21b and
program will use 68881 instructions to implement
Figure 12-28b shows an edited version of the asm
floating-point operations in the program. If your sys-
program produced from it. To make the program easier
tem does not contain a 68881, the program will use
to follow, we have added the C statements as comments
floating-point library functions, which emulate the
in the assembly language code. As with Figure 12-9,
68881 instructions.
the assembly language was generated by using the
MONITOR command on the DEBUG menu and having
Writing Programs That Contain C and MacsBug disassemble the code directly from memory.
Assembly Language Read the C program in Figure 12-28a, skim through
the asm version in Figure 12-28b to see how much you
INTRODUCTION can intuitively understand, and then come back to the
The C language is very useful for writing user-interface discussion here to get more details. The analysis of this
programs, but code produced by a C compiler does not program should help you better understand some of
execute fast enough for applications such as drawing a the earlier discussions of passing arguments to func-
complex graphics display on a CRT. Therefore, system tions and variable storage classes. The assembly lan-
programs are often written with a combination of C guage listing contains several columns, which indicate
and assembly language functions. The main user in- the memory address where the code was found, then
the name of the routine the code represents (main or
terface may be written in C and specialized, high-speed
functions written in assembly language. These assem- c2f), then the offset within the routine, and finally the
bly language functions are simply called from the C assembly language itself.
program as needed. The C program in Figure 12-28a calls our c2f func-
Also, when writing a program that is mostly assem- tion to compute the Fahrenheit equivalent of 25°C and
bly language, you may find it useful to call one of the calls the predefined printf function to display the
predefined C functions to do some task that you don’t result. You should use these same conventions when
want to take the time to implement in assembly lan- you write an assembly language function to be called
guage. from a C program. We will step through the assembly
The main points you have to consider when interfac- language instructions once and explain what each
ing C with assembly language are these: group of instructions is doing. As we told you in
Chapter 5, the easiest way to keep track of the position
1. How do you call a desired function? of everything in the stack is with a simple stack map
such as that in Figure 12-29. Follow what is on the
2. How do you pass parameters to the called function? stack using Figure 12-29 as we step through the
program.
3. How are parameters passed back to the calling
program from the function? The first instruction in main is a LINK instruction,
which creates a ‘‘stack mark’”’ linking the area for the
4. How do you declare code and data in the function so main routine with the routine that called it (the debug-
that they are compatible with those in the calling ger executive in this case). Similarly, the c2f function
program? starts with a LINK instruction. Looking at the stack
diagram in Figure 12-29, the call to main leaves a
In the next section we answer these questions. return address (4 bytes) on the stack. The LINK
#include<stdio.h>
int tempc = 25, tempf; /* external (global) variables */
main()
FIGURE 12-28 (a) Simplified version of Figure 12-21b. (b, p. 420) Assembly
language equivalent of C program in a produced by C compiler.
A6,#SFFFC instruction then pushes the old value of copy of ctemp to the function, so the function cannot
A6 onto the stack and moves the value of A7 (the stack change the actual value of ctemp. Remember, if you
pointer) into register A6. The LINK instruction then want a function to change the value of a variable, you
subtracts 4 bytes from A7, which has the effect of pass the address of the variable to the function.
reserving 4 bytes of memory on the stack. The LINK Once the function c2f returns, main has an ADDQ.L
instruction works using a negative value to allocate #$2,A7 instruction. This instruction has the effect of
memory, and SFFFC is equal to —4 decimal, which removing the argument space from the stack that was
allocates 4 words of stack space. As indicated in Figure placed there by the MOVE.W instruction before the call
12-29 these 4 words are used as space for the variables to c2f. Finally, the MOVE.W DO,SFFFC(A6) instruction
tempc and tempf. In the rest of the main routine, notice takes the return value from the function c2f and places
that the variables tempc and tempf are accessed using it into tempf. By convention C functions always return
offsets from A6. The MOVEQ #$19,DO and MOVE.W their return values in register DO.
DO,SFFFE(A6) move 25 into DO and then into tempc. The next group of instructions represents the call to
Looking at the next group of instructions, we can printf. First the arguments are pushed on the stack. By
answer the question, How does C call an assembly convention the arguments are pushed on the stack
language routine? The answer is surprisingly simple: from right to left, in the reverse order from their order
the same way an assembly language routine calls in the C function call. So, first tempf is printed (with a
another assembly language routine—that is, using a MOVE.W SFFFC(A6),—(A7)), then tmepc is pushed
JSR instruction. In this case the instruction is JSR (with a MOVE.W SFFFE(A6),—(A7)), and, finally, the
C2F. Notice that the C compiler uses all capital letters address of the printf string is pushed (with a PEA
for the assembly language entry points. SF3FC(A5). Looking at the next two instructions, no-
The next point to consider here is how C passes tice that the JSR NVS388E (which is actually the call
arguments to a function. If you call an asm function to the printf routine) is followed by an ADDQ.L
from a C program, this is the way the arguments will be #$8,A7. This ADDQ.L ‘removes’ the arguments from
passed to the function. If you call a C function from an the stack. After the call to printf, 8 bytes must be
asm program, this is how you have to pass arguments removed because 8 bytes were passed to printf (4 bytes
to the C function. for the two word arguments tempc and tempf; and 4
C passes almost all arguments to functions by push- bytes for the address of the printf string argument
ing them on the stack. The first instruction in the c2f “Celsius = %d, Fahrenheit = %d \n’’).
calling group of instructions in main in Figure 12-28b The last thing that main does is to free up the
pushes the value of tempc on the stack to pass to c2f. memory it used with an UNLK (‘‘unlink’’) instruction.
The instruction MOVE.W SFFFE(A6),—(A7) gets a copy This instruction also restores A6 to the value it had
of the value in tempc and pushes it onto the stack for when main was called. Finally, main uses an RTS to
c2f to use. As we said earlier, this call just passes a return to whomever called it.
; tempL£ea=aczmeeempCyr
@BE262: MAIN +Q00A MOVE.W SFFFE(A6),-A7
@BEE266: MAIN +@QQ@E JSR G2 rh @000 ; @@OBE28E
@EE26A: MAIN +Q@Q012 ADDQ.L #S$2,A7
@EE26C: MAIN +0014 MOVE.W D®,SFFFC(A6)
; }
@BE282: MAIN +@Q02A UNLK A6é
@EE284: MAIN +QQ2C RTS
; cM cl2ie(( ae ce)
’ {
; Age, Cp
@BE28E: C2F +0000 LINK A6,#SFFFE
; saxsepelgh. ((3e))8
@EE2A8: C2F +@@01A MOVE.W SFFFE(A6) ,D@
; }
@EE2AC: C2F +Q@Q01E UNLK A6é
@EB2AE: C2F -+Q@Q@20 RTS
Now let’s look at how the function accesses the is —2 decimal = SFFFE). A7, the stack pointer, is left
tempc value passed to it on the stack. The process here pointing below the area for the c2f function, just in
is the same one we introduced to you in Figure 5-17. case c2f, in turn, wanted to call some other routine.
Looking again at the stack diagram of Figure 12-29, The next group of instructions in c2f computes the C
notice that the JSR instruction pushed a 4-byte return expression 9*c/5 + 32. See if you can follow how this
address on the stack. The first instruction in c2f isa computation is done. The final value is left in DO.
LINK instruction, just as was used in the main routine. Remember that the arguments in the assembly lan-
The LINK instruction pushed the old value of A6. In guage are in hexadecimal (e.g., $0020 = 32 decimal).
this case the value of A6 was the one the main routine Finally, the routine c2f places the return value in DO,
was using to remember where its variables (tempc and which is the standard convention for C functions. That
tempf) were on the stack. Register A6 is loaded with is, the computed value of f is returned to the calling
the stack pointer value (A7), and 2 bytes of memory are program in register DO. Finally, c2f uses an UNLK
reserved on the stack (since the LINK second argument instruction to free up the 2 bytes of memory it was
#include<stdio.h>
int tempc = 25, tempf; /* external (global) variables*/
int extern c2f(int c); /* declare function c2f which */
/* returns an int value */
void extern show(void);/* function show is in
another module */
void main()
{
tempf = c2f(tempc); /* call c2f function, pass
value of tempc to function.
Returned value assigned
to tempf */
show();
}/* end of main */
XDEF PRENTE
XREF C2F
XREF SHOW
XREF TEMPC
XREF EME &
FIGURE 12-30 Program with C and assembly language modules. (a) C mainline
module. (b) Assembly language functions.
count +=4; Uses a nested for loop to write the ASCII code for a
strobe—val & 0x0001 blank, $20, to each element in the array.
y =a>>4; Writes your name in the array elements that approxi-
2Pee
PQS a4 mately correspond to the center of the screen.
b = 39%a;
~~ If(ech == ‘Y’ | eh == )Y) 12. Use the array-index method as shown in Figure
goto start; 12-20a to write a program that does the following:
6. Write printf statements that do the following. Declares a two-dimensional array of seven rows and
a. Print the decimal value of an integer named three columns. $
count.
Reads in the maximum and minimum temperatures
b. Print a prompt message that tells the user to
for each of 7 d and puts the values in the array.
enter his or her weight.
c. Print the value of a float variable named Computes the average temperature for each day and
conversion—factor with 4 decimal places and puts the result in the appropriate position in the third
a total of 10 digits. column of the array.
d. Print the value of a float variable called
average—lunar—distance in exponential for- Computes the average maximum temperature for the
mat.
week.
Computes the average minimum temperature for the
7. Given the array declared by int nums| ] = {45, 65,
38, 72};, write a program that computes the aver- week.
age and prints the result. Computes the average temperature for the entire week.
8. Use Figure 12-12 to help you write a program that Prints out the results with appropriate labeling.
does the following:
13. Rewrite the program in problem 12 using pointer
Declares a six-element array of integers. notation instead of array-index notation.
Reads five test scores entered by a user into the array.
14. Explain the difference between formal arguments
Computes the average of the five scores and puts the and actual arguments.
computed average in the sixth element in the array.
15. Write the declaration, definition, and call for a
9. Write a program that does the following: function that converts a Fahrenheit temperature
to its Celsius equivalent. The formula is F = 9C/5
Declares an array for 25 characters.
roe:
Prompts the user to enter his or her name.
16. Write a program that reads characters from the
Reads an entered name into the array. keyboard until an EOF (Ctrl Z) is entered, uses a
function to detect and convert the ASCII codes for
Determines the number of characters in the name.
uppercase letters to their lowercase equivalents,
Prints out appropriate text and the number of letters. and writes the codes in an array.
In the preceding chapters we discussed basic micro- large LCD screens are interfaced to a microcomputer.
computer systems and some of the programmable For now, however, we want to discuss the operation
peripheral devices used in these systems. In this chap- and interfacing of CRT-type displays.
ter we expand outward to discuss the hardware and
software of system peripherals such as CRT displays,
computer vision devices, disk drives, and printers. Basic CRT Operation
A CRT is a large, bottle-shaped vacuum tube. The
picture tube used in a TV set is an example of a CRT.
An electron gun at the rear of the tube produces a beam
OBJECTIVES of electrons that is directed toward the front of the
1. Describe how characters are produced on a CRT tube. The inside surface of the front of the tube is
or an LCD screen. coated with a phosphor substance, which gives off light
when it is struck by electrons. The color of the light
2. Use OS calls to display a message on the CRT dis- given off is determined by the particular phosphor
play of an Apple Macintosh compatible computer. used. To produce color displays, as in a color TV set,
3. Describe how bit-mapped and vector graphic dis- dots of red-, blue-, and green-producing phosphors are
plays are produced on a CRT. put on the inside of the screen in triangle patterns.
Separate electron beams are focused on the dots for
4. Describe how computer vision systems produce each color phosphor. By altering the intensity ratio of
an image that can be stored in a digital memory. the three beams, the three-dot triangle can be made to
appear to be any desired color. Equal beam intensities
5. Show in general terms the formats in which digit-
produce white.
al data is stored on magnetic and optical disks.
The most common method of producing images on
6. Describe the operation of disk-controller circuitry. the CRT screen is to sweep the electron beam(s) back
and forth across the screen. When the beam reaches
7. Use OS calls to open, read or write, and close disk
the right side of the screen, it is turned off (blanked)
files.
and retraced rapidly back to the left side of the screen
8. Describe the mechanism used in several common to start over. If the beam is slowly swept from the top of
types of computer printers. the screen to the bottom of the screen as it is swept
back and forth horizontally, the entire screen appears
9. Describe how phoneme, formant filters, and lin-
lighted. When the beam reaches the bottom of the
ear predictive coding synthesizers produce hu-
screen, it is blanked and rapidly retraced back to the
man-sounding speech from a computer.
top to start over. A display produced in this way is
10. Describe the basic principle used in speech-recog- referred to as a raster display. To produce an image the
nition systems. electron beams are turned on or off as they sweep
across the screen. The trick here is to get the beam
intensity, or video information, synchronized with the
horizontal and vertical sweeping so that the display is
MICROCOMPUTER DISPLAYS stable. :
Black-and-white TVs in the United States use a
Currently there are several different technologies used horizontal sweep frequency of 15,750 HZ and a verti-
by a microcomputer to display numbers, letters, and cal sweep frequency of 60 Hz. One sweep of the beam
graphics. The most common types are the cathode-ray from the top of the screen to the bottom is called a field.
tube (CRT) and liquid crystal display (LCD). In Chap- Sixty fields per second are then swept out. To get better
ter 9 we discussed the operation of alphanumeric LCD picture resolution and avoid flicker, TVs use interlaced
displays and a little later in this chapter we show how scanning. As shown in Figure 13-la, this means the
426
START OF FIELD 1 START OF FIELD 2 The field rate and the frame rate are both 60 Hz in this
case.
Whether the CRT you are using to display your
programs is in a TV set, a video monitor, or a terminal,
there are certain basic circuits required to drive the
CRT: the vertical oscillator to produce the vertical
sweep signal for the beam, the horizontal oscillator to
produce the horizontal sweep signal for the beam, and
the video amplifier to control the intensity of the
electron beam. A unit that contains only this basic
drive circuitry is referred to as a video monitor. A TV
set contains the basic monitor functions plus RF and
audio-decoding circuitry. A CRT terminal contains a
keyboard, memory, communication circuitry, and
(usually) a microprocessor to control all of these parts.
The basic CRT drive circuitry for a one-color, or
monochrome, display requires three input signals to
END OF FIELD1 END OF FIELD2 operate properly. It must have horizontal syne pulses
to keep the horizontal oscillator synchronized and
262% LINES/FIELD vertical sync pulses to keep the vertical oscillator
2 FIELDS/FRAME
525 LINES/FRAME FOR 15,750 Hz synchronized. Also, it must have the video information
HORIZONTAL AND 60 Hz VERTICAL for each point as the beam sweeps across the screen.
(a) All this must be synchronized so that a particular dot
of video information is displayed at the same point on
Gar OF FIELD
the screen during each frame. If you have seen a TV
picture rolling or a TV picture with jagged horizontal
lines in it, you have seen what happens if the horizon-
tal, vertical, and video information are not synchro-
nized.
When transmitted to a TV set or to a video monitor,
the two sync signals and the video information are
usually combined into a single signal called composite
video. Figure 13-2 shows a typical TV-type composite
video signal waveform. It is hard to show in a figure,
but there is one vertical sync pulse for each of the
262.5 horizontal sync pulses. The video information is
represented by the waveform sections between hori-
zontal sync pulses. For these waveforms, a more posi-
tive voltage turns the beam off. Therefore, the beam
will be blanked during the horizontal retrace time
7
END OF FIELD represented by the pulse on which the horizontal sync
260 LINES/FIELD
pulse sits. The beam will also be blanked during the
1 FIELD/FRAME vertical retrace time. Now let’s see how we generate
260 LINES/FRAME FOR these three signals to display characters on a CRT
15,600 Hz HORIZONTAL AND
60Hz VERTICAL screen.
(b)
FIGURE 13-1 CRT scan patterns. (a) Interlaced. (b) Creating a Page of Monochrome Characters
Noninterlaced. on a CRT
Characters or graphics are generated on a CRT screen
as a pattern of light and dark dots. To generate these
scan lines for one field are offset and interleaved with patterns, the electron beam is turned on and off as it
those of the next field. After every other field, the scan sweeps across the screen. Figure 13-3 shows how this
lines repeat. Therefore, two fields are required to make works. The round dots in the figure represent the beam
a complete picture, or frame. The frame rate is then 30 on, and the empty square boxes represent the beam
frames/s. The beam sweeps 262.5 times horizontally off. With this dot matrix we can produce a reasonable
for each vertical sweep. approximation to any letter or symbol. The more dots
CRT units used for computer readouts usually have used for each character, the better the representation.
noninterlaced scanning, as shown in Figure 13-1b. In Common dot-matrix sizes for a character are 5 X 7,7 Xx
this case a horizontal sweep rate of 15,600 Hz anda 9, and 7 X 12. The dot patterns for each character we
vertical sweep rate of 60 Hz give 260 sweep lines/field. want to display are stored in a ROM called a character-
generator ROM. Figure 13-4 shows the matrix for a 0000, so the dot pattern output will be that for dot row
Motorola MC6571 character generator. The MC6571 0000 of the character. The output from the character
uses a 7 X 9 matrix for the actual character, but it has generator is in parallel form. In order to turn the beam
extra dot rows to leave space between rows of charac- on and off at the correct time as it sweeps across the
ters and to allow lowercase letters to be dropped in the screen, this dot pattern must be in serial form. A
matrix to show descenders correctly. Each dot row in simple parallel-to-serial shift register is used to do this
Figure 13-4 represents the pattern of dots for a hori- conversion. Note that the eighth data input of the shift
zontal scan line of the character. Figure 13-5 shows register is tied to ground, so that there is always one
how the character generator is connected with some dark dot, or undot, between characters. The high-
RAM, a shift register, and some counters to produce frequency clock used to clock this shift register is
the signals required to display characters on a CRT. called the dot clock because it controls the rate at
Here’s how it works. which dot information is sent out to the video amplifier.
The ASCII or EBCDIC code for the characters to be After the dots for the first scan line of the first
displayed on the screen is stored in a RAM so that it character are shifted out, the character counter is
can be changed when you want to display something incremented by 1. It then points to the ASCII code for
new on the screen. This RAM is often referred to as the the second character in the top row of characters in the
display RAM, or the display refresh RAM. The RAM display RAM. Therefore, the ASCII code for this second
must contain at least one byte location for each charac- character will be output to the character-generator
ter to be displayed. A common display size is 25 rows of ROM. Since the dot line counter inputs to the ROM are
characters with 80 characters in each row. This dis- still 0000, the ROM will output the dot pattern for the
play then requires about 2 Kbytes of display RAM. A top scan line of the second character in the top row of
character counter and a row counter are used to characters on the screen. When all the dots for the top
address the ASCII codes in this RAM.
To start the display in the upper left corner, the
character counter and the row counter outputs are all
Os, so the ASCII code for the first character is ad-
dressed in the display RAM. The addressed code will be
output from the ROM to the data inputs of the charac-
ter-generator ROM. The outputs of a dot row counter
are also applied to the character generator. With these
two inputs the character generator will output the
7-bit dot pattern for one dot row in the character. For
the first scan across the screen, the counter will output
FIGURE 13-3 Producing characters on a CRT screen FIGURE 13-4 Dot format for Motorola MC6571
with dots. character-generator ROM.
CLOCK
A8 AO R3 | Rl ;. VERTICAL
R2 RO HORIZONTAL SYNC
SYNC 15, 600 Hz 60 Hz
OSCILLATOR
6 MHz + 384 aS + 20
AO | A2| A4 RO | R2 AS | A7
Al A3 R1 R83 AB A8
CHARACTER DOT LINE
COUNTER COUNTER
32/ROW + HORIZONTAL 13 LINES/
BLANKING/RETRACE CHARACTER
TIME
scan line of this character are shifted out, the charac- pulse to retrace the beam to the left side of the screen
ter counter will be incremented by 1 again, and the and a vertical sync pulse to retrace the beam to the top
process will be repeated for the third character in the of the screen. When the beam reaches the top left
top row of characters. The process continues until corner of the screen, the whole screen-refresh process
the first scan line for all 80 characters in the top row of that we have described repeats. As we mentioned
characters is traced out. before, the entire screen must be scanned (refreshed)
A horizontal sync pulse is then produced to cause 30 to 60 times a second to avoid a blinking display. Now
the beam to sweep back to the left side of the screen. let’s see what frequencies are involved in each major
After the beam retraces to the left, the character part of the circuitry.
counter is rolled back to zero to point to the ASCII code
for the first character in the row again. The dot line CRT Display Timing and Frequencies
counter is incremented to 0001 so that the character
generator will now output the dot patterns for the There are many different horizontal, vertical, and dot
second scan line of each character. After the dot clock frequencies commonly used in raster-scan CRT
pattern for the second scan line of the first character in displays. The horizontal sweep frequency is usually in
the row is shifted out to the video amplifier, the charac- the range of 15 to 30 kHz, the vertical sweep frequency
ter counter is incremented to point to the ASCII code is usually 50 or 60 Hz, and the dot clock frequency is
for the second character in the display RAM. The usually 5 to 25 MHz. For our first specific example, we
process repeats until all the scan lines for one row of use the frequencies used in the IBM monochrome
characters have been scanned. display adapter, which we use as a circuit example ina
The character row counter is then incremented by 1. later section.
The outputs of the character counter and the character The IBM monochrome display adapter produces a
row counter now point to the display RAM address display of 25 rows of 80 characters per row. Each
where the ASCII code for the first character of the character is produced asa 7 X 9 matrix of dots ina 9 x
second row of characters is stored. The process we 14 dot space. This means that because clear space is
described for the first row is repeated for the second left around each actual character, each character uses
row of characters. After the second row of characters is 9 dot spaces horizontally and 14 scan lines vertically.
swept out, the process goes on to the third row of The active horizontal display area then is 9 dots/
characters, and then on to the fourth, and so on until character X 80 characters/line, or 720 dots. The active
all 25 rows of characters have been swept out. vertical display area is 25 rows X 14 scan lines/row, or
When all the character rows have been swept out, 350 scan lines.
the beam is at the lower right corner of the screen. The According to the IBM Technical Reference Manual,
counter circuitry then sends out a horizontal sync the monochrome adapter uses a dot clock frequency of
SYSTEM BUS
LCO-3
8257 ee) CHARACTER VIDEO SIGNAL
CONTROLLER aes.) GENERATOR
CCO-6 DOT HORIZONTAL SYNC
CRT TIMING
CONTROLLER AND [VERTICAL SYNC
ams INTERFACE
INTENSITY
VIDEO CONTROLS
FIGURE 13-6 Block diagram showing connections of Intel 8275 CRT controller
in a microcomputer system.
DAT
PROCESSOR e
DATA
CHARACTER
CLOCK
CHARACTER
AO GENERATOR
CHIP MC6845
SELECT CRTC SHIFT
REGISTER
TIMING
SIGNALS
HSYNC, VSYNC, CURSOR, DISPEN
CHARACTER CLOCK
MONITOR DIRECT
DRIVE OUTPUTS
RESET ——+]2 EA
decreased intensity. As you may have observed, it is
LPSTB RB
Ww
«2
common practice to display a menu at reduced intensi-
( MAO w 0
ty so it does not distract from the main text on the ac cO E
screen.
MAI a°0ga
Now observe that there is a multiplexer in series with MA2 oS
= ow
the address lines going to the character and attribute MA3 S) oO
joss
RS Register Function
number
OUTPUT
LATCH
ADDRESS DATA DATA
PROCESSOR 6845 LATCH LATCH LATCH
DATA
CRT
CONTROLLER GRAPHICS
SERIALIZER
R
CHARACTER ALPHA COLOR G
GENERATOR
ROM
SERIALIZER ENCODER B
|
PALETTE/
OVERSCAN
HORIZONTAL
VERTICAL
COMPOSITE
ODE TIMING COLOR
Daveke at GENERATOR GENERATOR
& CONTROL
color and intensity for each pixel is specified by the I, R, this mode there are only 2 bits per PEL available to
G, and B bits in the lower half of a byte in the display store color information. With 2 bits we can specify only
RAM. Since 4 bits are being used to specify color and one of four colors for each PEL. As you can see,
intensity, a PEL can be any one of 16 colors. Because a increasing the resolution of the display has reduced
byte is used to store the information for each PEL, all the number of colors that can be specified with a given
16 Kbytes of the display RAM are used to display the amount of memory. Figure 13-14 shows the format in
100 X 160 PEL display. which the PEL information is stored in RAM bytes and
In the medium-resolution mode, each PEL is a single the meaning of the bits in these bytes. The background
dot. The display consists of 200 rows of PELs with 320 color is selected by outputting a control byte through
PELs in each row, or a total of 64,000 PELs. The 16 port $3D9 to the palette circuit shown on the left edge
Kbytes of display refresh RAM correspond to 16K x 8, of Figure 13-12.
or 128 Kbits. Dividing the number of PELs into the In the high-resolution graphics mode, the IBM color/
number of bits available for storage tells you that in graphics adapter board displays 200 rows of PELs with
640 PELs in each row, or a total of 128,000 PELs. Since
the 16-Kbyte refresh RAM contains 128,000 bits, this
DISPLAY-CHARACTER CODE BYTE ATTRIBUTE BYTE corresponds to 1 bit per PEL. Therefore, you can
er Ope Oren eee lee 0 d (Je ty LS} Zo 0) specify for each bit only whether it is on or off. In other
words, in this high-resolution mode you are limited toa
black-and-white display, because there are no bits left
tg specify colors. Figure 13-15 shows the format in
ATTRIBUTE FUNCTION which PEL data is stored in display RAM bytes for
high-resolution displays. Here again we want to point
out that if you want to produce color graphics displays
as part of your programs, the best approach is probably
to buy one of the commercially available graphics
NORMAL packages. These programs allow you to produce the
REVERSE VIDEO figures you want with a mouse or with drawing in-
NONDISPLAY (BLACK)
NONDISPLAY (WHITE)
structions rather than specifying the bit values for
each pixel.
| = HIGHLIGHTED FOREGROUND (CHARACTER) As you should see by now, the limiting factor for color
B = BLINKING FOREGROUND (CHARACTER)
graphics displays is the amount of memory you are
(b) willing to devote to the display. Some high-resolution
displays used in engineering work stations have a
FIGURE 13-13 Data storage formats for IBM color display of 1000 PELs by 1000 PELs with 16 colors. A
graphics board operating in alphanumeric mode. (a) display such as this requires about 500 Kbytes of
Character byte and attribute byte. (b) Attribute byte high-speed refresh RAM.
format. For each of the graphics formats discussed, data for a
Y (LUMINANCE) —SIGNAL
INVERTER
LOW-PASS
FILTER
COMPOSITE
BLUE COLOR
FROM
COLOR
CAMERA RED
(OR
MEMORY)
3.579545 MHz
HORIZONTAL, VERTICAL
AND BLANKING PULSES
COMPUTER VISION
For many applications we need a microcomputer to be
able to ‘‘see’’ its environment or perhaps a part on
TRANSMITTED
which the machine it controls is working. As part of a PULSE
microcomputer-controlled security system, for exam- i REFLECTED
ple, we might want the microcomputer to look down a \_ ECHO
OPTICRAM Cameras
CCD Cameras
Figure 13-20 shows a picture of the Micron Eye camera
Charge-coupled devices, or CCDs, are constructed as produced by Micron Technology in Boise, Idaho. This
long shift registers on semiconductor material. Figure camera is relatively inexpensive, interfaces easily to
13-19 shows the structure for a CCD shift register common microcomputers, and has enough resolution
section. As you can see, the structure consists simply for simple robot-type applications.
‘|
music. The robot uses seventeen 16-bit microproces-
sors and fifty 8-bit controllers to control all its activi-
ties.
If you think about what is involved in recognizing INDEX HOLES
complex visual shapes in all their possible orientations ©©
with a computer program, it should give you a new
appreciation for the pattern-recognition capabilities of
cE DRIVE
29 SPINDLE
the human eye-brain system. af HOLE
Another area where the human brain excels is in
that of data storage. Only very recently have the
devices used to store computer data approached the
HEAD SLOT
capacity of the human brain. In the next section we WRITE
look at how some of these mass data-storage systems PROTECT
NOTCH
operate and how they are interfaced to microcomput-
ers.
6.25 in (159 ape
8.00 in (200 mm)
INDEX POST aoe SES URe See eee SECTOR | SECTOR | SECTOR
|PREAMBLE| ADDRESS INDEX GAP
MARK
wa mas
INDEX 1 138
HOLE as BYTE See YTES i
wor
SVTES la BV iE
\
\
j \
\
| x
/ \
/ \
TRACK SECTOR DATA CHECKSUM
NUMBER aes SECM
—— Bytes ——_—_——+ +128 eyTes —+,-2 By TES
FIGURE 13-25 IBM 3740 floppy-disk soft-sectored track format (single density).
is written in after the data bytes as the CRC bytes. netism. This form of recording is often called nonre-
When the data bytes and the CRC bytes are read out, turn-to-zero (NRZ) recording, because the magnetic
the CRC bytes are subtracted from the data string. The field is never zero on a recorded track. Each point on
result is divided by the original constant. the track is always magnetized in one direction or the
Since the original remainder has already been sub- other. The read head produces a signal when it is
tracted, the result of the division should be zero if the passed over by a region where the magnetic field
data was read out correctly. Higher-quality systems changes. As you read through the next section, keep in
usually write data to a disk and immediately read it mind that what we show in the waveforms as a pulse
back to see if it was written correctly. If an error is simply represents a change in magnetic polarity on the
detected, then another attempt can be made. If 10 disk.
write attempts are unsuccessful, then the operator can Figure 13-26 shows how bits are stored on a disk
be prompted to throw out the disk or the write can be track in single-density format. This format is often
directed to another sector on the disk. called frequency-modulation, FM, or F2F recording.
The IBM 3740 format we have been describing is Note that there is a clock pulse, C, at the start of each
referred to as single density. An 8-in. disk in this bit cell in this format. These pulses represent the basic
format has one index track and 76 data tracks. Since frequency. A 1 is written in a bit cell by putting ina
each track has 26 sectors with 128 data bytes in each pulse, D, between the clock pulses; a O is represented
sector, the total is about 250 Kbytes. If we use both by no pulse between the clock pulses. Putting in the
sides of the disk, we get about 500K bytes. To increase data pulses modifies the frequency, which gives the
the storage capacity even further, most systems use name frequency modulation.
double-density recording. Double-density recording The recorded clock pulses are required to synchro-
uses a different clock and data bit pattern to pack twice nize the read-out circuits. The actual distance—and
as many sectors in a track. Now let’s look at how data therefore time—between data bits read from an outer
is actually recorded on floppy disks. track is longer than it is for data bits read from an
inner track. A circuit called a phase-locked loop
Recorded Bit Formats—FM and MFM adjusts its frequency to that of the clock pulses and
produces a signal that tells the read circuit when to
A | bit is represented on magnetic disks as a change in check for a data bit. Recording clock information along
the polarity of the magnetism on the track. A 0 bit is with data information not only makes it possible to
represented as no change in the polarity of the mag- read data accurately from different tracks, but it also
—| 2 us |+—
D D D D
2 1s ——|
FIGURE 13-26 FM and MFM recording formats for magnetic disks.
reduces the chances of a read error caused by small we use a specially designed floppy-disk controller to do
changes in disk speed. it. AS our example device here we use the Intel 8272A
A disadvantage of standard F2F recording is that a controller, which is equivalent to the NEC uPD675
clock pulse and the data bit are required to represent controller used in the IBM PC. However, it is easier to
each data bit. Since bits can be packed only so close find data sheets and application notes for the 8272A if
together on a disk track without interfering with each you need further information.
other, this limits the amount of data that can be stored
on a track in this format. To double the amount of data 8272 SIGNALS AND CIRCUIT CONNECTIONS
that can be stored on a track, the modified frequency- Figure 11-3 showed you how an 8272A controller can
modulation, or MFM, recording format (shown as the be connected in a 68000-based microcomputer sys-
second waveform in Figure 13-26) is used. The basic tem. Also in Chapter 11, we discussed in detail how
principle of this format is that both clock pulses and 1 data can be transferred to and from a floppy disk
data pulses are used to keep the phase-locked loop and controller on a DMA basis. Now we want to take a
read circuitry synchronized. A clock pulse is not put in closer look at the controller itself to show you the types
unless data pulses do not happen to come often enough of signals it produces and how it is programmed.
in the data bytes to keep the phase-locked loop locked. To start, take a look at the block diagram of the
Clock bits are put at the start of the bit cell and data 8272A in Figure 13-27. The signals along the left side
bits are put in the middle of the bit cell time. However, of the diagram should be readily recognizable to you.
a clock bit will be put in only if the data bit in the The data bus lines, RD/WR, AO, RESET, and CS are
previous cell was a O and the data bit in the current bit the standard peripheral interface signals. The DRQ,
cell is also a 0. Since this format has, in all cases, only DACK, and INT signals are used for DMA transfer of
one pulse per bit cell, a bit cell can be half as long, or, data to and from the controller. To refresh your memo-
in other words, twice as many of them can be packed ry from Chapter 11, here’s a review of how the DMA
into a track. This is the way that double-density re- works. When a microcomputer program needs some
cording is achieved in the IBM PC and other common data from the disk, it sends a series of command words
microcomputers. For a 5.25-in. double-density record- to registers inside the controller. The controller then
ed disk, data bits will be read out at about 250,000 reads the data from the specified track and sector on
bits/s. Incidentally, a new disk-recording technology the disk. When the controller reads the first byte of
called perpendicular, or vertical, recording should data from a sector, it sends a DMA request, or DRQ,
allow four to eight times as much data to be put ona signal to the DMA controller. The DMA controller
given-size disk. With perpendicular recording the tiny sends a hold request signal to the HOLD input of the
magnetic regions are oriented perpendicularly to the CPU. The CPU floats its buses and sends a hold-
disk surface instead of parallel to it as they are for acknowledge signal to the DMA controller. The DMA
standard disks. controller then sends out the first transfer address on
Now that we have shown you how digital data is the bus and asserts the DACK input of the 8272 to tell
stored on floppy disks, we show you the circuitry it that the DMA transfer is underway. When the num-
required to interface a floppy disk drive to a microcom- ber of bytes specified in the DMA initialization has
puter. been transferred, the DMA controller asserts the TER-
MINAL COUNT input of the 8272. This causes the
8272 toassert its interrupt output signal, INT. The INT
A Floppy-Disk Controller—the Intel 8272A signal can be connected to a CPU or 8259A interrupt
As you can probably tell from the preceding discussion, input to tell the CPU that the requested block of data
writing data to a floppy disk and reading the data back has been read in from the disk to a buffer in memory.
requires coordination at several levels. One level is the The process would proceed in a similar manner for a
motor and head-drive signals. Another level is the DMA write-to-disk operation.
actual writing and reading at the bit level. Still another Now let’s work our way through the drive-control
level is interfacing with the rest of the circuitry of a signals shown in the lower right corner of the 8272
microcomputer. This coordination is a full-time job, so block diagram in Figure 13-27. Reading through our
DRQ a
=
DACK READ S READY
INT WRITE N zi INPUT WRITE PROTECT/TWO SIDE
DMA iS PORT INDEX
= CONTROL FAULT/TRACK 0
RD/WR LOGIC
A
ApEn DRIVE DRIVE SELECT0
INTERFACE DRIVE SELECT 1
ss CONTROLLER MEM MODE
brief descriptions of these signals should give you a to tell the drive hardware to put the read/write head in
better idea of what is involved in the interfacing to the contact with the disk. When interfacing to a double-
disk-drive hardware. Note the direction of the arrow on sided drive, the HEAD SELECT from the controller is
each signal. used along with this signal to indicate which of the two
The READY input signal from the disk drive will be heads should be loaded.
high if the drive is powered and ready to go. If, for During write operations on inner tracks of the disk,
example, you forget to close the disk-drive door, the the LOW CURRENT/DIRECTION signal is asserted
READY signal will not be asserted. by the controller. Because the bits are closer together
The WRITE PROTECT/TWO SIDE signal indicates on the inner tracks, the write current must be reduced
whether the write-protect notch is covered when the to-prevent recorded bits from splattering over each
drive is in the read or write mode. When the drive is other. When executing a seek-track command this
operating in track-seek mode, this signal indicates signal pin is used to tell the drive whether to step
whether the drive is two-sided or one-sided. outward towards the edge of the disk or inward to-
The INDEX signal is pulsed when the index hole in wards the center.
the disk passes between the LED and phototransistor The FAULT RESET/STEP output signal is used to
detector. reset the fault flip-flop after a fault has been corrected
The FAULT/TRACK 0 signal indicates some disk- when doing a read or write command. When the
drive problem during a read/write operation. During a controller is carrying out a track-seek command, this
track-seek operation, this signal is asserted when the pin is used to output the pulses that step the head from
head is over track O, the outermost track on the disk. track to track.
The DRIVE SELECT output signals, DSO and DS1, Now that we have led you quickly through the drive
from the controller are sent to an external decoder, interface signals, let’s take a look at the 8272A signals
which uses these signals to produce an enable signal used to read and write the actual clock and data bits on
for one to four drives. a track. To help with this, Figure 13-28 shows a block
The MFM output signal is asserted high if the con- diagram of the circuitry between these pins and the
troller is programmed for modified frequency modula- read/write head.
tion and low if the controller is programmed for stan- Remember from our discussion of FM and MFM
dard frequency modulation (FM). recording that clock information is recorded on the
The RW/SEEK signal is used to tell the drive to track with the data information. We use the clock bits
operate in read/write mode or in track-seek mode. to tell us when to read the data bits. The VCO SYNC
Remember, some of the other controller signals have signal from the controller tells an external phase-
different meanings in the read/write mode than they do locked-loop circuit to synchronize its frequency with
in the seek mode. that of the clock pulses being read off the disk. (In the
The HEAD LOAD signal is asserted by the controller case of MFM recording, the data bits are also part of
FIGURE 13-28 Block diagram of external circuitry used READ TRACK—Load head, read all sectors on track.
with Intel 8272A floppy-disk controller for reading and
READ |D—Return first ID field found on track.
writing serial data.
SCAN EQUAL—Compare sector of data bytes read from
disk with data bytes sent from CPU or DMA controller
until strings match. Set bit in status register if match.
the signal on which the PLL locks). The output from
SCAN HIGH OR EQUAL—Set flag if data string from
the phase-locked-loop circuitry is a DATA WINDOW
disk sector greater than or equal to data string from
signal. This signal is sent to the controller to tell it
CPU or DMA controller.
where to find the data pulses in the data stream
coming in on the READ DATA input. SCAN LOW OR EQUAL—Set flag if data string from disk
For writing pulses to the disk, the story is a little sector is less than or equal to data string from CPU or
more complex. External circuitry supplies a basic WR DMA controller.
CLOCK signal at a frequency of 500 kHz for FM and 1
MHz for MFM recording. The 8272 outputs the serial Working out a series of commands for a disk control-
stream of clock bits and data bits that are to be written ler such as the 8272 on a bit-by-bit basis is quite
to the disk on its WR DATA pin. During a write tedious and time consuming. Fortunately, you usually
operation, the 8272 asserts its WR ENABLE signal to don’t have to do this, because in most systems, you can
turn on the external circuitry that actually sends this use higher-level procedures to read from and write toa
serial data to the read/write head. Data bits written in disk. In the next section we show you some of the
MFM on a disk will tend to shift in position as they are software used to interface to disk drives.
read out. A 1 bit, for example, will tend to shift toward
an adjacent O bit. This shift can cause errors in
Disk-Drive Interface Software
readout unless it is compensated for. The PRE-SHIFT 0
and PRE-SHIFT 1 signals from the controller go to There are several different software levels at which you
external circuitry that shifts bits forward or backward can interact with a disk drive. One level is directly at
as they are being written. The bits are then in the the controller level. The next level up is at the BIOS
correct position when read out. level. A still-higher and easier-to-use level is at the
operating system level, or OS level. Figure 13-29 shows
8272 COMMANDS this situation diagramatically. Figures like that of Fig-
The 8272 can execute 15 different commands. Each of ure 13-29 are often called stack diagrams, obviously
these commands is sent to the data register in the because they look like a stack of boxes. The order of the
controller as a series of bytes. Consult an 8272 data stacking is important, however, because the order
sheet to find the formats for these commands if you implies the calling sequences used between the layers.
need them. After a command has been sent to the Where two of the stacked boxes meet is an interface.
8272, it carries out the command and returns the re- The implication is that the software routines in the
sults to status registers in the 8272 and/or to the data upper box call the routines in the lower box (using
register in the 8272. To give you an overview of the them as subroutines), but the routines in the lower box
commands you can send to an 8272, we list them here
with a short description for each.
OPERATING SYSTEM INTERFACE ROUTINES
SPECIFY—Initialize head load time, head step time,
BASIC I/O SYSTEM ROUTINES
DMA/non-DMA.
SENSE DRIVE STATUS—Return drive status information. CONTROLLER (DRIVER) ROUTINES
0-7 Filename
8-10 Filename extension
Operating System (OS) Interfacing 11 File attribute
$01 Read only
DISK OPERATING SYSTEM (DOS) OVERVIEW $02 Hidden file
First of all, let’s clarify some terms for you. An oper- $04 System file
ating system is simply a program or collection of $08 Volume label in first 11 bytes,
programs that allows you to format disks, execute not filename
other programs, create disk files, write data to files, $10 File is a subdirectory of files in
read data from files, communicate with system peri- lower level of hierarchical file
pherals such as modems and printers, etc. As we tree
discuss in Chapter 14, some operating systems allow $20 File has been written to and
several users to share a CPU on a timeshare basis. The closed
term disk operating system, or DOS, means that the =D Reserved
operating system resides on a disk and is loaded into 22-23 Time the file was created or last up-
memory and executed when you turn on or reset the dated :
system. In common usage the acronym DOS has come 24-25 Date the file was created or last up-
to imply specifically the IBM PC disk operating system, dated
PC-DOS. The term file in this case refers to a collection 26-27 Starting cluster number; DOS allo-
of related data accessible by name. The principle is the cates space for files in clusters of
same as having a named file folder in an office file one or more adjacent sectors in
cabinet. size
Using the OS to format disks, write files, and read 28-31 Size of the file in bytes
files relieves you of the burden of keeping track of the
individual tracks and sectors. The OS does all this for DOS uses the first file allocation table, or FAT, to
you. Now, before we show you how to use the OS keep track of which clusters on a disk are currently
procedure calls, we briefly show you how IBM’s PC- being used for each file and which clusters are still
DOS keeps track of where it puts everything. available. The FAT is part of the link between a file-
Figure 13-30 shows the ‘‘housekeeping”’ information name and the actual track and sector numbers where
that IBM PC-DOS puts on the first track of a disk to that file is stored. The second FAT is simply a copy of
keep track of where it puts data. The basic structure the first, included for backup purposes.
for these parts is put on a disk when it is formatted Most current microcomputer operating systems—
IBM PC DOS 2.1 and later versions, for example—
allow you to set up a hierarchical file structure. In this
structure you have one main, or root, directory which
resides in the directory of the disk, as shown in Figure
13-30. This root directory can contain the names of
First copy of file allocation program or data files. The root directory can also have
table—variable size
the names of subdirectories of files. Each subdirectory
Second copy of file allocation can also refer directly to program or data files or it can
table—variable size refer to lower subdirectories. The point here is that this
structure allows you to group similar files together and
to avoid going through a long list of filenames to finda
particular file you need. To get to a file in a lower-level
directory, you simply specify the path to that file. The
path is the series of directory names that you go
FIGURE 13-30 IBM PC DOS format for floppy disks. through to get to that file.
; C equivalent:
; WriteFile( refNum, p, num )
; int refNum;
; char p;
: long num;
; {
; age ioe
; io = FSWrite( refNum, &num, p);
: }
FSWrite:
Sue DP ; Set D1 to 1) (thissflags val Write)
LINK A6é,SFFCE ; allocate (34) byte #onethelistack
LEA SFFCE(A6),A@
MOVE.L $0008(A6) ,$0020(AQ)
MOVE.W $0010(A6) ,$0018(AQ)
MOVEA.L S@0Q@C(A6),A1
MOVE.L (A1),$0024(AQ)
CLR.W $Q02C (AQ)
CLR.L $Q02E(AQ)
Tet Tees D1
BNE.S XS@Q006 ; @Q@12F9FC
TRAP SAQO2 ; Read
BRA.S XSQ@Q04 >; @@12F9FE
TRAP SAQ@@3 ; Write
MOVE.W. D®,S0012(A6)
MOVEA.L S@@@C(A6),A1
MOVE.L $@028(AQ),(A1)
UNLK A6
MOVEA.L (A7)+,Al1 >; get return address from stack
ADDA.W #S00@A,A7 ; move up stack pointer
JMP (Al) s “return to calling routine
FIGURE 13-31 Instruction sequence fragments to access Macintosh disk and
display.
RAM DISKS
you would for any other drive. Here’s the point of this.
Currently available for most microcomputers are pro- Suppose you are using Wordstar to edit program files.
grams that allow you to set aside an area of RAM in Most of the time when you execute a Wordstar com-
such a way that it appears to DOS as simply another mand, the system must go and get the code for that
disk drive. In an IBM PC that has two actual drives, A: command from the Wordstar system disk and load it
and B:, the installed RAM disk becomes C:. You can into memory before it can execute the command. This
copy files to and from this RAM disk by name just as means you spend a lot of time waiting. If you load all
and convert the reflections from a data track to a data AVERAGE DATA TRANSFER RATE (SEQUENTIAL) = 150 KBYTES/SEC.
stream of 1s and Os. A bit is erased by turning off the
(b)
vertical magnetic field and heating the spot corre-
sponding to that bit with the laser. When heated with FIGURE 13-34 Industrywide data structure for audio
no field present, the magnetism of the spot will flip compact disk (CD) optical disks. (a) Disk format. (b) Track
around in line with the horizontal field on the disk. format. (Electronic Engineering Times, March 25, 1985)
Other techniques for producing read/write disks are
now being researched intensely because of the promise
this form of data storage has.
Data is stored on optical disks in several different the disk at 150 Kbytes/s (about three times the rate for
formats. Figure 13-34 shows the format in which floppy disks), the disk contains so much data that it
digital data is stored on the 4.7-in. audio compact takes an hour to read out all the data on the disk. Also
disks. note that a large area at the start of the track and a
As shown in Figure 13-34a, data is stored serially in large area at the end of the track are used as gaps. In
one long spiral track, starting near the center of the all, about half of the total area on an optical disk is
disk. The track is divided into blocks, each containing used for synchronization, identification, and error cor-
2 Kbytes of actual data. Figure 13-34b shows the rection. This is not a big drawback because of the
format for each block. Note that many bytes in each immense amount of data that can be stored on the
block are used for header, synchronization and error- disk.
detecting or error-correcting codes. Extensive error Several ‘‘jukebox’’ optical-disk systems, which con-
detection and correction is necessary to bring the error tain up to 256 disks, are currently available. Typically
rate down to that of magnetic disks. The position of it takes only a few seconds to access a disk. The
each block on the track is identified with coordinates of potentially low cost of a few cents per megabyte and
minutes, seconds, and block number. As shown in the hundreds of gigabytes of data storage possible for
Figure 13-34a, a second represents 75 blocks num- optical-disk systems may change the way our society
bered 0-74. A minute represents 60 seconds, or a total transfers and processes information. The contents of a
of 4500 blocks. The entire disk represents 1 h, or 270K sizable library, for example, could be stored on a few
blocks. Note that although data can be read out from disks. Likewise, the entire financial records of a large
SPHERICAL Mh a
Wi ii
ee Ik
“GOLF-BALL”—~ \9
= fleAY
eA
DAISY-WHEEL PRINTERS
Figure 13-36 shows a drawing of a daisy-wheel print- a
er mechanism. Here the raised letters are attached at CHARACTER
ARMS
the ends of spokes of a wheel. To print a letter the
wheel is rotated until the desired letter is in position
over the paper. A solenoid-driven hammer then hits FIGURE 13-36 Daisy-wheel printer mechanism. (Data
the ‘‘petal’’ against the ribbon to print the letter. Products Corporation)
Ges I Bae i.
for near-letter-quality printing. A big advantage of
dot-matrix impact printers is their ability to change
fonts or print graphics under program control.
PAPER
SCAN PATH OF
Laser and Other Xerographic Printers LIGHT BEAM ON
INTERMEDIATE
Laser printers operate on the same principle as most SURFACE :
DEVELOPER UNIT
office copy machines, commonly called *‘Xerox’’ ma-
chines. The basic approach is first to form an image of
the page that is to be printed on a photosensitive drum
in the machine. Powdered ink, or ‘‘toner,’’ is then
applied to the image on the drum. Next the image is
Sx
MULTIPLE MIRRORS
MOUNTED ON
PHOTO-CONDUCTIVE
INTERMEDIATE SURFACE
ON ROTATING DRUM Ze
|
ROTATING DRUM
electrostatically transferred from the drum to a sheet fs LASER
of paper. Finally, the inked image on the paper is LIGHT BEAM MODULATOR LIGHT
(CONTROLLED BY BEAM
‘“‘fused,’’ usually with heat. CHARACTER GENERATOR) SOURCE
In a Xerox machine the image on the photosensitive MIRROR
PATH OF LIGHT
drum is simply a copy of an original produced with a BEAM FROM LASER
camera lens. A more computer-compatible method of
producing an image on the photosensitive drum is with FIGURE 13-39 Laser printer mechanism. (Data Products
a laser. Turning a laser on and off as it is swept back Corporation)
MICROPHONE
ZERO CROSSING
DETECTOR
SELECT
In Chapter 2 we discussed ‘‘computerizing”’ an elec- 6. Describe the different types of modulation com-
tronics factory. This means that computers are inte- monly used by modems.
grated into all the operations of the factory and that 7, Show the formats for a byte-oriented protocol and
each person in the company has access toa computer. for a bit-oriented protocol used in synchronous
The company may have a large centrally located main- serial data transmission.
frame computer, several minicomputers that serve
groups of users, individual computer engineering 8. Draw diagrams to show the common computer
workstations, and portable computers spread around network topologies.
thé world with the salespeople. In order for all these Describe the operation of an Ethernet system.
9.
computers to work together, they must be able to
communicate with each other in an organized manner. 10. Describe the operation of a token-passing ring
In this chapter we show you some of the devices, signal system.
standards, and systems used for communication with
and between computers. 11. Show the major signal groups for the GPIB (IEEE
In the first section of the chapter we discuss the 488) bus, describe how bus control is managed,
and indicate how data is transferred on a hand-
hardware and low-level software required to interface
shake basis for the GPIB.
microcomputer buses to serial data communication
lines. Then we discuss how the serial data signals are
transmitted from one place to another. This discussion
includes RS-232C-type standards, modems, and fiber- INTRODUCTION TO ASYNCHRONOUS
optic cables. The next section of the chapter shows you SERIAL DATA COMMUNICATION
how to write programs that perform simple serial data
Overview
communication. As an example, in this section we use
a program that allows you to download programs from Serial data communication is a somewhat difficult
a Macintosh® computer to an URDA® MDS. In the final subject to approach because you need pieces of infor-
sections of the chapter we discuss the operation of mation from several different topics in order for each
several common computer networks. part of the subject to really make sense. To make this
approach easier, we first give an overview of how all the
pieces fit together and then describe the details of each
OBJECTIVES piece later in specific sections. A problem with this
subject is that it contains a great many terms and
At the end of this chapter, you should be able to acronyms. To help you absorb all these, you may want
to make a glossary of terms as you read the chapter.
1. Show and describe the meaning of the bits in the Within a microcomputer, data is transferred in par-
format used for sending asynchronous serial data. allel, because that is the fastest way to do it. For
transferring data over long distances, however, paral-
2. Initialize a common UART for transmitting serial
lel data transmission requires too many wires. There-
data in a specified format.
fore, data to be sent long distances is usually converted
3. Describe several voltage, current, and light (fiber- from parallel form to serial form so that it can be sent
optic) signal methods used to transmit serial data. on a single wire or pair of wires. Serial data received
from a distant source is converted to parallel form so
4. Describe the function of the major signals in the that it can easily be transferred on the microcomputer
RS-232C standard.
buses. Three terms often encountered in literature on
5. Show how toconnect RS-232C equipment directly serial data systems are simplex, half-duplex, and
or with a ‘“‘null-modem”’ connection. full-duplex. A simplex data line can transmit data only
WML |
|
|
|
|
START | pa. | ps | be |PARITY, STOP | STOP |
|
| | | | | | | | | |
ONE CHARACTER
FIGURE 14-1 Bit format used for sending asynchronous serial data.
Chip select
Transmitter data
Receiver clock
Receiver data
GND Ground
(6)
FIGURE 14-3 Block diagram and pin descriptions for the Intel 8251A USART.
(a) Block diagram. (b) Pin descriptions.
at the center of the bit times rather than at leading indicates an intentional break in data transmission or
edges. This reduces the chance of signal noise at the a break in the signal line. When programmed for
start of the bit time causing a read error. synchronous data transmission, this pin will go high
The 8251A is double-buffered. This means that one when the 8251A finds a specified syne character or
character can be loaded into a holding buffer while characters in the incoming string of data bits.
another character is being shifted out of the actual The four signals connected to the box labeled
transmit shift register. The TxRDY output from the MODEM CONTROL in the 8251A block diagram are
8251A will go high when the holding buffer is empty handshake signals, which we described in the previous
and another character can be sent from the CPU. The section.
TxEMPTY pin on the 8251A will go high when both the
holding buffer and the transmit shift register are emp-
ty. The RxRDY pin of the 8251A will go high when a INITIALIZING AN 8251A
character has been shifted into the receiver buffer and To initialize an 8251A you must first send a mode word
is ready to be read out by the CPU. Incidentally, if a and then a command word to the control register
character is not read out before another character is address for the device. Figure 14-4 shows the formats
shifted in, the first character will be overwritten and for these words and for the 8251A status word, which
lost. is read from the same address. Baud rate factor, speci-
The sync-detect/break-detect (SYNDET/BD) pin has fied by the two least significant bits of the mode word,
two uses. When the device is operating in asynchro- is the ratio between the clock signal applied to the
nous mode, in which we are interested here, this pin TxC-RxC inputs and the desired baud rate. For exam-
will go high if the serial data input line, RxD, stays low ple, if you want to use a TxC of 19,200 Hz and transmit
for more than 2 character times. This signal then data at 1200 Bd, the baud rate factor is 19,200/1200,
= Terese [u [1]
D7 D5 ee DAs DS DZS DiI DO
r= TRANSMIT ENABLE
1 = ENABLE
0 = DISABLE
RECEIVE ENABLE
1 = ENABLE RXRDY
@ = DISABLE RXRDY
INTERNAL RESET
He HIGH RETURNS 8251
INVALID TO MODE INSTRUCTION
“he Ee BITS
FORMAT
(ONLY EFFECTS Tx; Rx
NEVER REQUIRES MORE
ENTER HUNT MODE
THAN ONE STOP BIT) 1 = ENABLE SEARCH FOR
SYN CHARACTERS
D7 D6 D5 D4 D3 D2 D1 DO
RECEIVER READY
Indicates USART has received a
character on its serial input and
SYNC DETECT is ready to transfer it to the CPU.
When set for internal syne detect
indicates that character sync has been
achieved and 8251 is ready for data. TRANSMITTER EMPTY
Indicates that parallel to serial
OVERRUN ERROR converter in transmitter is empty.
The OE ‘flag is set when the CPU does
not read a character before the next
FRAMING ERROR (ASYNC ONLY) one becomes available. It is reset by PARITY ERROR
FE flag is set when a valid stop bit is not the ER bit of the Command instruction. PE flag is set when a parity error is
detected at end of every character. It is OE does not inhibit operation of the detected. It is reset by ER bit of
reset by ER bit of Command instruction. 8251; however, the previously overrun Command instruction. PE does not
FE does not inhibit operation of 8251. character is lost. inhibit operation of 8251.
(c)
FIGURE 14-4 Formats of 8251A mode, command, and status words. (a) Mode
word. (b) Command word. (c) Status word. (Inte! Corp.)
or 16. If bits DO and D1 are both made Os, the 8251A is the same TxC and RxC. The character length specified
programmed for synchronous data transfer. In this by bits D2 and D3 in the mode word includes only the
case the baud rate will be the same as the applied TxC actual data bits, not the start bit, parity bit, or stop
and RxC. The other three combinations for these 2 bits bit(s). If parity is disabled, no parity bit is inserted in
represent asynchronous transfer. A baud rate factor of the transmitted bit string. If the 8251A is programmed
1 can be used for asynchronous transfer only if the for 5, 6, or 7 data bits, the extra bits in the data
transmitting system and the receiving system both use character byte read from the device will be Os.
11 10 8
12 ie
— S
PIN14=+12V PIN14=+5V
FIGURE 14-5 Connectors often used for RS-232C PINT =—12V PIN7 = GND
PIN 7 = GND
connections. (a) DB-25P 25-pin male connector.
(b) DE-9P 9-pin male DIN connector. (a) (b)
FIGURE 14-6 TTL-to-RS-232C-to-TTL signal conversion.
(a) MC1488 used to convert TTL to RS-232C.
MC1488 quad TTL-to-RS-232C drivers and MC1489
(b) MC1489 used to convert RS-232C to TTL.
quad RS-232C-to-TTL receivers shown in Figure 14-6.
The MC1488s require + and — supplies, but the
MC1489s require only +5 V. Note the capacitor to
ground on the outputs of the MC1488 drivers. To
reduce cross talk between adjacent wires, the rise and operates in the reverse direction from the forward
fall times for RS-232C signals are limited to 30 V/s. channel and at a much lower baud rate. Pins 12, 13,
Also note that the RS-232C handshake signals such as 14, 16, and 19 are the data and handshake lines for
RTS are active low. Therefore, if one of these signals is this backward channel.
asserted, you will find a positive voltage on the actual Pins 15, 17, 21, and 24 are used for synchronous
RS-232C signal line when you check it during trouble- data communication. We tell you a little more about
shooting. Now let’s look at the RS-232C pin descrip- these in the section on modems. Next we want to show
tions. you some of the tricks in connecting RS-232C-compat-
ible equipment.
RS-232C SIGNAL DEFINITIONS
Figure 14-7 shows the signal names, signal direction,
CONNECTING RS-232C-COMPATIBLE EQUIPMENT
and a brief description for each of the 25 pins defined A major point we need to make is that you can seldom
for the RS-232C. For most applications only a few of just connect together two pieces of equipment de-
these pins are used, so don’t be overwhelmed. Here are scribed by their manufacturers as RS-232C compati-
a few additional notes about these signals. ble and expect them to work the first time. There are
First note that the signal direction is specified with several reasons for this. To give you an idea of one of
respect to the DCE. This convention is part of the the reasons, suppose that you want to connect the
standard. We have found it very helpful to put arrow- terminal in Figure 14-2 directly to the computer rather
heads on all signal lines, as shown in Figure 14-2, than through the modem-modem link. The terminal
when we are drawing circuits for connecting RS-232C and the computer probably both have DB-25-type con-
equipment. nectors so that, other than a possible male-female
Next observe that there is both a chassis ground (pin mismatch, you might think you could just plug the
1) and a signal ground (pin 7). To prevent large ac- terminal cable directly into the computer. To see why
induced ground currents in the signal ground, these this doesn’t work, hold your fingers over the modems
two should be connected together only at the power in Figure 14-2 and refer to the pin numbers for the
supply in the terminal or the computer. RS-232C signals in Figure 14-7. As you should see,
The TxD, RxD, and handshake signals shown with both the terminal and the computer are trying to
common names in Figure 14-7 are the ones most often output data (TxD) from their number 2 pins to the
used for simple systems. We gave an overview of their same line. Likewise, they are both trying to input data
use in the introduction to this section of the chapter (RxD) from the same line on their number 3 pins. The
and discuss them further in a later section of the same problem exists with the handshake signals. RS-
chapter on modems. These signals control what is 232C drivers are designed so that connecting the lines
called the primary, or forward, communications together in this way will not destroy anything, but
channel of the modem. Some modems allow communi- connecting outputs together is not a productive rela-
cation over a secondary, or backward, channel, which tionship. A solution to this problem is to make an
AA PROTECTIVE GROUND
TRANSMITTED DATA
RECEIVED DATA
REQUEST TO SEND
CLEAR TO SEND
DATA SET READY
SIGNAL GROUND (COMMON RETURN)
RECEIVED LINE SIGNAL DETECTOR
(RESERVED FOR DATA SET TESTING)
(RESERVED FOR DATA SET TESTING)
UNASSIGNED
SECONDARY RECEIVED LINE SIGNAL DETECTOR
SECONDARY CLEAR TO SEND
SECONDARY TRANSMITTED DATA
TRANSMISSION SIGNAL ELEMENT TIMING (DCE SOURCE)
URDA MAC
MDS Syl
DTE DTE 25 43
(a) (b)
FIGURE 14-8 Nonmodem RS-232C connections. (a) Null modem for connecting two RS-232C data
terminal-type devices. (b) Macintosh to URDA MDS serial port connection.
RS-423
INTERFACE 450Q
% MC3486
-12V =
3-STATE
RECEIVER
CABLE
LENGTH
(m) 100 CABLE
(ft)
LENGTH
Ww
labels on the waveforms in Figure 14-16.
>
Y At the left side of the waveforms, a call is being made
—
w from one modem to another. Assuming that the DTR of
e DATA the called modem is asserted, the ringing signal on the
MODEM
ANALOG/ line will cause the DAA circuitry to assert the ringing
DIGITAL input (RI) of the 7910. In response to this, the 7910 will
FRONT
END
send out a silent period of about 2 s to accommodate
billing signals, and then it will send out an answer
tone of 2025 Hz to the calling modem for 2 s. If the DTR
and the RTS of the calling modem are asserted, indi-
FIGURE 14-15 Block diagram of combination fax and cating that data is ready to be sent, the calling modem
data modem. then puts a tone of 2225 Hz (mark) on the line for 8 ms
to let the called modem know that contact is complete.
In response to this mark, the called modem asserts its
carrier-detect (CD) output to enable the receiving
mission, and the corresponding data communication
UART. The calling modem then sends data until its
uses V.22 bis full-duplex, 2400-bit/s transmission.
RTS input is released by the computer or terminal
The box labeled DAA in Figure 14-15 is the data ac- sending the data. While it is receiving data on the main
cess arrangement circuitry, which actually interfaces
channel, the called modem can send data to the calling
the signals with the phone lines. This circuitry must
modem on the 5-bit/s back channel. Releasing RTS
conform to the provisions of FCC rules, Section 68.
causes the modem to release CTS to the sending
LSI has made it possible to build a modem with very
computer and remove the carrier from the line. The
few parts. A device such as the Advanced Micro Devices
called modem senses the loss of the carrier and unas-
Am7910, for example, can be used to produce a 1200-
serts its CD signal.
Bd FSK modem. The EXAR Corp. XR-2901 and 2902
If the called system is to send some data back to the
chip set contains a major part of the circuitry needed to
calling system on the main channel, it asserts the RTS
implement a modem that can send or receive facsimile
input to its modem. The called modem sends a mark-
data at 9600 bits/s or send and receive full-duplex
ing tone to the calling modem for 8 ms. The calling
modem data at 2400 bits/s.
modem asserts its CD output to its UART. The called
modem then sends data to the calling modem on the
MODEM HANDSHAKING
main channel until its RTS input is unasserted by the
Earlier in the chapter we gave an overview of the called system, indicating no more data to send. While
handshake process between a terminal and a remote the called modem is transmitting on the main channel,
computer through modems and the phone lines. Now the calling modem can transmit over the back channel
that you know more about modems, we can take a if necessary. For a full-duplex system, the handshake
closer look at the handshake sequence. is similar, but the data rates are equal in both direc-
Most of the currently available modems contain a tions.
dedicated microprocessor. The built-in intelligence al-
lows these units automatically to dial a specified num-
ber with either tones or pulses and redial the number if
Codecs, PCM, TDM, and ISDN
it is busy or doesn’t answer. When a smart modem
makes contact with another moden,, it will automati- In the previous sections we described how modems
cally try to set its transmit circuitry to match the baud produce signals suitable for transmission over stan-
rate of the other modem. Many modems can be set to dard phone lines. Now we want to discuss briefly how
automatically answer a call after a programmed num- telephone companies actually transmit the signals
ber of rings so that you can access your computer from output by modems and some new developments that
a remote location. Some units allow the user to estab- we hope will eliminate the need for modems as we
lish voice contact and then switch over to modem know them.
operation. Digital signals have much better noise immunity
After a modem dials up another modem, a series of than analog signals, so as soon as a phone company
handshake signals takes place. The handshake signals receives a voice or modem signal in its local branch
may be generated by hardware in the modem or by office, the signal is converted to digital form. A D/A
software in the system connected to the modem. Figure converter at the destination uses the received binary
14-16 shows an example of the data and handshake codes to reconstruct a replica of the original analog
MARK HOLD
RD
|
MAIN
MARK/SPACE MARK/SPACE DATA CALLED TO CALLING
CHANNEL SOFT TURN (tey) SOFT TURN__|[_ ¢_
+ LINE OFF TONE | OFF TONE S10
MARK
=
BACK
CHANNEL
R
TE ITTED
CeRGE DATA CALLING TO CALLED
——
DATA CALLED TO CALLING MARK HOLD
RD MARK HOLD
FIGURE 14-16 Handshake sequence for Bell-type 202 FSK modem using
AM7910 modem chip. (Advanced Micro Devices)
signal. Sending analog signals, such as phone signals, the accuracy for small signals where it is needed,
as a series of binary codes is called pulse-code modula- without going to a converter with more bits of resolu-
tion, or PCM. The A/D converter that produces the tion. The D/A in the codec is nonlinear in the reverse
binary codes in this application is usually called a manner, so that when the binary pulse codes are
coder, and the D/A converter that reconstructs the converted to analog, the result is expanded to duplicate
analog signal from the pulse codes is referred to as a the original waveform. A codec that has this intention-
decoder. Since both a coder and a decoder are needed al nonlinearity is often referred to as a compander, or
for two-way communication, they are often packaged a companding codec. Consult the Intel 2910A data
in the same IC. This combined coder and decoder is sheet for more information about this.
called a codec. A common example of a codec is the In most systems the output of the codec A/D is not
Intel 2910A. This device contains a sample-and-hold simply sent on a wire by itself; instead, it is multi-
circuit on the analog input, an 8-bit A/D converter, an plexed with the outputs of many other codecs in a
8-bit D/A converter, and appropriate control circuitry. manner known as time-division multiplexing, or TDM.
Normal A/D converters are linear, which means that There are several different formats used. A simple one
the steps are the same size over the full range of the will give you the idea of how it’s done.
converters. The A/D converters used in codecs are One of the first TDM systems was the T1 or DS-1
nonlinear. They have small steps for small signals and system, which multiplexes 24 PCM voice channels
large steps for large signals. In other words, for signals onto a single wire. For this system an 8-bit codec on
near the zero point of the A/D converter, it only takes a each channel samples and digitizes the input signal at
small change in the signal to change the code on the an 8-kHz rate. The 8-bit codes from the codecs are sent
output of the A/D. For a signal near the full scale of the to a multiplexer, which sends them out serially, one
converter, a large change in the input signal is re- after the other. One set of bits from each of the 24
quired to produce a change in the output binary code. codecs plus a framing bit is referred to as a frame.
This nonlinearity of the A/D converter is said to com- Figure 14-17 shows the format of a irame for this
press the signal, because it reduces the dynamic range system. The framing bit at the start of each frame
of the signal. Compression in this way greatly improves toggles after each frame is sent. It is used to keep the
COMPUTER NETWORK
DIGITAL TERMINAL TERMINATOR
TELEPHONE TE1 NETWORK
TE2
DIGITAL
TELEPHONE LINE TERMINATOR
TE1 (LINE CARD)
TERMINAL EXCHANGE
ADAPTER TERMINATOR
TA
PRINTER
(a) (continued)
FIGURE 14-18 Integrated services digital network (ISDN). (a) Line connections
and interfaces. Reprinted from EDN, April 27, 1989, © 1989 Cohners Publishing
Company, a division of Reed Publishing USA. (b, p. 478) Example S interface
frame format showing how B1, B2, and D channel bits are packaged for
transmission. (NOTE: Frames sent from network termination to terminal
equipment are offset 2 bits from frames sent from terminal equipment to
network termination.)
TE TO NT
NOTES:
B1 AND B2 = TRAFFIC CHANNELS F = FRAMING BITS
D = SIGNALLING CHANNEL F, AND N = AUXILIARY FRAMING
E = ECHO OF D CHANNEL A = ACTIVATION BIT
(NOTE ARROWS FROM D TO E) L = DC BALANCING BITS
(b)
FIGURE 14-18 (continued)
+5 V
SN74LS132
(1/4)
MFOE71
(EMITTER) (A) a
SS
2N3904
MFOD73
TTLIN (RECEIVER)
cladding material, which is also transparent to light. of refraction, the more the beam will be bent when it
An outer sheath protects the cladding and prevents goes from one material to another.
external light from entering. Figure 14-20c shows a unique situation that occurs
Now that you have an overview of an optical-fiber when a beam going from a dense material to a less
link, let’s take a look at how the light actually propa- dense material hits the boundary at a special angle
gates through the fiber and the trade-offs with different called the critical angle. The beam will be bent so that
fibers. it travels parallel to the boundary after it enters the
less dense material.
THE OPTICS OF FIBERS A still more interesting situation is shown in Figure
14-20d. If the beam hits the boundary at an angle
The path of a beam of light going from a material with greater than the critical angle, it will be totally reflect-
one optical density to a material of different optical ed from the boundary at the same angle on the other
density depends on the angle at which the beam hits side of the normal. This is somewhat like skipping
the boundary between the two materials. Figure 14-20 stones across water. In this case the light beam will not
shows the path that will be taken by beams of light at leave the more dense material.
various angles going from an optically dense material To see how all this relates to optical fibers, take a
such as glass to a less dense material such as a look at the cross-sectional drawing of an optical fiber in
vacuum or air. If the beam hits the boundary at a right Figure 14-20e. If a beam of light enters the fiber
angle, it will go straight through, as shown in Figure parallel to the axis of the fiber, it will simply travel
14-20a. When a beam hits the boundary at a small through the fiber. If the beam enters the fiber so that it
angle away from the perpendicular, or normal, it will hits the glass-cladding-layer boundary at the critical
be bent away from the normal when it goes from the angle, it will travel through the fiber-optic cable in the
more dense to the less dense, as shown in Figure cladding layer, as shown for beam Y in Figure 14-20e.
14-20b. A light beam going in the other direction would However, if the beam enters the cable so that it hits the
follow the same path. A quantity called the index of glass-cladding-layer boundary at an angle greater than
refraction is used to describe the amount that the light the critical angle, it will bounce back and forth be-
beam will be bent. Using the angle identifications tween the walls of the fiber, as shown for beam X in
shown in Figure 14-20b, the index of refraction, n, is Figure 14-20e. The glass or plastic used for fiber-optic
defined as (sine B)/(sine A). A typical value for the cables has very low absorption, so the beam can
index of refraction of glass is 1.5. The larger the index bounce back and forth along the fiber for several feet or
1700 6100 016C MACW: BSR INFO ;GET START,END ADDRESS FROM USER
1704 2c7Cc 0000 TFB6 MOVEA.L § #F ILE_NAME,A6
170A 3016 MOVE .W (A6) ,DO 7GET FILE NAME
170C 0c 40 OOOA CMPI.W $000A,D0 7IF ASCII,GO TO AFILE
1710 6708 BEQ AFILE
Lei2 2c7C 0000 0018 MOVEA.L — # (NOCONV-CONV+2) ,A6 ;ELSE SET UP FOR NO COVERSION
1718
171A
1720
6006
2c7C 0000
16BC 0006
0002 x BRA
MOVEA.L
MOVE .B
WRITE
#(CONV-CONV+2)
$$06,A3
,A6 #SET UP FOR CONVERSION
sENABLE DUART TO TRANSMIT
1724 4280 CURSL DO #CLEAR DO
1726 4281 CLR.L D1 7CLEAR Dl
1728 1018 MOVE .B (AO) +,D0 7GET NEXT BYTE
172A 4EFB E800 IMP CONV-2 (PC, A6)
172E 1200 CONV: MOVE.B DO,D1 ;COPY BYTE TO Dl
1730 E818 ROR.B #4,D0 7GET UPPER NIBBLE
1732 0200 OOOF AND.B #$0F,D0
1736 103B 0824 MOVE .B ASCII(PC,DO.L)
,DO #GET ASCII VALUE FROM TABLE
173A 6114 BSR SENDBY #SEND TO MACINTOSH
173c 0201 OOOF AND.B #S0F,D1 #GET LOWER NIBLE
1740 103B 181A MOVE .B ASCII(PC,D1.L)
,DO #GET ASCII VALUE FROM TABLE
1744 610A NOCONV: BSR SENDBY
1746 4A46 TsT D6 7TEST COUNTER
1748 S7CE FFDE DBEQ D6, SEND 3IF COUNTER <>0,GO TO SEND
174¢c 6000 007C BRA TOMAIN
1750 1412 SENDBY : MOVE.B (A2) ,D2 ;READ DUART STATUS REGISTER
1752 0802 0002 BIST D2, #2 IS DUART READ?
1756 67F8 BEQ SENDBY ;IF NOT, TRY AGAIN
1758 1880 MOVE .B DO, (A4) ;WITE BYTE TO TX REGISTER
175A 4E75 RTS
175¢ 30 ASCII: DC.B $30 zASCII CODE FOR
175D 31 DC.B $31 zASCII CODE FOR
17SE 32 DC.B $32 #ASCII CODE FOR
LSE, 33 DC.B $33 sASCII CODE FOR
1760 34 DC.B $34 #ASCII CODE FOR
1761 35 DC.B $35 #ASCII CODE FOR
1762 36 DC.B $36 #ASCII CODE FOR
1763 37 DC.B $37 #ASCII CODE FOR
1764 38 DC.B $38 #ASCII CODE FOR
1765 39 DC.B $39 #ASCII CODE FOR
1766 41 DC.B $41 #ASCII CODE FOR
1767 42 Dc.B $42 7ASCII CODE FOR
L768 43 DC.B $43 ;ASCII CODE FOR OBIDHMWSWNPO
AWPU
176C 6100 0100 MACR: BSR INFO #GET START,END ADDR FROM USER
1770 2G7G 0000 7FB6 MOVEA.L = #F ILE_NAME,A6
1776 3016 MOVE .W (A6) ,DO #GET FILE NAME
1778 0c40 OO0A CMPI.W $000A,D0 7IF ASCII,GO TO AAFILE
ake 6708 BEQ AAFILE
177E 2c7C¢ 0000 OO1E MOVEA.L = # (RNOCOV-RCONV+2) ,A6 #ELSE SET UP FOR NO COVERSION
1784 6006 BRA READ
1786 2c7c 0000 0002 AAFILE: MOVEA.L — #(RCONV-RCONC+2) ,A6 *SET UP FOR CONVERSION
178C 16BC 0009 MOVE .B #$09, (A3) sENABLE DUART TO RECEIVE
1790 4280 CEReU DO *CLEAR DO
1792 4281 CLR.L D1 *CLEAR Dl
1794 617A BSR NOLIMIT 7GEL FIRST BYTE
1796 4EFB E80c JMP RCONV=2 (PC, A6)
179A 223¢ 0000 0000 RECEIV: MOVE .L #$0000,D1 ;CLEAR D1
17A0 617A BSR LIMIT #GET NEXT BYTE
17A2 4EFB E800 IMP RCONV-2 (PC, A6)
17A6 6100 0096 RCONV: BSR ASTOBI *CONVERT UPPER NIBBLE TO BINARY
17AA ocoo0 OOFF CMPI.B #SFF,DO #WAS AN INVALID CHARACTER SENT?
17AE 67EA BEQ RECEIV 7IF SO TRY AGAIN
17B0 1200 MOVE .B DO,D1 +PUT UPPER NIBLE IN Dl
17B2 E919 ROL.B #4,D1 *ROTATE INTO POSITION
17B4 6166 LOWER: BSR LIMIT +GET NEXT BYTE
17B6 6100 0086 BSR ASTOBI *CONVERT LOWER NIBBLE TO BINARY
17BA 0co0 OOFF CMPI.B #SFF,DO 7WAS AN INVALID CHARACTER SENT?
17BE 67F4 BEQ LOWER
17¢0 8001 OROUT : OR.B D1,D0 ;COMBINE UBBER AND LOWER NIBBLE
17¢2 10c0 RNOCONV: MOVE.B DO, (AQ) + ;WRITE BYTE TO MEMORY
17¢4 4A46 TST D6 *TEST D6
17Cc6 S7CE FFD2 DBEQ D6,RECEIV #LOOP BACK IF COUNT <> ZERO
17CA 16BC 000A TOMAIN: MOVE .B #S0A, (A3) *DISABLE DUART
17CE 90FC 0001 SUB.W #1,A0 #FIND LAST ADDRESS
17D2 3408 MOVE .W AO,D2 #PUT ADDRESS IN D2
17D4 163¢ 0004 MOVE.B #4,D3 #FOUR CHARACTERS TO BE FORMATTED
17D8 4EB8 O76A JSR FORMAT _CHAR +FORMAR ADDRESS FOR DISPLAY
17D¢C 227C 0000 7FAO MOVEA.L #LAST_KEY,Al
17E2 22G MOVE .L D1, (Al) + #PUT FORMATTED ADDRESS IN BUFFER
17E4 1410 MOVE .B (AQ) ,D2 #PUT DATA IN D2
17E6 163¢C 0002 MOVE .B #2,D3 #TWO CHARACTERS TO BE FORMATTED
17EA 4EB8 076A JSR FORMAT_CHAR #FORMAT DATA FOR DISPLAY
17EE 2281 MOVE .L D1, (Al) #PUT FORMATTED DATA IN BUFFER
17F0 227C 0000 TE76 MOVEA.L § #USER_ADDRESS,Al
17F6 2288 MOVE .L AO, (AI) #STORE USER ADDRESS
17F8 227¢ 0000 TEAO MOVEA.L § #LAST_KEY,Al
LIFE 4EB8 0950 JSR LOAD_MESSAGE #LOAD DISPLAY
1802 227C 0000 7FA1 MOVEA.L #$7FA1,Al
1808 12BC 0002 MOVE .B #$02, (Al) #SET DATA SIZE TO WORD
180C 4EF8 O4DA JMP MAIN+ #BACK TO MAIN PROGRAM
181¢ 2A3C 0004 BEE LIMIT: MOVE .L #0004 FFFF,DS +SET TIMER
1822 $385 AGAIN: SUB.L #1,D5 #DECREMENT TIMER
1824 670C BEQ TOUT +IF TIMER EQ 0, TIME IS UP
1826 1412 MOVE .B (A2),D2 sREAD STATUS REGISTER
1828 0802 0000 BTST D2, #0 sIS DUART READY?
182C 67F4 BEQ AGAIN +IF NOT TRY AGAIN
182E 1014 MOVE .B (A4) ,DO *GET BYTE
1830 4E7S RTS
1832 2C9r TOUT: MOVEA.L (SP) +,A6 7FIX STACK
1834 103¢ 0000 MOVE .B #500,D0 ;CLEAR DO
1838 3€38 0000 MOVE .W #$0000,D6 7;CLEAR COUNTER
183¢c 6082 BRA OROUT 7GO TO OROUT
s INITIALIZE DUART
that the transmitter must stop after each block of data -— —> EXTERNAL SYNC DETECT
is transferred and wait for an ACK or NAK signal from 1 = SYNDET IS AN INPUT
0 =SYNDET IS AN OUTPUT
the receiver. Due to the wait and line turnaround
times, the actual data transfer rate may be only half SINGLE CHARACTER SYNC
1 = SINGLE SYNC CHARACTER
the theoretical rate predicted by the physical bit rate of 0 = DOUBLE SYNC CHARACTER
the data link. The HDLC protocol discussed in a later
NOTE: IN EXTERNAL SYNC MODE, PROGRAMMING DOUBLE
section greatly reduces this problem. Next we want to CHARACTER SYNC WILL AFFECT ONLY THE Tx.
return to the Intel 8251A USART, which is used on the
(a)
IBM PC Synchronous Communication Adapter, and
give you a brief look at how it is used for BISYNC D/e DEN EDSa D4 D3 D1
communication.
;TRANSMIT ENABLE
1 = ENABLE
0 = DISABLE
RECEIVE ENABLE
We initialize an 8251A by first getting its attention, 1 = ENABLE
sending it a mode word, and then sending it a com- 0 = DISABLE
mand word. To initialize the 8251A for synchronous
SEND BREAK CHARACTER
communication, Os are put in the least-significant 2 1 = FORCES TXD “LOW”
bits of the mode word. The rest of the bits in the mode 0 = NORMAL OPERATION
I-FRAME (INFORMATION
TRANSFER
High-level Data Link Control (HDLC) and COMMANDS/RESPONSES) Nr Nr Nr P/F Ns Ns Ns @
Synchronous Data Link Control (SDLC) S-FRAME (SUPERVISORY
Protocols COMMANDS/RESPONSES) Ne Ne Ne Rie SS: ssw 4
U-FRAME (UNNUMBERED
The BISYNC-type protocols we discussed in the previ- COMMANDS/RESPONSES) M MM P/E M iM 4 1
ous section work only in half-duplex mode; except for
SENDING ORDER - BIT @FIRST, BIT 7 LAST
XMODEM, have difficulty transmitting pure 8-bit bina- NS THE TRANSMITTING STATION SEND SEQUENCE NUMBER, BIT 2 IS THE
ry data such as object code for programs; and are not LOW-ORDER BIT.
easily adapted to serving multiple units sharing a P/F THE POLL BIT FOR PRIMARY STATION TRANSMISSIONS, AND THE
common data link. In an attempt to solve these prob- FINAL BIT FOR SECONDARY STATION TRANSMISSIONS.
lems, the International Standards Organization (ISO) Nr THE TRANSMITTING STATION RECEIVE SEQUENCE NUMBER, BIT 61S
proposed the high-level data link control protocol THE LOW-ORDER BIT.
(HDLC) and IBM developed the synchronous data link S THE SUPERVISORY FUNCTION BITS
control protocol (SDLC). The standards are so nearly
M THE MODIFIER FUNCTION BITS
identical that, for the discussion here, we will treat
them together under the name HDLC and indicate any (b)
significant differences as needed.
As we said previously, BISYNC is referred to as a FIGURE 14-25 (a) Format of HDLC frame. (b) Meaning
byte-controlled protocol because character codes or of bits in 8-bit control field of frame.
we
grab it and transmit. We discuss this more in a later
ETHERNET,
section.
CSMA/CD OR TENS TO The final topology we want to discuss here is the
CSMA WITH HUNDREDS PER
ACKNOWLEDGMENT SEGMENT tree-structured network, which often uses broadband
uC CLUSTERS
COMMON BUS transmission. Before we can really explain this one, we
PRIMENET, need to introduce you to a couple of terms commonly
SDLC TENS TO
HUNDREDS PER
DOMAIN, used with networks. In some networks such as
(TOKEN PASSING) CHANNEL
OMNILINK
uC CLUSTERS Ethernet, data is transmitted directly as digital signals
at rates of up to 10 Mbits/s. With this type of signal,
CSMA/CD
TWO TO WANGNET,
only one device can transmit at a time. This form of
RS-232C &
OTHERS PER HUNDREDS PER LOCALNET data transmission is often referred to as baseband
CHANNEL CHANNEL M/A-COM
OTHER SERVICES transmission, because only one basic frequency is
BROADBAND BUS
used. The other common form of data transmission on
e@ TERMINAL
8 DISTRIBUTED CONTROL a network is referred to as broadband transmission.
© LOCAL CONTROLLER Broadband transmission is based on a frequency-
division multiplexing scheme such as that used for
MULTINETWORK CONTROLLER community antenna television (CATV) systems. The
FREQUENCY DIVISION MULTIPLEX radio-frequency spectrum is divided up into 6-MHz-
bandwidth channels.
FIGURE 14-26 Summary of common computer network A single device or group of devices can be assigned
topologies. one channel for transmitting and another for receiv-
| BITCELL |
ACTUAL DATA
Jor
rats merit
| o
\
[ce
/ \
ee / \
| mane
1 | g/t | sr aies | ay | Qr' |
| |
(MANCHESTER-ENCODED DATA) | | | | |
TRANSCEIVER
CABLE TRANSCEIVER
CABLE
SS Deere
[RY meters re poe
TERMINATOR TRANSCEIVER TRANSCEIVER TRANSCEIVER TERMINATOR
AND TAP TAP
Token-Passing Rings out the not-busy token again, the next station on the
loop can grab the token and transmit on the network.
IEEE standard 802.5 defines the physical layer and the The first station that transmitted cannot transmit
data link layer for a token-passing ring network. As the again until the not-busy token works its way around
name implies, systems on a token-passing ring are the ring. This gives all units on the network a chance
connected in series around a ring. To simplify wiring, to transmit in a ‘“‘round-robin”’ manner.
however, token rings are often connected as shown in
Figure 14-30. The Multistation access unit, or MAU, is NOTE:
put in a wiring closet or some readily accessible place. Some token-passing ring networks use tokens
Unlike the passive taps used in an Ethernet system, with priority bits so that high-priority stations
each active station or node on a token ring receives
data, examines it to see if the data is addressed to it,
and retransmits the data to the next station on the
ring. A bypass relay in the MAU will automatically
shunt data around defective or inactive nodes. Data
always travels in one direction around the ring. Data is
transmitted as HDLC or SDLC frames. Early token-
passing ring network adapter cards transmitted data
at 4 Mbits/s, but 16-Mbit/s network adapter cards are
now becoming widely available.
Token-passing ring networks solve the multiple-
access problem in an entirely different way than the
CSMA/CD approach described for Ethernet. A token is
a byte of data with an agreed-upon, unique bit pattern
such as 0111 1111. If no station is transmitting, this
token is circulated continuously around the ring.
When a station needs to transmit, it withdraws the
not-busy token, changes it to a busy token of perhaps
0111 1110, and sends the busy token on around the
ring. The transmitting unit then sends a frame of data
around the ring to the intended receiver(s). When the
transmitting station receives the busy token and the
NOTE: MAU = MULTISTATION ACCESS UNIT
data frame back again, it reads them in and removes
them from the ring. It then sends out the not-busy FIGURE 14-30 Block diagram of a token ring network
token again. As soon as a transmitting station sends system showing multistation access unit (MAU).
IBM PC/AT
FiberWay® 100 Mbps
TDMA Backbone
J
— ik
LAN
802.3
802.3
Devices
IEEE 802.6
brary that could be made available on CD ROM. The network transmits data at 10 Mbits/s over standard
server will also need a 1.2-Mbyte floppy drive and a twisted-pair phone wire for distances up to 100 m.
1.44-Mbyte floppy drive to transfer software from flop- UNIX typically requires a minimum 2 Mbytes of
pies to the hard disk. memory in the server, and it works better with 8M or
The next step is to decide on the software you want to 16M, so you should include this in the bid specifica-
use to manage the network and to provide the file tions for the server.
server and print server functions. The best approach While you are waiting for hardware bids to come in,
for this is to choose the network software that will do purchase orders to go out, and the hardware to arrive,
the best job and then choose network hardware com- we will give you an overview of how network software
patible with that software. works so you will have some idea how to install and use
The typical UNIX® OS works with Ethernet, ARCnet, it.
and IBM’s Token Ring boards. Since the workstations Part of the network software resides in each work-
in this lab are physically all in the same room, you station and part of it resides in the server. Let’s start
might consider using the 10BaseT, or Thin Ethernet, with the workstation part. To refresh your memory,
network we described earlier, because it is the cheap- Figure 14-32a shows the software hierarchy for a
est of these alternatives. Remember that this type of UNIX-based workstation operating in stand-alone
SHIELD
ATN (E. G., CALCULATOR)
SRQ
IFC
NDAC
NRFD DEVICE B
DAV ABLE TO TALK AND
E01 LISTEN
D104
D103
D102
D101
DEVICE C
GENERAL INTERFACE
(E. G., SIGNAL GENERATOR) MANAGEMENT
(a) | (5 SIGNAL LINES)
DEVICE D
(c) (b)
st T7777
FIRST DATA BYTE SECOND DATA BYTE
DIO1-8
DAV
NRFD
NDAC
ACCEPTED
NONE ACCEPTED
(d)
FIGURE 14-33 GPIB pins, signals, and handshake waveforms. (a) Connector.
(b) Bus structure. (c) Command formats. (d) Data transfer handshake
waveforms.
The GPIB also has five bus-management lines, (low), indicates that the controller is putting a univer-
which function basically as follows. The interface clear sal command or an address-command such as “‘listen”’
line (IFC), when asserted by the controller, resets all on the data bus. When the ATN line is high, the data
devices on the bus to a starting state. It is essentially a lines contain data or a status byte. Service request
system reset. The attention (ATN) line, when asserted (SRQ) is similar to an interrupt. Any device that needs
Electronic mail
As we told you in an earlier chapter, a general-purpose 8. Describe the mechanism used to schedule tasks
operating system in its simplest form is a program that in RMX 86.
allows a user to create, print, copy, delete, display, and
in other ways work with files. It also allows a user to 9, List some of the differences between UNIX and
load and execute other programs. The operating sys- RMX 86.
tem insulates the user from needing to know the 10. Draw a block diagram of the internal structure of
intricate hardware details of the system in order to use the 68030.
it. Up to this pointin the book we have referred only to
single-user operating systems such as the Apple Mac- 11. List the major hardware and software features
intosh® OS. To round out the book we now want to give that the 68030 microprocessor has beyond those
you an overview of multiuser/multitasking operating of the 68000.
systems and an introduction to the 68020 micro-
12. Show how the 68030 constructs physical ad-
processor. The 68020 (used in the Apple Macintosh II)
dresses in its real address mode and in its protect-
has advanced features that make it suitable as the CPU
ed virtual address mode. :
in a multitasking system. Finally, in this chapter we
discuss a few directions in which microcomputer evo- 13. Describe how the 68030 uses descriptor tables
lution seems to be heading. and call gates to control memory access.
14. Define the term demand-paged virtual memory
and describe briefly how the 68040 produces a
OBJECTIVES physical address in paged mode.
At the conclusion of this chapter, you should be able to
1. Describe the difference between time-slice sched- OPERATING SYSTEM CONCEPTS AND
uling and preemptive priority-based scheduling. TERMS
2. Define the terms blocked, task queue, deadlock, Multiuser/Multitasking Operating System
deadly embrace, critical region, semaphore, ker- Overview
nel, memory-management unit, and virtual mem-
ory. Newer 16-bit and 32-bit microprocessors are designed
to be used as the CPU in multiuser/multitasking mi-
3. Describe two methods that can be used to protect crocomputer systems. Therefore, to understand how
a critical region of code. these processors operate, you need to understand some
4. Show with assembly language instructions how a of the terms and concepts of operating systems.
semaphore can be used to accomplish mutual In Chapter 2 we discussed how several terminals can
exclusion. be connected to a single CPU and operated on a
timeshare basis. An operating system that coordinates
5. Describe the major features of the UNIX™ opera- the actions of a timeshare system such as this is
ting system and define the terms kernel, pipe, and referred to as a multiuser operating system. The basic
shell. principle of a timeshare system is that the CPU ser-
6. List and describe the types of “‘objects’’ used in vices one terminal for a few milliseconds, then services
the RMX 86 operating system. the next for a few milliseconds, and so on until all the
terminals have had a turn. It cycles through all the
7. List and describe the states in which an RMX 86 terminals over and over, fast enough that each user
task can be. seems to have the complete attention of the CPU. The
504
program or section of a program that services each (environment) of each task when execution is switched
user is referred to as a task or process. A multiuser to another task. This is necessary so that the task can
operating system, then, can also be referred to as be restarted correctly. The usual way to preserve the
multitasking, but this term is more often used when environment is to keep it on a stack. Often the opera-
referring to real-time industrial-control operating sys- ting system keeps a separate stack for each task.
tems. With the addition of a user interface, the factory- Current processors such as the 68000 and 68010 have
controller program in Figure 10-35 would be an exam- the MOVEM, LINK, and UNLINK instruction to make it
ple of a very simple real-time multitasking operating easy to save and restore the environment. Any routines
system. used in a multitasking system have to be reentrant.
The multiple tasks that are to be executed by a CPU
must in some way be scheduled so that they execute
ACCESSING RESOURCES
properly. The part of the operating system responsible
for this is called the scheduler, dispatcher, or supervi- The second problem encountered in a multitasking
sor. There are several different methods of scheduling system is assuring that tasks have orderly access to
tasks, but we are interested primarily in two of them. resources such as printers and disk drives. As one
The first method is the time-slice method, which we example of this, suppose that a user at a terminal
discussed previously. In this approach the CPU exe- needs to read a file from a hard disk and print it on the
cutes one task for perhaps 20 ms and then switches to system printer. Obviously the file cannot be read in
the next task. After all tasks have had their turns, from the disk and printed in one of the 20-ms time
execution returns to the first. The UNIX operating slices allotted to the terminal service, so several provi-
system, which we discuss in detail later, uses this sions must be made to gain access to the resources and
scheduling approach for a multiple-user system. The hang on to them long enough to get the job done
advantage of the time-slice approach in a multiuser properly. A flag, or semaphore, in memory is used to
system is that all users are serviced at approximately indicate whether the disk drive is in use by another
equal time intervals. As more users are added, howev- task or not. Likewise, another semaphore is used to
er, each user gets serviced less often, so each user’s indicate whether the printer is in use. If a task cannot
program takes longer to execute. This is referred to as access a resource because it is busy, the task is said to
system degradation. In industrial-control operating be blocked. Rather than making the user type in a
systems, this variable time between services is often print command over and over until the disk drive and
not acceptable, so a different scheduling method is the printer are available, most operating systems of
used. this type set up queues of tasks waiting for each
The second scheduling method in which we are resource. When one task finishes with a resource, it
interested is preemptive priority-based scheduling. resets the semaphore for that resource. The next task
In this approach an executing low-priority task can be in the queue can then set the semaphore to indicate the
interrupted by a higher-priority task. When the high- resource is busy and use the resource.
priority task finishes executing, execution returns to In order to keep track of the state of a task, a block of
the low-priority task. This approach is well suited to data called a process-control block, process header,
some control applications because it allows the most or process descriptor is set up by the operating system
important tasks to be done first. Priority interrupt for each task. Part of the information contained in the
controllers such as the 8259A are often used to set up process-control block is the progress of the read disk
and manage the task service requests. The Motorola and print job. To simplify the disk and printer queues,
PISOS operating system, which we discuss later, uses all that needs to be put in these queues are pointers to
priority-based scheduling. the process-control blocks of tasks that are waiting for
In addition to scheduling, several other considera- access. This is similar to the way a pointer to a string
tions have to be taken into account with multitasking descriptor table is passed to a procedure, rather than
operating systems. The next section discusses some of passing the string itself, as shown in Figure 13-29.
these. Incidentally, most systems use a separate I/O proces-
sor to actually handle disks, printers, and other slow
resources so that these do not load down the main
Problems Encountered in Building Multitasking processor.
Operating Systems Another problem situation in a multitasking system
There are a great many operating system variations
can occur when two tasks need the same two re-
and many different ways of solving various problems in sources, such as a disk drive and a printer. Suppose
that one task gains access to the disk drive and sets its
an operating system. What we have tried to do in this
semaphore to indicate that the disk drive is busy at the
section is use simple enough examples to illustrate the
end of its time slice. The next task finds the disk busy,
basic problems without getting lost in all the possible
so its request goes on the queue. However, suppose that
variations.
the second task finds the printer not busy, so it sets the
printer semaphore to indicate it has control of the
PRESERVING THE ENVIRONMENT printer and goes on about its business. When execu-
The first problem to be solved in a multitasking system tion returns to the first task, it will try to access the
is to preserve the registers, data, and return address printer so it has both the disk drive and the printer it
OPERATING SYSTEMS, THE 68030 MICROPROCESSOR, THE 68040, AND THE FUTURE 505
needs. However, it finds the printer busy, so its request struction resets the semaphore to indicate that the
is put on the printer queue. The situation here is that critical region is no longer busy. Task 2 can then swap
each task controls a resource that the other needs in the semaphore and access the critical region when
order to proceed. Therefore, neither can proceed. This needed. The semaphore functions in the same way as
condition is called deadlock, or deadly embrace. The the ‘‘occupied’”’ sign on a restroom of a plane or train. If
problem can be solved in a number of ways. One way is you mentally try interrupting each sequence of in-
to link the printer and the disk drive together under structions at different points, you should see that there
one semaphore so that the two resources are accessed is no condition under which both tasks can get into the
with a single action. Another more practical approach critical region at the same time.
is to set up a hierarchy among the tasks, so that if
deadlock occurs, the higher-priority task can gain The Need for Protection
access to all the resources it needs.
Still another interesting problem can occur in a Most single-user operating systems do little to prevent
multitasking operating system when two or more users user programs from ‘‘tromping on’’ the code or data
attempt to read and change the contents of some areas of the operating system. The usual results of this
memory locations at the same time. As an example, and Murphy’s law are that an incorrect address in a
suppose that an airline ticket-reservation system is user program will cause it to write over critical sections
operating on a time-slice basis. Now, further suppose of the operating system. The system then locks up, and
that one user examines the memory location that the only way to get control again is to reboot the
represents a seat on a plane and finds the seat empty, system. In a multitasking system this is intolerable, so
just before the end of its time slice. Another user on the several methods are used to protect the operating
system can then, in its time slice, examine the same system.
memory location, find it empty, mark it full, and print The major method is to construct the operating
out a reservation confirmed on the CRT. When execu- system in two or more layers. Figure 15-2, p. 508,
tion returns to the first user, it has already checked the shows an ‘‘onionskin’’ diagram for a two-layer opera-
seat during its previous time slice, so it marks the seat ting system. The basic principle here is that the inner
full and prints out a reservation confirmation on the circle represents the code and data areas used by the
CRT. The two people assigned to the same seat may operating system. The outer layer represents the code
make nasty remarks about computers unless this and data areas of user programs or tasks that are being
problem is solved. run under control of the operating system. The inner
The section of a program where the value of a layer is protected because user programs can access
variable is being examined and changed must be pro- operating system resources only through very specif-
tected from access by other tasks until the operation is ic mechanisms rather than a simple, accidental call
complete. The section of code that must be protected is or jump. The Motorola MC68000 family of micro-
called a critical region. A technique called mutual processors is designed to accommodate a two-level
exclusion is used to prevent two tasks from accessing structure such as this. The MC68000 has two modes of
a critical region at the same time. In the CHK_N— operation, user and supervisory. Certain privileged
DISPLAY subroutine in Figure 14-24, we showed one instructions that affect the operating system can be
way in which a critical region can be protected from an executed only when the processor is in supervisory
interrupt-service routine by simply masking the inter- mode.
rupt. In a time-slice system, however, a semaphore is The UNIX operating system, which we discuss in the
used to provide mutual exclusion. next major section of the chapter, is an example of a
Figure 15-1 shows how this can be done with 68000 three-layer operating system. Figure 15-3, p. 508,
assembly language instructions. The instruction se- shows the three layers for UNIX. The innermost layer,
quence is the same for each task. If task 1 needs to or kernel, contains the major operating system func-
enter a critical section of code, it first loads the sema- tions such as the scheduler. The middle layer, or shell,
phore value for critical-region-busy into DO. The single contains the command line interpreter, which trans-
instruction, TSET SEMAPHORE, then tests the sema- lates user-entered commands to a sequence of kernel
phore and sets it toa 1. It is important to do this in one operations. The shell level is the user-interface level.
instruction so that the time-slice mechanism cannot The outer layer contains application programs such as
switch to another task halfway through the test and data base—management programs. It also contains
set and cause our airline problem. utilities such as editors and compilers, which program-
After the semaphore is tested in Figure 15-1, p. 507, mers can use to write more application programs.
the zero flag tells whether the resource is busy. If the Other systems use even more levels of protection.
critical region is busy, execution will remain in a wait The Intel 80286 processor has designed into its hard-
loop for the number of time slices required for the ware a mechanism that allows up to four levels of
critical region to become free. If the semaphore value is protection to be built into an operating system running
a 0 (i.e., the zero flag is set), indicating not busy, then on it.
execution enters the critical region. The TSET instruc- In addition to protecting the operating system from
tion has already set the semaphore to indicate the being tromped on by executing tasks, an operating
critical region is busy. After execution of the critical system should provide some way of protecting tasks
region finishes, the MOVE.B #S00,(SEMAPHORE) in- from each other. Throughout the rest of this chapter
END
OPERATING SYSTEMS, THE 68030 MICROPROCESSOR, THE 68040, AND THE FUTURE 507
GLOBAL SPACE A common problem, especially in older, single-user
systems, is that the physical RAM is not large enough
to hold, for example, an assembler and the program
being assembled. The traditional solution to this
problem is to write the assembler in modules and
use an overlay scheme. When the assembler is in-
voked, the executive module of the assembler is
loaded into memory and reserves an additional
memory space called the overlay area. The assembler
then reads through the source program. When it
reaches a point where it needs a particular module,
it reads that module, referred to as an overlay, from
the disk into the overlay area reserved in memory.
When the assembler reaches a point where it needs
another overlay, it reads the overlay from the disk and
loads it into the same overlay area in memory. The
overlay approach is commonly used and works well for
specific cases such as the assembler example we used
here, but it is not flexible enough for multitasking
systems.
Another approach traditionally used to expand the
available memory in a microcomputer is bank switch-
ing. A system that has only 16 address lines can
TASK directly address only 64 Kbytes of memory. As shown
B in Figure 15-4, however, the addition of some simple
FIGURE 15-2 Onionskin diagram for multitasking selection hardware allows the system to access up to
eight memory banks of 64 Kbytes each. The hard-
operating systems with two levels of protection.
ware is configured so that when the power is turned
on, the system is using bank O. To switch to bank 1,
a byte that turns off bank O and turns on bank 1 is
system. The first reason is that the physical RAM is output to the selection port. Execution then proceeds
usually not large enough to hold all the operating in bank 1. In practice, some system-dependent tricks
system and all the application programs that are being are often necessary to get execution smoothly from
executed by the multiple users. The second reason is to one bank to another, but the approach does help
make sure that executing tasks do not access protected overcome the memory limits designed into the proces-
areas of memory. Memory management can be done sor.
totally by the operating system or with the aid of To use bank switching in a multiuser system, each
hardware called a memory-management unit, or user’s program might be assigned to a bank. The
MMU. Before we get into the operation of an MMU, we difficulties with this are that a copy of the operating
want to give you a little background on methods used to system kernel must be kept in each bank, the actual
solve the limited-memory problem. memory available for each user is still limited to 64
Kbytes, and users cannot easily share code or data.
Thus memory is not very efficiently used. Also, protec-
tion is not as easily implemented as it is in the MMU
approaches we discuss next.
APPLICATIONS
(COMMAND
INTERPRETER)
PROGRAMMING TOOLS
AND UTILITIES
OPERATING SYSTEMS, THE 68030 MICROPROCESSOR, THE 68040, AND THE FUTURE 509
segment have been changed. If the dirty bit is set, a nounced ‘‘cash’’). The descriptors for the currently
segment must be swapped back to secondary storage if used segments or pages are kept in the cache memory
its space is needed. If the dirty bit is not set, then the so that they can be accessed much more quickly than
segment has not been altered. The copy of the segment they could if they were in the main memory. The
in secondary storage is still correct, so the segment can descriptors for pages not currently being used are kept
just be overwritten. This eliminates one write-to-disk in a table in main memory. If the descriptor for a
operation. required page is not present in the cache, then it is
Another term often found in MMU data sheets is the read in from the descriptor table in main memory. The
term hit rate. Hit rate refers to the percentage of the descriptor is then used to read in the required page.
time that the segment required at a particular time is To summarize, then, MMUs translate logical pro-
present in the physical memory. In a well structured gram addresses to physical addresses with an indirect
system the hit rate may be 85 to 90 percent. method through a descriptor table. This indirect ap-
The use of a descriptor table to translate logical proach makes possible a virtual address space much
addresses to physical addresses has another major larger than the physical address space. The indirect
advantage besides making virtual memory possible. approach also makes it possible to protect a memory
The selector component of each address contains one segment or page from access by a program section with
or two bits, which represent the privilege level of the a lower privilege level. You will meet all of these
program section requesting access to a segment. The concepts again in a later section, which describes the
descriptor for each segment also contains one or two operation of the 80286 microprocessor. First, however,
bits that represent the privilege level of that segment. we want to give you overviews of UNIX, a common
When an executing program attempts to access a multiuser operating system, and RMX 86, a common
segment, the MMU can compare the privilege level in real-time multitasking operating system.
the selector with the privilege level in the descriptor. If
the selector has the same or greater privilege, then the
MMU allows the access. If the selector privilege is
lower, the MMU can send an interrupt signal to the THE UNIX OPERATING SYSTEM
CPU that indicates a privilege-level violation. The indi-
rect method of producing physical addresses then pro- The purpose of this section is to show you the struc-
vides a method of providing privilege levels and pro- ture, terminology, and overall operation of the UNIX
operating system so you can see how it relates to
tecting program sections such as the operating system
kernel.
multiuser microcomputer systems. If you are going to
There are currently two major approaches used by
be working with UNIX, there are available several
MMUs. One is the segmentation approach we have just books that use step-by-step examples to illustrate it.
described. The logical address in this case consists of a
segment selector and an offset within that segment. History
Segments can be any size from 1 byte to 64 Kbytes in
the example we used before. In most segment-oriented In 1969 Ken Thompson, a researcher at Bell Laborato-
systems the segments swapped in and out of physical ries, decided to write some system programs that
memory are quite large. The disadvantages of these would make it easier to develop other programs. Over
large segments are the time required to load them and the next few years, with the help of another research-
the compaction that often must be done to make space er, Dennis Richie, these programs evolved into a pow-
for a segment in physical memory. erful multiuser operating system. The original ver-
The second major approach currently used is called sions were written in assembly language for a DEC
demand-paged virtual memory. In this approach the PDP-7 minicomputer, but when the value of the opera-
virtual memory is mapped as fixed-length pages of ting system became obvious, there was a strong desire
perhaps 4 Kbytes in length. The two components of the to write versions for other machines. Adapting an
virtual address are called the page address and the assembly language program to run on another ma-
page offset. The page offset, as the name implies, chine with a different CPU means rewriting the whole
contains the offset of a desired byte within a page. The thing. To help solve this portability problem, Dennis
page address is used as a pointer to a descriptor table, Richie developed a high-level language called C. This
just as the selector is in the segmentation approach. language has much of the capability of assembly lan-
The descriptors function in about the same way here guage to work with hardware and twiddle bits, but it
that they do in the segmentation scheme. When a also allows a programmer to write high-level-language
demanded page is found to be not present in the structured programs. Adapting a high-level-language
physical memory, the MMU or the CPU swaps it in. The program to run on a different machine involves rewrit-
typically smaller and fixed lengths of the pages makes ing the I/O sections as needed by the hardware of the
the swapping operation much easier. new machine and compiling the high-level-language
Before we summarize and go on to the next topic, we program to the machine code for the new machine. By
need to explain one more term commonly used with 1972 a version of UNIX written in C was operating
MMuUs. For some MMUs the descriptor table is stored in successfully on the DEC PDP-11 computer.
a part of the main physical memory. Other MMUs have In the following years Western Electric, a parent
a built-in, high-speed memory called a cache (pro- company of Bell Laboratories, licensed the source code
OPERATING SYSTEMS, THE 68030 MICROPROCESSOR, THE 68040, AND THE FUTURE 511
ROOT DIRECTORY
.e
Ss &
Ko} R
1
OPERATING g c 9 & C
SYSTEM CODE key C Z Ms
T x 4 TERMINALS, DISKS,
MAIN COMMANDS
gt 9 > LINE PRINTERS, ETC.
Sa [ea]
oO =
Z\/ea
|B ||CMRA
B \A ADDITIONAL
ie OOOOO
D = DIRECTORY Xe COMMANDS
T = DEVICE
8 10
and subdirectory contains a 2-byte inode number. The kernel procedures as needed to do this. The UNIX
inode number identifies the position of the inode for command shell has some interesting features with
that file or directory in a table of inodes kept by the which we want to acquaint you.
operating system kernel. An inode is similar to a The first feature of the shell to discuss is how it
file-control block, which we discussed in Chapter 12. It handles I/O. At the user level, UNIX essentially treats
contains the type of the file, the length of the file, the I/O devices as files in a directory called dev, as shown
location of the file, the identification number of the in Figure 15-6. A modem connected to the system at
owner, and the times the file was created, modified, point 5 in the system, for example, can be referred to
and last accessed. The kernel uses inodes to manipu- simply as /dev/com3. Devices are opened, read from or
late files, but normally a user has to be concerned only written to, and closed, just as other files are. When a
with the file names. process is created, it has three files already open for
Still another function of the kernel is to provide a use. The three are referred to as standard input,
means of communication between processes. The two standard output, and error output. Standard input
methods it provides are signals and pipes. Signals are usually means the keyboard on the user’s terminal.
software interrupts generated by one process to tell Standard output and error output usually mean the
another process to stop what it is doing, respond to the CRT on the user’s terminal.
signal, and then go on with what it was doing. Signals What this means is that when a user enters a
can also be generated by user commands such as an command, which requires input, the input will be
abort command or by processing errors such as a taken from the keyboard unless otherwise specified.
divide by O error. Likewise, a command that produces output data will
A pipe is a mechanism for passing the output data send it to the user’s CRT unless some other destination
from one program directly to another program as is indicated. The UNIX command ls, for example, will
input. We discuss how a pipe is used later. Now that send a simple list of the user’s directory to the CRT on
you have an overview of some of the kernel functions, his or her terminal. However, input data or output data
let’s take a look at some of the shell functions. can be redirected to other devices or files. The < and >
symbols are used to indicate redirection. For a user at
THE UNIX SHELL
point 3 in Figure 15-6, the command Is /usr/doug >
As we said before, the shell layer of UNIX is the level at /dev/com3, for example, reads the directory of /usr/
which a user usually interacts with the system. The doug and sends it to the device named com3 instead of
shell executes user commands and programs. It calls to the user’s CRT. The command sort —d < /usr/pat >
OPERATING SYSTEMS, THE 68030 MICROPROCESSOR, THE 68040, AND THE FUTURE 513
difficult to implement on small systems such as per- The nucleus is the only software module required in a
sonal computers. Another major problem is that the system. All the other modules shown in Figure 15-7
basic time-slice approach of UNIX, which works well are optional.
for a time-share system, responds too slowly for many The basic input/output system contains device
real-time control applications. For these applications, drivers to interface the system to disk drives, UARTS,
an operating system such as Intel’s RMX 86, which we keyboards, multiple CRT terminals, parallel printers,
describe in the next section, is used. and other devices. The extended input/output sys-
tem, or EIOS, contains higher-level I/O routines, which
include built-in buffering. The application loader al-
lows user programs to be loaded from disk into memory
THE INTEL RMX 86™ OPERATING SYSTEM to be run. The human interface part of the system
The UNIX operating system, described in the preced- corresponds roughly to the shell in a UNIX system. It
ing section, is designed to allow several users to devel- decodes and carries out user-entered commands. The
op programs or run application programs on a time- basic human interface comes with commands for
share basis. UNIX and similar operating systems are working with disk files, but other commands can be
usually sold to users as complete packages, which can added as needed for a particular application. The final
simply be configured to the hardware of a particular piece of the puzzle shown in Figure 15-7 is the uni-
system and run. The time-slice approach of UNIX versal development interface, or UDI. This software
works well for a multiuser timeshare system, but it module, when added to the basic system, allows pro-
does not respond fast enough and does not have a gram-development tools such as editors, assemblers,
suitable priority setup for many real-time control sys- compilers, and linkers to be loaded and run. Other
tems. Several companies offer operating systems more software modules are also available. The point here is
suitable to the needs of real-time control systems. One that software modules can be included, added to, or left
example is the Intel RMX 86 operating system. out to produce a wide variety of custom operating
RMX 86 is a “‘building-block”’ operating system. It is systems. Now let’s look a little closer to see how RMX
intended primarily to assist OEMs (original equipment 86 provides for multitasking.
manufacturers) in building custom control systems for
sale to end users. Therefore, RMX 86 consists of a
group of highly structured functional modules and RMX 86 Objects
utilities from which a system designer can choose the
required functions. The purpose of this section of the The basic building blocks for RMX 86 programs are
chapter is to introduce you to the structure, terminolo- called objects. Objects are program structures that are
gy, and scheduling used in this common operating created and manipulated by calls to routines in the
system. nucleus. The major object types are tasks, jobs, seg-
ments, mailboxes, regions, and semaphores. We briefly
describe each of these types and then show how they
RMX 86 Structure are used.
Tasks in RMX 86 are equivalent to processes de-
Figure 15-7 shows an onionskin diagram of the basic scribed previously. Tasks are the only active type of
structure of RMX 86. At the center is the nucleus, object. As a task executes, it manipulates the other
which corresponds to the kernel in UNIX. The nucleus types of objects by calling routines in the nucleus.
consists mostly of a few dozen routines that system Tasks compete with each other for CPU time. Tasks are
developers can call as needed to implement a desired scheduled for execution on a preemptive, priority ba-
end-user application program. This is indicated in sis. We talk about this more later, but basically what it
Figure 15-7 by the fact that the user-application sec- means is that if several tasks are ready to run, the task
tion of the diagram extends all the way to the nucleus. that has been assigned the highest priority will be run
first.
A job in RMX 86 is a logical environment in which
tasks and other objects reside. A job usually corre-
sponds to an application. The system initially has one
job called the root job and a task that can be used to
create other jobs. Tasks use system calls to create jobs.
When a job is created, it is given a memory pool. From
this memory pool tasks can create child jobs and other
objects as needed. Figure 15-8, p. 515, shows a simple
diagram to illustrate this hierarchy.
A segment in RMX 86 is a contiguous block of
memory up to 64 Kbytes in size. When a task requests
USER APPLICATIONS
a segment, the requested memory is taken from the
memory pool of the job that contains that task.
FIGURE 15-7 Onionskin diagram of Motorola RM8 86 A mailbox is an object used to pass objects from one
operating system. task to another. The object being passed through a
OPERATING SYSTEMS, THE 68030 MICROPROCESSOR, THE 68040, AND THE FUTURE 515
(NONEXISTENT) 10. A task can be deleted with the delete-task system
call.
Note 1. The MC68010 supports a 3-word cache for the loop mode.
Virtual Memory/Machine
MC68010,
MC68020, and Provide Bus Error Detection, Fault Recovery
MC68030
MC68030 On-chip MMU
Coprocessor Interface
MC68000,
MC68008, and Emulated in software
MC68010
MC68020 and
MC68030 In Microcode
Control Registers
MC68000 and
MC68008 None
MC68010 SEC; DEC; VBR
MC68020 SFC, DFC, VBR, CACR, CAAR
MC68030 SFC, DFC, VBR, CACR, CAAR, CRP, SRP, TC, TTO, TT1, PSR
FIGURE 15-10 M68000 family summary. (Reprinted with permission of
Motorola, Inc.)
OPERATING SYSTEMS, THE 68030 MICROPROCESSOR, THE 68040, AND THE FUTURE 517
TOP VIEW
supported by the 68000 is also supported by the various segments of logical memory that are actually in
68030; however, the 68030 also supports some addi- physical RAM. The more recent 68851 provides for
tional instructions. The 68030 instruction set is alsoa demand-paged virtual memory management. That is,
superset of the 68020 instruction set. the 68851 contains page tables describing the various
The 68030 was designed to be upward compatible pages of logical memory that are actually in the physi-
from the 68000, the 68010, and the 68020 so that the cal RAM.
huge amount of software developed for these could The following brief descriptions are intended to in-
easily be transported to the 68030. Previously de- troduce you to the instructions that the 68851 pro-
bugged modules can then be integrated with new vides. These instructions are built in for the 68030,
program modules written to take advantage of the since the 68030 contains most of the 68851 functions
advanced features of the 68030. Let’s take a look at built right into the CPU IC.
how some of these advanced features work.
PBcc—Branch on MMU condition (68851 only)
PDBcc—Test MMU condition, decrement, and branch
68851 Instructions
(68851 only)
Motorola offers two memory-management units for use
PFLUSH—Flush MMU address translation cache en-
with the 68000 family. The simpler and first-intro-
tries
duced is the 68451. The 68451 provides for a segment-
ed virtual memory environment. That is, the 68451 PFLUSHR—Flush MMU ATC entries and root pointer
provides base and bounds registers describing the table (68851 only)
Vee
BOTTOM
O
VIEW
STERM DSACK1 GND
O O O
DSACKO Vcc GND
O O O
CLK AVEC GND
OU
FC2
Ouno!
FCO OCS e Vcc NC*
O O O O O O O O
FC1 CIOUT, »BGACK At GND GND A18 GND
© O O © O O O O
RMC .° BG A381 —-A29 A27 A22— A20 A16
O O O O O &) O O
BR AO A30 = A28 A26 A233. A21 A19
1 2 3 4 5 6
*NC — Do not connect to this pin
FIGURE 15-12 Pin diagram for 68030 microprocessor pin grid array package.
(Reprinted with permission of Motorola, Inc.)
OPERATING SYSTEMS, THE 68030 MICROPROCESSOR, THE 68040, AND THE FUTURE 519
520
HSADN3SNOISSOXDIN
GNV TOXLNOD
CHAPTER
3YHOLS
1OYLNOD
FIFTEEN
TOBXLNOD
dID07
IWNHSLNI
S
sns NOILND3X3
LINA
SS3b00V
NOILONYLSNI
Ud)
>
WOISAHd
WOIDO1
ssayqgv
SSayu0g0v
ve
ssayqav
SH31SI93Y
ssadaqv SS3400V
NOIL93S viva
NO|LO3S
sna sad = NOILOSS
o1v
LNSWNONVSIN
YAXAIdIL INN
|
viva
SNS Y3TIOYLNOO SS3u0qv
sng
SLIM
HO13538d
ONIGN3d
¥3444Nd CEPEIats!
SN8
O8OIN
SNE
YSTIOHLNODTOXLNOS
SIVNOIS
IANO ~EL-SL JeUJAIU]yDO]q WeIBeIP
JO P[OLOJOW
YEYSO *10SS9D01dOITIW
pajulsday)
Y}IM UOIssIuad
JO ‘ejosOJO-:
(‘Qu
larger data words, and higher processing speeds. We There are several different ways of connecting proc-
use the remainder of this chapter to introduce you to essors in parallel. The difficulty with a simple bus
some developing areas, the Motorola 68040 32-bit structure such as this is that processors compete for
microprocessor, parallel processing, RISC machines, shared resources such as memory. If one processor is
and optical computers. using the bus, others must wait. This slows down the
overall processing speed. One of the more efficient
multiprocessor architectures is the hypercube topolo-
The Motorola 68040 32-bit Microprocessor gy developed by Seitz and Fox at Caltech. A diagram of
this topology is shown in Figure 15-14. Each node in
The Motorola 68040 is the most récent, fastest mem- the system consists of a complete processing unit with
ber of the 68000 CPU family. The 68040 is Motorola’s the ability to communicate with other units. The
third generation of M68000-compatible, high-perform- number of nodes can be expanded to give the
ance, 32-bit microprocessors. The 68040 can be power and speed needed to handle the problem the
thought of as a 68030 with most of the 68881 built in computer is being used to solve. Each processor unit
and with two 68851s built in. Higher performance is is typically connected to its nearest neighbors, as
facilitated by a variety of improvements, including, shown.
notably, 4K instruction and data caches. By placing Intel has produced the iPSC family of commercial
the FPU and MMU on a chip, the 68040 can achieve products based on the hypercube topology. The three
much higher performance than a 68020 or 68030 currently available versions have 32, 64, and 128
combined with these ICs off-chip. nodes. Figure 15-15 shows the components contained
The 68040 provides the same programmer’s model on the processor board for each node. Each node is a
as does the 68030, 16 general-purpose registers (8 complete microcomputer with an 80286 processor,
data and 8 address) and eight 80-bit floating-point 80287 math coprocessor, 500 Kbytes of RAM, 64
registers. The addressing modes and MMU/FPU Kbytes of ROM, and interface circuitry. The processor
operation are the same as we have studied with the board also has an Intel 82586 Ethernet coprocessor to
older members of the 68000 family. The 68040 is control communications with other nodes. Each proc-
available in a 179-pin package roughly 1.85 by 1.85 in. essor has seven 10 Mbit/s lines to communicate with
in size. other processors and one 10-Mbit/s line to communi-
The 68040 is available today in some manufacturers’ cate with a central controller. The Intel systems use an
workstations. 68040s currently can operate with clock Intel 286/310 minicomputer as the central controller
speeds of up to 50 MHz. for the hypercube. The advantage of this structure is
that each processor has enough memory to operate
independently, and communication between proces-
Parallel Processing sors can take any one of several routes, rather than
Some computer jobs, such as analyzing weather data, being limited to a single bus. Current systems operate
modeling the response of complex drugs, or creating at 2 to 10 megaflops, which puts them in the low end of
the graphics for high-tech movies such as The Last the supercomputer range. However, because common
Starfighter, require a type of computer commonly LSI components are used, the cost is much less than
called a supercomputer. Supercomputers typically
work with 64-bit data words, address large amounts of
memory, and execute hundreds of millions of instruc-
tions per second. The processing speed of these super-
computers is usually expressed in millions of instruc-
tions per second (MIPS) or in millions of floating-point
operations per second (megaflops). An example of a
floating-point operation is adding together two num-
bers expressed in floating-point form. One current
supercomputer, the X-MP2 from Cray Research, Inc.,
is capable of about 500 megaflops. Depending on con-
figuration, the X-MP2 costs between $9 million and
$12 million. The high price of supercomputers is
caused by the fact that in order to achieve their great
speed, they have to use large quantities of expensive,
state-of-the-art discrete components. Less expensive
LSI components are not nearly fast enough for a
supercomputer with a traditional one- or two-processor
architecture. One solution to this problem is to builda
system using many LSI processors that operate in
parallel, or concurrently. Each processor can then
work on a part of the overall problem that the comput- FIGURE 15-14 Hypercube multiprocessor topologies for
er is analyzing. 1 to 32 nodes.
OPERATING SYSTEMS, THE 68030 MICROPROCESSOR, THE 68040, AND THE FUTURE 521
computer community. RISC computers are making
inroads in certain areas such as the area of computer
2x 4 EUROCARD servers on large networks. CISC-based systems con-
gx11
tinue to be the dominant machines in terms of num-
i
bers of systems sold.
PROM
80286
NUMERIC
80287
NUMERIC LBX II
Motorola produces a line of RISC VLSI, the MC88000
64KBYTES PROCESSING
UNIT
PROCESSING
UNIT
INTERFACE
family. This family includes the MC88100, a RISC
CPU, and the MC88200 cache/memory-management
TT
L| 0 TT
L1
[ PROCESSOR BUS unit (CMMU). The MC88100 has 51 instructions and
U U L seven operand types. It includes separate data and
instruction memory ports, pipelined load and store
10 DUAL PORT MEMORY INTERRUPT
CONTROL 512KBYTES PROCESSING operations, and support for big-endian or little-endian
byte ordering. Pipelining is an architectural feature
used to get higher throughput from existing computer
component technology. As an example, let’s consider a
I program that adds a whole sequence of numbers. This
happens in several of the programs we have seen as
COMM
CHO
COMM
CH1
examples in earlier chapters. In a traditional computer
82586 82586
each addition is performed sequentially. One addition
cannot begin until the one before it is completed. Ina
pipelined architecture a second and possibly even
more additions can begin before the first is completed.
The way this works is by breaking the addition circuit-
ry (the ALU) into a series of stages. For example, in
10MBIT SEC GLOBAL CHANNEL
order to add two 32-bit integers, the first stage might
add the first 8 bits, then the second stage would add
FIGURE 15-15 Block diagram of Intel iPSC hypercube the second 8 bits, and so on for four stages. Each stage
node processor board. would possibly pass a carry bit and the result of its
8-bit addition on to the next stage. Thus, we could
have up to four additions happening at once, each
having a different byte operated on. The four-stage
that of an equivalent single-processor supercomputer. adder is called a pipeline because we move integers
Adding more nodes should produce faster systems in into one end and the addition results come out the
the future because parallel processors eliminate much other end. We could put up to four pairs of integers
of the bottleneck caused by a single serial processor. into the ‘pipe’ at the same time. The MC88100 has a
Another method currently being developed to speed up five-stage add pipeline and a six-stage multiply pipe-
the operation of processors is to streamline their in- line.
struction set. The terms big-endian and little-endian refer to the
two ways we can view numbers in memory. That is, ifa
RISC Machines 4-byte integer is stored in bytes addressed $0000,
$0001, $0002, and $0003; which byte is the most
The term RISC stands for reduced instruction set significant? With the big-endian view, the “‘big end”’ of
computer. By designing a microprocessor instruction the number comes first, so the byte at address SO000 is
set with only simple logical and arithmetic instruc- the most significant. The Motorola machines with
tions, the processor can operate faster. There are which we have been working store $0000 as the most
several reasons for this. First of all, fewer instructions significant. So the 68000 family is a family of big-
mean a simpler and faster instruction decoder. Sec- endian machines. The Intel 8086 family is a family of
ondly, instruction sequences can be written to do the little-endian machines. When the 8086 stores multi-
desired operation most efficiently. The trade-off here, byte numbers, the byte at address $0000 is the least
of course, is that writing a program requires more work significant byte. The MC88100 can be configured
on the part of the programmer. The RISC designers when it is reset so that it handles either byte-ordering
claim that most programmers do not write in assembly scheme.
language. Most programmers write in higher-level lan-
guages. Thus the RISC programming problems can be
addressed by the few programmers who write the
Optical Computers
high-level language compilers. These compilers are
more difficult to write than are compilers for CISC So far in this book the microcomputer devices we have
(complex instruction set computers) such as the discussed use electrical currents or voltage levels to
68030. However, once the compilers are written prop- represent logic levels. In the final section of this chap-
erly, the resultant code should execute faster on the ter we want to introduce you to experimental comput-
faster RISC hardware. This debate still rages in the ers that use light beams to represent logic levels and
68030
If there are terms or concepts in this list you do not
remember, use the index to find them in this chapter. 68040
Deadlock Grapevine
Critical region
OPERATING SYSTEMS, THE 68030 MICROPROCESSOR, THE 68040, AND THE FUTURE 523
REVIEW QUESTIONS AND PROBLEMS
List and briefly describe the two types of schedul- 13. For what types of applications was the RMX 86
ing commonly used in multiuser/multitasking operating system designed? Compare the schedul-
operating systems. ing method of RMX 86 with that of UNIX.
Suppose that two users in a timeshare computer 14. List the major processing units in a 68030 micro-
system each want to print out a file. How can the processor and briefly describe the function of
system be prevented from printing lines from one each.
file between lines of the other file?
15. The data sheet for a computer which uses the
Define the term deadlock and describe one way it 68030 as its CPU indicates that the 68030 is
can be prevented. operated in its ‘“‘real address mode.’’ What does
this mean?
Define the term critical region and show with
68000 assembly language instructions how a 16. How is a 68030 switched from real address mode
semaphore can be used to protect a critical region. to protected virtual address mode operation? How
The UNIX operating system is set up as a three- can it be switched back to real address mode
operation?
layer operating system. What is the major reason
it is configured in layers? Identify and describe the 17. Explain the term virtual memory. How much
function of each of the three layers. virtual memory can a 68030 address? How much
Describe how an overlay scheme is used to run physical memory can a 68030 address?
programs such as compilers, which are too large 18. Why is the length of the segment included in the
to be loaded into physical memory all ac once. descriptor for the segment? How does the 68030
Define the term virtual memory, and use Figure keep track of where the global descriptor table and
15-4 to help you briefly describe how a logical the currently used local descriptor table are locat-
address is converted to a physical address by a ed in memory?
memory-management unit using a descriptor ta- 19. How are tasks in a 68030 system protected from
ble. What action will the MMU take if it finds that each other?
a requested segment is not present in physical
memory? What is another major advantage of the 20. How can operating system kernel procedures and
indirect addressing provided by descriptor tables, data be protected from access by eat gfe pro-
besides the ability to address a large amount of grams in an 68030 system?
virtual memory? 21. In a 68030 system, a task operating at a level 2
How does a UNIX scheduler determine which privilege can in a special way call a routine at a
active process to service next? higher privilege level. Describe briefly the mecha-
nism that is used to make this access.
Define the term hierarchical file structure as used
in the UNIX operating system. What is the advan- 798 The 68030 maintains a task state segment for
tage of this type file structure over a simple list each active task in a system. How are these task
type? state segments accessed?
10. In a UNIX system, input or output can be “‘redi- 235 List three major advances that the 68040 micro-
rected.”’ Explain briefly what this means. processor has over the 68030.
11. What is meant by the term piping in a UNIX 24. What are the major advantages of using parallel
system? What symbol is used to indicate a pipe? processors, such as is done in the Intel hypercube,
instead of using a single fast processor?
12. A programmer was heard to say that she ‘‘sent the
file off to the print spooler before going to lunch.”’ 25. What factor makes optical computers an inviting
What did she mean by this statement? technology?
BIBLIOGRAPHY 525
Programmer's Introduction to the Macintosh Family, Addison MC68030 32-Bit Microprocessor User’s Manual, Prentice-
Wesley, Reading, Mass., 1988. Hall, Englewood Cliffs, N.J., second edition, 1985.
THINK C User’s Manual, Semantec Corporation, Cupertino, MC68030 Enhanced 32-Bit Microprocessor User’s Manual,
Calif., 1989. Prentice-Hall, Englewood Cliffs, N.J., second edition, 1989.
Waite, Michael, and Stephen Prata, New C Primer Plus, MC68040 32-Bit Third-Generation Microprocessor User's
Howard W. Sams & Company, Carmel, Ind., 1990. Manual, Motorola Inc., 1989 (Databook).
Pappas, Chris H., and William H. Murray, Inside the Model
80, Osborne/McGraw-Hill, Berkeley, Calif., 1988.
Chapter 13
Williams, Steve, 68030 Assembly Language Reference, Addi-
An Intelligent Data Base System Using the 8272, Application son Wesley, Reading, Mass., 1989.
Note AP-116, Intel Corporation, Santa Clara, Calif., 1981.
(Old, but good basics.)
Periodicals
Lesea, Austin, and Rodnay Zaks, Microprocessor Interfacing
Techniques, Sybex Inc., Berkeley, Calif., latest edition. BYTE. ISSN 0360-5280. Byte Publications, Inc., 70 Main
Peripherals, Intel Corporation, Santa Clara, Calif., latest Street, Peterborough, N.H. 03458.
edition (Databook). EDN. ISSN 0012-7515. Cahners Publishing Co., 221 Colum-
Raster Graphics Handbook, Conrac Corporation, Covina, bus Avenue, Boston, Mass. 02116.
Calif., latest edition. Electronic Design. USPS-172-080. Hayden Publishing Co.,
Inc., 50 Essex Street, Rochelle Park, N.J. 07662.
526 BIBLIOGRAPHY
APPENDIX A
A.1 INTRODUCTION
periods. In
This Appendix contains listings of the instruction execution times in terms of external clock (CLK)
cycle times are four clock periods. A longer memory
this data, it is assumed that both memory read and write
cycle will cause the generation of wait states that must be added to the total instruction time.
This data is
The number of bus read and write cycles for each instruction is also included with the timing data.
of clock periods and is shown as: (r/w) where r is the number of
enclosed in parentheses following the number
the number of write cycles included in the clock period number. Recalling that either a read
read cycles and wis
relates to 12 clock periods for the
or write cycle requires four clock periods, a timing number given as 18(3/1)
write cycle, plus 2 cycles required for some internal function
three read cycles, plus 4 clock periods for the one
of the processor.
NOTE
stores.
The number of periods includes instruction fetch and all applicable operand fetches and
8(2/0) 12(3/0)
dg(PC) Program Counter with Displacement
4(1/0) 8(2/0)
#<data> Immediate
*The size of the index register (Xn) does not affect execution time.
527
A.3 MOVE INSTRUCTION EXECUTION TIMES
Tables A-2 and A-3 indicate the number of clock periods for the move instruction. This data
includes instruction
fetch, operand reads, and operand writes. The number of bus read and write cycles
is shown in parenthesis as
(r/w).
528 APPENDIX A
A.4 STANDARD INSTRUCTION EXECUTION TIMES
store
The number of clock periods shown in Table A-4 indicates the time required to perform the operations,
as
the results, and read the next instruction. The number of bus read and write cycles is shown in parenthesis
write cycles must be added respectively to
(r/w). The number of clock periods and the number of read and
those of the effective address calculation where indicated.
= data register
In Table A-4 the headings have the following meanings: An = address register operand, DN
operand, ea = an operand specified by an effective address, and M = memory effective address operand.
Long
d 6(1/0) + 4(1/0)+
6(1/0) + 6(1/0)+
158(1/0)+*
APPENDIX A 529
A.S IMMEDIATE INSTRUCTION EXECUTION TIMES
The number of clock periods shown in Table A-5 includes the time to fetch immediate operands, perform the
operations, store the results, and read the next operation. The number of bus read and write cycles is shown in
parenthesis as (r/w). The number of clock periods and the number of read and write cycles must be added
respectively to those of the effective address calculation where indicated.
In Table A-5, the headings have the following meanings: # = immediate operand, Dn = data register operand,
An = address register operand, and M = memory operand. SR = status register.
ie Byte, Word
avo |ee)
82/0).
[evo | aRIz2s
_ta/ar
Es ES OI
ee ns PCr:
an
[Bye Word[870 ||ars]
:MOVEO sgl [aneLori |oA /0 | eae= aE
la oep es ee
veo |__| 20/21
an azo |__| rae
Fen
veo
4(1/0)
|__|
8(1/0)*
201872F
81/1) +
8(1/0) 8(1/0) 12(1/2)+
+ add effective address calculation time
*word only
Table A-6 indicates the number of clock periods for the single operand instructio
ns. The number of bus read
and write cycles is shown in parenthesis as (r/w). The number of clock periods
and the number of read and
write cycles must be added respectively to those of the effective address calculati
on where indicated.
530 APPENDIX A
A.7 SHIFT/ROTATE INSTRUCTION EXECUTION TIMES
Table A-7 indicates the number of clock period s for the shift and rotate instructions. The number of bus read
and write cycles is shown in parenthesis as (r/w). The number of clock periods and the number of read and
write cycles must be added respectively to those of the effective address calculation where indicated.
APPENDIX A 531
A.9 CONDITIONAL INSTRUCTION EXECUTION TIMES
Table A-9 indicates the number of clock periods required for the conditional instructions. The number of bus
read and write cycles is indicated in parenthesis as (r/w). The number of clock periods and the number of read
and write cycles must be added respectively to those of the effective address calculation where indicated.
fee
Bcc
|} 10(2/0) 8(1/0)
10270) agiSage
(a2 ae |Se cr
15221oR | Sema
BS R
BERT
Ed ee el
cc false, Count
’ 10(2/0)
A.10 JMP, JSR, LEA, PEA, AND MOVEM INSTRUCTION EXECUTION TIMES
Table A-10 indicates the number of clock periods required for the jump, jump-to-subroutine, load effective
address, push effective address, and move multiple registers instructions. The number of bus read and write
cycles is shown in parenthesis as (r/w).
Table A-10. JMP, JSR, LEA, PEA, and MOVEM Instruction Execution Times
[and [Tan + [=Tan[ay(Ant GVA Xe Goo W[ood |aratPCT idgiPC,Xn
a 2) TO ON ET
Perera | z2czyy [saan] 2009/2
pea | avof | — | 8070 | rat aan] 1209/0
Paiva ara zvaray | r2r2y} 00sr2y| 0272)|20272
a a ed a Pd
MOVEM (3+n/0) | (3+n/0) (4+n/0) | (4+n/0) | (44+n/0)} (5+n/0) | (4+n/0) | (4+n/0)
i Gee (2/2n)
n is the number of registers to move
(2/2n) (3/2n) eee
(3/2n) (3/2n) (4/2n)
* is the size of the index register (Xn), does not affect the instruction’s execution time
Table A-11 indicates the number of clock periods for the multiprecision instructions. The number of
clock
periods includes the time to fetch both operands, perform the operations, store the results, and read the
next
instructions. The number of read and write cycles is shown in parenthesis as (r/w).
In Table A-11, the headings have the following meanings: Dn = data register operand and M
= memory
operand.
Table A-11. Multiprecision Instruction Execution Times
[instruction [Size [| opDn, On | opMM_|
Bey 4(1/0) 18(3/1)
8(1/0) 30(5/2)
cmem Lov
Word |
e.— | 1213/0
ae
a a4(1/0) 7)
18(3/1)
8(1/0) 30(5/2)
ABCD 6(1/0) 18(3/1)
SBCD |
Byte | 61/0) 18(3/1)
532 APPENDIX A
A.12 MISCELLANEOUS INSTRUCTION EXECUTION TIMES
Tables A-12 and A-13 indicate the number of clock periods for the following miscellaneous instructions. The
number of bus read and write cycles is shown in parenthesis as (r/w). The number of clock periods plus the
number of read and write cycles must be added to those of the effective address calculation where indicated.
MOVE to CCR
MOVE to SR
4(1/0)
4(1/0)
4(1/0)
UNLK
+add effective address calculation time
16(2/2) 16(4/0)
24(2/4) 24(6/0)
Table A-14 indicates the number of clock periods for exception processing. The number of clock periods
includes the time for all stacking, the vector fetch, and the fetch of the first two instruction words of the handler
routine. The number of bus read and write cycles is shown in parenthesis as (r/w).
(4
/
(5/3
Privilege Violation 34 (4/3)
RESEIe: 40 (6/0)
34(4/3)
TRAP Instruction (4/3
TRAPYV Instruction 34(5/3)
+add effective address calculation time
*The interrupt acknowledge cycle is assumed
to take four clock periods.
**\ndicates the time from when RESET and
HALT are first sampled as negated to when
instruction execution starts.
APPENDIX A 533
= :
, : bal
This appendix provides a summary of the primary words in each instruction of the instruction set. The
complete instruction definition consists of the primary words followed by the addressing mode operands such
as immediate data fields, displacements, and index operands. Table B-1 is an operation code (opcode) map
that illustrates how bits 15 through 12 are used to specify the operations.
Bits
15 through 12 Operation
Bit Manipulation/MOVEP/Immediate
Move Byte
Move Long
Move Word
Miscellaneous
ADDQ/SUBQ/Scc/DBcc
Bcc/BSR
MOVEQ
OR/DIV/SBCD
SUB/SUBX
(Unassigned, Reserved)
CMP/EOR
AND/MUL/ABCD/EXG
ADD/ADDX
Shift/Rotate
Coprocessor Interface (MC68020)
535
Table B-2. Effective Addressing Mode Categories
Assembler
Address Modes Mode Register Data Memory Control Alterable Syntax
[DataRegister Dwect_ | 0001, | rog.inov |weXnn| Comes |ann | GR Ea
[Address Register Direct 001 reg.no. [ - | - [| - | x | an
Address Register Indirect : x Xx (An)
Address Register Indirect
with Postincrement (An)+
Address Register Indirect
with Predecrement — (An)
Address Register Indirect
with Displacement (d46,An) or
d46(An)
Address Register Indirect with
Index (dg,An,Xn) or
dg(An, Xn)
Absolute Short 111 000 X X Xx Xx (xxx).W
Absolute Long 111 001 xX Xx Xx Xx (xxx).L
Program Counter Indirect
with Displacement (d46,PC) or
d46(PC)
Program Counter Indirect with
Index (dg,PC,Xn) or
dg(PC,Xn)
«= Boolean AND
+ = Boolean OR
N= Boolean NOT N
536 APPENDIX B
STANDARD INSTRUCTIONS
OR Immediate
i a Sky ee ahh 3 2 1 0
Effective Address
OR Immediate to CCR
1514 13 12 11 10 9 5
pepe peTepe totote forers iE a
Pn ie ie
OR Immediate to SR
14 13 12 11 2 1
Word Data
Dynamic Bit
14 1S ee 2 et 3 2 1 0
Data 1 Effective Address
e
Register uP Mode Register
MOVEP
15,214 ee 12 he1)
Data Oued Address
Register rE pee Register
AND Immediate
15 14 11 10 3 2 1 0
Si Effective Address
5 Register
Size field: 00=byte O01=word 10=long
APPENDIX B 537
AND Immediate to CCR
i154 ee | Oe 10 9 8 7 6 5 4 3 2 1 0
le BO BML
Hs Bn Ao a a Byte Data
AND Immediate to SR
iy eb aks eh 10 9 8 7 6 5 4 3 2 1 0
[oJ 0: [0 [soi] 0 [oh] 1g [pon[eon|ai1.a| ste etee| aan] om eon)
Word Data
SUB Immediate
15 14 #13 «#12~«214 10 9 8 if 6 5 4 3 2 1 0
Effective Address
Mode Register
ADD Immediate
us) Uh ay aS ah 10 9 8 7 6 5 4 3 2 1 0
» Effective Address
Register
Size field: 00=byte 01=word 10=long
Static Bit
1S 14 13 2d 10 9 8 7 6 5 4 3 2 1 0
Effective Address
Register
Bit Number
EOR Immediate
15S 14 loa At 10 9 8 7 6 5 4 3 2 1 0
‘ Effective Address
538 APPENDIX B
EOR Immediate to CCR
1S 4 eee Ol oot 10 9 8 7 6 5 4 3 2 1 0
(Oo DOT BIEe ee oe
fom|mom son [eoween gos [vow|eom [my he ByteData
EOR Immediate to SR
ue) KS KY) 9 8 if 6 5 4 3 2 1 0
EO? ES De Ee cia | 2 |sO] 9.0.)
Word Data
CMP Immediate
1Sigon14 ore13 ee 2s 10 9 8 7 6 5 4 3 2 1 0
4 Effective Address
MOVES (MC68010/MC68012)
SY
Effective Address
Mode Register
MOVE Byte
MOVEA Long
1Saeel4e te Li2e Tt 10 9 8 if 6 5 4 3 2 1 0
Destination Source
Register
APPENDIX B 539
MOVE Long
15 14 ey ual 10 9 8 7 6 5 4 3 2 1 0
MOVEA Word
15 14 13 12 11 10 9 8 7 6 5 4 3) 2 1 0
Destination Source
MOVE Word
eh Ee wea es ae ehh} 10 9 8 7 6 5 4 3 2 1 0
NEGX
15 14 13 12 11 3 2 1 0
Effective Address
Register
Size field: 00 = byte 01=word 10=long
MOVE from SR
Te ues ee 3 2 1 0
Effective Address
Register
CHK
1S 145 S13 2d 3 2 1 0
Data ES Address
Register Register
Size field: 10 = Longword (MC68020)
11=Word
540 _ APPENDIX B
LEA
14 13 12 11 3 2 1 0
Address Effective Address
Register
CLR
14 13 Wahl 5 4 3 2 1 0
Si Effective Address
ze
| Mode | Register
1S 4 Sel Se 3 2 1 0
Effective Address
NEG
the) 14 13 12 11 10 9 3 2 1 0
Effective Address
MOVE to CCR
15 14 13 12 11 3 2 1 0
Saas Address
Register
NOT
15 el 4 GO lo we 5 4 3 2 1 0
Effective Address
MOVE to SR
15 14 12 3 2 1 0
sHeane Address
APPENDIX B 541
NBCD
ie EE AK ae 3 2 1 0
Effective Address
Register
SWAP
1514 1S 2a
sus
Register
BKPT (MC68010/MC6801 2)
ie) a ee ahh
FS BC BC IE
PEA
15 14 ey ke 6 3 2 1 0
See Address
EXT Word
ue eb Kes)
4 Data
ype Register
MOVEM Registers to EA
Uy Ane akh 9 ah 2 1 0
, ae Address
Register
Sz field: 0=word transfer 1=long transfer
542 APPENDIX B
TST
TAS
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
, , : Effective Address
Mode
ILLEGAL
i 0 Ae ie 10 9 8 if 6 5 4 3 2 1 0
Lt eB De ee ee ee
MOVEM EA to Registers
i ve AR) ea 10 9 8 7 6 5 4 3 2 1 0
1 { 1 Effective Address
TRAP
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LINK Word
15 14 «#13 es afl 10 9 8 7 6 5 4 3 2. 1 0
Address
1 : 4 Register
UNLK
Sy 4 ema 11 10 9 8 1 6 5 4 3 2 1 0
1 1 1 1 Address
Register
APPENDIX B 543
MOVE to USP
vey UES 10
Address
Register
1S) 4 eee Oe 2 10 9
Address
Register
RESET
i eo YS el 10 3 2 1 0
En Xe ACHRG En SE SO Galen,
NOP
15 14 13 12 11
STOP
We AK es
RTE
‘hy UES 10 9 8 if 6 5 4 3 2 1 0
20] ts Owls 04)et] Ste] 210M] FOP] 1a ee ies 0 (OR ee
RTD (MC68010/MC68012)
154 Cl 2 tO 9 8 i 6 5 4 3 2 1 0
RTS
15 13. «12
544 APPENDIX B
TRAPV
15 ee 4 eee et Oc til 10 9 8 6 5 4 3
RTR
i aes ky aks al 10 9 8 7 6 5 4 3 2 1 0
MUD
TE GE aS i Se a ee ee
MOVEC (MC68010/MC68012)
i WY ce (2 3 10 9
Register Control ta
dr field: 0=control register to general register
1= general register to control register
JSR
iy KE ay ke 3 2 1 0
Effective Address
| Mode | Register
JMP
15a) 4 | Se 3 2 1 0
Effective Address
ADDQ
15 14 3 2 1 0
Dat Effective Address
as
Data field: Three bits of immediate data, 0, 1-7 representing a range of 8,
1 to 7 respectively.
Size field: 00=byte 01=word 10=long
Scc
1 1 Effective Address
Conditi
APPENDIX B 545
DBce
15 14 13 leet 10
Data
1 Condition
Register
SUBQ
15 14 #13 #«212~«#'11 3 2 1 0
o Effective Address
wi Register
Data field: Three bits of immediate data, 0, 1-7 representing a range of 8,
1 to 7 respectively.
Size field: O0O=byte 01=word 10=long
Bcc
BRA
ui ES a 10 9 8 7 6 5
Pots [+ [o[o[o[oyo]
4 3 2 1 0
—~esnipiaconen 1]
BSR
Se 4 Od oe 1 7 6 5 4 3 2 1 0
Pots Te To[ope p sar pret —
MOVEQ
ue ae) kK) eh 5 4 3 2 1 0
a AS
Register bia
Data field: Data is sign extended to a long operand and all 32 bits are
transferred to the data register.
546 APPENDIX B
OR
14 13 12 11 3 2 1 0
Data Ds Stee Effective Address
Register eae
Op-Mode field: Byte Word Long Operation
000. 86-001 010 (<ea>)v(<Dn>)—
<Dn>
100 101 110 (<Dn>)v(<ea>)—
<ea>
DIVU/DIVS Word
15 14 4 3 2 1 0
Data Effective Address
Register Mode Register
Type field: O={DIVU 1=DIVS
SBCD
wy oe 4 hl
Destination Source
Register * Register*
SUB
Sees 4 ee Se ot 3 2 1 0
Data OnMod Effective Address
Register reo
Op-Mode field: Byte Word Long Operation
000 001 010 (<Dn>)-(< ea>)— <Dn>
100 101 110 (<ea >)-—(<Dn>)— <ea>
SUBA
itSel 4g Se 2 3 2 it 0
Data onued Effective Address
Register mies
Op-Mode field: Word Long Operation
011 111 (<An>)-(<ea>)— <An>
SUBX
ie iS Ski ae ah!
Destination Source
R/M
Register * Register*
APPENDIX B 547
CMP
16 14 13 12 11 3 2 1 0
Data Onan Effective Address
Register pace [7 Mose] Resister__|
Op-Mode field: Byte Word Long Operation
000 001 010 (<Dn>)-(<ea>)
CMPA
15 14 13 12 11 3 2 1 0
Data On od Effective Address
Register A
Op-Mode field: Word Long Operation
011 111 (<An>)-(<ea>)
EOR
15 14 13 12 11 3 2 1 0
Data Conn Effective Address
Register pees’ _[ Mode ‘Register|
Op-Mode field: Byte Word Long Operation
100 101 110 (<ea>)
® (<Dn>)— <ea>
CMPM
15 14 13 12 HW
era ae
Register Register
Size fleld: 00O=byte 01=word 10=long
AND
Omens Sales 3 2 1 0
ais apes secs Address
Register ie |
Mode —|_—Register
Op-Mode field: Byte Word Long Operation
000 001 010 (<ea>)A(<Dn>)— <Dn>
100 101 110 (<Dn>)A(<ea>)— <ea>
MULU Word
MULS Word
ue} AK aK) bi 3 2 1 0
San Sioa Address
548 APPENDIX B
ABCD
14 13 12 11 10
Destination Source
Register * Register*
15 14 13 12 11
Data Data
Register Register
15 14 13 12 11 8 tf 6 5 4 3 2 1 0
Address
Register
15 14 13 12 11 10 9 8 if 6 5 4 3 2 1 0
{ Address
Register Register
ADD
14 3 2 1 0
Data Rae Effective Address
ADDA
3 2 1 0
Address GoMod Effective Address,
Register pee
Op-Mode field: Word Long Operation
011 111 (<ea>)+(<An>)— <An>
APPENDIX B 549
ADDX
15 14 13 12 11 10 9 8 i 6 5 4 3 2 1 0
Destination ource
1 1 \ Register * 1 Register*
Size field: O0O=byte O01=word 10=long
R/M field: 0=data register to data register 1= memory to memory
*If R/M=0, specifies a data register
lf R/M=1, specifies an address register for the predecrement addressing mode.
SHIFT/ROTATE — Register
15 14 13 12 WA 10 9 8 U 6 5 4 3 2 1 0
4 4 Count/ ir 7we Data
Register yP Register
SHIFT/ROTATE — Memory
15 914 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Effective Address
1 a] 1 Type 1 1
Type field: 00= arithmetic shift 01=logical shift 10=rotate with extend 11=rotate
dr field: O=right 1=left
550 _APPENDIX B
NX iy
1’s complement, 11, 13 8051 family of dedicated 8254 programmable timer/counter
2’s complement, 10-13, 62, 151 controllers, 33 (continued)
4-bit microprocessors, 32 8080 microprocessor, 32 system addresses of, 223
4N33 optical coupler, 227, 228 8085 microprocessor, 33 system connections for,
5-minute rule, 109, 178, 187, 522 8086 microprocessor, 33 220-222
7-segment LCDs, 280, 281 8096 family of dedicated timed interrupt generator (mode
7-segment LEDs, 4-6, 268-279 controllers, 33 2), 227-229
8-bit microprocessors, 32-33 82C08 DRAM controller, 350-352 timing waveforms for, 225-231
10BaseT (thin Ethernet) networks, 8237A DMA controller 8259A priority interrupt controller
493 circuit connections and added to URDA MDS, 220-222
16-bit microprocessors, 33-34 operation of, 343, 345-347 block diagram of, 233
18-segment LCDs, 280 initializing, 346-348 cascading, 234-235
18-segment LEDs, 268, 270, 279, timing waveforms for, 346, 348 command (control) words for,
280 8251A USART 235-240
32-bit microprocessors, 33, 34 BISYNC communication with, fixed-priority mode of, 233
74LS14 inverter, 217-218 488-489 initializing, 235-240, 336-337
74LS138 address decoder, block diagram of, 463, 464 overview of, 232—234
221-222 command (control) word for, system connections for,
74LS181 ALU, 20-22 464-466, 488 234-235
555 timer, 218-219 hardware reset of, 466 use of, 232
741 op amp, 296 initializing, 464-466 8272A floppy-disk controller,
1372 chroma modulator, 437 mode word for, 464—466, 488 444-446
2421 binary-coded decimal (BCD) pin descriptions for, 463, 464 8275 CRT controller, 429-430
code, 4, 5 sending and receiving 8279 dedicated display controller
2900 family of bit-slice characters with, 466-467 7-segment display interfacing
processors, 33 status word for, 464-466 with, 271-274
4004 microprocessor, 32 system connections and signals, circuit connections, 271-274
5421 binary-coded decimal (BCD) 463-464 control words for, 274-277
code, 4, 5 write-recovery time of, 466 display driver using, 277-279
6502 microprocessor, 33 8253 programmable initializing and communicating
6571 character-generator ROM, timer/counter, 220 with, 274-277
427-428 8254 programmable timer/counter keyboard interfacing with,
6800 microprocessor, 33 8253 versus, 220 271-274
6801 dedicated controller, 33 added to URDA MDS, 220-222 scan time for, 272
6809 microprocessor, 33 block diagram of, 220 timing waveforms for, 272-273
6821 programmable parallel port clock frequency for, 220 8421 binary-coded decimal (BCD)
block diagram of, 184, 245-246 control word for, 223-225, code, 4, 5
Centronics parallel interface 231-232 9900 family of microprocessors,
connections for, 255, 256 hardware-retriggerable one-shot 33
control words for, 246-248 (mode 1), 226-228 32032 microprocessor, 33
dc operating characteristics of, hardware-triggered strobe (mode 68000 assembly language. See
281 5), 230-231 also 68000 instructions
internal addressing of, 185, 246 initializing, 222-225 addresses in, 52, 53
lathe and tape reader interface internal addresses of, 223 code bytes in, 52, 53
using, 248-251 interrupt on terminal count coding sheets for, 52, 53
parallel printer interface for, (mode 0), 225-226 comments in, 38, 39, 52, 53,
253-262 nonsystem clock usage with, 54
speech synthesizer interface, 231 converting algorithms to, 76
251-253 operation of, 220 data bytes in, 52, 53
system connections for, read-back feature of, 220, destinations in, 39
245-246 231-232 field in, 38-39
6845 CRT controller, 430-432 reading the count from, hand-coding, 40, 52, 53, 59
7445 decoder, 271-272 231-232 indirection in, 56
7447 decoder, 268-271 software-triggered strobe (mode instructions for. See 68000
8008 microprocessor, 32 4), 229-230 instructions
8048 microprocessor, 33, 268, square-wave mode (mode 3), labels in, 38, 52, 53
269 228-229 mnemonics in, 38
INDEX 551
68000 assembly language 68000 assembly language 68000 instructions (continued)
programs (continued) programs (continued) conditional tests in, 536
opcodes (operation codes) in, 38, inflation factor adjustment, data movement, 49
52, 53, 535-550 98-102 effective address (EA) in, 40-41,
operands in, 38, 40, 52, 53 int array pointers, 393 54-58, 101-102, 527,
overview of, 38—39 interrupt input, 215-217, 536-550
program development tools for, 238-240 execution times for, 104-105,
63-67 keyboard interrupt input, 527-533
programs. See 68000 assembly 215-217, 238-240 immediate, 530
language programs keyboard strobed input, 96-98 initialization, 51-52
sources in, 39 keypad input, 262—267 integer arithmetic, 49-50, 76
statements in, 38—39, 52, 53 labels in, 62-63 logical operation, 50
syntax of, 52 Macintosh disk and display multiprecision, 532
68000 assembly language access, 448-449 multiprocessor, 51
programs microcomputer-based industrial opcodes (operation codes) in, 38,
6821 control words, 248 process-control system, 52, 53, 535-550
6821 lathe and tape reader 327-335 primary words in, 535-550
interface, 248-251 microcomputer-based scale, privileged (sensitive), 37-38, 51
8254 initialization, 224-225, 313-321 program control, 50-51,
238-240 modules in, 136-140 103-104
8259A initialization, 238-240 moving strings, 105-106 read cycles for, 527-533
8279 initialization, 276-277 multiplication, 59-65 shift and rotate, 50, 531, 550
68000 initialization, 238-240 packed BCD conversion from single operand, 530
adding constants to arrays of ASCII, 70-73 standard, 529
data, 98-102, 393 password checking, 106-109 system control, 51
arithmetic average, 73—76 printed-circuit-board-making templates for, 54-58
ASCII conversion to packed machine, 85-92 timing for, 104—105, 527-533
BCDA70=73 printer driver, 259-262 write cycles for, 527-533
ASCII-encoded keyboard input, printer driver exception 68000 microprocessor
96-98 handler, 208, 209 68881 math coprocessor
backward jump, 80, 81 profit factor adjustment, cooperation with, 360-361
BCD packing, 70-73 98-102, 393 accumulators of, 27, 35; 36
BCD-to-HEX conversion, real-time clock, 238—240 address (AO—A7, A7’) registers
124-131 recursive subroutine, 132—136 of, 35, 36, 115, 117-118,
C programs with, 418-423 reentrant subroutine, 131-133 120-123
comparing strings, 106-109 REPEAT-UNTIL structure, addressing modes for. See
conditional jumps, 84-96 96-209 Addressing modes
critical region protection, 505, scale, 313~321 arithmetic logic unit (ALU) of,
506 sequence structure, 70-73 35, 36
data sampling, 118-124 stack initialization, 117 assembly language for. See
debugging. See Debugging strobed input, 96-98 68000 assembly language
programs unconditional jumps, 80-82 autovectoring of, 202, 212
delay loops, 104-105 uploading, URDA block diagram of, 34, 35
development tools for, 63— MDS-to-Macintosh, bus activities of, 170-175
67 ; 481-486 bus arbitration control lines of,
display driver, 277-279 WHILE-DO structure, 90, 169-170
divide-by-zero handling, 97-96 bus control lines of, 168, 169
203-207 zero divide handling, 203-207 buses in, 35, 38, 516
division, 136-139 68000 family of microprocessors, cache memory in, 35-36
downloading, 33-34, 515-520 data (DO-D7) registers of, 35, 36
Macintosh-to-URDA MDS, 68000 instructions. See also dual-state nature of, 37
65-66, 481-486 68000 assembly language even memory bytes and, 36, 37
factorials, 132—136 addressing mode operands in, exception processing with, 533
forward jump, 80, 82 535-550 exception vector table for, 201,
hand-coding, 40, 52, 53, 59 arithmetic, 49-50, 76 202, 204-205
heater control, 90, 92-96 binary-coded decimal (BCD), 50 execution unit (EU) of, 35-36
IF-THEN-ELSE structure, bit-manipulation, 50, 531 hard exception vector table for,
85-92 bus read and write cycles for, 204-205
IF-THEN structure, 84-85 527-533 I/O interface of, 34-35
industrial process-control clock cycles for, 104-105, input signals for, 166-170
system, 327-335 527-533 interrupt-acknowledge
conditional, 532 processing flowchart, 212
ney INDEX
68000 microprocessor (continued) 68030 microprocessor ABCD instruction, 50, 145, 532,
interrupt-acknowledge timing block diagram of, 519 549
waveforms, 212, 213 buses in, 516 Absolute long addressing mode,
interrupt-control lines of, 169 cache memory in, 36, 516 57
interrupt response of, 200-201 memory management with, Absolute long (ABS_LONG)
math coprocessor for. See 517-518 directive, 63, 162
68881 math coprocessor pin configuration of, 516, 517, Absolute shaft encoders, 286—
memory banks of, 179-180 518 287
memory blocks of, 179, 181 summary of, 34, 516 Absolute short addressing mode,
memory bytes and, 36, 37 68040 microprocessor, 520 57
memory interface of, 34, 35 cache memory in, 36 Absolute short (ABS_SHORT)
_ odd memory bytes and, 36, 37 summary of, 34, 520 directive, 63, 162
output signals for, 166—170 68451 MMU, 517 Abstracts for programs, 52, 54
peripheral control lines of, 168 68681 ACIA, 485 Accumulators, 27, 35, 36
pin configuration of, 166, 167 68851 MMU, 34, 517-518, 520 Accuracy (precision) of numbers,
prefetch queue of, 35-36 68881 math coprocessor 362
privilege states of, 37, 505 68000 microprocessor ACK (affirmative acknowledge)
processor status lines of, 169, cooperation with, 360-361 character, 487-488
170 68020 microprocessor Active filters, 294, 297-298
program counter of, 35 cooperation with, 360-361, Active state of lines, 167
programmer’s model of, 166 369-370 Actual arguments (parameters) of
read machine cycle bus 68040 built-in version of, 520 functions in C, 410
activities of, 170-172 block diagram of, 363, 364 A/D converters. See
read-modify-write machine cycle circuit connections for, Analog-to-digital converters
bus activities of, 174, 175 369-370 ADD instruction, 38, 39, 49,
reset line of, 157 control word for, 363, 364 145-146, 529, 549
semaphore use with, 161, data types for, 361-363 ADDA instruction, 49, 146, 529,
504-506, 514 double-precision numbers for, 549
signal summary for, 167-168 361, 363 Adders (mixers), 294, 296
soft exception vector table for, exceptions and, 365 ADDI instruction, 49, 146, 530
204-205 fixed-point numbers for, 362 Addition
stack pointer (SP) of, 35, 36 floating-point numbers for, 361, 68000 instructions for, 49
stacks of. See Stacks 362-363 binary, 10-12
status register of, 35, 36-38 hypotenuse calculation with, binary-coded decimal (BCD), 15,
summary of, 33-34, 516 367-369 145
supervisor stack pointer (SSP) instructions for, 363-367 hexadecimal, 14
of, 35, 36 integers for, 361-362 octal, 14
supervisor state of, 37, 505 internal architecture of, 363, ADD@Q instruction, 49, 59, 146,
system control lines of, 364, 365 530, 545
168-169 Macintosh motherboard location Address bus, 20, 25, 34, 35, 38,
system timing requirements for, of, 341, 342 516
187-192 overview of, 360-361 Address decoding
timing parameters for, 187-192 packed decimal numbers for, complete, 186
user state of, 37, 505 361, 362 defined, 179
write machine cycle bus programming example for, functions of, 179
activities of, 172-173 367-369 incomplete, 186
zero divide interrupt, 202—208 real numbers for, 361, 362— port, 180, 183-186
68008 microprocessor, 33-34, 363 RAM, 180, 182-183
186-187, 516 single-precision numbers for, ROM, 180-182
68010 microprocessor, 34, 36, 361, 362—363 Address error exception, 202,
504, 516 stack operation of, 363, 365 208, 212-214
68012 microprocessor, 34 status word for, 363, 364 Address inputs, 19, 20
68020 microprocessor 74148 multiplexer, 215, 217, 218 Address manipulation
68881 math coprocessor 80386 microprocessor, 33 instructions, 49
cooperation with, 360-361, 82064 hard disk controller, 450 Address marks, 442
369-370 82385 cache controller, 355-358 Address register direct addressing
cache memory in, 36, 516 88100 RISC CPU, 521 mode, 56
math coprocessor for. See 88200 cache/MMU (CMMU), 521 Address register indirect
68881 math coprocessor addressing modes, 56-57
multimaster mode of, 342, 344 AO-A7 and A7/ address registers, Address registers (AO—A7, A7’),
pin configuration of, 342, 344 sonoOnt los ll7-1 18; sorsGelio Liv L18;
summary of, 34, 516 120-123 120-123
INDEX 553
Addresses Algorithms (continued) Apple Macintosh family, form
68000 assembly language, 52, pH sampling with interrupts, factors for, 341-342
53 218-219 Apple Macintosh operating system
base, 508-509 printer driver, 256-259 (OS), 68000 assembly
breakpoint, 66, 109-110, program development, 66—67 language interface to,
139-140 Align on even memory address 448-449
decoding. See Address decoding (EVEN) directive, 163 Apple Macintosh Plus, 349
displacements (offsets) in, Allocation of space on stacks, 153 Apple Macintosh SE, 349
40-41, 508-509 Alphanumeric codes, 6—10 Application layer (OSI model), 492
down (toward lower), 118 Alphanumeric displays. See Application loader (RMX 86), 513
effective (EA), 40-41, 54-58, Light-emitting diodes; Arguments (parameters) of
101-102; 527, 536-550 Liquid-crystal displays subroutines, 124
logical, 508-509 Alphanumeric/graphics Arithmetic average, 73-76
named (labels), 38, 52, 53, liquid-crystal displays (LCDs), Arithmetic instructions, 49-50,
62-63 438 76
odd, 212-213 Alterable addressing modes, 144, Arithmetic logic unit (ALU)
page, 508-509 145 74LS181, 20-22
physical, 101—102, 508-509 ALU. See Arithmetic logic unit 68000, 35, 36
port, 180, 183-186 AM (amplitude modulation), 472 defined, 20, 24
return, 114 American Standard Code for microprocessor categorization
up (toward higher), 118 Information Interchange using, 32-34
virtual, 508, 509 (ASCII) Arithmetic operators in C,
Addressing modes character strings in C, 397-398
absolute long, 57 396-397, 416 Arithmetic shift instructions, 50
absolute short, 57 converting EBCDIC codes to, Arrays
address register direct, 56 267-268 data, 98-103
address register indirect, 56-57 in data statements, 62 elements of, 98-103
alterable, 144, 145 described, 6 names of, 408
asynchronous, 168 packed BCD characters from, pointers to, 408
control, 144, 145 10-73 ASCII. See American Standard
control-alterable, 144, 145 table of codes, 7-9 Code for Information
data, 144, 145 Amplifiers. See Operational Interchange
data-alterable, 144, 145 amplifiers ASL instruction, 50, 147, 531
data register direct, 54, 55-56 Amplitude modulation (AM), 472 asm (assembly language)
defined, 39 Analog circuit simulators, 374 statements in C, 422-423
direct, 40 Analog-to-digital (A/D) converters ASR instruction, 50, 147, 531
double indexed, 101-103 conversion time for, 307 Assembler directives
immediate, 40 dual-slope, 307-308, 309-310 absolute long (ABS_LONG), 63,
immediate data, 57 flash (parallel comparator), 307, 162
immediate quick data, 57 309 absolute short (ABS_SHORT),
implicit reference, 57, 144 high-speed, 307 63, 162
indirect, 40-41 microcomputer interfacing for, align on even memory address
introduced, 39 309-310 (EVEN), 163
memory, 144, 145 output codes for, 308-309 define constant (DC), 61-62,
memory-alterable, 144, 145 successive-approximation, 308, 162-163
operands for, 535-550 309, 310 define storage (DS), 62, 163
program counter, 57 AND instruction, 50, 71, 72, 147, end program (END), 63, 163
register direct, 40 529, 548 equate (EQU), 61, 163
summary of, 54, 55, 101-102 AND logic gates, 16-17 external definition (XDEF), 136,
synchronous, 168 ANDI instruction, 50, 147, 530, 137, 164
ADDX instruction, 49, 146, 532, 533, 537-538 external reference (XKREF), 136,
550 Answer modem, 475 137, 164
Affirmative acknowledge (ACK) Apple Macintosh INCLUDE, 163-164
character, 487-488 debuggers for, 66 originate (ORG), 60, 164
Algorithms downloading programs to URDA output listing (LIST, NOLIST),
converting to assembly MDS from, 65-66, 481-486 164
language, 76 linker for, 66 Assembler list file, 64-65
data sampling, 119 motherboard of, 341, 342, 343 Assembler macros
defined, 43 uploading programs from URDA defined, 140
divide-by-zero program, 203 MDS to, 481-486 dummy variables in, 141
microcomputer-based scale, Apple Macintosh II, schematic expanding, 140
311-313 diagram of, 369 in-line code and, 140
554 INDEX
Assembler macros (continued) Biased exponent for numbers, Bit-manipulation instructions, 50,
passing parameters to, 361, 362-363 531
140-141 Bidirectional bus, 25 Bit-mapped raster-scan display,
subroutines versus, 140, 141 Big-endian byte ordering, 521 432-433
without parameters, 140 Binary (base-2) numbers Bit-oriented protocol (BOP),
Assembler program, 39, 52, 1’s complement of, 11, 13 489-490
59-60, 64 2’s complement of, 10-13, 62, Bit-slice processors, 33
Assembly language. See 68000 151 Bits (binary digits)
assembly language described, 1-3 check (encoding), 359-360
Assembly language (asm) signed, 10-13 data, 462
statements in C, 422-423 Binary addition, 10-12 defined, 1
Assertion level, 16 Binary-coded decimal (BCD) code dibits, 473
Assignment operator in C, 397 2421,4,5 dirty, 508-509
Asynchronous addressing mode, 5421, 4,5 flag, 486-487, 489
168 8421, 4,5 frames of, 476-477, 489-490
Asynchronous bus control, 168, 68000 instructions for, 50 masking, 71, 72
169 addition with, 15, 145 numeric, 6
Asynchronous communication, decimal adjust operation for, 15 parity, 6, 358-359, 462
462 described, 4, 15 quadbits, 473
Asynchronous inputs, 17 excess-3, 4, 5 sign, 10-13
Attribute byte, 434-435 hexadecimal conversion from, start, 462
Audio speaker buffers, 228-229 124-131 stop, 462
Automatic variables in C, 386, packed, 70—73 tag, 356-359
387, 411-412 subtraction with, 15, 159 zone, 6
Autovectoring, 202, 212 unipolar, 308-310 Bitwise operators in C, 398
Auxiliary carry, 15 unpacked, 70—73 BKPT instruction, 51, 542
Average of numbers, 73-76 Binary-Coded Decimal Blanking of cathode-ray tube
Interchange Code (BCDIC), (CRT) displays, 426, 427
.B (byte) suffix, 40, 61, 62 659 Block check characters (BCC), 487
Backbones for networks, 495, Binary-coded decimal (BCD) to Blocked processes, 510
496 decimal conversion, 4, 5 Blocked tasks, 504
Background colors, 434-435 Binary codes, 308-310 Boot record on disks, 447
Background processes, 512 Booting computer systems, 447
Binary counters, 18-19
Backward jumps, 80, 81 BOP (bit-oriented protocol),
Binary digits. See Bits
Band-pass filters, 297, 298 489-490
Binary division, 13-14 Bottom of stacks, 37, 117-118
Band printers, 454
Bang-bang (on-off) control, 335 Binary multiplication, 12-13 Bottom-up design, 45-46
Bank switched memory, 507 Binary numbers Bounds register, 149
Base-2 numbers. See Binary 1’s complement of, 11-13 BPL instruction, 148
numbers 2’s complement of, 10-13, 62, BRA instruction, 50, 78-80, 82,
Base-8 (octal) numbers, 3 151 148, 532, 546
Base-10 numbers. See Decimal in data statements, 62 Branch instructions, 50
numbers Binary point, 1 Break character, 466
Base-16 (hexadecimal) numbers, Binary subtraction, 12, 13 Breakpoint addresses, 66,
3-4 Binary Synchronous 109-110, 139-140
Base addresses, 508-509 Communications Protocol Breakpoint frequency, 297-298
Baseband transmission, 491 (BISYNC), 487-488 Bridges (gateways) for networks,
Basic input-output system (BIOS), Binary-to-decimal conversion, 2 495
208, 513 Binary-to-hexadecimal conversion, Broadband-bus (tree-structured)
Batch processing, 30 3,4 networks, 491-492
Baud rate, 175, 462 Binary-to-octal conversion, 3 Broadband transmission, 491
BCC (block check characters), 487 Binary words BSET instruction, 50, 148-149,
Bec instruction, 50, 83-84, binary digits (bits) in. See Bits 505, 506, 531
147-148, 532, 546 byte (8-bit), 1 BSR instruction, 50, 114-115,
BCD. See Binary-coded decimal doubleword (32-bit), 1 116, 149, 532, 546
code least significant bit (LSB) of, 1, 2 BTST instruction, 50, 149, 531
BCDIC (Binary-Coded Decimal most significant bit (MSB) of, 2 Buffers
Interchange Code), 6-9 nibble (4-bit), 1 audio speaker, 228-229
BCHG instruction, 50, 148, 531 word (16-bit), 1 IC, 281-282
BCLR instruction, 50, 148, 531 BIOS (basic input-output system), inverting, 16
Begin flowchart symbol, 44 208, 513 noninverting, 16, 296
Behavioral models (EDA), 373 Bipolar binary codes, 309, 310 transistor, 282—283
INDEX 555
Bus arbitration control lines, C programming language C programming language
169-170 (continued) (continued)
Bus control, asynchronous, 168, char (character) pointers in, passing parameters by
169 396-397 reference, 391
Bus error exception, 202, 208, char (character) variables in, passing parameters by value,
213-214 385-387 391
Bus read and write cycles, 68000 character strings in, 396-397, pointer method of accessing
instructions, 527-533 416 array elements in, 407-408
Buses combined operators in, 398 pointers and functions with
68000, 35, 38, 516 curly braces in, 382 arrays, 412—414
68030, 516 data types in, 385, 386 pointers to functions in,
address, 20, 25, 34, 35, 38, declaring functions in, 408-411 414-415
516 defining functions in, 408-411 preprocessor directives in, 381
control, 25, 35, 38 dereferencing pointers in, 391 program development tools for,
control lines for, 168, 169 do-while structure in, 403-405 382-384
data, 20, 25, 34, 35, 38, 168, enumerated data type in, 385, programs. See C programs
169; 516 386 prototypes for functions in,
defined, 20 extern (external) variables in, 409-410
general-purpose interface bus 386, 387, 411-412 register variables in, 411-412
(GPIB), 497-499 float (floating-point) pointers in, relational operators in, 398-399
Hewlett-Packard interface bus 394-395 REPEAT-UNTIL structure in,
(HPIB), 497-499 float (floating-point) variables in, 403-405
IEEE 488, 497-499 388-389 scope (visibility) of variables in,
read machine cycle activities of, for loop in, 404-408 411-412
170-172 formal arguments (parameters) static variables in, 411-412
read-modify-write machine cycle of functions in, 409 storage classes in, 386, 387,
activities of, 174, 175 functions and arrays in, 411-412
write machine cycle activities 412-414 string library functions in, 416
of, 172-173 global variables in, 386, 387, switch structure in, 402—403
Bypass capacitors, 178 411-412 variables in, 385-389
Byte (8 bits), 1 header files in, 415 WHILE-DO structure in,
Byte (.B) suffix, 40, 61, 62 history of, 509 403-404
Byte-type operand, 40 if-else structure in, 400-402 while structure in, 403-404
Bytes IF-THEN-ELSE structure in, C programs
attribute, 434-435 400-402 68000 assembly language
big-endian ordering of, 521 IF-THEN structure in, 401 programs with, 418-423
character, 434-435 include files in, 415 adding constants to arrays of
COdE RoI EDS index method of accessing array data, 380-381, 391-395,
data, 52, 53 elements in, 405-407 412, 413
even, 36, 37 inline assembler for, 422-423 arithmetic average, 405-408,
line of, 356 int (integer) pointers in, 412-414
little-endian ordering of, 521 389-391 asm (assembly language)
odd, 36, 37 int (integer) variables in, statements in, 422-423
system (status register), 37-38 387-388 calling functions, 408-411
user (status register), 36-37 int array (integer array) pointers char pointers, 396-397
in, 391-394 char variables, 386-387
Integrated Development do-while structure, 403-405
C (carry) flag, 36-37, 76-77 Environment for, 382-384 float pointers, 394-395
C programming language introduced, 385 float variables, 388-389
68000 assembly language keyboard input library functions for loops, 404-408
programs and, 418-423 in, 415 functions, 408-411
actual arguments (parameters) library functions for, 415-418 hypotenuse calculation,
of functions in, 410 lifetime of variables in, 417-418
arithmetic operators in, 411-412 if-else structure, 400-402
397-398 local variables in, 386, 387, index method of accessing array
asm (assembly language) 411-412 elements, 405-407
statements in, 422—423 logical operators in, 399 inline assembler for, 422—423
assignment operator in, 397 math library functions in, int array pointers, 391-394
automatic variables in, 386, 416-418 int pointers, 389-391
387, 411-412 operator precedence in, int variables, 387-388
bitwise operators in, 398 399-400 main, 381, 382
calling functions in, 408-411 output library functions in, 416 passing array pointers to
CASE structure in, 402-403 parentheses in, 382 functions, 412, 413
556 INDEX
C programs (continued) CASE structure, 47, 48, 90, Character (char) pointers in C,
pointer method of accessing 402-403 396-397
array elements, 407-408 Cathode-ray tube (CRT) displays Character (char) variables in C,
pointers and functions with 6571 character-generator ROM 385-387
arrays, 412-414 for, 427-428 Character byte, 434-435
profit factor adjustment, 6845 CRT controller for, Character-generator read-only
380-381, 391-395, 412, 430-432 memory (ROM), 427-428
413 8275 CRT controller for, Character strings in C, 396-397,
program output to printer, 416, 429-430 416
417 bit-mapped raster scanning for, Characters
Pythagorean theorem, 417-418 432-433 affirmative acknowledge (ACK),
_ source-level debugger for, 384 blanking of, 426, 427 487-488
string functions, 416, 417 character display on, 426-428 block check (BCC), 487
switch structure, 402—403 color graphics for, 433-437 break, 466
temperature conversion, composite video for, 426, 427, control, 6, 7, 10
408-411, 418-422 434, 436-437 counter approach for, 257
while structure, 403-404 display refresh RAM for, 427, end-of-block (ETB), 487
Cache hit, 356-357 428 end-of-text (ETX), 487
Cache memory dot clock for, 427, 428 end-of-transmission (EOT),
68000, 35-36 field of, 425-426 488
68010, 36, 516 frequencies for, 428-429 enquiry (ENQ), 487
68020, 36, 516 horizontal sync pulse for, header, 487
68030, 36, 516 426-428 negative acknowledge (NAK),
68040, 36, 520 interlaced scanning for, 487-488
82385 cache controller for, 425-426 sentinel, 257
355-358 monochrome, 426-428 start-of-header (SOH), 487
defined, 36 noninterlaced scanning for, 426 start-of-text (STX), 487
direct-mapped, 355-357 operation of, 425-427 sync, 486-487
DRAM, 355-359 overscan in, 429 text, 487
fully associative, 357, 358 raster scanning for, 425-426, Charge-coupled device (CCD)
introduced, 355 432-437 cameras, 439
memory management unit terminals, 426, 433 Check (encoding) bits, 359-360
(MMU), 509 timing for, 428-429 Checksums, 442
SRAM, 355-358 vector-scan, 437-438 Child jobs, 513, 514
summary of, 357-358 vertical sync pulse for, 426-428 Child processes, 510
two-way set-associative, 357, video monitors, 426 Chip enable input, 19, 20
358 CCD (charge-coupled device) CHK instruction, 51, 149, 202,
Cache miss, 357 cameras, 439 208, 533, 540
CAD (computer-aided design), CD (compact disk) optical disks, Chroma modulator, 437
335-336 451, 452 Chroma signal, 437
CAE (computer-aided engineering), Center-trigger display, 195 CIM (computer-integrated
370 Central processing unit (CPU). See manufacturing), 336, 377
Call table, 328, 334 also Microprocessors CISC (complex instruction set
Called modem, 475, 476 address counter in, 24 computer), 521
Calling functions in C, 408-411 ALU in. See Arithmetic logic Clock cycles
Calling modem, 475, 476 unit 68000 instructions, 104-105,
Calls, Macintosh OS, 448-449 buses connected to. See Buses 527-533
Cameras defined, 24 bit manipulation instruction
charge-coupled device (CCD), dual-state, 37 execution, 531
439 execution sequence for, 25-27 conditional instruction
OPTICRAM, 439-440 general-purpose, 33 execution, 532
video, 439 purposes of, 24 effective address (EA)
Capacitive keyswitches, 259, 261, registers in. See Registers calculation, 527
263 summary of operation, 27 exception processing execution,
Capacitors, bypass and filter, 178 Centronics parallel interface 533
Cards, punched, 6, 10 6821 connections for, 255, 256 immediate instruction
Carrier sense, multiple access circuit connections for, execution, 530
with collision detection 254-256 JMP, JSR, LEA, MOVEM, and
(CSMA/CD), 491, 493 pin descriptions for, 254-255 PEA instruction execution,
Carry, auxiliary, 15 printer driver program for, 532
Carry (C) flag, 36-37, 76-77 255-262 miscellaneous instruction
Case (enclosure) design, 377 Chain printers, 454 execution, 533
INDEX 557
Clock cycles (continued) Codes (continued) Control characters, 6, 7, 10
MOVE instruction execution, Manchester, 493 Control flags, 37
528 scan, 268 Control registers, 516
multiprecision instruction Selectric, 6—9 Control words
execution, 532 trellis, 474 6821, 246-248
shift/rotate instruction Coding sheets for assembly 8251A, 464-466, 488
execution, 531 language, 52, 53 8254, 223-225, 231-232
single operand instruction Cold-junction compensation, 300 8259A, 235-240
execution, 530 Collision of transmissions, 493 8279, 274-277
standard instruction execution, Color graphics, 433-437 68881, 363, 365
529 Combined operators in C, 398 Coprocessors. See Math
Clocks Command words. See Control coprocessors
generator for, 175 words Counters. See also 8254
input to, 17 Comment field, 38, 39 programmable timer/counter
in logic analyzers, 194 Comments in programs, 38, 39, binary, 18-19
nonsystem, 231 52, 53, 54 character, 257
real-time, 219, 238-240 Common-bus networks, 491 flip-flops as, 18-19
Closed-loop gain, 294-296 Common-mode rejection, 297 interrupts for, 217-218
CLR instruction, 49, 150, 530, Common-mode signals, 296-297 registers as, 99-101
541 Compact disk (CD) optical disks, semaphores as, 514
CMP instruction, 49, 150, 529, 451, 452 CPU. See Central processing unit
548 Companders (companding codecs), CRC (cyclic redundancy
CMPA instruction, 49, 150, 529, 476 characters/check), 442-443,
548 Comparators, 293-295 487, 489, 490
CMPI instruction, 49, 150, 530, Comparing strings, 106-109 Critical angle, 479, 480
539 Comparison instructions, 49 Critical frequency, 297-298
CMPM instruction, 49, 150, 532, Compiler program, 39 Critical region, 497, 505, 506
548 Complete address decoding, 186 CRT displays. See Cathode-ray
CNC (computer numerical control) Complex instruction set computer tube displays
machines, 249 (CISC), 521 CSMA/CD (carrier sense, multiple
Code bytes, 52, 53 Composite video, 426, 427, 434, access with collision
Codecs, 476 436-437 detection), 491, 493 ~
Coders, 476 Computer-aided design (CAD), Current loops, 462, 467
Codes. See also Binary numbers; 335-336 Cyclic redundancy
Decimal numbers; Computer-aided engineering characters/check (CRC),
Hexadecimal numbers; Octal (CAE), 370 442-443, 487, 489, 490
numbers Computer-integrated Cylinders of hard disks, 450
7-segment display, 4—6 manufacturing (CIM), 336,
A/D output, 308-309 377 DO-D7 data registers, 35, 36
alphanumeric, 6-10 Computer numerical control (CNC) D flip-flops, 17, 18
ASCII. See American Standard machines, 249 D-latch, 17
Code for Information Computer vision, 438-441 D/A converters. See
Interchange Computerizing, 30-32 Digital-to-analog converters
BCD. See Binary-coded decimal Concurrent (parallel) processing, Daisy-wheel printers, 453
code 520-521 Darlington transistors, 282-283
binary, 308-310 Condition codes. See Flags DAS (data acquisition system),
Binary-Coded Decimal Conditional instructions, 532 308, 323, 324, 326-327
Interchange Code (BCDIC), Conditional jumps, 83-84, 93-96 Data
6-9 Conditional tests, 536 arrays of, 98-103
condition. See Flags Connector flowchart symbol, 44, latched, 34
D/A input, 305 45 packets of, 491
error detecting-correcting Connector symbol, 177, 178 redirected, 511-512
(ECCs), 359-360 Constellation (phase-amplitude subroutine in module separate
Extended Binary-Coded Decimal graph), 473, 474 from, 136-139
Interchange Code (EBCDIC), Contact bounce, 259, 261-267 trace, 66, 109, 195, 196
6-9 Contactors, 284 Data (DO—-D7) registers, 35, 36
Gray, 4, 5, 286-287, 473 Control addressing modes, 144, Data acquisition system (DAS),
Hamming, 359-360 145 308, 323, 324, 326-327
Hollerith, 6—10 Control-alterable addressing Data addressing modes, 144, 145
in-line, 140 modes, 144, 145 Data alignment, 516
linear predictive coding (LPC), Control block of memory, 257 Data-alterable addressing modes,
456-457 Control bus, 25, 35, 38 144, 145
558 INDEX
Data area on disks, 447 Dedicated controllers (continued) Direct read after write (DRAW)
Data bases, defined, 31 8051 family of, 33 optical-disk systems, 451
Data bits, 462 8096 family of, 33 Directives. See Assembler
Data bus, 20, 25, 34, 35, 38, 168, overview of, 33 directives
169, 516 TMS-1000 family of, 33 Directories
Data bytes, 52, 53 Define constant (DC) directive, parent, 510-511
Data communication equipment 61-62, 162-163 root, 447, 510-511
(DCE), 463 Define storage (DS) directive, 62, subdirectories, 447
Data field, 442 163 UNIX, 510-511
Data link layer (OSI model), 492 Defining functions in C, 408-411 Dirty bit, 508-509
Data movement instructions, 49 Delay loops, 104-105, 118-124, Disk crashes, 450
Data outputs, 19 156 Disk operating system (DOS),
Data register direct addressing Delta (differential) modulation, 447-448
mode, 54, 55-56 457 Disks
Data sampling, 118-124 Demand-paged virtual memory, boot record on, 447
Data statements, numbers in, 62 509 data area on, 447
Data storage registers, 18 Dereferencing pointers in C, 391 file allocation table {FAT) on,
Data strobes, 168, 169 Derivative feedback, 322-323 447
Data terminal equipment (DTE), Descramblers, 474 floppy. See Floppy disks
463 Descriptor tables, 508-509 hard, 450-451
Data types in C, 385, 386 Design and development tools. interface software for, 446-447
DBcc instruction, 50, 83-84, See Electronic design optical, 451-453
150-151, 532, 546 automation random-access memory (RAM),
DC (define constant) directive, Design for test (EDA), 375 449-450
61-62, 162-163 Destinations for instructions, 39 root directory on, 447
DCE (data communication Dibits, 473 subdirectories on, 447
equipment), 463 Differential (delta) modulation, Dispatcher, 504
Deadlock, 504-505 457 Displacements (offsets) in
Deadly embrace, 504-505 Differential operational amplifiers, addresses, 40—41, 508-509
Debouncing keyboards, 259, 294, 296-297 Display driver, URDA MDS,
261-267 Differential phase-shift keying 277-279
Debuggers, C source-level, 384 (DPSK) modulation, 473 Display page, 429
Debugging programs Differential-pressure transducers, Display refresh random-access
breakpoints for, 66, 109-110, 302, 304 memory (RAM), 427, 428
139-140 Differentiators, 294, 297 Displays
RUN command and, 109-110 Digit punches, 6, 10 alphanumeric. See
single-step command for, 109 Digital feedback, 288 Light-emitting diodes;
with subroutines, 139-140 Digital filters, 337-338 Liquid-crystal displays
techniques for, 109-110 Digital-to-analog (D/A) converters CRT. See Cathode-ray tube
trace data for, 66, 109, 195, characteristics and displays
196 specifications of, 304-305 dot-matrix, 268, 270, 279
Decimal (base-10) numbers full-scale output voltage of, multiplexed, 269-271
in data statements, 62 304-305 static, 268-270
defined, 1 input codes for, 305 triplexed, 280
Decimal-adjust operation, 15 linearity of, 305 Distributed processing systems,
Decimal-to-binary-coded-decimal maximum error of, 305 31, 32
(BCD) conversion, 4, 5 microcomputer interfacing for, Divide-by-zero interrupt, 202—
Decimal-to-binary conversion, 2 305-306 208
Decimal-to-hexadecimal operation of, 303-304 Division
conversion, 3, 4 output converter, 305 68000 instructions for, 50
Decimal-to-octal conversion, 3 resolution of, 304 68000 program for, 136-139
Decision (selection) operations for settling time for, 305 binary, 13-14
programs, 46-48 Direct addressing, 40 DIVS instruction, 50, 151, 529,
Decision flowchart symbol, 44, 45 Direct-digitization speech 547
Declaring functions in C, synthesis, 457 DIVU instruction, 50, 151, 529,
408-411 Direct input/output (I/O), 186 547
Decoders, 476 Direct memory access (DMA) DMA. See Direct memory access
Decoding instructions, 25-27, controller for. See 8237A DMA Do-while structure in C, 403-405
35-36 controller Documentation of programs,
Dedicated controllers defined, 309 52-54
6801, 33 overview of, 342-343 Dollar sign ($) prefix for
8048, 33, 268, 269 principle of, 309 hexadecimal numbers, 3
INDEX 559
DOS (disk operating system), Dynamic random-access memory Electronic design automation
447-448 (continued) (continued)
Dot clock, 427, 428 parity check for, 358-359 system software development,
Dot-matrix displays, 268, 270, precharging, 353 377
2/9 refresh controllers for, 20, 350 Electronic mail, 492
Dot-matrix printers, 454-455 row-address strobe (RAS) for, Elements of arrays, 98-103
Double bus error, 169, 214 350, 351 EMI (electromagnetic interference),
Double-density recording for single-in-line package (SIP) for, 284
disks, 443 348, 350 Emulators, 66, 336
Double-handshake input/output soft errors for, 358 Enable input, 17
(I/O), 244-245 static column mode, 353-354 Encoding (check) bits, 359-360
Double-indexed addressing mode, syndrome words and, 359-360 END (end program) directive, 63,
101-103 timing in microcomputer 163
Double-precision numbers, 361, systems, 352-353 End-of-block (ETB) character,
363 timing waveforms for a read 487
Doubleword (32 bits), 1 cycle, 348, 350, 351 End-of-text (ETX) character, 487
Downloading programs, End-of-transmission (EOT)
Macintosh-to-URDA MDS, character, 488
65-66, 481-486 EA (effective address), 40-41, End program (END) directive, 63,
DPSK (differential phase-shift 54-58, 101-102, 527, 163
keying) modulation, 473 536-550 Enquiry (ENQ) character, 487
DRAM. See Dynamic EBCDIC (Extended Binary-Coded Entry point, 46
random-access memory Decimal Interchange Code), Enumerated data type in C, 385,
DRAW (direct read after write) 6-9, 267-268 386
optical-disk systems, 451 ECCs (error detecting-correcting), Environment preservation for
Drivers 359-360 multiuser/multitasking
address bus, 34 EDA. See Electronic design operating systems (OS), 504
data bus, 34 automation EOR instruction, 50, 151, 529,
I/O, 255-262 EDAC (error-detecting and 548
Drum printers, 454 -correcting) device, 359-360 EORI instruction, 50, 151-152,
DS (define storage) directive, 62, Editor program, 64 530, 533, 538-539
163 EEPROM (electrically erasable EOT (end-of-transmission)
DTE (data terminal equipment), programmable read-only character, 488
463 memory), 20 EPROM (erasable programmable
Dual-ported random-access Effective address (EA), 40-41, read-only memory), 20, 182
memory (RAM), 434 54-58, 101-102, 527, Equate (EQU) directive, 61, 163
Dual-slope analog-to-digital 536-550 Erasable programmable read-only
converters, 307-308, EIOS (extended input/output memory (EPROM), 20, 182
309-310 system), 513 Error-detecting and -correcting
Dual-state central processing unit Electrically erasable (EDAC) device, 359-360
(CPU), 37 programmable read-only Error detecting-correcting (ECCs),
Dummy subroutines (stubs), memory (EEPROM), 20 359-360
139-140 Electromagnetic interference Error output files, 511
Dummy variables, 141 (EMI), 284 Error trapping, 267
Dynamic random-access memory Electronic design automation ETB (end-of-block) character, 487
(DRAM) (EDA) Ethernet, 493-494
82C08 controller for, 350-352 case design, 377 ETX (end-of-text) character, 487
block diagram of, 348, 349 design for test, 375 EU. See Execution unit
burst mode refresh, 350 design overview, 370 Even byte, 36, 37
cache mode, 355-359 design review committee and, EVEN (align on even memory
characteristics of, 348-351 370 address) directive, 163
column-address strobe (CAS) initial design, 370-371, 372 Even parity, 6
for, 350, 351 introduced, 370 Event-driven programming, 448
described, 20 microcomputer simulation Exception (trap), 149
distributed mode refresh, 350 example, 374-375 Exception-handling routines,
error detection and correction printed-circuit-board design, 161-162, 203-207
for, 358-360 375, 377 Exception processing, 533
Hamming codes and, 359-360 production and test, 377 Exception service routine, 158
hard errors for, 358 prototyping with simulation, Exception vector table, 201, 202,
microcomputer interfacing for, 371, 373-376 204-205
350-352 schematic capture, 370-371, Exception vectors, 201, 202,
page mode, 353-354 372 204-205
560 INDEX
Exceptions. See also Interrupts FCOS instruction (68881), 365 Files (continued)
68000 response to, 200—201 FCOSH instruction (68881), 365 uploading, URDA
68881, 365 FCS (frame check sequence), 489, MDS-to-Macintosh,
divide-by-zero, 202—208 490 481-486
group O (address error, bus FDBcc instruction (68881), 365 Filter capacitors, 178
error, and reset), 202, 208, FDDI (fiber distributed data Filter programs, 512
212-214 interface), 495, 496 Filters
group 1 (illegal, interrupt, trace, FDIV instruction (68881), 365 active, 294, 297-298
and privilege), 202, 208, Feedback band-pass, 297, 298
210-213 derivative, 322-323 digital, 337-338
group 2 (CHK, TRAP, TRAPV, digital, 288 formant, 457
; and zero divide), 202—210 integral, 322, 323 high-pass, 294, 297-298
priority of, 208, 211, 214 negative, 295-296, 321 low-pass, 294, 297-298
zero divide, 202—208 proportional, 322, 323 switched-capacitor, 338
Excess-3 binary-coded decimal Fetching instructions, 25-27, Finite-impulse response (FIR)
(BCD) code, 4, 5 35-36 digital filters, 337-338
Exclusive or (XOR) logic gates, 16, FETOX instruction (68881), FINT instruction (68881), 365
17. 365 FINTRZ instruction (68881), 365
Executing instructions, 25-27, FETOXM1 instruction (68881), FIR (finite-impulse response)
35-36 365 digital filters, 337-338
Execution times for 68000 FGETEXP instruction (68881), Firmware, defined, 25
instructions, 104-105, 365 Fixed-point numbers, 362
527-533 FGETMAN instruction (68881), Flag bits, 486-487, 489
Execution unit (EU), 68000, 365 Flag field, 489
35-36 Fiber distributed data interface Flags
Executive program, 323, 325 (FDDI), 495, 496 carry (C), 36—37, 76-77
EXG instruction, 49, 152, 533, Fiber-optic communication, control, 37
549 478-480, 495, 496 defined, 36
Exit point, 46 Fibers, modes of, 480 extend (X), 37, 76-77
Exponent of numbers, 362 Fields interrupt mask (IO, I1, and [2),
EXT instruction, 49, 152, 533, of cathode-ray tube (CRT) Bi, 2A
542 displays, 425-426 in memory, 203
Extend (X) flag, 37, 76-77 data, 442 negative (N), 37, 77
Extended Binary-Coded Decimal of frames, 489 overflow (V), 37, 77
Interchange Code (EBCDIC), ID, 442 semaphores, 161, 504—506,
6-9, 267-268 index, 442 514
Extended input/output system for statements, 38-39 supervisor state (S), 37
(EIOS), 513 File allocation table (FAT), 447 trace (T), 37, 202, 210
Extension words, 57-58 File-control block (FCB), 448 ZELOWUZ)s ot 1 6
Extern (external) variables in C, File directories. See Directories Flash (parallel comparator)
386, 387, 411-412 File handle (token), 448 analog-to-digital converters,
External definition (XDEF) File locking in UNIX, 497 307, 309
directive, 136, 137, 164 File server, 451, 495-497 Flip-flops
External reference (XREF) Files as counters, 18-19
directive, 136, 137, 164 assembler list, 64-65 Dr lias
External (extern) variables in C, defined, 447 JK, 17-18
386, 387, 411-412 downloading, as registers, 18
Macintosh-to-URDA MDS, Floating-point (real) numbers, 62,
F2F (FM or frequency modulation) 481-486 361, 362-363
recording, 443-444 error output, 511 Floating-point (float) pointers in C,
FABS instruction (68881), 365 header, in C, 415 394-395
FACOS instruction (68881), 365 include, in C, 415 Floating-point (float) variables in
Factorials, 132—136 library, 65 C, 388-389
FADD instruction (68881), 365, link, 65 FLOG2 instruction (68881), 365
366, 367 link map, 65 FLOG10 instruction (68881), 365
FASIN instruction (68881), 365 list, 64-65 FLOGN instruction (68881), 365
FAT (file allocation table), 447 object, 64 FLOGNP1 instruction (68881),
FATAN instruction (68881), 365 paths to, 447 365
FATANH instruction (68881), 365 shell, 512 Floppy disks. See also Disks
FBcc instruction (68881), 365 source, 64 8272A floppy-disk controller for,
FCB (file-control block), 448 standard input, 511 444-446
FCMP instruction (68881), 365 standard output, 511 double-density, 443
INDEX 561
Floppy disks (continued) Formal arguments (parameters) of Generators (continued)
error detection for, 442—443 functions in C, 409 timed interrupt, 227-229
formats for, 442—443, 447 Formant filters, 457 Gigabyte (Gbyte), 34
hard-sectored, 442 Formants, 456, 457 Gigabyte (unit), 33
head positioning for, 442 Formed-character impact printers, Global variables in C, 386, 387,
IBM 3740 format for, 442—443 453-454 411-412
index holes in, 441, 442 Forward jumps, 80, 82 GPIB (general-purpose interface
overview of, 441 Four-phase stepper motors, bus), 497-499
recorded bit formats, 443-444 285-286 Graphics
single-density, 442-443 Frame check sequence (FCS), 489, alphanumeric/graphics LCD
sizes for, 441 490 displays, 438
soft-sectored, 442 Frames of bits, 476-477, color, 433-437
Flow sensors, 302, 304 489-490 monochrome, 432-433,
Flowcharts FREM instruction (68881), 366 437-438
68000-byte read-cycle, Frequency modulation (FM or F2F) raster-scan, 432-437
170-171 recording, 443-444 vector, 437-438
68000-byte write-cycle, 172, Frequency-shift keying (FSK) Gray code, 4, 5, 286-287, 473
173 modulation, 472 Group O (address error, bus error,
68000 interrupt-acknowledge FRESTORE (privileged) instruction and reset) exceptions, 202,
processing, 212 (68881), 366 208, 212-214
68000 read-modify-write-cycle, FSAVE (privileged) instruction Group 1 (illegal, interrupt, trace,
174 (68881), 366 and privilege) exceptions, 202,
CASE structure, 47 FSCALE instruction (68881), 366 208, 210-213
comparing strings, 107 FScc instruction (68881), 366 Group 2 (CHK, TRAP, TRAPV,
defined, 44 FSGLDIV instruction (68881), 366 and zero divide) exceptions,
downloading program, 481 FSGLMUL instruction (68881), 366 202-210
factorials, 133 FSIN instruction (68881), 367
IF-THEN-ELSE structure, 47, FSINCOS instruction (68881), 367 H suffix for hexadecimal numbers,
86, 90 FSINH instruction (68881), 367 3
IF-THEN structure, 47 FSK (frequency-shift keying) Half-duplex communication, 462
keyboard input, 262-263, 264 modulation, 472 Hamming codes, 359-360
microcomputer-based industrial FSQRT instruction (68881), 367 Hand-coding programs, 40, 52,
process-control system, FSUB instruction (68881), 367 53, 59
323-325 FTAN instruction (68881), 367 Hard disks, 450-451
microcomputer-based scale, FTANH instruction (68881), 367 Hard exception vector table,
311-313 FTENTOX instruction (68881), 204-205
password checking, 107 367 Hard-sectored floppy disks, 442
program design with, 48 FTRAPcc instruction (68881), 367 Hardware
REPEAT-UNTIL structure, 47, FTST instruction (68881), 367 defined, 25
97, 995 107 FTWOTOxX instruction (68881), emulator, 66
sequence structure, 47 367 Hardware considerations for
strobed input, 97 Full-duplex communication, 462 interrupts, 214
symbols for, 44—45 Full functional models (EDA), 373 Hardware interrupts, 200
uploading program, 481 Functions in C, 408-411, Hardware models (EDA), 373
WHILE-DO structure, 47, 92 414-415 Hardware-triggered strobes,
FM (F2F or frequency modulation) 230-231
recording, 443-444 Gain Hardware verification model
FMOD instruction (68881), 365 closed-loop, 294-296 (EDA), 373
FMOVE instruction (68881), operational amplifier, 294-296 Hash tables, 267-268
365-366 voltage, 293-296 HDLC (high-level data link control)
FMOVECR instruction (68881), Gain-bandwidth product, 296 protocol, 489-490
366 Gap (separator), 442 Head crashes, 450
FMOVEM instruction (68881), 366 Gates. See Logic gates Header characters, 487
FMUL instruction (68881), 366 Gateways (bridges) for networks, Header files in C, 415
FNEG instruction (68881), 366 495 Hewlett-Packard interface bus
FNOP instruction (68881), 366 Gbyte (gigabyte), 34 (HPIB), 497-499
Fonts, 453 General-purpose central Hexadecimal (base-16) numbers
FOR-DO loops, 48, 102-103 processing unit, 33 BCD converted to, 124-131
For loop in C, 404-408 General-purpose interface bus in data statements, 62
Force transducers, 301-303 (GPIB), 497-499 defined, 3-4
Foreground colors, 434-435 Generators Hexadecimal addition, 14
Foreground processes, 512 Square-wave, 228-229 Hexadecimal subtraction, 15
562 INDEX
Hexadecimal-to-octal conversion, Index of refraction, 479, 480 Instrument interfaces (IEEE 488
3 Indirect addressing, 40-41 bus), 497-499
Hierarchy chart, 113, 114 Indirection in assembly language, Instrument prototyping, 335-337
High-byte erasable programmable 56 Instrumentation operational
read-only memory (EPROM), Indirection routines for the URDA amplifiers, 294, 297
182 MDS, 204-205 Integer (int) pointers in C,
High-level data link control (HDLC) Inductive kick, 283 389-391
protocol, 489-490 Industrial process control. See Integer (int) variables in C,
High-level languages, 39 also Microcomputer-based 387-388
High-pass filters, 294, 297-298 industrial process-control Integer arithmetic instructions,
Hit rate, 509 system 49-50, 76
Holding current, 284 data acquisition system (DAS) Integer array (int array) pointers
Hollerith code, 6-10 for, 308, 323, 324, 326— in C, 391-394
Horizontal sync pulse, 426-428 327 Integral feedback, 322, 323
HPIB (Hewlett-Packard interface overview of, 321-324 Integrated circuits (ICs)
bus), 497-499 proportional-integral-derivative buffers using, 281-282
Human interface (RMX 86), 513 (PID) control loops and, handling, 193-194
Hypercube topologies, 520-521 322-323 on schematics, 177, 178
Hypotenuse calculation, 417-418 residual error and, 322 Integrated Development
Hysteresis, 294, 295 servo control and, 321-322 Environment for C, 382-384
set points and, 321—322 Integrated services digital network
10, 11, and 12 (interrupt mask) Infinite-impulse response (IIR) (ISDN), 477-478
flags, 37, 211 digital filters, 337-338 Integrators (ramp generators),
IBM 3740 floppy-disk format, Infrared light-emitting diodes 294, 297
442-443 (LEDs), 217, 218 Interlaced scanning, 425-426
IBM Selectric printer mechanism, Initialization instructions, 51—52 Internal memory, 36
453 Ink-jet printers, 455-456 International Standards
ICs. See Integrated circuits Inline assembler for C programs, Organization (ISO)
ID fields, 442 422-423 high-level data link control
IEEE 488 bus, 497-499 Inline code, 140 (HDLC) protocol, 489-490
If-else structure in C, 400-402 Inode numbers, 510-511 open systems interconnection
IF-THEN-ELSE structure, 46-48, Input flowchart symbol, 44 (OSI) model, 492
85-92, 400-402 Input impedance, 296 Interpreter program, 39
IF-THEN structure, 46—48, Input/output (I/O) Interrupt-control lines, 169
84-85, 401 68000, 34-35, 166-170 Interrupt input/output (I/O),
IIR (infinite-impulse response) device interrupts, 208, 211 215-217, 238-240
digital filters, 337-338 direct, 186 Interrupt mask (I0, I1, and 12)
ILLEGAL instruction, 51, 152, double-handshake, 244-245 flags, 37, 211
211, 543 event-driven, 448 Interrupt pointers, 201, 202,
Illegal instruction trap, 152, 202, interrupt, 215-217, 238-240 204-205
208, 210-211 memory-mapped, 34-35, 180, Interrupt-service routines (ISRs),
Immediate addressing mode, 40 186 131-133, 203—207, 216-219
Immediate data addressing mode, microcomputer, 24, 25 Interrupt vectors, 201, 202,
57 parallel interface driver for, 204-205
Immediate instructions, 530 255-262 Interrupts. See also Exceptions
Immediate quick data addressing polled, 215, 448 68000 response to, 200-201
mode, 57 simple, 243, 244 for counting, 217-218
Impact printers, 453-454 simple strobe, 243-244 divide-by-zero, 202—208
Impedance, input, 296 single-handshake, 244 hardware, 200
Implicit reference addressing Input ports, 24, 25 hardware considerations for,
mode, 57, 144 Instructions 214
In-line assembler for C programs, 68000. See 68000 instructions 1/O device, 208, 211
422-423 decoding, 25-27, 35-36 multiple, 232
In-line code, 140 destinations for, 39 nonmaskable, 169, 211
INCLUDE directive, 163-164 executing, 25-27, 35-36 priority interrupt controller
Include files in C, 415 fetching, 25-27, 35-36 (PIC) for. See 8259A priority
Incomplete address decoding, 186 mnemonics for, 38 interrupt controller
Incremental shaft encoders, overhead, 105 priority of, 208, 211, 214
287-288 pipelined, 35, 521 for real-time clocks, 219
Index field, 442 privileged (sensitive), 37-38, 51 software, 200
Index holes in floppy disks, 441, sources for, 39 software considerations for,
442 supersets of, 34, 516-517 214-215
INDEX 563
Interrupts (continued) Keyboards (continued) Links on stacks, 153, 162
spurious, 202, 212 keypad input, 262-267 Liquid-crystal displays (LCDs)
time base for timing, 219-220 keyswitch types for, 259, 261, 7-segment, 280, 281
for timing, 218-219 263 18-segment, 280
user, 202 N-key rollover for, 274 alphanumeric/graphics, 438
zero divide, 202—208 strobed input from, 96-98 backplane drive of, 279, 280
Inverters, 16 two-key lockout for, 262, 274 described, 267
Inverting buffers, 16 two-key rollover for, 267, 274 dynamic scattering type, 279
Inverting input of operational Keypad URDA MDS interfacing, field effect type, 279
amplifiers, 293, 294 271-274 nonmultiplexed, 280, 281
Inverting operational amplifiers, operation of, 279-280
294, 296 .L (long) suffix, 40, 61, 62 triplexed, 280
I/O. See Input/output Labels (named addresses), 38, 52, LIST (output listing) directive, 164
ISDN (integrated services digital 53, 62-63 List file, 64-65
network), 477-478 LANs. See Local area networks Little-endian byte ordering, 521
ISO. See International Standards Laser printers, 455 Load cells, 301, 303
Organization Last in, first out (LIFO) structure, Local area networks (LANs)
ISRs (interrupt-service routines), 122-123 10BaseT (thin Ethernet), 493
131-133, 203-207, 216-219 Latches, 17, 34 application example of,
Iteration (repetition) operations for Lathe, microcomputer-controlled, 495-497
programs, 46—48 248-251 backbones for, 495, 496
Layers of operating systems, 505, bridges (gateways) for, 495
Jack (J) symbol, 177, 178 SOMO Ethernet, 493-494
JK flip-flops, 17-18 LCDs. See Liquid-crystal displays fiber distributed data interface
JMP- instruction, 50, 78-81, 152, LEA instruction, 49, 152-153, (FDDI) for, 495, 496
SID), Sales 532, 541 fiber-optic, 495, 496
Jobs (RMX 86), 513, 514 Least significant bit (LSB), 1, 2 file server for, 495-497
JSR instruction, 50, 114, 115, Least significant digit (LSD), 2, 3 overview of, 491
L523 24545 LEDs. See Light-emitting diodes print server for, 495-497
Jukebox optical-disk systems, Library files, 65 protocols for, 492
452-453 Lifetime of variables in C, software example for, 495-497
Jump table, 90 411-412 topologies for, 491—492°
Jumps LIFO (last in, first out) structure, Local variables in C, 386, 387,
68000 instructions for, 50 122-123 411-412
backward, 80, 81 Light-emitting diodes (LEDs) Locality of reference, 355
conditional, 83-84, 93-96 7-segment, 4-6, 268-279 Logic analyzers, 194-196
forward, 80, 82 18-segment, 268, 270, 279, 280 Logic gates
unconditional, 78—82 8279 controller for. See 8279 AND, 16-17
dedicated display controller exclusive or (XOR), 16, 17
Kernel of operating systems, 505, described, 268, 270 NAND, 16-17
507, 510-511 directly driven (static), 268-270 NOR, 16-17
Keyboards dot-matrix, 268, 270, 279, 280 optical, 521-522
8048 microprocessor for, 268, infrared, 217, 218 OR, 16=17
269 in optical couplers, 227, 228 Logical addresses, 508-509
8279 interfacing with, 271-274 software-multiplexed, 269-271 Logical operation instructions, 50
add and point conversion Light sensors, 298-299 Logical operators in C, 399
technique for, 263, Line 1010 and line 1111 Logical shift instructions, 50
267-268 emulation exceptions, 202, Long (.L) suffix, 40, 61, 62
C library functions for, 415 210-211 Long-type operand, 40
circuit connections for, Line of bytes, 356 Loop networks, 491
261-262, 264 Linear predictive coding (LPC), Looping primitives, 150
compare code conversion 456-457 Loops
technique for, 263-267 Linear ramp, 297 delay, 104-105, 118-124, 156
debouncing, 259, 261-267 Linear variable differential event, 448
detecting keypress on, 261-267 transformers (LVDTs), FOR-DO, 48, 102-103
EBCDIC to ASCII conversion for, 301-303 phase-locked, 443-444
267-268 Linear voice coil mechanism, 450 program, 46-48
encoding keypress on, 261-267 Link file, 65 structure for, 103-104
hardware interfacing for, LINK instruction, 49, 153, 162, Low-byte erasable programmable
267-269 504, 533, 543 read-only memory (EPROM),
interrupt input from, 215-217, Link map file, 65 182
238-240 Linker program, 65 Low lines, 167
564 INDEX
Low-pass filters, 294, 297-298 Memory (continued) Microprocessors. See also Central
LPC (linear predictive coding), ROM. See Read-only memory processing unit (CPU)
456-457 segmentation of, 508-509 4-bit, 32
LSB (least significant bit), 1, 2 up in (toward higher addresses), 8-bit, 32-33
LSD (least significant digit), 2, 3 118 16-bit, 33-34
LSL instruction, 50, 153, 531 virtual. See Virtual memory 32-bit, 33, 34
LSR instruction, 50, 153, 531 volatile, 20 ALU categorization of, 32-34
Luminance, 436 Memory addressing modes, 144, complex instruction set
LVDTs (linear variable differential 145 computer (CISC) type, 521
transformers), 301-303 Memory-alterable addressing defined, 28
modes, 144, 145 evolution of, 32—33
Machine language, 38 Memory banks, 179-180 reduced instruction set
Machines, computer numerical Memory blocks, 179, 181 computer (RISC) type, 521
control (CNC), 249 Memory-management units second-generation, 32
Macintosh. See Apple Macintosh (MMUs), 507-509, 517-518 Millions of floating-point
entries Memory map for the URDA MDS, operations per second
Macros. See Assembler macros 35, 185 (megaflops), 520
Magnetic disks Memory-mapped input/output Millions of instructions per second
floppy. See Floppy disks (I/O), 34-35, 180, 186 (MIPS), 520
hard, 450-451 Messages, 513-514 Minicomputers, 28
Mailboxes, 513-514 MFM (modified frequency Mixed-mode simulators, 374
Mainframes, 27-28 modulation) recording, 444 Mixers (adders), 294, 296
Mainline program, 323, 325 Microcode, 33 MMUs (memory-management
Manchester code, 493 Microcomputer-based industrial units), 507-509, 517-518
Mantissa (significand) of numbers, process-control system Mnemonics for instructions, 38
362 68000 assembly language Modems
Marking state, 462 program for, 327-335 amplitude modulation (AM) for,
Mask-programmed read-only block diagram of, 323, 324 472
memory (ROM), 20 flowchart for, 323-325 answer, 475
Masking bits, 71, 72 hardware for, 324, 326-327 called, 475, 476
Math coprocessors overview of, 323-325 calling, 475, 476
68881. See 68881 math Microcomputer-based instrument defined, 463
coprocessor prototyping, 335-337 frequency-shift keying (FSK)
defined, 360 Microcomputer-based scale modulation for, 472
interfaces for, 516 68000 assembly language handshake sequence for, 475,
Math library functions in C, program for, 313-321 476
416-418 algorithm for, 311-313 hardware overview of, 474-475
MAU (multistation access unit), flowchart for, 311-313 introduced, 472
494 input circuitry for, 311, 312 null, 469, 470
MDS. See Microcomputer overview of, 310-311 originate, 475
development system Microcomputer-controlled lathe, phase-shift keying (PSK)
Mechanical keyswitches, 259 248-251 modulation for, 473-474
Mechanical relays, 283-284 Microcomputer development RS-232C connections for,
Megaflops (millions of system (MDS) 467-470
floating-point operations per assembler use with, 39 XMODEM protocol for, 487-488
second), 520 described, 64 Modes of fibers, 480
Membrane keyswitches, 259, 263 URDA. See URDA MDS Modified frequency modulation
Memory Microcomputers (MFM) recording, 444
68000 instructions for, 49 block diagram of, 25 Modulator-demodulators. See
68008 access of, 186-187 CPU of, 24-25 Modems
bank switched, 507 described, 28 Modules of programs, 45,
cache. See Cache memory execution sequence for, 25-27, 136-140
control block of, 257 35-36 Monitor program, 52, 66
down in (toward lower I/O section of, 24, 25 Monochrome cathode-ray tube
addresses), 118 memory section of, 24, 25 (CRT) displays, 426-428
flags in, 203 three-instruction program for, Monochrome graphics, 432-433,
internal, 36 Ba PM 437-438
named, 126, 127 troubleshooting, 189-197 Most significant bit (MSB), 2
nonvolatile, 19 types of, 28, 29 Most significant digit (MSD), 2, 3
overlay area, 507 uses of, 29-32 Motherboards
RAM (read-write). See Microcontrollers. See Dedicated Apple Macintosh, 341, 342, 343
Random-access memory controllers Apple Macintosh Plus, 349
INDEX 565
Motherboards (continued) Multiuser/multitasking operating Noninverting operational
Apple Macintosh SE, 349 systems (continued) amplifiers, 294, 295-296
Motors UNIX. See UNIX operating Nonmaskable interrupts, 169, 211
absolute shaft encoders for, system Nonreturn-to-zero (NRZ) recording,
286-287 MULU instruction, 50, 155, 529, 443-444
D/A converters and, 305-306 548 Nonvolatile memory, 19
drivers for, 283-284 Mutual exclusion of tasks, 505, NOP instruction, 50, 59, 156,
incremental shaft encoders for, 506 533, 544
287-288 NOR logic gates, 16-17
servo control of, 321—322 N (negative) flag, 37, 77 Normalizing numbers, 362
stepper, 285-286 N-key rollover for keyboards, 274 NOT instruction, 50, 156, 530,
Mouse input devices, 433 NAK (negative acknowledge) 541
MOVE instruction, 39-40, 49, character, 487-488 NPS (noninterruptible power
54-59, 153-154, 528, 533, Named addresses (labels), 38, 52, supply), 352
539, 540, 541, 544 53, 62-63 NRZ (nonreturn-to-zero) recording,
MOVEA instruction, 49, 58-59, Named memory for parameter 443-444
154, 539, 540 passing, 126, 127 Null modem, 469, 470
MOVEC instruction, 51, 545 NAND logic gates, 16-17 Numbers
MOVEM instruction, 49, NBCD instruction, 50, 155-156, accuracy (precision) of, 362
154-155, 504, 532, 542, 543 530, 542 average of, 73—76
MOVEP instruction, 49, 155, 537 NEG instruction, 49, 156, 530, biased exponent for, 361,
MOVEGQ instruction, 49, 155, 530, 541 362-363
546 Negative (N) flag, 37, 77 double-precision, 361, 363
MOVES instruction, 51, 539 Negative acknowledge (NAK) exponent of, 362
Moving strings, 105-106 character, 487-488 fixed-point, 362
MSB (most significant bit), 2 Negative feedback, 295-296, 321 floating-point (real), 361,
MSD (most significant digit), 2, 3 NEGX instruction, 49, 156, 530, 362-363
MULS instruction, 50, 155, 529, 540 mantissa (significand) of, 362
548 Nested subroutines, 113-114 normalizing, 362
Multilevel simulators, 373-374 Network layer (OSI model), 492 scientific notation for, 362
Multimaster mode, 342, 344 Networks single-precision, 361, 362-363
Multimode fibers, 480 10BaseT (thin Ethernet), 493 Numeric bits, 6 ;
Multiple interrupts, 232 application example of,
Multiplexed displays, 269-271 495-497
Multiplication backbones for, 495, 496 Object file, 64
68000 instructions for, 50 bridges (gateways) for, 495 Object-oriented operating systems
68000 program for, 59-65 broadband-bus (tree-structured), (OS), 448
binary, 12-13 491-492 Objects
Multiprecision instructions, 532 common-bus, 491 defined, 448
Multiprocessing systems, 31, 32 Ethernet, 493-494 RMX 86, 513-514
Multiprocessor instruction, 51 fiber distributed data interface Octal (base-8) numbers, defined, 3
Multiprogramming systems, 30 (FDDI) for, 495, 496 Octal addition, 14
Multistation access unit (MAU), fiber-optic, 495, 496 Octal subtraction, 14-15
494 integrated services digital Octal-to-binary conversion, 3
Multitasking systems, 30-31, 504 network (ISDN), 477-478 Octal-to-hexadecimal conversion,
Multiuser/multitasking operating LANs. See Local area networks 3
systems (OS) loop, 491 Odd addresses, 212-213
accessing resources with, protocols for, 492 Odd byte, 36, 37
504-506 ring, 491, 494-496 Odd parity, 6
defined, 503-504 software example for, 495-497 Off-page connector flowchart
environment preservation for, star, 491 symbol, 44, 45
504 token-passing ring, 491, Offsets (displacements ) in
layers of, 505, 507 494-496 addresses, 40-41, 508-509
memory management for, topologies for, 491-492 On-off (bang-bang) control, 335
506-509 Nibble (4 bits), 1 One-shots, 226-228
onionskin diagram for, 505, NOLIST (no output listing) Onionskin diagrams of operating
507 directive, 164 systems, 505, 507, 513
overview of, 503-504 Noninterlaced scanning, 426 Opcode field, 38
protection in, 505-507 Noninterruptible power supply Opcodes (operation codes), 38, 52,
RMX 86. See RMX 86 operating (NPS), 352 53, 535-550
system Noninverting buffers, 16, 296 Open systems interconnection
scheduling for, 504 Noninverting input of operational (OSI) model, 492
tasks of. See Tasks amplifiers, 293, 294 Operand field, 38
566 INDEX
Operands, 38, 40, 52, 53 Output flowchart symbol, 44 PC (program counter), 35
Operating systems (OS) Output library functions in C, 416 PCL (processor control language),
defined, 447, 503 Output listing (LIST, NOLIST) 373
disk operating system (DOS), directives, 164 PCM (pulse-code modulation),
447-448 Output ports, 24, 25 476
kernel of, 505, 507 Overdamped response, 322 PDBcc instruction (68851 only),
layers of, 505, 507 Overflow ol7,
Macintosh. See Macintosh stack, 130-131 PEA instruction, 49, 157, 532,
operating system V flag for, 37, 77 542
multiuser/multitasking. See Overhead instructions, 105 Pel (picture element or pixel), 433
Multiuser/multitasking Overlapped erasable Per-process segment, 510
1 operating systems (OS) programmable read-only Peripheral control lines, 168
object-oriented, 448 memory (EPROM), 182 Peripheral devices, 211
onionskin diagrams of, 505, Overlays, 507 Perpendicular (vertical) recording,
507, 513 Overscan in cathode-ray tube 444
RMX 86. See RMX 86 operating (CRT) displays, 429 PFLUSH instruction, 517
system Overshoot, 322 PFLUSHR instruction (68851
shell of, 505, 507 only), 517
UNIX. See UNIX operating P68000 MDS. See URDA MDS Phase-amplitude graph
system P (plug) symbol, 177, 178 (constellation), 473, 474
Operation codes (opcodes), 38, 52, Packed binary-coded decimal Phase-locked loop, 443-444
53, 535-550 (BCD) code, 70-73 Phase-shift keying (PSK)
Operation flowchart symbol, 44 Packets of data, 491 modulation, 473—474
Operational amplifiers (op amps) Paddle wheels, 302, 304 Phonemes, 251-253, 456, 457
active filters, 294, 297-298 Page addresses, 508-509 Photocells, 298
adders (mixers), 294, 296 Page offsets, 508-509 Photodiodes, 298-299
characteristics of, 293 Paper tape reader, 248-251 Photoresistors, 298
comparators, 293-295 Parallel (concurrent) processing, Phototransistors, 217, 218, 227,
differential, 294, 296-297 520-521 228
differentiators, 294, 297 Parallel comparator (flash) Physical address, 101-102,
instrumentation, 294, 297 analog-to-digital converters, 508-509
integrators (ramp generators), 307, 309 Physical layer (OSI model), 492
294, 297 Parallel data transfer, 243, 244. PIA (programmable interface
inverting, 294, 296 See also 6821 programmable adapter), 175-176
inverting input of, 293, 294 parallel port; Centronics PIC (priority interrupt controller).
noninverting, 294, 295-296 parallel interface See 82594 priority interrupt
noninverting input of, 293, 294 double-handshake I/O, 244-245 controller
voltage gain of, 293-296 simple strobe I/O, 243-244 Picture element (pel or pixel), 433
Operator precedence in C, single-handshake I/O, 244 PID (proportional-integral-
399-400 Parallel printers, 253-262 derivative) control loops,
Optical computers, 521-522 Parameter passing 322-323
Optical couplers, 227, 228 by reference, 391 Pipelined instructions, 35, 521
Optical disks, 451-453 by value, 391 Pipes for processes, 511, 512
Optical logic gates, 521-522 to macros, 140-141 Pitch of sounds, 456
Optical motor shaft encoders, named memory for, 126, 127 Pixel (pel or picture element), 433
286-288 pointers for, 126, 128 PLOAD instruction, 518
Optical read-only memory registers for, 124-126 Plug (P) symbol, 177, 178
(OROM), 451 stacks for, 126, 128-131 PMOVE instruction, 518
OPTICRAM cameras, 439-440 summary of, 131 Pointer arithmetic, 407
OR instruction, 50, 72, 156-157, Parameters Pointers
529, 547 arguments of subroutines, 124 to arrays, 408
OR logic gates, 16-17 of functions in C, 409 char (character), in C, 396-397
ORG (originate) directive, 60, 164 Parent directory, 510-511 dereferencing, in C, 391
ORI instruction, 50, 157, 530, Parity bit, 6, 358-359, 462 float (floating-point), in C,
533, 537 Parking zone for hard disks, 450 394-395
Originate (ORG) directive, 60, 164 Partitions of hard disks, 450-451 to functions in C, 414-415
Originate modem, 475 Passing parameters. See int (integer), in C, 389-391
OROM (optical read-only memory), Parameter passing int array (integer array), in C,
451 Password checking, 106-109 391-394
OS. See Operating systems Paths to files, 447 interrupt, 201, 202, 204-205
OSI (open systems PBcc instruction (68851 only), passing parameters using, 126,
interconnection) model, 492 O17 128
INDEX 567
Pointers (continued) Priority interrupt controller (PIC). Programs (continued)
program counter (PC), 35 See 8259A priority interrupt critical region of, 505, 506
registers as, 99-101 controller debugging. See Debugging
Polled input/output (I/O), 215, Priority of interrupts, 208, 211, programs
448 214 decision (selection) operations
Pop operations for stacks, Privilege states, 37, 505 for, 46-48
123-124 Privilege trap, 202, 208, 210 development tools for, 63-67,
Ports Privileged (sensitive) instructions, 382-384
68008 access of, 186—187 37-38, 51 documentation of, 52-54
address decoding for, 180, Procedures. See Subroutines downloading,
183-186 Process control. See Industrial Macintosh-to-URDA MDS,
addresses of, 180, 183-186 process control 65-66, 481-486
defined, 24 Process-control block, 504 editor, 64
input, 24, 25 Process descriptor, 504 error trapping for, 267
output, 24, 25 Process flowchart symbol, 44 event-driven, 448
Posted write, 357 Process header, 504 executive, 323, 325
Postfix operations, 400 Process tables, 510 filters, 512
Posttrigger display, 195 Processes. See also Tasks flowcharts of. See Flowcharts
Potential well, 439 background, 512 hand-coding, 40, 52, 53, 59
Power supplies, noninterruptible blocked, 510 interpreter, 39
(NPS), 352 child, 510 iteration (repetition) operations
Precedence of operators in C, defined, 504, 510 for, 46-48
399-400 foreground, 512 linker, 65
Precision (accuracy) of numbers, pipes for, 511, 512 loops in, 46-48
362 put to sleep, 510 mainline, 323, 325
Preemptive priority-based signals for, 511 modules of, 45, 136-140
scheduling, 504 suspended, 510 monitor, 52, 66
Prefetch queue, 35-36 swapped, 510 pseudocode for. See Pseudocode
Prefix operations, 400 Processor control language (PCL), relocatable, 65, 79
Preprocessor directives in C, 381 373 sequence operations for, 46—48
Presentation layer (OSI model), Processor status lines, 169, 170 simulation, 336
492 Program control instructions, simulator, 371, 373-376
Pressure transducers, 301-303 50-51, 103-104 source, 64
PRESTORE instruction (68851 Program counter (PC), 35 standard structures for, 46—48
only), 518 Program counter addressing statements in, 46, 52, 53
Pretrigger display, 195 modes, 57 structured, 45-48
Primary station, 490 Program development algorithm, system, 52
Primary words, 535-550 66-67 top-down design of, 45, 48, 113
Primitives Program development tools, uploading, URDA
graphics routine, 433 63-67, 382-384 ~MDS-to-Macintosh,
looping, 150 Programmable interface adapter 481-486
Print server, 495-497 (PIA), 175-176 PROM (programmable read-only
Printed-circuit-board design, 375, Programmable read-only memory memory), 20
377 (PROM), 20 Proportional feedback, 322, 323
Printer daemon, 512 ~ Programmer’s model, 166
Proportional-integral-derivative
Printers. See also Centronics Programming languages
parallel interface (PID) control loops, 322-323
68000 assembly language. See
band, 454 68000 assembly language Protocols
chain, 454 C. See C programming language Binary Synchronous
daisy-wheel, 453 high-level, 39 Communications Protocol
dot-matrix, 454-455 machine language, 38 (BISYNC), 487-488
drum, 454 Programs. See also Software bit-oriented (BOP), 489-490
IBM Selectric printer 68000 assembly language. See defined, 487
mechanism, 453 68000 assembly language high-level data link control
impact, 453-454 programs (HDLC), 489-490
ink-jet, 455-456 abstracts for, 52, 54 LAN, 492
laser, 455 algorithms of. See Algorithms network, 492
parallel, 253-262 assembler, 39, 52, 59-60, 64 open systems interconnection
spark gap, 455 bottom-up design of, 45—46 (OSI) model for, 492
thermal, 454-455 C. See C programs Synchronous Data Link Control
train, 454 comments in, 38, 39, 52, 53, 54 (SDLC), 489
xerographic, 455 compiler, 39 XMODEM, 487-488
568 INDEX
Prototypes for C functions, Random-access memory Registers (continued)
409-410 (continued) control, 516
Prototyping, 335-337, 371, dual-ported, 434 counters using, 99-101
373-376 microcomputer use of, 24, 25 data (DO-—D7), 35, 36
PSAVE instruction (68851 only), OPTICRAM cameras, 439-440 data storage, 18
518 static (SRAM), 20, 348, defined, 18
PScc instruction (68851 only), 518 355-358 passing parameters in,
Pseudo-operations. See Assembler volatile nature of, 20 124-126
directives Random-access memory (RAM) pointers using, 99-101
Pseudocode disks, 449-450 shift, 18, 439
CASE structure, 47, 90 Raster-scan graphics, 432—437 stack pointer (SP), 35, 36
comparing strings, 107 Raster scanning, 425-426 status, 35, 36-38
~ data sampling, 119 RC snubber circuits, 284 supervisor stack pointer (SSP),
defined, 46 Read cycles for 68000 35, 36
divide-by-zero program, 203 instructions, 527-533 Relational operators in C,
downloading program, 481 Read-only memory (ROM) 398-399
factorials, 132 address decoding for, 180-182 Relays, 283-284
FOR-DO structure, 102—103 character-generator, 427-428 Relocatable programs, 65, 79
IF-THEN-ELSE structure, 47, described, 19-20 REPEAT-UNTIL structure, 46-48,
85, 86, 88, 89 electrically erasable 96-109, 403-405
IF-THEN structure, 47, 77 programmable (EEPROM), Repetition (iteration) operations
moving strings, 105 20 for programs, 46—48
password checking, 107 erasable programmable Reset (R) input, 17
REPEAT-UNTIL structure, 47, (EPROM), 20, 182 Reset exception, 202, 208,
96; 97; 99, 105, 107 mask-programmed, 20 212-214
sequence structure, 47 microcomputer use of, 24, 25 RESET instruction, 51, 157, 533,
strobed input, 97 nonvolatile nature of, 19 544
uploading program, 481 optical (OROM), 451 Reset line, 157
WHILE-DO structure, 47, 90, 92 programmable (PROM), 20 Residual error, 322
PSK (phase-shift keying) Read-only optical-disk systems, Resistor packs, 177, 178
modulation, 473-474 451 Retriggerable one-shots, 226-228
PTEST instruction, 518 Read/write head for magnetic Return address, 114
PTRAPcc instruction (68851 disks, 441-442 Return instructions, 50-51
only), 518 Read/write input, 20 RGB (red-green-blue) signals, 434,
Pulse-code modulation (PCM), 476 Read/write mechanism for optical 436-437
Punched cards, 6, 10 disks, 451 Richie, Dennis, 509
Push operations for stacks, Read-write memory. See Ring networks, 491, 494-496
122-124 Random-access memory RISC (reduced instruction set
PVALID instruction (68851 only), Read/write optical-disk systems, computer), 521
518 451 RMX 86 operating system (OS)
Pythagorean theorem, 367, Real (floating-point) numbers, 62, objects in, 513-514
417-418 361, 362-363 overview of, 513
Real-time clocks, 219, 238-240 structure of, 513
QAM (quaternary amplitude Recursive subroutines, 132-136 task execution with, 514-515
modulation), 473, 474 Red-green-blue (RGB) signals, 434, task-state diagrams for,
Quadbits, 473 436-437 514-515
Quaternary amplitude modulation Redirected data, 511-512 Robotics, 287-288, 335, 440-441
(QAM), 473, 474 Reduced instruction set computer ROL instruction, 50, 72,
Queues, 35-36 (RISC), 521 157-158, 531
Reentrant subroutines, 131-133, ROM. See Read-only memory
R (reset) input, 17 504 Root directory, 447, 510-511
RAM. See Random-access Refresh controllers, 20, 350 Root jobs, 513, 514
memory Regions in RMX 86, 514 ROR instruction, 50, 157-158, 531
Ramp generators (integrators), Register direct addressing mode, Rotate instructions, 50, 531, 550
294, 297 40 ROXL instruction, 50, 72, 158,
Random-access memory (RAM) Register variables in C, 411-412 531
address decoding for, 180, Registers ROXR instruction, 50, 158, 531
182-183 68000 instructions for, 49 RS-232C standard, 467-470
described, 20 accumulators, 27, 35, 36 RS-422A standard, 470-472
display refresh, 427, 428 address (AO—A7, A7’), 35, 36, RS-423A standard, 470
DRAM. See Dynamic 115, 117—1187 120-123 RS-449 standard, 472
random-access memory bounds, 149 RTD instruction, 51, 544
INDEX 569
RTE instruction, 51, 158, 533, Sensors (continued) Single-in-line package (SIP), 348,
544 temperature, 299-301, 324, 350
RTR instruction, 51, 158, 533, 326 Single operand instructions, 530
545 Sentinel character, 257 Single-precision numbers, 361,
RTS instruction, 50, 115, 116, Separator (gap), 442 362-363
158-159, 533, 544 Sequence structure, 46-48, Single-step command, 109
RUN command, 109-110 70-73 Single subroutines, 113, 114
Sequential list of tasks, 43-44 SIP (single-in-line package), 348,
S (supervisor state) flag, 37 Serial data communication. See 350
S (set) input, 17 also 8251A USART Slice, defined, 33
Saturation of operational asynchronous, 462 Soft exception vector table,
amplifiers, 297 baud rate for, 462 204-205
SBCD instruction, 50, 159, 532, data bits for, 462 Soft-sectored floppy disks, 442
547 full-duplex, 462 Software. See also Programs
Scale. See Microcomputer-based half-duplex, 462 defined, 25
scale marking state and, 462 emulation, 336
Scan code, 268 modems for. See Modems emulator, 66
Scc instruction, 50, 159, 530, 545 parity bit for, 462 upward-compatible, 34, 517
Scheduler, 504 RS-232C standard for, 467—470 Software breadboarding, 371
Scheduling, 504 RS-422A standard for, 470-472 Software considerations for
Schematic capture, 370-371, 372 RS-423A standard for, 470 interrupts, 214-215
Schematic diagrams RS-449 standard for, 472 Software interrupts, 200
connector symbol on, 177, 178 simplex, 461-462 Software-triggered strobes,
ICs on, 177, 178 start bit for, 462 229-230
input signal lines on, 369 stop bit for, 462 SOH (start-of-header) character,
jack (J) symbol on, 177, 178 synchronous, 462 487
output signal lines on, 369 Servo control of motors, 321-322 Solar cells, 299
plug (P) symbol on, 177, 178 Session layer (OSI model), 492 Solenoid drivers, 283-284
resistor packs on, 177, 178 Set (S) input, 17 Solid-state relays, 283-284
URDA MDS, 177, 178 Set points, 321-322 Source file, 64
zone coordinates for, 177, 178, Settling time, 322 Source-level debugger for C, 384
369 Shaft encoders Source program, 64 :
Scientific notation for numbers, absolute, 286—287 Sources for instructions, 39
362 defined, 286 SP (stack pointer), 35, 36
Scope (visibility) of variables in C, incremental, 287-288 Spark gap printers, 455
411-412 Shell file, 512 Speech recognition, 456, 457-458
Scramblers, 474 Shell of operating systems, 505, Speech synthesis, 251-253,
SDLC (Synchronous Data Link 507, 511-512 456-457
Control) protocol, 489 Shell script, 512 Spooling (simultaneous peripheral
Second-generation Shift and rotate instructions, 50, operation on line), 512
microprocessors, 32 53157550 Spurious interrupt, 202, 212
Secondary stations, 490 Shift registers, 18, 439 Square-wave generators, 228-229
Segment selectors, 508-509 Sign bit, 10-13 SRAM (static random-access
Segmentation of memory, Signals for processes, 511 memory), 20, 348, 355-358
508-509 Signed binary (base-2) numbers, SSP (supervisor stack pointer), 35,
Segments 10-13 36
pre-process, 510 Significand (mantissa) of Stack diagrams, 117-118,
RMX 86, 513 numbers, 362 130-131, 135-136, 446-447
Selection flowchart symbol, 44, 45 Simple input/output (I/O), 243, Stack management instructions,
Selection (decision) operations for 244 49
programs, 46—48 Simple strobe input/output (I/O), Stack overflow, 130-131
Selectric code, 6—9 243-244 Stack pointer (SP), 35, 36
Semaphores, 161, 504—506, 514 Simplex communication, 461—462 Stack underflow, 131
Semiconductor temperature Simulation programs, 336 Stacks
sensors, 299, 300 Simulators, 371, 373-376 68000, 115, 117-118
Sensitive (privileged) instructions, Simultaneous peripheral operation 68881, 363, 365
37-38, 51 on line (spooling), 512 allocation of space on, 153
Sensors. See also Transducers Single-density recording for disks, bottom of, 37, 117-118
defined, 293 442-443 defined, 36, 115
flow, 302, 304 Single-handshake input/output down (toward lower addresses),
light, 298-299 (I/O), 244 118
570 INDEX
Stacks (continued) Stubs (dummy subroutines), Switched-capacitor filters, 338
exception (group 0), 213 139-140 Switched telephone lines, 462
initialization of, 117 STX (start-of-text) character, 487 Symbol table, 64, 65
last in, first out (LIFO) operation SUB instruction, 49, 160, 529, Sync characters, 486—487
of, 122-123 547 Synchronized tasks, 514
links on, 153, 162 SUBA instruction, 49, 160, 547 Synchronous addressing mode,
passing parameters using, 126, Subdirectories, 447 168
128-131 SUBI instruction, 49, 160, 530, Synchronous communication, 462
pop operations for, 123-124 538 Synchronous Data Link Control
push operations for, 122-124 Subprograms. See Subroutines (SDLC) protocol, 489
reentrant subroutines and, SUBQ instruction, 49, 160-161, Syndrome words, 359-360
132-133 530, 546 Syntax of assembly language, 52
- system, 117-118, 120-123 Subroutines System (status register) byte,
top of, 36, 37, 117-118, arguments (parameters) of, 124 37-38
120-123 BSR instruction for, 114-115, System control lines, 168—169
up (toward higher addresses), 116 System controller, 169
118 data in module separate from, System degradation, 504
user, 117 136-139 System program, 52
word aligned, 153 debugging programs with, System stack, 117-118, 120-123
Standard input files, 511 139-140
Standard instructions, 529 defined, 113 T (trace) flag, 37, 202, 210
Standard output files, 511 dummy (stubs), 139-140 Tachometers, 321-322
Standard programming flowchart symbol for, 44—45 Tag bits, 356-359
structures, 46—48 JSR instruction for, 114, 115 Tape reader (paper), 248-251
Star networks, 491 macros versus, 140, 141 TAS instruction, 51, 161, 530,
Start bit, 462 nested, 113-114 543
Start flowchart symbol, 44 passing parameters to and from. Tasks. See also Processes
Start-of-header (SOH) character, See Parameter passing blocked, 504
487 program flow for, 113-114 defined, 504
Start-of-text (STX) character, recursive, 132—136 mutual exclusion of, 505, 506
487 reentrant, 131-133, 504 RMX 86, 513-515
Statements in programs, 46, 52, RTS instruction for, 115, 116 semaphores and, 514
53 single, 113, 114 sequential list of, 43-44
States, undefined, 222-223 stacks and. See Stacks synchronized, 514
Static displays, 268-270 Subtraction TDM (time-division multiplexing),
Static random-access memory 68000 instructions for, 49 476-477
(SRAM), 20, 348, 355-358 binary, 12, 13 Temperature sensors, 299-301,
Static variables in C, 411-412 binary-coded decimal (BCD), 15, 324, 326
Status register, 35, 36-38 159 Templates for instructions, 54-58
Status register (system) byte, hexadecimal, 15 Terabyte (unit), 33
37-38 octal, 14-15 Terminals, 426, 433
Stepper motors, 285-286 SUBX instruction, 49, 161, 532, Termination flowchart symbol, 44,
Stop bit, 462 547 45
Stop flowchart symbol, 44, 45 Successive-approximation Text characters, 487
STOP instruction, 51, 159-160, analog-to-digital converters, Thermal printers, 454-455
533, 544 308, 309, 310 Thermocouples, 299-302
Storage classes in C, 386, 387, Summing point, 296 Thin Ethernet (10BaseT)
411-412 Supercomputers, 520-521 networks, 493
Strain gages, 301, 303 Supersets of instructions, 34, Thompson, Ken, 509
Streaming tape systems, 451 516-517 Thrashing, 357
Strings Supervisor for scheduling tasks, Three-state outputs, 19-20
C library functions for, 416 504 Time base for timing interrupts,
comparing, 106-109 Supervisor stack pointer (SSP), 35, 219-220
defined, 105 36 Time-division multiplexing (TDM),
moving, 105-106 Supervisor state, 37, 505 476-477
Strobes Supervisor state (S) flag, 37 Time-slice scheduling, 504
data, 168, 169 Suspended processes, 510 Time steps, 373
hardware-triggered, 230-231 SWAP instruction, 50, 161, 533, Timed interrupt generators,
keyboard input with, 96-98 542 227-229
software-triggered, 229-230 Swapped processes, 510 Timers
Structured programming, 45-48 Switch structure in C, 402—403 555, 218-219
INDEX 571
Timers (continued) Timing waveforms (continued) UDI (universal development
8253, 220 DRAM read cycle, 348, 350, interface), 513
8254. See 8254 programmable 351 Ultrasonic vision, 438—439
timer/counter phoneme transfer, 251-253 Unconditional jumps, 78-82
Timesharing systems, 30-31 simple I/O, 243, 244 Undefined states, 222—223
Timing simple strobe I/O, 243-244 Underdamped response, 322
68000 instructions, 104-105, single-handshake I/O, 244 Underflow of stacks, 131
527-533 TMS-1000 family of dedicated Undots, 427
bit manipulation instruction controllers, 33 Unipolar binary-coded decimal
execution, 531 Toggling of JK flip-flops, 18 (BCD) codes, 308-310
cathode-ray tube (CRT) displays, Token (file handle), 448 Unipolar binary codes, 308, 310
428-429 Token-passing ring networks, Unity-gain bandwidth, 296
conditional instruction 491, 494-496 Universal asynchronous receiver
execution, 532 Top-down design, 45, 48, 113 transmitter (UART), 462
delay loops for, 104—105, Top of stacks, 36,.37, 117-118, Universal development interface
118-124, 156 120-123 (UDI), 513
effective address (EA) Topologies Universal
calculation, 527 hypercube, 520-521 synchronous/asynchronous
exception processing execution, for networks, 491—492 receiver-transmitter (USART),
533 Trace (T) flag, 37, 202, 210 175, 462. See also 8251A
immediate instruction Trace data, 66, 109, 195, 196 USART
execution, 530 Trace exception, 202, 208, 210 UNIX operating system (OS)
interrupts for, 218-219 Trace handler, 202, 210 applications/utilities layer of,
JMP, JSR, LEA, MOVEM, and Train printers, 454 505, 507, 512-513
PEA instruction execution, Transducers. See also Sensors directory structure of, 510-511
532 defined, 301 file locking in, 497
miscellaneous instruction force, 301-303 file structure of, 510-511
execution, 533 pressure, 301-303 history of, 509-510
MOVE instruction execution, Transistor buffers, 282—283 kernel of, 505, 507, 510-511
528 Transistors, Darlington, 282—283 layers of, 505, 507, 510
multiprecision instruction Transport layer (OSI model), 492 onionskin diagram for, 505, 507
execution, 532 Trap (exception), 149 shell of, 505, 507, 511-512
shift/rotate instruction Trap-generating instructions, 51 UNLK (unlink) instruction, 49,
execution, 531 TRAP instruction, 51, 161-162, 153, 162, 504, 533, 543
single operand instruction 202, 208, 214, 533, 543 Unpacked binary-coded decimal
execution, 530 Traps (BCD) code, 70-73
standard instruction execution, CPU, 38, 149, 161-162 Uploading programs, URDA
529 illegal instruction, 152 MDS-to-Macintosh, 481—486
Timing parameters for the 68000, Macintosh operating system Upward-compatible software, 34,
187-192 (OS), 448-449 517
Timing waveforms TRAPV instruction, 51, 162, 202, URDA MDS. See also
6821 handshake data input 208, 210, 211, 533, 545 Microcomputer-based
from a tape reader, Tree-structured (broadband-bus) industrial process-control
249-250 networks, 491-492 system; Microcomputer-based
8237A DMA transfer, 346, 348 Trellis code, 474 scale
8254 modes, 225-231 Triacs, 284 7-segment display interfacing
8279, 272-273 Trigger signals, 194-195 with, 271-274, 277-279
68000 interrupt-acknowledge, Triplexed displays, 280 7-segment LCD interfacing
PIF, ONS Troubleshooting microcomputers, with, 280, 281
68000 read-cycle, 187-189 139-197, 74LS138 address decoder use
68000 read-modify-write-cycle, TST instruction, 50, 162, 530, of, 221-222
174, 175 543 8254 added to, 220-222
68000 word- and Two-key lockout for keyboards, 8259A(s) added to, 220-222
byte-read-cycle, 171-172 262, 274 address decoding for, 180-186
68000 word- and Two-key rollover for keyboards, block diagram of, 174-176, 178
byte-write-cycle, 172-173 267, 274 debugger program of, 66
68000 write-cycle, 190 Type byte, 61, 62 display driver for, 277-279
Centronics parallel interface, Type long word, 61, 62 downloading programs to,
255 Type word, 61, 62 65-66, 481-486
data acquisition system, 326, I/O port addresses of, 185
327 UART (universal asynchronous indirection routines for,
double-handshake I/O, 244-245 receiver transmitter), 462 204-205
Sls INDEX
URDA MDS (continued) Variables (continued) Voltage gain, 293-296
initialization list for, 51-52 char (character) in C, 385-387 Votrax SC-01A phoneme speech
keypad interfacing with, dummy, 141 synthesizer, 251-253
271-274 extern (external), in C, 386,
.W (word) suffix, 40, 61, 62
memory map of, 35, 185 387, 411-412
Wait states, 527
monitor program of, 66 float (floating-point), in C,
Waveform-modulation speech
overview of, 174-178 388-389
synthesis, 456-457
photograph of, 174, 175 global, in C, 386, 387, 411-412
WHILE-DO structure, 46-48, 90,
port address decoding for, 180, int (integer), in C, 387-388
92-96, 403-404
183-186 lifetime of, in C, 411-412
While structure in C, 403-404
RAM address decoding for, 180, local, in C, 386, 387, 411-412
Winchester hard disks, 450
182-183 register, in C, 411-412
Word (16 bits), 1
~ RAM addresses of, 119, 185 scope (visibility) of, in C,
Word (.W) suffix, 40, 61, 62
ROM address decoding for, 411-412
Word aligned stacks, 153
180-182 static, in C, 411-412
Word-type operand, 40
ROM addresses of, 185 Vector graphics, 437-438
Words
schematic diagram of, 177, 178 Vector-scan cathode-ray tube
binary. See Binary words
start address for RAM on, 119, (CRT) displays, 437-438
defined, 1
185 Vectors, exception (interrupt),
extension, 57—58
start address for user code, 119 201, 202, 204—205
syndrome, 359-360
troubleshooting, 189-197 Vertical (perpendicular) recording,
Write cycles for 68000
uploading programs from, 444
instructions, 527-533
481-486 Vertical sync pulse, 426-428
Write-once/read optical-disk
user code start address on, 119 Video cameras, 439
systems, 451
USART (universal Video information, 425, 427
synchronous/asynchronous Video monitors, 426 X (extend) flag, 37, 76-77
receiver-transmitter), 175, Video signals, composite, 426, XDEF (external definition)
462. See also 8251A USART 427, 434, 436-437 directive, 136, 137, 164
User bytes (status register), 36-37 Vidicons, 439 Xerographic printers, 455
User interrupts, 202 Virtual addresses, 508, 509 XMODEM protocol, 487-488
User stack, 117 Virtual ground, 296 XOR (exclusive or) logic gates, 16,
User state, 37, 505 Virtual memory NZ
User tables, 510 68010 implementation of, 34 XREF (external reference)
demand-paged, 509 directive, 136, 137, 164
V (overflow) flag, 37, 77 segmentation approach for, 508
Variable declarations in C, Visibility (scope) of variables in C, Z80 microprocessor, 33
385-389 411-412 Zero (Z) flag, 37, 77
Variable types in C, 385-389 Vocal tract model, 456 Zero divide interrupt, 202—208
Variables Voice coil mechanism, 450 Zone bits, 6
automatic, in C, 386, 387, Voiced sounds, 456 Zone coordinates, 177, 178, 369
411-412 Volatile memory, 20 Zone punches, 6, 10
INDEX 573
»
~ : :
ise
— ~ i] > Fy “
ee
ae
- Jae
i 7 i
a Sa e\
rant Leura Li
ae | os AA i Ox 7 7
| ara : tnd
thy ee ik
j a4 i +h ’. em eked
et
a 2
iene 2 beSie tbe Skt
re ae ae
enamel
nae |
: SP apa SPP.» er naar
ie ear, ee al ik Jr tats i ses
“ i:AngII) ox wks Ee os
4 Se Patewcor
Macmillan/McGraw-Hill
ISBN O-0O?-0O256591-8
oe kc a I
9 "780070'256910 | |