Intro To Microprocessor
Intro To Microprocessor
eft
VOLUME
I
BASIC CONCEPTS
Copyright
1976 by
Adam
Is! Prinlinq.
2nd
Printing
1977
o!
AH
in
reproduced stored
ars.
a retrieve
system
cr transmitted
Published by
P.O.
Associates, Incorporated
California
94702
For ordering and pricing information outside the U.S.A., please contact:
SYBFX (European
313
Flue
Distributor)
Lraiurbe
F-/501S Pare
Franco
ARROW
INTERNATIONAL (Japanese
Distributor
English Translation)
LA.
VARAH LTD
10.
(Canadian Distributor)
Vancouver
B.C.
CanadD Taiwan Foreign Language Book Publishers Council P.O Box 1444 Taipei, Taiwan
TABLE OF CONTENTS
CHAPTER
1
PAGE
WHAT
IS
A MICROCOMPUTER
1-1
1-1
1-4 1-6
1-6
ABOUT
THIS
HOW
THIS
2-2
2-4
2-5 2-5 2-5 2-7 2-7 2-7
"AND" OPERATION "EXCLUSIVE OR" OPERATION "NOT" OPERATION COMBINING LOGICAL OPERATIONS DE MORGAN'S THEOREM
THE MAKINGS OF A MICROCOMPUTER
2-10
3-1 3-1
3-3
3-4 3-4
MEMORY ADDRESSES
INTERPRETING THE CONTENTS OF
MEMORY WORDS
3-10
3-11
STAND ALONE PURE BINARY DATA INTERPRETED BINARY DATA CHARACTER CODES INSTRUCTION CODES
THE MICROCOMPUTER CENTRAL PROCESSING UNIT
3-12
3-20 3-22
4-1 4-1
CPU REGISTERS HOW CPU REGISTERS ARE USED THE ARITHMETIC AND LOGIC UNIT THE CONTROL UNIT STATUS FLAGS
INSTRUCTION EXECUTION INSTRUCTION TIMING INSTRUCTION CYCLES
4-4
4-11
4-11
INSTRUCTION DO?
4-25
PAGE
4-31
5-5
5-8
PROGRAMMED
INTERRUPT I/O
I/O
5-8
5-14 5-18
5-22
5-26 5-34
5-37
5-41
SIMULTANEOUS DMA SIMULTANEOUS VERSUS CYCLE STEALING THE EXTERNAL SYSTEM BUS SERIAL INPUT/OUTPUT
IDENTIFYING SERIAL TELEPHONE LINES
5-45
DMA
5-47 5-47
5-48
5-49
DATA
BITS
5-54
5-55 5-55 5-56
5-57
SYNCHRONOUS SERIAL DATA TRANSFER SYNCHRONOUS TELEPHONE PROTOCOL ASYNCHRONOUS SERIAL DATA TRANSFER SERIAL I/O COMMUNICATIONS DEVICE DUAL IN-LINE PACKAGE SIZE
LOGIC DISTRIBUTION
THE CPU-SERIAL I/O DEVICE INTERFACE THE SERIAL I/O INTERFACE SERIAL I/O CONTROL SIGNALS MODEM CONTROL SIGNALS CONTROLLING THE SERIAL I/O INTERFACE DEVICE ADDRESSING THE SERIAL I/O INTERFACE DEVICE REALTIME LOGIC
LOGIC DISTRIBUTION
5-62 5-65
5-66
AMONG MICROCOMPUTER
DEVICES
5-70
PAGE
PROGRAMMING MICROCOMPUTERS
THE CONCEPT OF A PROGRAMMING LANGUAGE SOURCE PROGRAMS OBJECT PROGRAMS CREATING OBJECT PROGRAMS PROGRAM STORAGE MEDIA
6-1
6-1
6-2 6-3
6-4
6-5
6-5 6-6
6-11
MEMORY ADDRESSING
MICROCOMPUTER MEMORY ADDRESSING
IMPLIED MEMORY ADDRESSING DIRECT MEMORY ADDRESSING DIRECT VERSUS IMPLIED ADDRESSING
WHERE
6-12
IT
BEGAN
6-12 6-13
6-14 6-14
6-15 6-18
VARIATIONS OF DIRECT MEMORY ADDRESSING PAGED DIRECT ADDRESSING DIRECT MEMORY ADDRESSING IN MICROCOMPUTERS
6-24
6 32 6 32 6 . 32 6-34
MEMORY STACKS THE CASCADE STACK HOW A STACK IS USED NESTED SUBROUTINES AND USE OF THE STACK INDIRECT ADDRESSING
A PAGED COMPUTER'S INDIRECT ADDRESSING PROGRAM RELATIVE INDIRECT ADDRESSING
INDIRECT ADDRESSING
6-34
6-37 6-38 6-38
6-41
6 _ 42
MINICOMPUTERS VERSUS
...
MICROCOMPUTERS
INDEXED ADDRESSING
6 . 44
6-48
7_
y
'
AN INSTRUCTION SET
CPU ARCHITECTURE STATUS FLAGS ADDRESSING MODES A DESCRIPTION OF INSTRUCTIONS INPUT/OUTPUT INSTRUCTIONS MEMORY REFERENCE INSTRUCTIONS SECONDARY MEMORY REFERENCE (MEMORY REF^RCNC^
OPERATE) INSTRUCTIONS LOAD IMMEDIATE INSTRUCTIONS JUMP AND JUMP-TOSUBROUTINE IMMEDIATE OPERATE INSTRUCTIONS BRANCH ON CONDITION INSTRUCTIONS REGISTER-REGISTER MOVE INSTRUCTIONS REGISTER-REGISTER OPERATE INSTRUCTIONS
7 _1 7.4
7_4
7.5
7.5 7_8
7 _ 15
7 _ 19
7_23
7_25
7.3
7-32
PAGE
7-36
A-1
LIST OF FIGURES
FIGURE
1-1
PAGE
A
Microcomputer Chip And DIP
Digits
xvii
2-1
A
A
2-1
3-1
4-1
Memory
Device
3-5
Functional Representation Of
Control Unit Signals For
Register. Arithmetic
Control Unit
4-12
4-37
4-2
Simple Microcomputer
Slice
4-3 4-4
5-1
And
4-50
Two
4-Bit
ALU
Slices
Concatenated To Generate
An
8-Bit
ALU
4-51
5-2 5-3
5-5
5-2
Read-Only Memory Chip Pins And Signals ROM And CPU Connected Via External Data Bus Read-Write Memory Chip Pins And Signals
RAM
(Without
RAM
Interface).
External Data
Bus
RAM Interface. ROM And CPU Chips Connected A Single Port, Parallel I/O Interface Device A Two-Port. Parallel I/O Interface Chip
Parallel
5-7
5-10
5-11
5-8
5-9
5-13 5-15
5-10
Microcomputer Controlling The Temperature Of Shower Water An External Device Using An Interrupt Request To Let The
Microprocessor
Know
That Data
Is
"
Ready To Be Input
5-11
5-17
5-12
An
External
And ROM Chips To Handle Interrupts Device Using An Interrupt Request And A
5-23
Device Identification Code To Let The Microcomputer Know That Data Is Ready To Be Input
5-24
5-27
5-13 5-14
5-15 5-16
5-17
An An
5-30
5-35 5-42 5-46
5-71
Memory Access
DMA
Using
Device Controlling
DMA
Data. Address
Serial
And
Control Paths
5-18
6-1
A A
6-2 6-3
An
Source Program Written On Paper Object Program On Paper Tape Paper Tape Source Program
.
6-3
6-3 6-4
LIST
TABLE
2-1 3-1
OF TABLES
PAGE
Number Systems
Computer Word Sizes Signed Binary Numeric
2-4 3-3
Interpretations
3-2 3-3
4-1
3-14
3-17 4-37
'
4-2
When C0 =
Or C1 =1
4-3
4-4 4-5
An
Instruction Fetch
Microprogram
4-6
4-7 4-8
4-9
Accumulator Microprogram Three-Instruction Memory Read One Instruction To Load 16-Bit Address Into Data Counter Single Instruction, Direct Addressing, Memory Read ALU Sources As Defined By The Low Order Three
Microinstruction Bits
A Complement
4-43
4-51
4-10
4-1 5-1
7-1
ALU ALU
Serial
Bits
4-53 4-54
5-67 7-55
I/O
Mode
Parameters
A Summary
QUICK INDEX
INDEX
PAGE
ABSOLUTE BRANCH
4-30
4-1
ACCUMULATOR ACCUMULATOR DATA COUNTER ADDITION ADD ADD BINARY ADD DECIMAL ADD IMMEDIATE ADD OPERATION SIGNALS AND TIMING ADDRESS BITS THE OPTIMUM NUMBER
-
7-24
4-22
61
7-33
7-24
7-37
6-6
ASSEMBLER ASSEMBLER DIRECTIVES - THEIR VALUE ASSEMBLY LANGUAGE INSTRUCTION MICROPROGRAMS ASYNCHRONOUS EVENTS AUTO DECREMENT AUTO INCREMENT AUTO INCREMENT AND SKIP JUSTIFICATION AUTO INCREMENT OR DECREMENT JUSTIFICATION
v
7-23
4-41
7-17
2-2
5-57
3-1
BOOLEAN LOGIC JUSTIFIED BRANCH INSTRUCTION BRANCH ON CONDITION INSTRUCTION JUSTIFICATION BRANCH ON LESS EQUAL OR GREATER BRANCH ON WHAT CONDITIONS? BRANCH PHILOSOPHY BRANCH TABLE BRANCHING AT PAGE BOUNDARY
BYTES AND
C
WORDS
4-30 3-4
4-58 4-59 4-58
QUICK INDEX
INDEX
CARRY PROPAGATION CARRY STATUS CHARACTER SETS
CHIP
(Continued)
PAGE
4-58
4-12, 4-58
3-20
1-1
4-53
4-52
4-52 4-54 4-44 7-40 7-36
5-49. 5-53
AND
LOGIC UNIT
5-63
COMMENT
COMPARE
FIELD
6-10
7-15,7-17
7-33
COMPARE IMMEDIATE COMPLEMENT COMPLEMENT MICROPROGRAM COMPUTED JUMP COMPUTER HOBBYISTS THE CONCEPT OF AN INTERRUPT CONDITIONAL RETURN FROM SUBROUTINE
CONVERTING FRACTIONS CPU CPU OPERATE INSTRUCTIONS CPU PINS AND SIGNALS CPU REGISTERS SUMMARY
CYCLIC
7-24
7-36, 7-40
4-41
7-31
1-4
4-29 4-18
7-4
REDUNDANCY CHARACTER
I/O INTERFACE DEVICES
5-55
5-31
4-3, 7-1
4-49 7-17
2-2
7-40
6-12
7-35
6-12
1-1
5-32
4-27, 7-9
7-13
7-50 5-39
5-39
5-41
DMA END
QUICK INDEX
INDEX
(Continued)
PAGE
EXECUTION
INITIALIZATION
5-39
WRITE TIMING
5-38 5-40
3-7
DYNAMIC RAM
EDITORS EFFECTIVE ADDRESS EFFECTIVE MEMORY ADDRESS ENABLE INTERRUPT
' END DIRECTIVE EQUATE ASSEMBLER DIRECTIVE EQUATE DIRECTIVE EXCHANGE EXCLUSIVE OR
6-4
6-47
6-19 7-50
6-11
7-22
6-11. 7-35
7-32
7-15. 7-19
7-33 6-24
5-1
4-22
FIELD IDENTIFICATION
FLOATING BUSSES
G
H
GROUND
HALF DUPLEX HANDLING AN INTERRUPT REQUEST
HEXADECIMAL NUMBERS
IMMEDIATE INSTRUCTIONS JUSTIFICATION IMMEDIATE OPERATE INSTRUCTIONS JUSTIFIED IMPLIED ADDRESSING INCREMENT AND DECREMENT INCREMENT AND SKIP INCREMENT REGISTER
INDEX REGISTER INDIRECT ADDRESS INDIRECT ADDRESS COMPUTATION INDIRECT AUTO INCREMENT AND DECREMENT INDIRECT VIA BASE PAGE
7-19
7-24
7-9
7-36
7-10 7-40
6-45
6-38
-38
-41
-40
-37
-6
7-6
4-18 4-17
4-19 4-3
>
QUICK INDEX
INDEX
(Continued)
PAGE
INSTRUCTIONS INTERMEDIATE CARRY STATUS INTERRUPT ACKNOWLEDGE INTERRUPT ADDRESS VECTOR INTERRUPT PRIORITIES AND WHAT THEY MEAN INTERRUPT PRIORITY AND DAISY CHAINING INTERRUPT PRIORITY AND MULTIPLE REQUEST LINES INTERRUPT PRIORITY CHIP INTERRUPT REQUEST INTERRUPT SERVICE ROUTINE INTERSIL IM6100
I/O I/O I/O
4-4
4-13
5-16. 7-50
5-19 5-26
PORTS I/O PORTS ADDRESSED USING MEMORY ADDRESS LINES I/O STATUS ISOSYNCHRONOUS SERIAL I/O
5-10 5-12
5-67 7-22
4-30, 7-20
7-22. 7-23
JUMP JUMP INSTRUCTION JUMP TO SUBROUTINE JUMP TO SUBROUTINE INSTRUCTION JUMP TO SUBROUTINE ON CONDITION
LABEL FIELD LARGE SCALE INTEGRATION LITERAL OR IMMEDIATE DATA
7-44
7-21
7-30
6-7
1-3
4-6
7-8
IMMEDIATE
IMPLIED
LOAD/STORE WITH AUTO INCREMENT AND SKIP LOAD/STORE WITH AUTO INCREMENT OR DECREMENT
MACROINSTRUCTION COMPLEXITY MACROINSTRUCTIONS MACROLOGIC MARKING MEDIUM SCALE INTEGRATION
MEMORY MODULE MEMORY READ SIGNALS AND TIMING MEMORY WRITE SIGNALS AND TIMING MICROCOMPUTER MEMORY CONCEPTS
MICROCOMPUTER SYSTEM BOUNDS MICROINSTRUCTION BIT LENGTH
MICROINSTRUCTIONS
3-6
4-21
4-22
3-5
5-8
4-39 4-34
QUICK INDEX
INDEX
(Continued)
PAGE
MICROPROCESSOR MICROPROCESSOR SLICE MICROPROGRAM COUNTER MICROPROGRAM SEQUENCER LOGIC MICROPROGRAMMABLE MICROCOMPUTER
4-1
MICROPROGRAMS
MINICOMPUTER MEMORY CONCEPTS
4-34 3-5
6-6
MNEMONIC
FIELD
MODEM
MOVE
MULTIBYTE ADDITION MULTIBYTE BINARY ADDITION MULTIBYTE BINARY SUBTRACTION MULTIFUNCTION DEVICES MULTIPLE STACKS MULTIPLEXED LINES MULTIWORD BINARY DATA MULTIWORD SIGNED BINARY NUMBERS
NEGATIVE BCD DATA
NIBBLES
5-48
7-32
7-17
3-12
3-13
5-34
7-31
5-20
3-12 3-16 3-16
3-4
3-1
NON VOLATILE MEMORY NUMBER OF LOAD AND STORE INSTRUCTIONS NUMBER OF REGISTERS
OCTAL NUMBERS ONES COMPLEMENT OPERAND FIELD OR OR IMMEDIATE
ORIGIN DIRECTIVE
7-9
7-1
2-4
2-6
6-8
7-15, 7-33
7-24
6-11. 7-35
OUTPUT LONG OUTPUT SHORT OVERFLOW STATUS OVERFLOW STATUS SET STRATEGY
PACKING
ASCII DIGITS
7-7 7-7
4-14, 4-55
4-16 7-43
PAGE BOUNDARY ERROR PAGE NUMBER PAGED DIRECT ADDRESSING PAPER TAPE PARAMETER PASSING
PARITY PARITY BITS PARITY STATUS
6-20
6-19 6-30
6-3
7-46 3-20
5-55. 5-60
QUICK INDEX
INDEX
POP
POST-INDEXING POWER FAIL INTERRUPT POWER SUPPLIES PRE-INDEXING
(Continued)
PAGE
6-33, 6-34.
7-44
6-47
5-31
-19
-46
-6
PRIMARY ACCUMULATOR PROGRAM COUNTER PROGRAM LOOP PROGRAM RELATIVE BRANCH PROGRAM RELATIVE PAGING PROTOCOL IN SERIAL DATA
PUSH
-3
-28
-30
6-22 '5-54
6-33, 6-34,
7-44
RAM RAM
.
3-2
CHIP
MEMORY
SIZE
3-7
RECURSIVE SUBROUTINES REFERENCING DATA TABLES REGISTER BLOCK REGISTER TO REGISTER MOVE INSTRUCTIONS JUSTIFIED REGISTER TO REGISTER OPERATE INSTRUCTIONS JUSTIFICATION RESTORING REGISTERS FROM STACK RETURN FROM INTERRUPT RETURN INSTRUCTIONS
6-37
4-28
4-49
7-31
7-33
7-52 7-50 7-45
7-44
3-2 5-2
ROM ROM
DEVICE SELECT
ROTATE
SAVING REGISTERS AND STATUS SAVING REGISTERS ON STACK SECONDARY MEMORY REFERENCE INSTRUCTIONS
JUSTIFICATION
7-37
5-18
7-51
7-17
5-21
'
HANDSHAKING
INPUT
OUTPUT
RECEIVING CLOCK SIGNAL TRANSMITTING CLOCK SIGNAL
COMMANDS
ERROR CONDITIONS
5-67
5-67 5-68
5-67 5-65
I/O INPUT
CONTROL SIGNALS
MODE
CONTROL
5-65 5-57
QUICK INDEX
INDEX
(Continued)
PAGE
SERIAL TRANSMIT CONTROL SIGNALS SERIAL XI CLOCK SIGNAL SERIAL X16 CLOCK SIGNAL SERIAL X64 CLOCK SIGNAL
5-65
5-&
5-53 5-53
1-3
ROTATE ROTATE INSTRUCTIONS ROTATE THROUGH CARRY SHIFT ROTATE WITH BRANCH CARRY SHIFT MULTIBYTE SHIFTING BINARY CODED DECIMAL DATA SIGN OF ANSWER IN SUBTRACTION SIGN PROPAGATION SIGN STATUS SIGNAL SETTLING DELAY
SHIFT SHIFT
SHIFT SHIFT
7-36
7-36 7-40
7-37 7-37
7-41
7-38
2-7
4-31
4-13. 4-54
5-51
SIGNAL SETTLING TIME SIGNED BINARY NUMBERS SIMPLE SHIFT AND ROTATE SIZE OF CHIP SELECT
5-50 3-14
7-37
3-9 3-8
7-26
6-32
5-59
3-7
STATIC
RAM
STATUS IN MICROPROGRAMS STATUS RESET STATUS SET STOP BITS STORE STORE DIRECT STORE IMPLIED SUBROUTINE CALL SUBROUTINE PARAMETER PASSING SUBROUTINE PARAMETERS SUBROUTINE RETURN SUBROUTINES SUBTRACT DECIMAL SWITCH CHANGE TESTS SWITCH TESTING SYNC CHARACTER
TELETYPE SERIAL DATA FORMAT TENS COMPLEMENT TRI-STATE BUFFER TRUTH TABLES TWELVE-BIT WORD DIRECT ADDRESSING
4-41
7-53
7-53
5-59. 5-60
7-8
7-10 7-10
6-35 7-44 7-46 6-36
6-34. 7-22
7-15, 7-33
5-60
2-5
5-47
2-8
6-15
QUICK INDEX
INDEX
(Continued)
PAGE
TWOS COMPLEMENT
V
VOLATILE
2-6
3-1
MEMORY
MODIFIED
W
Z
4-13
3-3
-4-13,4-55
figure 1-1
microcomputer is a logic device. More precisely, it is an indefinite variety of implemented on a single chip; and because of the microcomputer, logic design will never be the same again.
The word "microprocessor" is also widely used in conjunction with microcomputers. The term "microprocessor" was coined to reflect the limited functions of these devices as compared to computers; a microprocessor, therefore, represents something less than a microcomputer. Current trends have blurred the distinction between "microprocessors" and "microcomputers"; therefore in this book we use only the term "microcomputer", identifying logic implemented on chips by
specific function
using
a
traditional terminology.
|
microcomputer. The logic of the microcomputer is on a chip, which is mounted in a Dual In-Line Package (DIP). We refer to the DIP as a logic device, as opposed to the silicon wafer, which is a logic chip.
Figure
1-1
illustrates
_____
\
CHIP
DEVICE
imply.
The microcomputer
is
name would
There are, indeed, striking similarities between microcomputers and other comvia instruction sets, puters. The established method of comparing computers makes some microcomputers look so addressing modes and execution speeds similar to other computers that any distinction between the two products appears to be a distinction in search of a difference.
But microcomputers are a new and different product, and that is why the established method of comparing computers does not apply to microcomputers. Instruction sets, addressing modes and execution speeds are of secondary importance to the microcomputer user. The distribution of logic on chips and the price of microcomputer devices are the comparisons of primary importance; and it is these comparisons that set microcomputers apart from all other types of computer, as a new and different product.
The purpose
addition;
of this
book
is
why
to explain not only what microcomputers are but, in in a way that differs so markedly from prior
The book does not assume you understand how computers work; therefore, computer concepts are described, beginning with
first principles.
other computers share a common ancestor, however. To acquire a little perspective, we will therefore begin with a short history of computer evolution and identify the origins of the microcomputer.
Microcomputers and
all
1-1
UNIVAC
limited
1,
for a very
of "expense-is-no-object" applications, frequently to solve mathematical problems that might otherwise be impossible to solve.
number
logic was not particularly well suited to scientific apwas the immediate and natural consequence of being built out of
digital
computer.
Indeed, the basic concepts for the design of a computing machine go all the way back to Charles Babbage, who in 1833 laid out the concepts that can be found, with minor variations, in every digital computer built today. In Chapters 2 and 3 we describe these basic concepts concepts that allow computing logic to be built out of binary digits, irrespective of how the computer will be used.
What we
been no
is that since the dawn of the computer industry, there have breakthroughs in the basic concepts of computing. It is advances in solid state physics that have been the computer industry's evolutionary force. New electronic technology has caused computer prices to fall so rapidly that every few years entire new markets have been engulfed by computers.
are saying
radical
In 1960 computer prices had declined to the point where they could be used for data processing, and the day of the general purpose computer had arrived.
1965 the PDP-8, at $50,000, brought computers into the laboratory and the manufacturing plant's production line; and the minicomputer industry was born. Today minicomputers cost as little as $1,000, and their sphere of influence has spread as prices have come down.
In
where
But microcomputer prices range from $5 to $250 and we have entered an era a computer can control a washing machine or an oven, or it can be a component in consumer products that are mass merchandised.
are the advances in solid state physics that
is
What
fifties
we
speak of?
was
a bulky device with expensive internal elements. In the late replaced by the transistor, a small piece of germanium metal, suitably
doped with
impurities.
Soon an array
of discrete,
available;
signal inverter:
An AND
gate:
o
gate:
D>
AB
An OR
gate:
r>
A+B
An EXCLUSIVE OR
>
as a single,
AB+AB
A NOT AND
but instead
was designed
new NAND
gate:
AB
*" b
1-2
Four
single
into
one chip (costing the same as. or little more than, a quadruple 2-input positive-NAND buffer:
affectionately
Devices such as the quadruple 2-input positive-NAND buffer spawned a whole range of devices, known, by a generation of logic designers, as 7400 series integrated circuits.
Indeed, the
7400
had as deep an impact on the electronics because 7400 series integrated circuits converted a
---
generation of "circuit designers" into a generation of "logic designers" occurred almost overnight.
Four gates on one chip became ten, and then a hundred, and then a thousand; today ten thousand gates worth of logic can be implemented on a single silicon chip, and the end is by no means predictable, or even in sight.
chip with a number of gates on it is called an integrated cirIf there are approximately 100 to 1000 gates on a chip, we refer to the logic as Medium Scale Integration (or MSI). At some
cuit.
7400
INTEGRATED
CIRCUITS
ill-defined level,
logic
on a chip,
The
interesting aspect of integrated circuits is that the cost of a chip is a function of physical size it is not a function of how
much
chips
logic
LARGE SCALE
INTEGRATION
Two
1
clarified:
not,
2)
is
so inexpensive,
why
has
not eliminated
all
other com-
all, the whole computer cannot shrink; only the electronics can. What remains is the human interface consoles and switches, means for accepting data inputs and generating results in human readable form all the parts of the computer that are unnecessary once a computer becomes a logic device.
First of
The microcomputer
will never eliminate all other computers because when computers are used to process data or solve scientific problems, there is a relentless economic need to make the computer more powerful. So with every major advance
1-3
-oiid state electronics technology, you get two new products: a yesterday's computer and a more powerful "today's" computer:
RANGE OF COMPUTERS
FIRST
COMPUTER
FOUR MAJOR ADVANCES IN SEMICONDUCTOR TECHNOLOGY
CHEAPEST COMPUTER
As time went
by, there developed a considerable spread between the capabilities of the cheapest computer and the most powerful computer. Thus in 1965 the first ar-
bitrary division
was made
large computers.
We will
not attempt to define what a minicomputer is, as against a large computer. A minicomputer is a minicomputer because the product's manufacturer calls it a
minicomputer.
In
1970, a second arbitrary division was made, between minicomputer and microcomputer; but this time the differences between products are easier to define:
logical devices, destined to
become
By way
But
ring
of contrast, all other computers are vehicles for the execution of computer programs, each of which transiently defines the function of the computer system.
this definitive difference
"microcomputer"
is
already blur-
for
two reasons:
is
First,
programs
for
it
COMPUTER
HOBBYISTS
just
Second, an increasing number of "microcomputers" are single chip implementations of existing "minicomputers"
Datapoint Corporation of San Antonio, Texas, are a manufacturer of "intelligent terminals" and small computer systems. In 1969, they (along with Cogar and Viatron) attempted to make a "great leap forward." Datapoint engineers designed a very elementary computer, and contracted with Intel and Texas Instruments to implement the design on a single logic chip. Intel succeeded, but their product executed instructions approximately ten times as slowly as Datapoint had specified; so Datapoint declined to buy, and built their own product using existing logic components.
were left with a computer-like logic device, whose development had been paid They were faced with the choice of manufacturing and selling it, or shelving it. They chose to sell it. called it the Intel 8008, and the microcomputer had arrived.
Intel
for.
1-4
Despite the fact that the Intel 8008 was designed to perform simple data processing, the traditional job for computers, it created a market where none had existed: as a programmable logic device. Let us explore this concept.
In
any catalog of
logic
we
components, there are perhaps ten thousand different have already described; simple logic gates may be
logic
illus-
AND
Inputs
OR XOR
etc.
Output
Data inputs are transformed into data outputs according to the criteria of some transfer function. But consider a more interesting logic device, a 4-bit, two-input, buffer multiplexer:
Data Inputs
There are two interesting concepts in this buffer multiplexer. First, data are being handled in 4-bit units. Second, there are two non-data signals present: Select and Enable. Select determines which data input will become the data output. Enable determines when it will become an output.
If an LSI chip can contain thousands of gates worth of logic on it, how about condensing a catalog of logic onto a single, general purpose chip, as follows:
AND
OR XOR
Data
Inputs
ADD
SUB BUFFER
etc.
Data Outputs
F~T
Select signals choose
one
logic device
1-5
illustrated above has a good deal of unnecessary, duplicated logic on it. Any one of the ten thousand chips listed in a catalog may be synthesized out of a few, basic logic functions AND, OR, XOR, ADD, SUB plus a
few
buffers, selects
and enables:
BASIC LOGIC
FUNCTIONS
Select
and
Enable
Signals
^^E^
mm.
[
|
|
BUF A
BUF B
BUF
Three bidirectional
data paths
This basic logic device can synthesize any individual logic device, or any sequence of
individual logic devices.
This
is
The purpose of
between microcomputers
build logic
The book does Jiot discuss the various technologies which are used to
chips because, in the end, the nature of the technology is usually quite unimportant to a user. Your application may have some key parameters such as the amount of power that you can afford to consume or the execution speeds that you can tolerate; indeed the various technologies that are used influence power consumption, execution speed and other critical factors, but where these factors are critical, selecting the right microcomputer simply involves looking at product specifications. Understanding whether the product is fabricated using N-MOS technology or C-MOS technology does not make it significantly harder or easier to understand what a microcomputer is or how to use it.
BEEN PRINTED
Notice that text in this book has been printed in boldface type and lightface type. This has been done to help you skip those parts of the book that cover subject matter with which you are familiar. You can be sure that lightface type only expands on information presented in the previous boldface type. Therefore, only read boldface type until you reach a subject about which you want to know more, at which point start reading the
lightface type.
1-6
binary digit
is
number
that can
or
1.
bi-
BINARY
DIGIT
What makes
is
that
it
thing that can be "on" or "off", "high" or "low", can represent a zero
one
state
and a one
in
And
that
is all
know
in
o
is
o
equivalent to
Digits Repre-
is
equivalent to
~z_T
Figure -2-1.
sented By
Bistable Device
NUMBER SYSTEMS
A computer
tunately,
no higher than one would not be a very useful machine. Forbinary digits can be used to represent numbers of any magnitude, just as a string of decimal digits can be used to represent numbers in excess of nine. Let us
that could count
of.
DECIMAL NUMBERS
When
each
a decimal
digit really represents?
number has more than one digit, have you ever considered what The two digits "11" really mean ten plus one:
11
= 1X10 +
Likewise, the
number 83
really
means
83
= 8X10 +
really
means two
2
There
is
fact that
man
ten toes almost certainly accounts for the universal use of base ten numbers, but any other
num-
BINARY NUMBERS
Because decimal digits cease to be unique with the digit 9. ten must be represented by "10". which means 1 times the number base (in this case, ten) plus 0. Usinq the letter "B" to represent
the
number
base,
we
have:
10
= 1XB +
2-1
Now
in
in
it
decimal
2:
10
Similarly, in
= 1X2
+0
1
1 1
= 1X2 +
Stated generally, suppose any numbering system's digits may be represented symbolically by dj d;, d|<, etc. If B represents the number base, then any number can be explained by this equation:
d^dkd,
Consider a decimal example
2
(B
= d,XB 3 + d,XB 2 +
d k XB
= 10)
17
4=
d,djd k d]
= d,xB 3 + d,xB 2 +
+
1
d,
BINARY
TO DECIMAL CONVERSION
10
+1
4,
therefore:
1X2+1
1
Continuous division by 2, keeping track of the remainders, provides a simple method of converting a decimal number to its binary equivalent;
for
1 1
to
its
binary
Quotient
5
Remainder
1
t
Thus
11 10
<
101
The
subscripts 10
and 2
identify the
2,
respectively.
2-2
may be
number to
its
CONVERTING FRACTIONS
(d,
d,d,d k di ...etc.
=(d,xB-
+(d,xB- 2 +
)
.
(d k
XB~ 3 +
)
XE
etc.
where
the
dj
d,j,
d|<.
etc.,
number
0.
base.
2
101
to
its
0.1011
-3
)
+ (1X2- 4
"3
where 2~' =
i
-L
0.5
~2
0.25
0.125
2~ 4 =
Thus,
0.0625
0.101
= =
0.5i
0.125,0
0.0625 10
0.6875,0
To convert a
0.6875 10 to
its
fractional decimal
number to its binary equivalent (e.g., to convert binary equivalent), use the following approximation method:
0.6875
0.3750
0.7500
0.5000
(p.3750
. 7500
(p. 5000
0000
T
1
Unfortunately, binary-decimal fractional conversions are not always exact; just as a 2 fraction such as h has no exact decimal representation, so a decimal fraction that is not the sum
of 2
_
"
terms
will
this
follows:
0.42357
0.84714
0.69428
0.77712
r
The answer
is
2
"
69428
Q). 38856
77712
0.55424
1
1
T
1 1
As
a check,
let
us convert back
0.01101
= 0X2 -1 + 1X2 -2 + 1X2~ 3 + 0X2 = + 0.03125 + 0.25 + 0.125 + = 0.40625,o 0.40625. which equals 0.01732;
In
-4
+ 1X2-
The
difference
is
0.42357
this difference
is
caused by the
0.55424 X 0.03125
0.01732
2-3
shown
in
binary number:
110111101100
By grouping the binary
to octal format:
digits into sets of three, the
number
is
converted
OCTAL
NUMBERS
110 111
6
7
101
100 4
= 6754 8
"
Base 8
(octal)
digits:
0.
1.
2,
3, 4,
5. 6.
7.
Decimal 8
is
the
same
as octal 10.
digits into sets of four,
the
number
is
converted to
HEXADECIMAL
NUMBERS
1101
DEC
digits:
1110 1100
= DEC 16
2,
3,
4, 5, 6, 7, 8, 9.
A, B, C, D,
E, F.
Decimal 16
is
the
same
as hexadecimal 10.
Table 2-1.
Number Systems
HEXADECIMAL
1
DECIMAL
1
OCTAL
1
BINARY
0000
0001
2 3
2 3
0010
0011
4
5
4
5 6
7
4
5 6
7
0100
0101
6
7
0110
0111 1000
1001
8 9
8
9
10
11
A
B
10
11
12
1010
1011
13 14 15 16
17
D
E F
12 13 14 15
1100
1101
1110
1111
2-4
BINARY ARITHMETIC
Binary numbers can be operated on in the same way as decimal numbers; in fact, binary arithmetic is much easier than decimal arithmetic. Consider binary addition, subtraction, multiplication and division.
BINARY ADDITION
The
possible combinations
Augend
+ + + + +
as
in
Addend
o1
Result
Carry
=
is
The
carry,
decimal addition,
is
added
carry
3
+6
9
+ 110
1001
is
11 -*
carry
1*-
-carry
"208
11010000
+92
300
+1011100
100101100
BINARY SUBTRACTION
Microcomputers cannot subtract binary digits; they can only add. Fortunately that no problem, since subtraction can be converted into addition.
Subtracting a decimal number complement of the number.
is is
TENS
COMPLEMENT
is
of a
number
10.
The final carry, however, must be ignored when performing decimal subtraction ment addition.
Consider the decimal subtraction.
tens comple-
of 2
is
8.
The decimal
ignore
final carry
2-5
via
is silly,
since
10-2
is
is
no simpler to
lot
twos complea
of sense;
ment. Performing binary subtraction via twos complement addition makes moreover, twos complement logic is well suited to computers.
The twos complement of a binary number is derived by replacing digits with digits, and digits with digits, then adding 1. The first step generates a "ones complement" of a binary number. For example, the ones complement of 10110111Q1 is 0100100010.
1 1
ONES
COMPLEMENT
The twos" complement of a binary number is formed by adding 1 to the ones complement of that number. For example, the ones
complement
of
TWOS
COMPLEMENT
0100
is
101
1:
Original
number:
0100
1011
Ones complement:
+
Twos complement:
1100
of the
Now
look at how binary subtraction can be performed by adding the twos complement SUBTRAHEND to the MINUEND. First consider the following binary subtraction.
MINUEND SUBTRAHEND
DIFFERENCE
10001
-01011
00110
of the to
The same operation can be performed by forming the twos complement adding to the minuend. The final carry must be discarded, just as had ment subtraction:
it it
subtrahend and
for tens
be
comple-
MINUEND
discard
final carry
is
001
10.
11001
-101
MINUEND SUBTRAHEND
11001
MINUEND
+11011
= 10100
discard
lll0100
"J
2-9
final carry
When
a larger number is subtracted from a smaller number, there is no carry to be discarded. Consider the decimal version of this case. becomes 2 + (10 - 9), or 2 + 1. The answer. +3, is the tens complement of the correct negative result, which is -(10 - 3)
-7. Here
is
a binary
thing:
2-6
101
-11011
MINUEND SUBTRAHEND
DIFFERENCE
101
MINUEND
400101
-10110
01010
larger binary
tive,
but
it
is in
101
10).
number has been subtracted from a smaller one. The answer on the right is negatwos complement form; taking the twos complement of 01010 (twos complement and assigning a minus sign, provides the same answer as on t he left, -101 10.
When
performing twos complement subtraction, the final carry provides the sign of the answer. If the final carry is 1, the answer is positive. (The minuend is greater than the subtrahend.) If the final carry is 0, the answer is negative (the minuend is smaller than the subtrahend), and is in its twos complement, positive form.
SIGN OF
ANSWER
IN
SUBTRACTION
BINARY MULTIPLICATION
Binary multiplication is actually easier than decimal multiplication, since each partial product, in binary, is either zero (multiplication by 0) or exactly the multiplicand
(multiplication
by
).
For example:
is
+1001
X1Q1
1001
X5
45
0000
1001
101101
BINARY DIVISION
Binary division can be performed using the
example:
same steps
is
an
1011-*Divisor
-Quotient -Dividend
-*-101
110111-*
101
0011
0000
111 101
Intermediate
multiplications
0101 0101
and subtractions
BOOLEAN ALGEBRA
and 1 to define logical decisions. Three Boolean algebra uses the binary digits Boolean operators, OR, AND, and Exclusive OR (XOR) combine two binary digits to produce a single digit result. A fourth Boolean operator, NOT. complements a binary
digit.
2-7
"OR" OPERATION
The OR operation
If
I
is
defined, for
J. or
two
integers
1,
and
J,
by the statement:
is 1.
OR
both, equal
Otherwise
the result
is zero.
plus sign
is
for
OR
is
also
used to repre-
Two
ORed
as follows:
0+0=0
+ 1=1 1+0 =
=
1) is
1
1+1=1
the only
last
OR
operation
( 1
OR
operation
where the
result differs
TRUTH
TABLES
given below:
AIM
OR GATE OUTPUT =
+J
1
"AND" OPERATION
The
AND
operation
If
I
may be
and
J by the statement:
AND J
is
are both
is 1.
Otherwise the
result
0.
The dot
and
binations of
symbol are both used to represent the and 1 for the AND operation are:
cofff
0-0=0 0-1=0
1
1-1=1
The
AND
is
given" below:
OUTPUT =
J
1
2-8
tion.
The
and
for the
XOR
operation are:
= = = =
is
given below:
OUTPUT =
B
AB
1
"NOT" OPERATION
"NOT" complements any
binary digit or group of digits.
NOT NOT
Because of the nature of microcomputer
tion: instead of
logic.
= =
NOT
is
using the
NOT
ones comple-
ment
is
employed.
Combining
results of
AND with NOT generates NAND. Combining OR with NOT NAND and NOR are the NOT of AND and OR. respectively.
digit to
bar
is
placed over a
T =
clusive OR;
some
operators
by
may be combined
B; this
:
three of the Boolean operators AND, OR and Exto generate others, as follows:
A + B
is
reproduced
is
illustrated as follows:
\a-% &
A
1
B
1
A-:^.B.
=
"=~
-'
1
=
-rJf>-"=
W$
'^^\
M^i
2-9
follows:
A
This
is
(A
B)
(A
B)
illustrated
as follows:
:#:':@:B:;
ixxiQix;:;:
A
1
B
1
'
'
-<A
'-:'
}'
A$.
>'
:
.B).
10
1
1 1
1:
10
.'&'
1
'.V:
11
= A + = A
Q:
DE MORGAN'S THEOREM
Boolean operations can be combined to produce any desired output from a set of known inputs. De Morgan's theorem is a valuable aid in designing such combinations. The theorem can be written in either of these ways:
A A +
B B
B B
others, since:
all.
A
generates
= A +
AND
out of
OR and NOT.
Similarly,
A
generates
(A
B)
(A
B)
XQR
out of
OR and NOT.
2-10
MEMORY ORGANIZATION
Binary data are stored
ble elements.
of
in memories. Every computer memory consists of an array of bistaMinicomputers used to use and still- frequently use "core" memories, which consist minute metal "donuts" which can hold a clockwise or counterclockwise magnetic charge:
*- DIRECTION
OF CURRENT
consist of an array of
gates
which
etc.
etc.
Core memories hold their magnetic charge even when disconNON VOLATILE electric power: you can pull a core memory card out of a MEMORY computer, plug into another similar computer, and the memory data should still be intact Core memories are therefore said to be "non volatile"
nected from
it
Semiconductor memories loose all stored data the moment you shut off their power source; therefore they are said to be
"volatile".
VOLATILE
MEMORY
3-1
"
The type
of
memory used
with a microcomputer
is
unimportant.
It
is
memory
consist of a
number
each representing a
10110011101011100100001011
There are two absolutely necessary properties which any memory must have:
1)
The
It
location
digit is stored
2)
With some memories it is not possible to change the state of ROM ~~ binary digits in the memory. If the state of binary digits can be read, but not changed, then the memory is called a Read-Only Memory, or ROM. Of course, by its very nature, any ROM memory is non volatile.
If the state of binary digits within a memory can be changed, RAM l l as well as being read, then the memory is called a Read-Write memory. Read-write memories are commonly referred to as Random-Access
Memories (RAM).
There
digits
is
no good reason
why
a read-write
memory, as against
is
a read-only
memory, should be
if
referred to as a
randomly accessible memory; memory within the memory can be accessed directly:
randomly accessible
individual binary
If
memory were
digits:
cessible,
which means
all
be accessed by
first
passing over
preceding
mon
Read-only memories and read-write memories are both randomly accessible. Nevertheless, comterminology refers to read-only memories as ROMs and read-write memories as RAMs.
3-2
MEMORY WORDS
combined to represent numbers in excess of 1. just as numbers in excess of 9. Table 2-1 gave some binary representations of small numbers. The primary level at which binary digits are grouped within any computer is one of the most imWORD porta nt features of the computer and is referred to as the comSIZE puter's word size. For example, an "8-bit" computer acquires the "8bit" label because binary data within the computer will be accessed and processed in eight binary
Chapter 2 explained
decimal
digits are
how
combined
to represent
digit units.
A memory
MEMORY
Each dot
word.
in
digit.
8-bit
bits of a word are numbered from right (0 for the low to left (7 for the high order bit) as illustrated above. Some computer manufacreverse the convention, numbering from left to right.
bit)
Table 3-1.
Computer Word
Sizes
Word
Size
(Bits)
Microcomputers
Minicomputers
Large Computers
4
6
Many
None
None
None None
A few
obsolete
models
8
12 16
Most common
A few
None None
few
few
A few
None
Most common
18
A few A few
24 32 64
few
None
Common
largest
for
computers
3-3
A large number of different word
sizes have been used by microcomputer, minicomputer and mainframe (large computer) manufacturers. Table 3-1 lists the more common word sizes and identifies those word sizes which are used by microcomputers, minicomputers and large computers.
8-bit
much
word. There are a number of 4-bit microcomputers which are logic replacement. There are also a number of 16-bit
for their traditional markets.
THE BYTE
An 8-bit data unit
puter industry;
puter, for
it
is called a byte. The byte is the most universally used data unit in the comused even by computers that do not have an 8-bit data word. A 16-bit comexample, will often have memory words interpreted as two bytes:
is
16-bit
.
word
/^_
15
1
14
1
13
1
12
1
11
10
0-
-Bit
number
v
High order
byte
-A.
Y
Low
order
byte
When
same
If
microcomputer has an
8-bit
word
size,
we
can
they
refer
in-
BYTES AND
terchangeably to
thing.
"memory
bytes" and
"memory words";
mean
the
WORDS
a microcomputer's
mean
the
refers to
word size is not eight bits, then a memory word and a memory byte do not same thing; a memory byte refers to an 8-bit memory unit, whereas a memory word a memory unit of the microcomputer's word size.
Many 4-bit microcomputers refer to the 4-bit unit as a "nibble". Thus each word of 4-bit memory is a "nibble", and two 4-bit
memory words
constitute a byte.
{NIBBL ES
MEMORY ADDRESSES
Even though every binary
digit
within a
memory must be
the smallest unit of information that is usually a word. For example, when using an 8-bit memory, each time
digits are referenced.
Each word of memory has a unique memory address. Words within memory have sequential memory addresses, with the first word in the memory having an address of 0, and the last word in the memory having the highest address of any word in that memory. The actual
value of this highest address
will
depend on the
size of the
memory.
)
Thus the address of a word is its location in memory; for example, the words of a 1000 (4096 16 10 word memory would be addressed and numbered as follows (in hexadecimal notation):
OFFE
OFFD
OFFA
0FF9
09C2
J
09C1
J
09C0
09BF
...
3-4
some subtle differences between the way minicomputer and microcomputer programmers use memories. Some of these differences are introduced now, while others are described later, since they will not be meaningful until you understand how microcomputers are used.
Conceptually, there are
is
simply a sequence
the size of the
MINI-
COMPUTER
and ending
puter's
at
some
will
large
It
MEMORY
CONCEPTS
as data
minicomputer's memory.
is
memory
programmer
never needs to worry about the physical implementation of memory. So long can be stored and retrieved on demand, where and how this happens is irrelevant.
will
memory
is
implemented, because
units.
there are
MICRO-
COMPUTER
be sold
in
tens of
MEMORY
CONCEPTS
thousands of
a
it
is
num-
ber of discrete components within the microcomputer system be kept to minimum, since every extra (and therefore unnecessary) component will be multiplied by tens of thousands thus increasing costs.
The microcomputer programmer has a further interest in memory organization because almost all microcomputer based products use ROM for some part of memory. The reason ROM is desirable
when
using microcomputers
in
safe. Since no binary digit within a ROM can be can be accidentally erased. This is a very desirable a product which may end up in obscure or inaccessible locations.
is is
The microcomputer user thinks of memory as semiconductor trates a 1024-bit memory device in a dual in-line package.
illus-
3 8 5
7 5 2
Figure 3-1.
1024-bit
Memory
Device.
ROM memory is implemented in single chips. For example, a microcomputer may have 1024 8-bit words of ROM memory on a single chip. This single chip will have a capacity of 8192 binary digits, divided into (and accessed as) 1024 8-bit units. A microcomputer
Usually
programmer
will
be interested
in
how memory
is
memory space
to the system.
provided by a single
ROM
3-5
Read-write
write
eight
memory
requires
more
logic
bits of a read-write
memory can be changed as well as being read. Therefore, readcommonly implemented on more than one chip. In a very simple case,
implement
8-bit read-write
memory
one
bit
if
One Memory Module
a single
8-bit
word
We
eight chips as a
memory module.
MEMORY MODULE
memories. For
may use fewer memory chips to implement small read-write example, two RAM chips may each contribute four bits of an 8-bit word:
a single 8-bit
word
3-6
Now
there are
in
the
memory module.
with entire words implemented on a single chip:
RAM memory
ROM,
RAM
single 8-bit
word
RAM
RAM
memories cost increases, in terms of cents-per-bit, when fewer chips are used to implement a single memory word. Thus implementing an 8-bit read-write memory word
using eight
RAM
entire 8-bit
word on one
Currently 4096-bit
RAM
chips are
common, and
RAM
chips
RAM
commercial
per chip.
There are two types of RAM memory: dynamic RAM and Static RAM. Dynamic RAM, which is cheaper, can only hold data for a
RAM
few milliseconds; therefore dynamic RAM must constantly be refreshed STATIC by having the contents of memory words rewritten. Dynamic RAM refresh RAM is handled automatically by some microcomputer systems; other microcomputer systems require external refresh logic when you use dynamic RAM. Static
costs more, but once data have been written into
it,
RAM
is
the data
will
power
being input.
Once
again, as a
microcomputer
user,
you
will
be very interested
in
is
RAM
chips.
An
is
memory may
require eight
new RAM
chips
expensive.
will
how memory
memory
addresses,
memory addresses
larger
computers.
Specifically,
every
word address
The chip
one
or
more chips
that constitute a
memory module.
bits identify
3-7
Suppose
8-bit
memory words are implemented on eight separate memory chips. The chip select an eight-chip memory module. The word address bits will identify one memory
word, as follows:
16-bit
memory address
The number of word address bits required by a memory module will depend on chip size. For example, a chip contains part or all of
if
SIZE OF
MEMORY
ADDRESS
will
= 00000000 = 00 16 = 00 10
word address
part or
all
1 1
FF, 6
= 255,
will
iarger
memory
chip
may have
of
Smallest
Largest
word address
1 1 1
111.1111
= 3FF 16 =
1023,
Notice that ten binary digits create three hexadecimal digits as follows:
these two
10 binary digits
binary digits
are implied
TLr
Hex
00 bb
digit
bbbbbbbb
Hex
digit
Hex
digit
3-8
The number
of chip select bits will be a function of the microSIZE OF computer's architecture; but concatenating the number of chip CHIP SELECT select bits with the number of word address bits generates the microcomputer's maximum memory capacity. For example, the microcomputer can address 65,536 10 (FFFF 16 memory words, 16 binary digits will be required to express the largest
if
)
allowed
memory
address:
1111111111111111
F
T"
digits,
Now
if
1024-word memory chips are used, the word address consumes ten binary
in
which
memory modules,
maximum memory will consist of 64 module, and the 16-bit memory address must be inother words,
terpreted as follows:
16 binary digit
memory
*
address
^
ssssssbbbbbbbbbb
6 binary
, . ,
digit
chip
'
cpippt
,
selects
one
from0to3FF lb
of40 16
(=64 10
)
Mn UUZdl
1fi
memory
modules
is that the microcomputer sets the TOTAL number binary digits; how they are split between chip select and word address depends on the type of memory chips used it is entirely up to the logic designer.
memory address
bensik
again at
how
a total
is
word address
01 10101
is
1
is
created
l6
in
a real case.
If,
as illustrated
is
earlier,
the
word
10 2 (1AE
0001
(07 16
),
then a 16
word address
created as follows
chip select
word address
\
1
Total
A
t
1
1
A
>
1 1 1
1
word address =
There
is
no reason
at zero
For example, a
ing 8 -bit
four bits
memory addresses need to be continuous, or even need to start microcomputer system may include one ROM chip implementwords and a RAM module made up of two RAM chips, each implementing of an 8 -bit word.
available
why
3-9
If the ROM chip has a chip select of 000001 2 and a capacity of 1024 10 then allowed ROM memory addresses will be 0400 16 through 07FF^:
memory bytes,
chip select
\
First
1
word address
A
2
ROM
address
=000001000000000
4
0,fi
chip select
word address
K
^
A
t
t
n 2
Last
ROM
address
=0000011111111111
will
.
now
have addresses
1024
If
We
ADDRESS SPACE
the ad-
memory addresses
the two
as the
space.
RAM
module has a select of 0001 1 2 and each chip holds 256 x 4 bits, then RAM chips constitute a memory module, and provide 8-bit RAM memory words with
.
chip select
word address
First
RAM
address
=0001 10000000000
1
0,r
chip select
t n
word address
r
1
^
2
Last
RAM
address
=000110001111111
Addresses
in
RAM
module's ad-
dress space.
INTERPRETING THE CONTENTS OF MEMORY WORDS A memory word consists of a number of binary digits; therefore, binary digits are the
only form in which information can be stored
in
word
of
memory.
An
contain 256 (2 8 ) different patterns of 0's and 1's. The pattern of zeros and ones within a memory word may be interpreted in any one of the following ways:
8-bit
1
)
2/
3-10
3)
is,
some
4)
An
instruction code; that is, a bit pattern which is to be transmitted to the microcomputer. The microcomputer will decode the bit pattern and interpret it as an identification of those operations which the microcomputer logic must immediately perform.
is
This
Upon examining the contents of any word of memory, it is impossible to determine whether the memory word contains numeric data, a code, or an instruction.
Chapter 4 you will learn how a microcomputer memory word may be interpreted in a number of interpretation of a memory word.
In
we
will
describe each
first
is
important to understand that you can represent pure binary data, on paper, as a binary
num-
number; the choice is purely a question of reader convenience and has no impact whatsoever on the data word. Here is an example for an 8-bit data word:
ber,
an
octal
number
or a hexadecimal
E-^
1
1 1
Hexadecimal
10
1 1
0-< Binary
-<
Octal
01001 110 2
Here
is
116 8
4E 16
an example
word:
B-<
Hexadecimal
110110111000101
1-* Binary
Octal
15
The choice
data interpretation;
it
6
2
3-<
155613 8
= DB8B 16
memory word's contents is not same thing on a piece of paper.
merely an alternative
way
of writing the
3-11
word, on the other hand, can represent numeric values ranging from
to
MULTIWORD
BINARY
65,535 10 There
is
no reason
be interpreted
will
in pairs.
Now
DATA
One
16-bit
word
10
One
Upper
10
8-bit
1111
v~
word.
One
8-bit
word
half of a
Lower
half of a
16-binary digit
16-binary digit
number.
number.
There is, in fact, no limit to the number of memory words that may be concatenated to generate very large numbers. Here is an example of a 48-bit number:
One
(
48-bit
word
"\
100111011101111010100110001110110101101100101101
byte 5
byte 4
byte 3
byte 2
byte
byte
Suppose
memory words are required to represent a single numeric unit, as illustrated six memory words would be contiguous; that is. they would have memory addresses adjacent to each other. However, there is nothing in the logic of a microcomputer that demands the many bytes of a multibyte number be contiguous; contiguous multibyte numbers are easier to process; that makes contiguous organizasix 8-bit
tion desirable.
What about multibyte arithmetic? Numbers that occupy many memory words can be added, subtracted, multiplied or divided
using the rules described
2 about the
if
in Chapter 2. Nothing was said in Chapter number of binary digits associated with any number. Thus a 16-bit number is stored in two adjacent 8-bit memory words, binary addition rules described in Chapter 2 would still be used, but the 16-bit numbers would have to be added in two steps as
follows:
word
word
10000110 11010100
10011101
carries
from word
and word
+00101010
1
=11001000
step 2
01011010
step
1
3-12
The
carry,
if
is
added
to the
to
low order
digit of
in
The logical extension of the above example words is self-evident. Here, for example, is words, would be added in four steps:
numbers stored
three, four or
more memory
word
word
word
11011010 00111001
+ =
110
00111111
step 3
10000101 10111010
01101011 01000010
1
10101110
step 2
00010011
step
1
There
is
MULTIBYTE
twos complement of the BINARY subtrahend and adding it to the minuend. Consider two 16-bit numbers SUBTRACTION stored in 16-bit memory words. The logic associated with subtracting one 16-bit number from another is very straightforward and may be illustrated as
that binary data are subtracted by taking the
follows:
Twos complement
of
124A 16 =
Answer =
0001000101011100
in
two adjacent
8-
memory words.
directly
reproduced as follows:
word
23 16
word
10100110 10110101
1
ones complement
of 12
16
=00100011 = 11101101
00010001
= A6 16
twos complement
of
4A 16
01011100
5
11
step 2
step .1
Notice that only the low order byte of the number is twos complemented. The high order byte is ones complemented. While this may seem confusing at first, it really is not. If you visualise a multibyte number as a single numeric unit, then it is self-evident that when the twos complement of the multibyte number is generated, will be added to the low order byte of the multibyte
1
number
only:
Twos complement
of
124A 16 = 1110110110110101
1
1110110110110110
Twos complement
Ones complement
of of
1
4A 16
"
16
^i
i^
11101101
10110101
1
Twos complement
of
124A 16
11101101
10110110
3-13
very useful
numbers would not be negative numbers? Here, for the first time, we get into the question of interpreting binary coded data. A very effective industry convention interprets the high order bit of a number as a sign bit. If this bit is 1 the number is negative.
microcomputer
that could only process positive
What about
SIGNED BINARY
NUMBERS
If
this bit
is 0,
the
number
is
positive:
Obbbbbbb
number
number
Ibbbbbbb represents
Table 3-2 gives the interpretations for 8 -bit signed binary data. Observe that negative numbers
are
+02, 6 = 00000010
-02,
11111101
1
110
+6A,
01101010
-6A,
10010101
1
10010110
When
eight binary digits are being interpreted as a signed number, the range of
1
.
numbers
is
from
-128,0 1 + 27 10 When sixteen binary digits are bers must fall in the range -32768, to +32767.
.
num-
Table 3-2.
BINARY
DECIMAL
HEXADECIMAL
80
81
10000000
10000001
-128
-127
10000010
10000011
-126
-125
82
83
11111110
11111111
-2
-1
FE
FF
00000000
00000001
1
00000010
00000011
2 3
2 3
01111101
01111110
01111111
7D
7E
7F
3-14
to represent signed numbers is that it calls for no arithmetic operations. Providing an arithmetic operation does not generate an answer which is too large to fit in the available space, you can ignore the sign of a number until you wish to interpret an answer; at that time, examining the high order bit of the answer indicates whether it is positive or negative. If the high order bit of the answer is 1, then the answer is negative and by taking the twos complement of the answer, the pure binary, positive representation of the answer is created. Here are some examples:
special logic
The beauty
of using this
scheme
when performing
63, 6
-3A 16
=29 16
ones complement
of
3A,
A
2
Answer = +
This
29, 6
3A 16
63 16
=29 16
This
1
00111010 10011100
1
ones complement
of
63 16
1010111
00101000
1
00101001
Answer = 29 ie
Now
(3A.,
.
-63 16 )=( 29 16
).
( 63 16
will
be
63, 6 -63 16
= 10011100 = 10011101
Therefore:
3A, 6
00111010
10011101
+(-63
1fi )
=(-29, 6
This
1
11010111
00
000
1_
Observe that using twos complement notation to represent signed binary numbers, 3A, 6 63 16 and 3A 16 + ( 63 16 have identical binary representations, which is only to be expected of a via)
ble
scheme
numbers.
3-15
Multiword signed binary numbers generate no special problems so long as you understand that operations must be performed one word at a time. This is illustrated below for the simple case of 6bit, signed binary data, which generates the same results when handled as single 16-bit words or as two 8-bit words.
1
MULTIWORD
SIGNED BINARY
NUMBERS
one
sign
bit
16-bit
word
n
&
r.
01
8-bit
v~
100101 1000010 /v
srv
'
word
8-bit
word
is
16-bit.
stored
in
in
two
8-bit words.
As
for
two
steps, as follows:
word
word
1A2C 16 0810
0Q011010
11110111
00101100
1 1 1
1fi )
T0000
121C U
sign
bit
Observe that
0810 16
is
0810 16
ones complement
twos complement
It is
BINARY
or from
to
10
By
ig-
CODED
noring binary digit combinations above 9, decimal numbers can be coded, DECIMAL two digits per 8-bit memory word, or four digits per 16-bit memory word. Table 3-3 identifies the combinations of four binary digits that may be interpreted as decimal numbers. AA/hen binary digits are being used to represent decimal numbers, the result
is
called Binary-Coded"
Signed binary number rules cannot be applied to BCD data, BCD demands that binary data be interpreted in 4-bit units:
NEGATIVE
BCD DATA
nnnnnnnnnnnnnnnn
digit digit
digit
1
digit
Each
8-bit
4-bit digit can have one of the bit patterns shown under the BCD column of Table 3-3. An word uses the high order bit for all numbers in excess of 79 10 the high order bit is needed
.
If
it
sign.
3-16
Table 3-3.
BINARY
HEXADECIMAL
BCD
0000
0001
1 1
0010
0011
2 3
0100
0101
4
5 6
7
4
5
0110
0111
1000
1001
6
7
8
9
8 9
Illegal Illegal Illegal
1010
1011
A
B
1100
1101
D
E
F
Illegal Illegal
Illegal
1110
1111
The sign of signed BCD numbers is therefore represented using a special "control" word which must precede the first data word of a multiword BCD numbers There are no common rules for control word format, but here is a simple example and a complex
example'.
First
Decimal data
.
in
BCD form
ri
Now
the complex example:
Control
most
T
significant
digits
least significant
digits
for positive
Control word,
is is
0000
0001
for
Decimal data
in
BCD form
Word,
TTTTm
sign
bit
= =
for
1
+
J
nn
A maximum
decimal point
of
for
H
| |
assumed here
7 post-decimal
words allowed
Total post-decimal
A maximum
of 16 data words-allowed
data
words
7
3-17
data cannot be added and subtracted using straightforward binary addition and subtraction rules. Here are some examples of the errors that could result:
BCD
Decimal
BCD
Decimal
BCD
23
+47
= =
00100011 01000111
54
-26 =28
= =
01010100 11011010
00101110 *-~ y~
2
Illegal
=70
01101010
6
Illegal
Note that
In
101 1010
is
the twos
complement
order to perform
carry out of
BCD arithmetic, special rules must be applied, and the each BCD digit must be recorded. Consider the addition:
97
BCD
ARITHMETIC
+68
= 165
It
is
was
Any
ex-
intermediate carry out of the low order digit addition must also be recorded. Here are
some
carry
(IC):
C
1
IC
1
C
i
IC
I
1
C
1
1
IC
I
C
I
1
IC
1
1
21
29
91
97
+32
+32
=61
+32
+68
=53
Conceptually,
1)
=123
= 165
BCD
addition
is
performed as follows:
Add
the
two numbers.
invalid digit, starting
2)
Serially
add 6 to each
digit. (This
six
invalid bit
BCD
0101
representation.)
= 0010
0001
0011
1001
1110
add
6:
0000
0100
0110 0100
==
44
This
of a
method
is
rather
is
BCD number,
clumsy to computerize. The following process, as described for two digits more efficient: adds 6 to each digit, then based on the carry statuses, which were not heeded:
it
first
2)
Add
this
the
second number
(the
addend)
to the
sum generated
digit.
in
step
The
carry generated
in
3-18
3)
sum from
step
2.
The
factor to
be added depends
on the carry
(C)
(IC)
stratuses as follows:
IC
Factor
9A, 6
1
A0 16
FA 16
oo 16
re are
some
addition examples:
23
29
92
87
+34 =63
00101001 01100110
10001111
+32
+79
= 124
10010010 01100110 11111000
= 166
10000111
00100011 01100110
10001001
01100110
11101101
sum = sum =
C/IC
Addend =
Step 2
00110010
10111011
00110100
11000011
1
00110010
01111001
00101010
1
01100110
1 1
=
10011010 10111011 01010101
5 5
10100000 11000011
11111010 00101010
01100011
6 3
00100100
2
1
=
(from Step 2)
=
is
BCD
1)
subtraction
the twos
BCD number
in this
via
Add
(the
complement
digit.
number being
subtracted) to the
The
carry generated
when
is
subtrahend
2)
multiword numbers are subtracted, only the lowest order word twos complemented. Higher order words are ones complemented.
for
of the
BCD
addition.
Here are
some
subtraction examples:
75
71
25
21
-21
-28
+43
00101000 11011000 01110001
01001001
.1
-71
-78 -57
01111000 10001000 00100001
10101001
+54
Subtrahend
-46
01110001 10001111 00100101
10110100
1
Twos
01010100
1 1
C/IC
Factor
=
=
00000000 01010100
01010100
5
1
11111010 01001001
10100000 10110100
Answer =
01000011
4
1
01010100
5
=
C
(after
AC)
3-19
When
performing
BCD
is
subtraction), but in
keeping with the decimal representation of numbers, the numeric value of the
tens
negative answer
is in
complement
is is
form, not
in
25
-71
twos complement form. Thus the answer final carry is 0. Similarly, the answer
final carry is 0.
to
to
21-78
57,
and the
CHARACTER CODES
A
of binary digits, or
computer would not be very useful if it required data to be entered as a sequence if answers were output in one of the uncoded or coded binary formats. It must be possible for a computer to handle text and other nonnumeric infor-
mation.
If
we
in
bear in mind that the combination of binary digits within any memory word can be re-used any number of ways, then all the binary codes which have been used to represent numeric
data, as described
so
far,
can
all
be re-used to represent
or
So long as
program correctly
arise.
memory
ambiguities cannot
For example,
if
to
use
memory words
it
with addresses
0A20 16
in
through
0A2A 16
is
up
to you, the
programmer,
errors.
your
subsequent
logic, to
remember
in
these
interpreted
cause
which are to codes have exactly the same binary irrelevant, So long as program logic correctly incannot arise; and program logic does not corare reserved to hold binary data
if
logic
is in
error
and must be
cor-
rected. In
in-
cludes:
26 lower case letters 26 upper case letters approximately 25 special characters 10 numeric digits
CHARACTER
SETS
(e.g.
(+/@!#,
etc.)
The above character set adds up to 87 characters. A six binary digit group allows 64 combinations of and 1 binary digits (2 6 which is insufficient to represent 87 characters. A seven binary digit group allows 128 possible arrangements of and binary digits, which is sufficient for our needs.
),
The 8-bit byte has been universally accepted as the data unit for representing character codes. The two most common character codes, listed in Appendix A, are known as the American Standard Code for Information Interchange (ASCII) and Extended Binary Coded Decimal Interchange Code (EBCDIC). ASCII is used by all minicomputer and microcomputer manufacturers.
Eight binary digits are used to represent characters
where seven
is
is
set to
or to 0, so that the
number
of
bits
PARITY
the byte
is
either
3-20
If odd parity is selected, then the parity always odd. Here are some examples:
bit will
total
number
of
bits
is
Parity Bit
of of
of of of
= = = = =
5
7
If
even
1
parity
is
num-
ber of
bits will
are
some examples:
Parity Bit
00000000
10000001 01010101 10010101 11111111
of of of
of
of
= = = = =
4 4 8
The
no
1
parity bit
is
used
to
of a character byte
and reading
even
it
back,
of
is
bit
for
example,
parity
is
odd, then
bits
detected
in
must be
in error. in
parity
selected, then
detected
must
be
in
error.
an example of how a message might be stored words using ASCII character codes with even parity: Here
is
in
sequence
of
contiguous
memory
blank
parity
and
error
at this point.
the high order bit of a byte can be used as a parity bit only when the byte contents are being interpreted as character codes. the contents of the byte are being inClearly,
If
terpreted as any form of binary data (coded or uncoded), then the high order
specified as an integral part of the byte's data contents; therefore, this
parity
bit,
bit
bit
cannot be used as a
elaborate schemes are used, not only to check that sequences of binary digits contain no errors, but further to detect what these errors are and to make appropriate corrections. These error correction codes have nothing in particular to do with
Many
in this
Microcomputers that have word sizes other than eight bits still use the byte to represent character codes. A 16-bit microcomputer will pack two bytes into each memory word as
follows:
1
1 1 1
16-bit
memory word
>
1
1 1
V,
Y
High order
byte
J^.
Y
Low
order
byte
3-21
will
code
in
bits
and
will
bits
as follows:
12-bit
mem ory
i i i
word
A
r~
i i i i
i i
v_
V
unused
bits
-v
V
character
byte
4-bit
Word
r
1 1
Word
V
1
1
1
" 1
-
Character
byte
microcomputers may actually be better suited to BCD applications such as hand held calculators. These applications treat 4-bit data units as unique entities one BCD digit per 4-bit data unit: the 8-bit byte is not significant, so the fact that the 4-bit microcom4-bit
in
4-bit units
INSTRUCTION CODES
Memory words have so far been interpreted as data of one form or another. The contents of a memory word can also be interpreted as a code, identifying an operation which is required of the microcomputer.
Consider the simple example of binary addition. Assume that the contents of the memory word with address 0A30 is to be added to the contents of the memory word with address 0A31, and the sum is to be stored in the memory word with address 0A31. Program steps to accomplish this binary addition may proceed as
follows:
Identify the address of the first
1)
memory word
to be added.
2) 3)
memory word
memory word
to the
4)
of this
memory word
to be stored.
6)
Transfer the
sum
to this
memory word.
3-22
Program
memory words
with addresses
are to contain
Address of
Memory
memory word
0A2F
0A300A31
0A32'
Let us
word
Assumed
to contain
assume
to
ing at 0400;
we
create
some
instruction
be stored in memory words with addresses startcodes to implement the six-step binary addition.
will
The
instruction
code which
identifies
memory addresses
occupy three
bytes, as follows:
10011100
9Ci6.
when
interpreted as an
instruction code,
be read and
memory address
program as follows:
We
can
now
of
start to create a
Address
Memory
I
memory word
word 9C
Read the contents of the next two memory words. Interpret them as a data memory address.
T
0400
0401
0A
30
0A30
is
the data
the
CPU
0402
will read.
0403
0404
Step 2 requires the contents of the addressed
memory word
to
data.
no need for the instruction to specify what kind of data the memory word contains. You, the programmer, must remember what kind of data the addressed word contains, and not try to do anything incompatible with the data type. So far as the microcomputer is concerned,
Note that there
is
data
is
less.
Let us
assume
[III!
01000000
3-23
if
memory word
tb be
now becomes:
Address
of
Memory
memory word
word
0400
0401
9C
OA
30
Step
0402
0403 0404
Step 3
is
40
Read contents of addressed data word (0A30 from step and interpret as pure binary data
1
)
a repeat of step
1,
memory
address (0A3
16
needs to be
specified.
Memory
memory word
word
0400
0401
9C
OA
30
>
|i
Step
0402
0403 0404
0405
40
!
1
Step 2
9C
OA
31
> )
a data
memory address
into the
0406
0407
CPU C
Step 4
data
is
a variation of step 2;
memory word, the data memory word is added, using binary addition, to the data memory word that was previously read: assume that this operation is identified by the instruction code:
1 1 1
10000000
Our program now increases one step as
Address
of
follows:
Memory
memory word
word
0400
0401
9C
OA
30
Step
0402
0403 0404
0405 0406 0407
40
Step 2
9C
OA
31
Step 3
Add
0408
0409
word
to
3-24
Step 5
is
a repeat of step
3;
the
sum
is
to
be stored,
0A31 16
is
the data
recently addressed
step
3).
be repeated
we
will
proceed to step
III llll
6,
and assume
01100000
when interpreted as an instruction code, causes data to be output data memory word. The complete program now looks like this:
Address of
to the
Memory
word 0400
0401
memory word
9C
0A
30
Step
40
Step 2
9C
0A
31
Step 3
80 60
'
Step 4
Store data
word
in
CPU
in
0409
Providing the microcomputer can be told
addressed by data
in
some way
,
that a
sequence
of instruction
will
be found beginning at<memory word 0400 16 then the fact that each of these memory words may have a pattern of 1 and binary digits which is also valid binary data, or ASCII characters, is
irrelevant.
identify
is
assumed
microcomputer programmer,
If. by
memory words do
do
add two character codes as though they were binary data. Only will alert you to the fact that a mistake has been made.
Illustrating
is,
program
How does the microcomputer perform the operations required by the instruction code? That question will be answered in Chapter 4.
What does
Chapter
5.
the microcomputer demand of external logic in order to complete the operations specified by an instruction code? That question will be answered in
We
will
in
3-25
microcomputer
is
implemented on one
.
or
more
packaged
The one
DIPs, as was
may be
found.
you can say for sure is that one of your DIPs will conis referred to as a Central Processing Unit, or "CPU"; this is the DIP commonly called a "Microprocessor". Whatever else a microcomputer has, or lacks, it must have a CPU.
tain logic that
CPU
MICROPROCESSOR
logic that constitutes a CPU can differ wildly from one microcomputer to the next; underlying these variations there are certain necessities, however. Our purpose in this chapter is to identify these necessities.
The
Recall
interpreted
in
one
of the
following ways:
1)
As pure
2)
As coded As
3)
a character
code
4)
As an
instruction code.
These four ways of interpreting the contents two major categories: data and instructions.
of a
Pure binary data, coded binary data, and character codes have one thing
data.
in
common: they
in
are
all
The contents
of data
conjunction
codes are input to the CPU as a means of identifying the next operation which you want the CPU to perform. A sequence of instruction codes, stored in memory, constitute a proInstruction
gram.
Consider the six-step binary addition program described at the end of Chapter 3. Let us examine, in the following paragraphs, the logic that the CPU must contain to perform this binary addition.
CPU REGISTERS
The CPU must have one or more registers in which data ACCUMULATOR that have been fetched from memory can be stored; we will call these registers Accumulators. Since the majority of microcomputers use an 8-bit word size, that is the word size we will adopt and assume an 8-bit
Accumulator:
7
6 5 4 3 2
10
Bit
number
(A)
TT
4-1
Accumulator
we will,
for the
is
just
one Acthe
Chapter 3
is
stored
in
The CPU usually operates on the contents of an Accumulator, rather than accessing memory words directly. Does this make sense? Remember, the Accumulator is a register
within the logic of the CPU:
CPU
Accumulator
Since data
is
permanently stored
in
external
that operating
on data
in
CPU
register forces
sequence:
CPU
Step 2
Accumulator
Step
Step 3
Memory
do:
4-2
Unfortunately the
quire
"One step" illustrated above does not always work. Some CPU operations two memory words' contents to be fetched from memory:
re-
Word A
ADDWord B
Sometimes the CPU operates on
a single word:
-> Word C
Word A
Ones Complement-
-Word C
Or we can look at the One step operation negatively: must we always spend time fetching data from memory, then returning results to memory? The answer is no. Every memory access takes time and logic. By having a few data storage registers in the CPU, we can have one memory access for every
for
is better than two memory accesses which the one step sequence requires. Therefore nearly all microcomputers have Accumulators, or Accumulator type registers in the CPU.
five
CPU
every
CPU
operation,
In order to access a data memory word, either to read its conDATA tents or to store data into the memory word, the data memory COUNTER word address must be identified; this address is held in a register which we will call the Data Counter. The size of the Data Counter will depend on the maximum amount of memory that the microcomputer can address. Here is a 16-bit Data Counter, which can address up to 65,536 words of data memory:
T
"i
Accumulator
i
(A)
r~i
r
Data Counter (DC)
A microcomputer's CPU can have one or more Data Counters. To keep things simple, we will, for the moment, assume that the CPU has only one Data Counter.
Referring again to the binary addition program described
in
Chapter
3,
the data
memory
ad-
dresses
In
16
would be held
in
order to access a
of the
word of data memory, the CPU needs an Accumulator to store the contents accessed data word, and a Data Counter to store the address of the data word being ac-
cessed.
Similarly, in
CPU
is
tion codes,
and
code
is
going to be fetched.
The
will
instruction code is stored in an Instruction register; the CPU always interpret the contents of the Instruction register as an instruc-
INSTRUCTION REGISTER
tion code.
The address
of the memory word from which the instruction code will be fetched is provided by a register which we will call the Program Counter.
PROGRAM
COUNTER
The Program Counter is analogous to the Data Counter, but the Data Counter is assumed to always address a data memory word, while the Program Counter is assumed to always address a
4-3
We now
registers:
Accumulator
(A)
Program Counter
There
(PC)
one important conceptual difference between the Data Counter and the Program storing instruction codes in sequential memory words, the problem of creating instruction code addresses in the Program Counter is resolved. All that is after accessneeded is to find some way of Ipading an initial address into the Program Counter. ing a memory word to fetch an instruction code, the contents of the Program Counter is incremented by 1, then the Program Counter will be left pointing to the memory word containing the
is
Counter.
By
If,
is
not
likely to
have long runs of sequential memory acor data tables are held
in
when
in
multiword
units,
contiguous
memory words, will the Data Counter be required to access sequential memory locations. Even when the Data Counter is required to access sequential memory locations, is not clear whether the Data Counter should start at a low memory address and increment, or start at a high memory address and decrement. Therefore, CPU logic is going to have to provide the microcomputer user with a great flexibility when it comes to setting addresses in the Data
it
Counter.
HOW CPU
In
order to fully understand how microcomputer CPU registers are used, we will step through the binary addition program of Chapter 3, showing how the contents of the four registers change. We will, from here on, refer to each step of the INSTRUCTIONS program as an Instruction, since in reality, each step, as illustrated, merely identifies an instruction's binary code.
Initially the Program Counter (PC) contains 0400 16 the address of the first instruction word in program memory; the contents of other registers is unknown. We assume, to complete the illustration, that data memory words 0A30 16 and 0A31 16 initially contain 7A, 6 and 2F, 6 respectively.
,
,
Address
of
Memorv Word
f
0400
0401
Memory Word
I
9C
A DC
I
0A
30
Instruction
0402
0400
Instruction 2
PC
0403
Program
40
0404
9C
Memory
0405
0406 0407
0A
31
V
)
Instruction 3
80
60
Instruction
0408
Instruction 5
I 0409
(
0A30
7A
2F
Data
Memory
\
j
^
0A31
4-4
of the memory word addressed by PC into the Instruction register memory word contents will be interpreted as an instruction code. The CPU
(I),
Address of
Memory Word
0400
0401
Memory Word
I
9C
A DC
PC
0A
30
>
)
Instruction
9C
0401
|
0402
0403
Program
40
Instruction 2
0404
0405 0406
0407
9C
Memory
0A
31
V
)
Instruction 3
80
60
Instruction 4 Instruction 5
0408 0409
0A30
Data
7A
2F
0A31
Memory
0A32
in the Instruction register, causes CPU logic to implement two steps. memory word addressed by PC is fetched from memory, but is stored in Data Counter (DC). The CPU then increments the contents of PC:
Address
of
Memory Word
Memory Word
9C
0400
0401
0A00
Instruction
1
A DC
PC
0A
30
V
)
9C
0402
0402 0403
Program
40
Instruction 2
)
9C
Memory
0A
31
>
1
Instruction 3
80
60
Instruction 4
0408
Instruction 5
0409
7A
Data
2F
Memory
4-5
memory word addressed by PC is fetched from memory and CPU increments the contents of PC:
stored
in
Address of
Memory Word
0400
0401
Memory Word
9C
0A30
Instruction
1
A DC
1
0A
30
>
)
9C
0402 0403
Program
0403
Instruction 2
PC
40
0404 0405
0406
0407 0408 0409
9C
Memory
0A
31
V
)
Instruction 3
80 60
Instruction
Instruction 5
0A30
Data
7A
2F
0A31
Memory
0A32
1
Execution of Instruction
is
now
LITERAL,
OR
and 0402 16 have been loaded' into the DC register. even though these two memory words are in program memory, and are addressed by the Program Counter (PC). The important concept here is
16
IMMEDIATE
DATA
to follow
it,
after instruction
codes
called Literal, or
Immediate data.
1, memory words 0401 16 and 0402 16 contain the immediate data code 9C, fetched from memory word 0400 16 identifies the way in which the immediate data 0A30 16 must be interpreted by the CPU. /
For example,
.
in
Instruction
0A30, 6 The
instruction
4-6
Let us
now
continue to Instruction
tents of the
2. Upon completion of Instruction 1, the CPU fetches the conmemory word addressed by PC, then increments PC. Having been given ho other
word
are stored
in
the
register, to
be
in-
Address
of
Memory Word
Memory Word
0400
0401
9C
0A30
Instruction
1
DC
I
0A
30
40
0402 0403
Program
0404
Instruction 2
PC
40
0404 0405
9C
Memory
0A
31
Instruction 3
0406
0407
Instruction 4
0408 0409
60
Instruction 5
0A30
Data
7A
2F
0A31
Memory
OA32
code causes the CPU to fetch the contents memory word into the Accumulator (A):
of the
This instruction
and to load
this
Address
of
Memory Word
0400
0401
Memory Word
7A 9C
A
0A30
DC
PC
0A
30 40
^
J
>
Instruction
40
0402 0403
Program
0404
Instruction 2
0404 0405
0406 0407
9C
Memory
0A
31
> J
Instruction 3
80 60
Instruction 4
0408 0409
Instruction 5
0A30
Data
7A
2F
0A31
Memory
0A32
4-7
DC
is
contents nor PC contents are incremented. PC contents are not increnot immediate data;
is
it was fetched from data memory. DC contents are no guarantee that data words will, in the normal course of events,
mented because 7A
be referenced sequentially.
Instruction 2 has
now completed
instruction
execution, and
code
for Instruction 3.
1,
a repeat of Instruction
1,
literal
data
0A30 16
0A31
16
As
for Instruction
1
CPU
registers
undergo changes
I
in
three steps
when
Instruction 3 ex-
ecutes; step
register:
Address of
.Memory
Memory Word
Word
7A
A
0A30
r
-
0400
0401
9C
DC
I
0A
30
>
Instruction
9C
0402
0405
Instruction 2
PC
0403
Program
40
0404 0405
,
9C
Memory
0A
31
>
Instruction 3
0406
0407
80
60
Instruction 4
Instruction 5
0408
I 0409
,
0A30
7A
2F
Data
i
(
Memory
^
0A31
Step 2 fetches
chance, that
is
0A
from word 0405 16 and stores it in the high order byte of the DC register; by what the DC register contained, so no change appears in the DC register:
Address
of
Memory Word
Memory Word
7A
I
A
DC
I
f 0400
1'
9C
0A30
>
Instruction
1
040
0402 0403
Program
0A
30
9C
0406
Instruction 2
PC
40
0404
'
9C
Memory
0405 0406
0407
0A
31
>
Instruction 3
80 60
Instruction 4
0408
Instruction
5.
I 0409
/
0A30 0A3
QA32
7A
2F
Data
<
(
Memory
4-8
Address
of
Memory Word
0400
0401
Memory Word
7A
9C
0A31
Instruction
1
A
DC
PC
0A
30 40
9C
0407
0402 0403
Program
Instruction 2
0404 0405
0406 0407 0408 0409
9C
Memory
0A
31
Instruction 3
Instruction 4
60
Instruction 5
0A30
Data
7A
2F
0A31
Memory
0A32
Instruction 3 has
now completed
into
I:
is
ready to begin. As
CPU
memo-
word addressed by PC
Address of
Memory Word
0400
0401
Memory Word
7A
9C 0A31
Instruction
1
A
DC
I
0A
30 40
80
0402
0408
Instruction 2
PC
0403
Program
j
*
9C
Memory
0A
31
Instruction 3
Instruction 4
0408 0409
60
Instruction 5
0A30
Data
7A
2F
0A31
Memory
0A32
4-9
The
instruction
and to add
this data
code 80 requires the CPU to fetch the contents of the data word addressed by DC word to the contents of the Accumulator (A):
Address
of
Memory Word
0400
0401
Memory Word
A9
9C
0A31
>
Instruction
1
A DC
I
0A
30
80
0402 0403
Program
0408
Instruction 2
PC
40 9C
)
J
Memory
0A
31
Instruction 3
80
60
Instruction 4 Instruction 5
0408
I 0409
0A30
0A31
7A
2F
Data
J
I
Mem0ry
0A32
Instruction 4 has
If
now completed
execution.
the
sum
in
A were
memory word
other than
0A31
16
we would now
have to execute another variation of Instruction 1 to load a data memory address into DC. But the Accumulator contents are to be stored in memory word 0A3T 16 and that is the memory word
,
memory
address" instruction
is
unnecessary.
into data
We conmemory
5,
word 0A31
Step
1,
16 via
these
two
steps:
code
in
Address
of
Memory Word
Memory Word
A9
A
0A31
0400
0401
9C
DC
I
0A
30
>
Instruction
60
0402
0409
Instruction 2
PC
0403
Program
40
0404
0405 0406 0407
9C
Memory
0A
31
>
Instruction 3
80 60
Instruction 4 Instruction 5
0408
L 0409
..
0A30
0A31
7A
2F
Data
Memory
{
I
4-10
Step
2,
store the
Accumulator contents
into the
Address
of
Memory Word
Memory Word
A9
9C 0A31
Instruction
1
0400
0401
A DC
PC
0A
30
60
0402
0409
Instruction 2
0403
Program
.
40
0404
9C
Memory
0405
OA
31
Instruction 3
0406
0407
Instruction 4
0408
60
Instruction 5
0409
0A30
Data
0A31
7A A9
Memory
OA32
completed execution, and the program
is
Instruction 5 has
done.
Binary addition
2)
Boolean operations
3)
4)
Complement
Shift a data
a data
word
bit to
word one
logic
the
right, or to
the
left.
may be
built
Instruction register.
Unit. In
4-11
The "Buffer register" holds data that are transiently in the CPU. For example, when two data bytes are added (as in Instruction 4 of the binary addition example), the data word which is fetched from memory, to be added to the Accumulator contents, will be stored in the Buffer
register.
r
STATUS FLAGS
. '
"~
"J
fe
<->
1
ACCUMULATOR
SHIFTER
DATA COUNTER
i
**
PROGRAM COUNTER
COMPLEMENTER
ADDITION
AND BOOLEAN
LOGIC
3 m < < a _
w
\
\v
-J
,-r-,
CONTROL UNIT
1 '
BUFFER REGISTER
,
**
Logic control paths are represented by:
Figure 4-1.
STATUS FLAGS
A CPU must
a status
flag.
have a set of single binary digit logic gates which are automatically set ALU operations. Each binary digit logic gate is called
Intermediate Carry.
the Carry status, so that
it
In
order
to
perform
multibyte
CARRY STATUS
memory words:
recorded
in
may be propagated
High order
-
Low
order
word
word
10 110 11 10 10
1 1
10
1 1
10
status from
bit of
MJ_0J__0__ Carry
1-*-
high order
10
10
10
bit
10
10
High order
position
The
Carry status
6.
is
also useful
when
performing multiword
shift operations,
as described
in
Chapter
4-12
In
order to perform
BCD
arithmetic,
bits of
it
is
any carry
in
INTERMEDIATE
an 8-bit
since,
as described
CARRY STATUS
Chapter
2,
each
encodes
There are some additional statuses which may also prove useful when performing various types of data manipulation or decision making operations.
A Zero status flag may be set to 1, to indicate that a data manipulation operation generated a zero result; this flag will be reset to otherwise. A word^of caution is required at this point. Most microcomputers and minicomputers have a Zero status
flag.
It
is
Zero status
flag will
be set to
if
data manipulation operation generates a zero result, while the status flag
is
ZERO STATUS
set to
for a
non-zero
result. In
is
complement
Another important point shoufctTtoe made concerning the Zero status flag, and most other status flags?^Wiose instructions which set or reset
WHEN
STATUSES ARE MODIFIED
status flags, and those which do not, are carefully selected by microcomputer designers.
Consider the very obvious case of multibyte addition, as illustrated above. The low order words of two 2 -word numbers are added, and the Carry status is set or reset to reflect any carry out of the high order bit of the low order words. The carry must be added to the low order bits of the two
high order words of the two-word numbers. This means that the Carry status must be preserved while the two high order words are loaded into CPU registers. Clearly it would be disastrous to
program
logic
if.
when
word
of data
was
cleared to
At
this point,
it
is
only important to
remember
in which status flags are set or reset is very immost carefully thought out feature of any microcomputer CPU design. In other words, status flags do not necessarily represent conditions within the CPU now; they may
way
portant and
is
one
of the
last
formed.
The use
is
of the high order bit of a memory word as a sign bit, when performing signed binary operations, gives rise to two^status flags. First, there is the Sign status, which
made
SIGN STATUS
or multiword:
^
highest
order
word
X
/
-\
sign
bit
bit of
every byte
will
be treated as a sign
to interpret
it.
bit.
and when
4-13
is
microcomputer
OVERFLOW
STATUS
a carry
when
legal
and simply reflects a carry into the next higher word of two 4-word numbers, with eight bits per word:
Magnitude
Sign
bits
of
number
A
00100011 00011101 01000001
of
Valid carries
^
if
01011011 10111001
00010101
^
a
11001011 11011000
10111100 11000111
10000011
a single
\*
numeric enwhether is in
it
Sign
vy
10100100
knowing whether
memory word
is
or part of a multiword
numeric
far
entity and,
of the
part of a multiword
numeric
entity,
word
is,
or at
one end
an addition
so
word. This being the case, a carry generated as the as the microcomputer logic is concerned, always perfectly valid.
When
in
the high order bit of a data word is being interpreted as a sign bit. any carry out of the penultimate bit will represent an error overflow, that is, a result that will not fit
the allocated space. Consider a single, 8-bit data word, being interpreted as signed binary data:
Sign
bit
5A
+ D3 = -3B?
+ 01101011 =1 10 10
kJ A carry
f~ 110 10
bit
10
1
bit
into the
We
(-2)
must devise
a
carry
Does
+(-2) =(-4):
bit
+ (-2) = (-4)
There
data
bit
Although there is a carry out of the high order data bit, the result is 4, which is correct. We will use the symbol C s to represent a carry out of the sign bit and C p to represent a carry out of the high order data bit. What if C s and C p are both 0?
2
+2 =4
10 10
Q c n =o-~ c s =o
1
4-14
11110100
(-0C)
+ 00001001 = 11111101
C
s
+
.
09
=(-03)
=0
zero, the
C
p
=0
is
answer
always
correct.
1
Now
10 10 + 01111001
1 1
(-75)
U C
10
+ 79 = + 4)
(
'J
(Recall that
is
01 110101. the
10 10
1
(-28)
1
+ 59 = (+31)
,w
110
+
111
1
(-39)
1110
1
110 10 10 110 u
c
+ -1A)
=(-53)
both
1.
the
is.
answer
is
always correct.
or the other, but never both are
1.
that
either
one
the answer
is
always
10
10
1
110
10 10 l
i
111
10
45 67
?
=(-54)
10 10 10 10 10 10
(-6E)
JO
110 110
+ (-5C) = +36
4-15
Our strategy
clear.
for setting
and
1),
resetting the
Overflow status
bits are
will
is
therefore
OVERFLOW
STATUS SET STRATEGY
When
and penultimate
will
the
same
(C
or both
differ,
be set
1.
to zero.
When
be set to
is
indicating that
therefore wrong.
Overflow
will
be the Exclusive
OR
and penultimate
bits:
OVERFLOW =
The
C,
Parity status is the only other status which is worth mentioning at this time. This flag, if present, is set to 1 each time a data transfer operation detects a data byte with the wrong
parity. Clearly this status
.
PARITY
STATUS
'
"
contents of a
memory
be ignored most of the time, since it is only meaningful word is being interpreted as a character code.
will
when
the
INSTRUCTION EXECUTION
We
a microcomputer CPU may interpret the contents of a memory word as an instruction code. But this leaves a number of unanswered questions. What maximum or minimum number of logical events constitutes an instruction? What occurs within the CPU during the course of an instruction's execution? And what external support logic does the CPU demand?
In answering these questions, we introduce a very critical microcomputer concept, and one of the key differences between the minicomputer and the microcomputer.
have described
how
tion set
the world of minicomputers, the most important feature to look for in an instrucis the versatility of operations performed by the CPU in response to each instruction code. This is reasonable for minicomputers; minicomputers are frequently called upon to perform varied and varying tasks, and programming may be an ongoing, major expense.
In In
is far
CPU demand
Complex
instructions usually demand complex- logic external to the CPU. This is of no concern to the minicomputer user, who buys CPU plus all external logic, packaged in a single box. This is of great concern to the microcomputer user, who must interface his logic, often directly to the CPU. If a microcomputer costs somewhere between $5 and $100, the entire economics of using the microcomputer will evaporate unless the interface logic demanded by the microcomputer CPU is also inexpensive.
Let us therefore examine how an instruction is executed, and then return, at the of this chapter, to the differences between -minicomputer and microcomputer.
end
INSTRUCTION TIMING
As with
microcomputer CPU are controlled by a which may vary from as little as 100 nanoseconds to as much as a microsecond. We will refer to this clock signal using the symbol
all
Clock Signal
.TLTLnLTL
Period
4-16
While the
crystal
must be
external to the
CPU
signal
may
or
may
not be on the
same
how
the
CPU
has
been designed, the timing signal may be a straightforward single signal, as illustrated above, or it may consist of a more complex interaction of signals. Here is one possible combination of two
signals, identified
<j> 2
_n
ji
Period
The simple
signal provides
Edge 2
State
2-p
1
^~ State
=
The more complex
signals provide four
|*Penod-*-J
0=0
period:
Period
State
1:
01 0,
(J),
State 2:
State
3:.
= = =
2
(j)
2 2
(j)
= = =
In this
chapter
we
will
(J).
INSTRUCTION CYCLES
The execution of every
instruction,
two
by any microcomputer, may be divided into and the instruction execute. This was illustrated
starts
earlier in this
chapter for the six-step binary addition example. Recall that every instruction
with the instruction code being loaded into the Instruction register.
as an instruction fetch.
We
operation
CPU
along
logic
Program
Counter
register,
is
with
INSTRUCTION FETCH
this
is
memory word
is
concerned,
simply a read
4-17
The contents
register,
of the
is
stored
in
the Instruction
instruction code.
CPU uses its own internal logic to Program Counter. The Program Counter now points to the memory word following the one from which the current instruction code was fetched.
responding to the instruction fetch, the
While external
1
add
Once the instruction code is in the Instruction register, triggers a sequence of events controlled by the Control Unit; this sequence of events
it
INSTRUCTION EXECUTE
Two
clock periods will be used to execute an instruction; one will time the instructime the instruction execute:
Instruction
Instruction)
Fetch
Execute
One
Instruction Cycle
Next consider the signals via which the CPU will communiCPU PINS cate with external logic. The 40-pin DIP, being the most popular AND SIGNALS among today's microcomputers, is the one we will adopt which means that 40 signals may be input and/or output, including the clock, power and ground.
The way
in which the 40 pins of the DIP are used constitutes one of the ble features of microcomputers, but they all begin along these lines:
most
varia
Vdd
Power and ground
Vss
Vgg
.clock
4-18
Vdd
Vss
is
power
input.
is
Vgg
is
is
not required
in all
LSI devices.
Many
devices
simply,
in
one
of
POWER
SUPPLIES
+ 5v+ 12v-
Gnd-
In this
case the device requires two power supplies, + 5v and + 12v, plus
GROUND
power supply
will suffice:
+ 5v-
Gnd-
The
is,
first
step,
in reality,
when executing any instruction, is the instruction fetch; that memory read. requires a memory address to be output,
It
in
response.
the
quired,
each binary
digit of
Vdd
2 3
Vgg
(])
w clock
AO
A1
A2 A3 A4 A5 A6
A7
Address
-<
A8
A9
A10
A11
A12 A13
A14 A15
4-19
All
data
will
A READ
enter and leave the microcomputer CPU via eight bi-directional signals. control signal, indicating that data must be input to the CPU, completes the
Vdd
Power and ground
v
clock
DO
D1
Vss
Vgg
D2
D3 D4 D5 D6 D7
>Data
AO
A1
A2
A3
A4 A5 A6
READ
A7
.
Address <
A8
A9
A10
A11
A12
A13 A14
A15
AO
to
A15-
ADDRESS
STABLE
X
E
XDATA Y "
STA
DO
to
D7
Instruction
Fetch
4-20
Consider the six-step binary addition program which was described at the end of Chapter 3. There are four separate and distinct types of instructions within the program. They are:
1)
and
3).
it
2)
Fetch the contents of the data word addressed by the Data Counter and store in the Accumulator (Instruction 2).
3)
Fetch the contents of the-data wordiaddressed by the Data Counter, add it to the contents of the Accumulator, and store the result in the Accumulator (Instruction
4).
4)
in
the
is
the simplest, so
it
we
will begioi
witrHt.
MEMORY READ
SIGNALS AND TIMING
instructions,
The Control Unit decodes the instruction code 40 16 and in response causes a data word to be fetched from memory. In reality, sine the data is in a memory word on a memory device, all the CPU can really do is generate. signals at its pins-ilogic external to the CPU must respond to these
.
signals
if
is
to
be accomplished.
As seen by
generated
CPU
Memory Read
instruction
is
as follows:*
AO
to
A15
V A
INSTRUCTION
ADDRESS
Y A
DATA
ADDRESS
Y A
DO
to
D7
MU3L
Instruction
I
Data
Fetch
Fetch
Memory Read
Instruction
4-21
instruction fetch
cycles:
During the instruction fetch cycle, the address output on AO - A 15 is the contents of the PC register; during the data fetch cycle, it is the contents of the Data Counter. During the instruction fetch, data input
fetch,
it
2)
is
stored
in
is
stored
in
the Accumulator.
If
scheme demands very little of the external logic. READ is when is high, then memory circuits must decode AO A 15. The selected memory module must extract the contents of the addressed memory word and make sure is at the microcomputer data pins when
This simple
EXTERNAL
LOGIC
high
REQUIREMENTS
it
is
low.
What
the microcomputer
is
CPU demands
is
standard, sim5,
part of
continue with
In
CPU
any memory device; but we will defer this discussion signals and timing for the ADD instruction.
to
Chapter
and
word, exactly as
did for a
CPU fetches the contents of a memory Memory Read instruction; however, for the
added
to the contents of the
ADD
OPERATION SIGNALS AND
TIMING
Add
Ac-
Memory Read
is
instruction
As seen by
Instruction
Memory Read
instruction.
4 causes the contents of the Accumulator to be stored in the the Data Counter; this is called a Memory
As seen by
sequences for a Memory Read and a Memory Write is that a WRITE signal must go high, instead of a READ signal, when We must therefore add a WRITE signal to our CPU device:
signal
between the
is
high
(Vdd
Vss
DO
D1
2 3
Vgg
fc_
D2 D3
rlnrk
>
Data.
AO
A1
D4
D5
D6
A2
A3
A4
D7
R
READ.
WRITE
A5 A6
A7
.Address
<
A8
A9
A10
A11
A12
4-22
Timing
for a
Memory Write
instruction
is
as follows:
AO
to
A15
INSTRUCTION
ADDRESS
V ^
DATA
ADDRESS
/^
DO
to
D7
MjQL
Instruction
Data
Store
Fetch
Memory
Write
Instruction
Instruction 1 loads a memory address into the Data Counter. This instruction occupies three memory words, one for the instruction code and two more for the memory address.
Notice that the Load Data Counter instruction
ry reads, with these differences:
1) is
equivalent to
two memo-
the 40 16
memory reads are specified by one 9C, 6 instruction code. By Memory Read instruction code triggers just one memory read.
instruction fetches data
con-
2)
Memory Read
from memory words whose addresses come instruction, the Data Counter provides the
memory
address.
3)
memory by
is
stored, in the
upper and
is
Memory Read
stored
the Accumulator.
4-23
The differences between the Load Data Counter and the Memory Read
may be
instructions
contrasted as follows:
MEMORY READ
While the logic operations internal to the CPU are completely different for the Load Data Counter and the Memory Read instructions, the external timing and signal sequences are remarkably similar. A very smart microcomputer CPU could execute the Load Data Counter instruction in three time periods, as follows:
AO
to
A15
INSTRUCTION
INSTRUCTION
ADDRESS
ADDRESS +
INSTRUCTION ADDRESS +2
DO
to
D7
I^XJQLJGEL
InstaEtiiun
I
First half
Second
of
j
half
Fetcrr
of
Address
Fetch
I
Address
Fetch
4-24
not try to be so clever. In order to simplify CPU logic, the Program Counter contents are only output, as an address, during the first clock period of an instruction. The Data Counter contents, likewise, are only output during the second clock period of an ininstruction. This simpler CPU will require six clock periods to execute the Load Data Counter
Some microcomputers do
struction:
_r
AO tn A 5 ttuluM,J
1
I
V
V
Y INSTRUCTION A * ADDRESS
INSTRUCTION ADDRESS +1
INSTRUCTION
V
J\
ADDRESS
+ 2
,_T~L
DO
to
D7
_A2LA_
Instruction
1
XE$
First half
|
X^L
!
Second
of
half
Fetch
of
Address
Fetch
|
|
Address
Fetch
I
INSTRUCTION DO?
in this
made
now consider ways in which the instructions described simpler or more complex.
chapter
may be
instruction loads the two 8-bit words which follow the instruction code into the Data Counter. This instruction could be broken up into two instructions, one to load the low order byte of the Data Counter, the other to load the high order byte of the Data Counter. Let us compare the two forms of the Load Data
Counter
instruction:
9C
9D
Load 0A30 16 into the Data Counter
Load
0A 16
into
Data Counter
OA
30
OA
9E
Load 30, 6
into
Data Counter
30
Low
order byte
One
Two
Counter Instructions
4-25
The three-byte Load Data Counter instruction's possible signals and timing have been The two 2-byte instructions could each execute in two time periods or in four
ecuting
in
illustrated.
two time
periods, signals
and timing
for
AO
to
A1
INSTRUCTION
ADDRESS
INSTRUCTION
ADDRESS +
V"
i
INSTRUCTION
ADDRESS
INSTRUCTION
ADDRESS +
I
I
I I
_r
DO
to
I
"
D7
L
i
lM-J^^_lKl^Ei
1
T
| I '
First
|
First half
Second
Instruction
Second
of
|
half
'
Instruction
of
Address
Fetch
Address
Fetch
Fetch
Fetch
Timing and
signals,
when
executing
in
would be as
follows:
J
i0 to
I
VinstructionV ftADDRESS + lA
I I
AIR
"VinstructionV ADDRESS A
ft
I
VinstructionV | ADDRESS ^
I
Vinstruct'IonV"
XaDDRESS + i'X
I
I
READ-J
DO
to
D7
First
JO.
First half
Second
Instruction
Second
of
half
Instruction
of
Address
Fetch
Address
Fetch
Fetch
Fetch
simplify the
Breaking the three-byte Load Data Counter instruction into two 2-byte instructions does not demands placed on external logic by the CPU: but it does make the microcomputer's
we
will
demonstrate
later in this
chapter
when
describing microprogram-
4-26
Now
Memory Read
instructions as
follows:
41
Load
into the
of the of this
memory
three-word
OA
30
As
tion;
Memory Read instrucmemory word whose contents is to be read into the Accumulator. Instructions that specify the memory address to be referenced, as this DIRECT three- byte Memory Read instruction does, are said to have direct memory
illustrated
above. 41
16 is
OA30 16
is
addressing.
Signals and timing for the three-byte
ADDRESSING
Memory
Read instructions could take one of
many
forms.
Here
is
the most
compact
possibility:
A0
to
A15
DO
to
D7
j
Instruction
III'
j
Fetch High
Fetch
Low
Fetch Data
Fetch
Order
half of
Order
half of
J
Data Address
Data Address
Instruction
I
Three-byte
Memory Read
Execution
To
Memory Read
a minicomputer designer, combining the Load Data Counter instruction with the is obvious. or with any memory reference instruction
virtues of direct addressing are not so obvious, for the immediately apparent reason that direct addressing instructions require more complex Control Unit logic; this will be illustrated later in this chapter
is
when microprogramming
But there
is
described.
immediately apparent reason why direct addressing is not obviously desirable; whereas most minicomputer programs are stored and executed out of RAM, most microcomputer programs are stored and executed out of ROM; that means direct addressing can only be used when the data address will hot change.
less
4-27
Consider an elementary instruction sequence which receives data input from an external device, then stores the data into a
REFERENCING
number
DATA TABLES
of consecutive
memory words:
From
External
Device
RAM
dress.
data
memory words in the above illustration constitute a "data table." The 0A10 16 has been arbitrarily selected; any other address would do as well.
.
beginning ad-
many
fill
in
selected
Program
addresses
Memory
9C
0280
0281
0A
10
Counter
0282
0283
08
60
E3
0284
0285 0286 0287
in
memory
BC
83
straightforward Load Data Counter instruction, stored in program memory 0281 16 and 0282 16 loads the address 0A10 16 into the Data , Counter; this is the address of the first word in the data table.
words 0280 16
instruction
The
code 08 16
in
of data to
be input
to
instruction code 60, . in program memory word 0284, , is a simple Store 6 instruction; it causes the contents of the Accumulator to be stored in the data memory word addressed by the Data Counter; initially that is the first word of the data table, with
The
Memory
address 0A10, R
The next two instructions, located in program memory words 0285, 6 0286, 6 and 0287, 6 increment the Data Counter contents (to address the next word of the data table), then change the value in the Program Counter to 0283, 6 execution now returns to
, . ;
PROGRAM
LOOP
the instruction which
program loop
task
have established a a group of instructions that continuously get re-executed; a slightly different
is
word
into the
We
is performed on each re-execution, because the Data Counter contents each pass.
incremented on
4-28
Four instructions, occupying five length of the data table may be!
memory
bytes, can
fill
We would
have:
Memory
0280
0281
08
61
0282
0A
10
in
data
memory word
bytes
third instruction
0283 0284
0285 0286
Increment what?
tlata table is addressed by the second and third bytes of the memory-storewith-direct-addressing instruction. This address cannot be incremented if it is going to reside in ROM! Minicomputers have a solution to this problem, of course (we shall see what the solution is in Chapter^), but the solution adds complexity to microcomputers and the complexity may bring with it more cost than savings.
The
in
Counter to be increased by
CPU OPERATE
INSTRUCTIONS
CPU
is
idle:
AOto A15
Y A
INSTRUCTION
* bpRESs
V A
DO
to
D7
Instruction
CPU
operations
Fetch
CPU
Operate Instruction
4-29
The instruction in program memory words 0286 16 and 0287 16 actually changes the contents of the Program Counter, and
thus changes the sequence in which instructions are executed. This is referred to as a Branch or Jump instruction.
BRANCH
INSTRUCTION
JUMP
INSTRUCTION
Branch instructions have many variations. A two-word version is illustrated in the program loop; the contents of the second instruction word is loaded into the low order half of the Program Counter as follows:
E3
ABSOLUTE BRANCH
BC
83
0285
0286 0287
E3
BC
83
The problem with this variation of the Branch instruction is that it will not work if the Program Counter high order byte
gets incremented. For example, suppose
in
was
stored
BRANCHING AT PAGE
memory
as follows:
BOUNDARY
Program
Memory
02FC
9C
\
J
02FD
02FE
02FF
0A
10
1
}
08
0300
0301
60
E3
Memory
Write
j
)
0302
BC
FF
j
0303
Branch to FF
Branch to FF 16 would branch to 03FF 16 not to 02FF 16 because the high order byte gram Counter got incremented between the input and memory write instructions.
, ,
of the Pro-
we can have a three-word Branch instruction which changes both halves of the Program Counter.
First,
Second,
struction
it
we
word
interprets the
can add the contents of the second Branch into the Program Counter, designing the CPU so that second Branch instruction word as a signed binary numprogram
loop, after the
PROGRAM
RELATIVE
BRANCH
this value to
0288 16
to
change
0283 16
of 5
is:
111110
11
4-30
8FB 16 This is the value that would be stored in program memory word 0287 16 Adding an value from memory to the 16-bit contents of the Program Counter using signed binary arithmetic is not a problem; CPU logic simply propagates SIGN the sign bit through the high order half of the value to be added PROPAGATION to the Program Counter. In this case we have:
or
. .
bit
Program Counter
Value added
(old)
0.0.0
.1.0
1:
1tflJ^J_1111011
Sign
bit
propagation
Sign
bit
Adding 5
to the
(old)
Q.
0.1.0
10
:i:^::^::^:-6:::0::Qx0:p
10 10
0000001
0T
0001 101
Sign
bit
bit
propagation
This
is
A microcomputer CPU may be illustrated functionally, as in Figure 4-1, but in reality, the CPU consists of a number of logic elements, activated by sequences of
enable signals.
The Complementer,
ing
for
example,
is
latently able, at
complementer
any time, to complement the contents of circuits. A single enable signal, emanat-
sequence.
We
However, complementing eight data latches within the Complementer serves no useful purpose. want to complement the contents of the Accumulator, and that means moving the contents returning the of the Accumulator to the Complementer, then, after enabling complementer logic,
results to the
Accumulator.
4-31
Complementing the contents of the Accumulator therefore requires these five steps: Move the contents of the Accumulator to the Data Bus: 1)
ARITHMETIC AND LOGIC UNIT
STATUS FLAGS
ACCUMULATOR
\
\
\ 1
\
I
H*
H
i
-t^_
DATA COUNTER
COMPLEMENTER
PROGRAM COUNTER
INSTRUCTION REG
ADDITION
AND BOOLEAN
LOGIC
:
d
CONTROL UNIT
BUFFER REGISTER
>-u
DATA BUS
2)
Move
r~
STATUS FLAGS
K*n
ACCUMULATOR
DATA COUNTER
COMPLEMENTER
*c
10110101
Kr
'
PROGRAM COUNTER
INSTRUCTION REG
ADDITION
AND BOOLEAN
LOGIC
*-<D
CONTROL UNIT
BUFFER REGISTER
4-32
3)
Activate
Complementer
logic:
n
ACCUMULATOR
r*H"
STATUS FLAGS
-*[
COMPLEMENTER
DATA COUNTER
PROGRAM COUNTER
INSTRUCTION REG
ADDITION
AND BOOLEAN
LOGIC
I
-h
^0
CONTROL UNIT
BUFFER REGISTER
4)
Move
Complementer
*W
STATUS FLAGS
|< >
ACCUMULATOR
DATA COUNTER
h: *c
J.
COMPLEMENTER
K-r
ADDITION
PROGRAM COUNTER
INSTRUCTION REG
AND BOOLEAN
LOGIC
I
"XD
,
CONTROL UNIT
BUFFER REGISTER
4-33
5)
Move
r-C
STATUS FLAGS
COMPLEMENTER
ACCUMULATOR
DATA COUNTER
-c
-o
i
PROGRAM COUNTER
INSTRUCTION REG
ADDITION
AND BOOLEAN
LOGIC
0'
CONTROL UNIT
BUFFER REGISTER
Each of these five steps is referred to as a microinstruction. Each microinstruction is enabled by a signal from the Control
Unit. By outputting the appropriate sequence of control signals, the Control Unit can sequence any number of microinstructions, to create a macroinstruction, which is the accepted response of
the
In
MICROINSTRUCTIONS
MACROINSTRUCTIONS
MICRO-
CPU
to
order to complement the Accumulator contents, the Control Unit must contain five binary codes, each of which triggers an appropriate control
signal (or signals). This
PROGRAMS
that are stored within
sequence
is
referred to
parallel
pro-
4-34
A
bly
microprogram
language
is
in
An assembly
language program
is
digits, usually in a
program
initiates
referred
to
as
macroprogram.
ROM
macroprogram
ROM
1
DATA
ALU
Z> - OQ
< 1<
CU DATA
\^
1
1
3.-rr
:
:
JVBCRDP.R(QGRAW:::
CPU
each macro- instruction code causes one entire microprogram to be executed
RAM
microprogram stored
in
of the
CPU
A macroprogram
consists of
ROM memory
for
RAM memory
r
i
*
:
yy-mM-yyco
y:+\
*
:-x::-:
:
A
DC
: :
:
::::::::::::
ALU
< < Q
i
: :
PC
L.J
'.
<
3 u
" "
."
.'..':
CP U
Microprogram
data area
o cc Q_ o cc u < 2
ROM
RAM
\
W T:A
;;:;::
RAM
IV
acroprograrn
d ata area
microprogram implement a small logic sequence within the logic of the macroprogram cause an entire microprogram to be executed, thus implementing a whole sequence of operations within the CPU.
Individual instructions of a
CPU.
Individual instructions of a
4-35
of operations associated with any MACROa direct function of the size of the INSTRUCTION microprogram whose execution the macroinstruction initiCOMPLEXITY ates. There are no logical breakpoints or levels at which a microprogrammer must terminate the microprogram which will be executed in response to any macroinstruction code. Of course, complex microprograms require large Control Units. A simple microcomputer may have a small Control Unit and therefore may be forced to execute very simple macroinstructions. Some large computers have no assembly language, but in response to a single macroinstruction code, execute complex sequences of events involving logic throughout the computer system
The complexity
macroinstruction
is
of every
microcomputer
is
in
reality
MICRO-
nothing but a microprogram. If you, the user, are able to PROGRAMMABLE create or modify the microprogram within the Control Unit, MICROCOMPUTER then the microcomputer is said to be "microprogrammable". If the Control Unit microprogram is designed by the microcomputer logic designer, and then becomes an unalterable part of the CPU chip, the microcomputer is not microprogrammable.
In this book we are going to describe these two separate and distinct classes of microcomputer product:
1
)
to a Central
Processing Unit, but not to the Control Unit. You sequence CPU logic using macroinstructions. referred to collectively as an Assembly Language instruction set. You cannot microprogram this class of microcomputer product; nonetheless, a basic understanding
of
microprogramming
will
when
The "microprocessor
blocks",
slice"
or
MACROLOGIC
MICRO-
PROCESSOR
SLICE
we
will describe
Let us identify an arbitrary set of control signals, as illustrated in Figure 4-2. Our microcomputer Control Unit will generate these control signals to implement macroinstructions. Tables 4-1, 4-2 and 4-3 describe these control signals.
When compared
make
real
to the ingenuity of real chip slice microinstruction codes. Tables 4-1, 4-2
inflexible
and
CPU
understand by
must
attain.
signals described in Tables 4-1, 4-2 and 4-3 do not allow the Control Unit to perform all of the operations which will be needed to support assembly language instructions. For example, nothing has been said about how the READ and WRITE control signals will be generated, or how the four status latches C (Carry), (Overflow), S (Sign) and Z (Zero) will be handled. One primitive scheme for handling these problems is to trap microinstructions that attempt to set both CO and C to this is an impossible condition, since specifies data moving on and off busses simultaneously. If CO and C1 are both 1, they will
1 1
;
The control
it
be output as
0, and the remaining signals, C2 through C8, will be interpreted as specifying the following five different classes of internal Control Unit operations:
1)
If
C2 through C8
are
in
all
0,
Z, S,
and
C, in the
ALU,
will.
have
their
condition recorded
the
CU DATA
buffer.
4-36
AO
A1
A? A3
A4
m 1
\c
1
M
AH A/
z K^=j>
cc
en
c6
n <
A8 A9 A10
A11
c7 ALU LATCHES
cARITHMETIC
A1?
A13
A14 A15
AND
BOOLEAN
LOGIC
ft
BUFFER REG
f
Dl
if
Accumulator -Bata Counter (HI) Data Counter (LO) Program Counter (HI) Program Counter (LO)
-
D2
D3
D4
D5 D6
D7
I
__7TTT
I I l
-Instruction
WRITE
Status
-Shifter
READ
Compl
ALU
-Buffer
Data Register
1
I
^Jc^
Figure 4-2.
Table 4-1.
SIGNAL
CO. CI
FUNCTION
C0=0. C1 =0; No data moved onto, or off Data Bus or Address C0=1. C1=0; Data moved onto Data Bus. or AddressRegister Data moved off Data Bus. or Address Register CO =0, C =
1 1
;
Register
C0=
C2.C3.
1.
C1
= 1;
Table 4-4)
C4.C5
C6.C7.C8
signals are
decoded
in
WRITE.
Direct connections
CU data
bits.
READ
Clock signal input to
CU
connected to four
c.o.sz
Four status
bits, directly
CU
data
bits.
4-37
Table 4-2
When CO=1
Or C1 =1
FUNCTION
Accumulator
Data Bus
select
Program Counter high order byte Data Bus select Program Counter low order byte Data Bus select
Instruction Register
-Data Bus
select
Status Register
Shifter
Complementer
ALU ALU
latches
Buffer
Data Bus
Data Register
Data
Bus select
Data Counter
Buffer Register
Not Used
Table 4-3.
ALU
Select Signals
c8
1
c7
c6
FUNCTION
Select shifter logic
Select complementer logic
AND logic*
"Operation
is
performed on contents of
in
ALU
latches
and Buffer
register.
Result appears
ALU
latches.
4-38
If
C2 and C3
S.
if
are
and
0.
will 0,
Z,
and C statuses,
C4
is
the
ALU
are
referenced:
C4
is 1.
DATA
C7 and C8
will will
will
each be checked
If
value.
If
is
1, then the next microinstruction be skipped. This use of the nine controls C through Cg may be illustrated as follows:
be checked.
Cfi
Cj Cr Ct C 4 Ct Co Ci Cn
.0
1
on status = = ALU status settings specified = CU DATA buffer status settings specified
1
,Z
_S Status selected, and should be tested
for setting of
1
.0
X
If
Do
C2 and C3 are and 1, then the logic of condition 2 described above will be repeated; however, corresponding status flags will be checked for values as the condition which forces the next microinstruction to be skipped.
If
C2,
C3 and C4
are
1,
and
0, respectively,
may
We
C8
two
far:
We
will
assume
that
tion of
READ and C7
may be
Ct;
Cq
through C 8
illustrated as follows:
C 8 C 7 Cc
C 4 Ct C? Ci Cn
1111
.Output control signals
.Not currently specified .Not currently specified
.WRITE assumes
value of this
bit
.READ assumes
5)
value of this
bit
When
C2,
C3 and C4
are
all
1,
then C5 through C8
will
be decoded
internally to specify
one
We will
will now create some microprograms. Let us begin simply, by creating an instruction fetch microprogram. Recall that every instruction's execution starts with an instruction fetch; therefore, the instruction fetch microprogram must precede every microprogram which implements an instruction's execution. The instruction fetch microprogram is shown in
Table 4-4.
We
Before analyzing the instruction fetch microprogram, microinstruction-by-microinstruction, a few general comments must be made.
Each microinstruction becomes nine binary digits within the MICROControl Unit. The 8 -bit (or byte) unit was selected as the word INSTRUCTION size for the microcomputer because this word size is useful BIT LENGTH when representing characters and numeric data, in addition to representing instruction codes. The Control Unit microprogram does not represent numeric data or instruction codes; therefore, the microinstruction bit length is arbitrarily set to whatever the microcomputer needs in this case nine bits. Since there
'
4-39
Table 4-4.
An
Instruction Fetch
Microprogram
Instruction
MICROINSTRUCTION
CODE
C 8 C} C5C5C4C3C2C Co
1 1
Number
1
FUNCTION
Move Program Counter
Set
to
110 110
Address Register
2 3
0001
1
READ Control
Data Bus to
signal true.
WRITE
false
10
10
11
to Data
Bus
4
5
110
1
Move
ALU
latches
6
7
8 9
10
11
10 10 10 10 10 10
1 1 1
Increment
1
ALU
latches
Move ALU latches to Data Bus Move Data Bus to Program Counter low Move Program Counter high order Move Data Bus to ALU latches
Skip next microinstruction
if
order byte
110
10
11
10
1
1
carry status
Increment
ALU
latches
12 13
110
10
1
1110
Data Bus to Program Counter high order byte Data Register to Data Bus Data Bus ^Instruction Register
14 "5
111010 110101
in
are 15 microinstructions
required,
s total
of
135 binary
digits will
be
a 9
tion fetch,
Notice also that a sequence of 15 microinstructions are executed during the instrucwhich must occur during one period of clock 0. The Control Unit will the cock therefore internally split the clock signal into 16 subdivisions. In other words has a oenod of one microsecond each microinstruction must execute withm 62 5 nanoseconds Since the average CPU chip consists of densely packed n MOS or p MOS logic, this time oenod is
f
reasonable
Now
The and
microprograms
CO and
it
first
two
bits of
the
first
microinstruction's C
will
nit
code, representing
0. respectively,
Address
10 1; they specify that is the contents of The next four bits are set to the Program Counter which must be moved to the Address register (see Table 4-2). Since no
register (see Table 4-1).
simultaneous
ALU
last
all
set to
The
illustrated as follows:
C 8 Ct C b C 5 C 4 C 3 C 2 C. Co
hhl'|i|o|i|i|ohl
Move
.4
.
1) is
Program Counter
If
some
understanding the crea" on of the first microinstruction, you should study see how they are also created from the informa-
tion m. Tables 4-
4-40
Microinstruction
moves
the contents of the Program Counter to the Address register, thus mak-
at
the
WRITE
and the
READ
AO through A15
be placed
to
at pins
memory word,
DO through
the time
it
takes
which
required
is
CPU
is
two
steps. Instructions 3
in
through
half of the
only),
Program Counter.
If
this
increment results
the
the
ALU
half of the
Program Counter must also be incremented. If the carry status is not set, then the high order half of the Program Counter must remain unaltered. Microinstructions 9 through 13 handle the high order half of the Program Counter. These microinstructions parallel microinstructions 3 through 7; however, microinstruction 10 specifies that the Carry status (in the ALU) is
if
STATUS
MICRO-
IN
PROGRAMS
0,
^^~
then microinstruc-
1, which actually performs the increment on the contents of the ALU latches, be skipped. Thus the high order half of the Program Counter is only incremented if the Carry status was set when the low order half of the Program Counter got incremented.
tion
in its
Note that Control Unit logic must be very specific about when it records statuses CU DATA buffer and when it does not. Use of the Carry (C) status as a means of conthe Program Counter increment
in
is
trolling
only valid
if
is
not permanently
in
recorded
the
buffer,
In
other words, the Control Unit can reference the status latches
instructions-reference the statuses stored
in
ALU any
Assembly language
in
the
CU DATA
buffer.
the
ALU
in
latches. Microinstruction
code 0000001
in
must be executed
the statuses
the
ALU
the
CU DATA
consider the five steps needed to complement the contents of the Accumulator. during the 15th step of the instruction fetch microprogram, the code loaded into the Instruction register is a Complement Accumulator instruction code, then Control Unit logic will
If,
Now
COMPLEMENT
MICRO-
PROGRAM
shown
in
Table 4-5.
order to
complement
one period
mands
time
that
of clock
will
be wasted.
Let us
or
tion
having simple
ASSEMBLY LANGUAGE
INSTRUCTION MICRO'
word
program which was described earlier in this chapter, recall that a of data can be loaded from memory into the Accumulator in one of
PROGRAMS
instructions,
Issue
two separate
half of the
data
memory
addressed data
memory word
2)
into the
Accumulator.
Use one instruction to load into the Data Counter the entire data memory address for the word whose contents is to be read into the Accumulator. Then issue a second instruction to
move
3)
memory word
to the Accumulator.
Have a single direct addressing instruction which loads the data the Data Counter, then loads the contents of the addressed data cumulator.
4-41
Table 4-5.
Instruction
A Complement Accumulator
Microprogram
MICROINSTRUCTION
CODE
C8C7C6C5C4C3C2C1C0
1
1
Number
1
FUNCTION
Move Accumulator
to
10
Data Bus
1110
1 1
110
10 10
1
Move
3 4 5
100000000
1
10 10
phase
Move Complementer to
Move
Data Bus
to
Data Bus
Accumulator
The
instruction execution
of
each
ways
in
shown
Table 4-6.
Three-Instruction
Memory Read
Instruction
MICROINSTRUCTION
CODE
C8C7C8C5C4C3C2C1C0
Fetch (Table 4-4)
Number
1
FUNCTION
Repeat microinstructions
1
through 14 of Instruction
14
15
1110
half of
10
10
to Data Counter,
(A)
Data Counter
Instruction
MICROINSTRUCTION
CODE
C 8 C7C e C 6 C4C3C2C ,Co
Fetch (Table 4
4)
Number
1
FUNCTION
Repeat microinstructions
1
through 14 of Instruction
14
15
11110
half of
10
(B)
Data Counter
MICROINSTRUCTION
CODE
C8C7C6C5C4C3C2C1C0
Number
1
FUNCTION
Move
Set
1110
10
1 1
110
10
1 1
READ
1
WRITE
false
10 10
Include
no operations
more
15 16
111110
1 1
10
10 10
1
Move Move
(C)
Into
Accumulator
4-42
Table 4-7.
One
Instruction
To Load
16-Bit
Address
Into Data
Counter
Instruction
MICROINSTRUCTION
CODE
FUNCTION
Repeat micromstrucions
Fetch (Table 4-4)
1
Number C8C7C6C5C4C3C2C1C0
1
through 14
of Instruction
14
15
1
1
10 10
1
10
c
Move
16 17
Timing
filler
1
through 14 of Instruction
30
31
11110
10
Move
Memory Read
Instruction
MICROINSTRUCTION
CODE
CSC7CQC5C4C3C2C-1C0
Number
1
FUNCTION
Repeat microinstructions Fetch (Table 4-4)
1
through 14 of Instruction
14 15
1
1
10 10 10
10
Move
16
17
Timing
filler
1
Repeat microinstructions
Fetch (Table 4-4)
through 14 of Instruction
30
31
11110
1 1
10
Move
32 33 34
1110
10
1 1
10
Timing
filler
110
Move
Set
10 111
READ
WRITE
false
35
10 10
more
46 47
111110
1 1
48
10
10 10
1
Move Move
briefest glance at Tables 4-6, 4-7 and 4-8 shows that microprograms are going to have a lot of duplicated microinstruction sequences. The very first thing a microcomputer designer will do is try to eliminate this duplication by re-using frequently needed microinstruction sequences.
Also, a
The
microcomputer designer
is
time to respond to a
READ
up 108
bits of
These are the complications which forced the early microcomputer designers to keep microcomputer assembly language instructions simple. There are many ways in which microprogram sequences can be re-used, and time delays can be implemented; we left 16 microinstructions free for just this kind of operation. Precious Control Unit storage is used up solving these complications, and the more complications there are within a single instruction, the more complex this extra
4-43
based microcomputer will not meet your needs; frehappen because the microprocessor is not fast enough. You are now a candidate for "chip slice" or "macro logic" based microcomputers, which let you design and build your own CPU, with any CPU architecture (within limits), and any, or no assembly
Suppose
a microprocessor
will
language instruction
set.
Before we examine what a chip slice product must consist of, a word of caution. This discussion of chip slice products is something of a tangent within the context of products discussed in this book.
CPU logic that will to this point we have been describing microprocessors be implemented on a single chip, or may be part of a single chip. Chapter 5 describes additional logic which supports microprocessor based microcomputers.
Up
As compared
to microprocessors, chip slice products take a wholly different philosophical direction:
build chips with less logic, where each chip provides building blocks of any CPU; then we justify less logic
We
chips
Thus, you could use chip slices to build the equivalent of any microprocessor. You would then have a product with perhaps ten chips instead of one, but it would execute instructions ten times
as
fast.
Describing chip slices at the end of Chapter 4 implies that chip slices are essentially
blocks.
CPU
building
That is the frame of reference in which we choose to describe chip slices; however, when you have finished reading Chapter 5, you will realize that chip slices could be used equally well to build the equivalent of any support logic device, excluding ROM or RAM.
If
we
are to create
CPU
building blocks,
how
should
CPU
logic
be divided
CHIP SLICING
We
limitations;
if
blocks
PHILOSOPHY
CPU:
All
A-
Registers
N ^
Status flags,
Shifter
C/5
C
t7)
o c n
Ji
CD
CC
TO
Buffer Register
A-
N V
::::::
: i
:
: :
: :
&<kFiftSf::SS;
Data
I;:.;,;,
Uoit
:.:-:
: :
: :
% ..
_in/0u
implement
separately
4-44
Now
if
you
refer
Control Unit,
in reality,
back to our discussion of microprogramming, you will see that a consists of a microprogram stored in Read Only Memory:
jMILflOPflOGRAM
The shaded area marked "microprogram" contains quences illustrated in Tables 4-5 through 4-8.
microinstruction
sequences
CU DATA
by the Control
Unit.
What we have
ignored, so far,
is
way
> MICROPROGRAM
The illustration above arbitrarily shows four separate microinstruction sequences (shaded), which must be executed in order to enable the logical sequence of events required by some undefined macroinstruction. The broken line identifies the order in which macromstruction sequences must
be executed.
Our Control Unit must have microprogram sequencer logic which allowsit to pick its way around the microprogram ROM, as illustrated above by the broken line. Let us look at some of the functions that our Microprogram Sequencer Logic must be
able to perform:
It
MICRO-
PROGRAM
SEQUENCER
LOGIC
a defined
first
must access
microinstruction,
contiguous sequence of microinstructions, beginning with and continuing for- a fixed number of microinstructions:
=-^
Fixed length,
sequence
of
4-45
2)
It
must be able
to
3)
It
must be able
to
branch to
a frequently
memory
4)
It
must be able
fixed
such as a No Operation,
some
number
of times:
Defined
start
>
"n" re-executions of
3E
w'
a single microinstruction
4-46
The Control
become a microprogram
ROM
and associated
Registers
Status flags.
Shifter
Complementer.
Arithmetic and
n logic
$=t
Buffer Registei
>=*
T
Data In/Out
Control signals
creation logic
1
ROM
n
Microinstruction
Microinstruction
Microinstruction
sequencing
logic
CONTROL UNIT
REGISTERS, ARITHMETIC AND LOGIC UNIT CHIP SLICE Now in practice, it is easier to implement Control signals creation logic as
the Registers, Arithmetic and Logic Unit:
part of
Status llaqs
Shilici
Registers.
Complementer
Arithmetic
and
s=s
*
*
Arithmetic
and Logic
Unit
Book-.in logic
Buffer Register I
In
/Out
Comroi
stgrtate
li-.(]ic
cif.-jlicn
r
ROM
Jl.
Microinstruction
Microinstruction
sequencing logic
Microinstruction
CONTROL UNIT
We
will
slice
Unit,
which
we
up
into
segments.
4-47
up this logic, it is imperative that we place as few restrictions as possible on the number and organization of registers. Also, we cannot limit CPU word size; even though we talk consistently about 8-bit microcomputers, it would be very short sighted to assume that an 8-bit word size is going to last forever. Within the microcomputer inIn dividing dustry you measure "ever"
wili therefore slice up our registers, in months, not years. arithmetic and logic unit into identical vertical slices, such that slices may be stacked to form a CPU with any word size:
We
2-bit
CPU
We
will refer to
each
size
slice as
an
ALU
slice.
ALU SLICE
is
2-bit
ALU
slices
and 4-bit
is
ALU
slices are
commonly seen. So
superior, since
it
long as your
word
requires
fewer
chips.
registers and ALU logic is to be sliced up, each slice must be able to interface If the combined with an identical neighbor on either side, in addition to a Control Unit.
organization, such as illustrated in Figure 4-1, presents a lot of problems. The innumerable data paths converging on the Data Bus are going, to become even they are to be general purpose, cannot be predefined or more complex, since the registers, to idenlimited in number, as shown. You would have to construct impractical microinstructions
if
tify
ALU
the innumerable valid data path combinations. Therefore we will reorganize our registers and sucwith an eye to streamlining the data paths, while maintaining flexibility. Remember, a end product. cessful chip slice makes no assumptions regarding the architecture of the
Now
the
number
of microprocessor-based
number
few chip
Therefore
we
will
reorganize the registers and ALU portion of Figure 4-1 to generally conform with the organization of 2900 and 6700 series 4-bit chip slice products which are described in Volume II. Figure 4-3 illustrates this reorganization. 3000 series 2-bit chip slice prosimilar, and represent the predecessor of 2900 and 6700 series pro10800 chip slice products represent the next generation the logical evolution of 2900 and 6700 series products.
ducts.
shows two
>
-bit slices
creating an
ALU.
in
overview.
must be specified within the Registers block. 16 registers are selected, since a 4-bit select code can address one of the 16 registers.
of
registers
Some
fixed
number
REGISTER
BLOCK
The Registers block has two output ports. AA and BB, plus one input port, ZZ. Having three ports, the register block needs three sets of register select logic one for each port. Select logic identifies the register which is effectively connected to each port at any point in time. can get by with two sets of register select logic by combining input ZZ select logic with either output port
We
AA
or
BB
select logic.
We
will arbitrarily
choose
to
combine ZZ and BB
means
be effectively connected to
Thus the chip slice DIP needs four register select pins:
Select -Register
for Port
A0
A1
A2
A3
BZ0
BZ1
Select Register
for Port
B or Z
BZ2
BZ3
4-BIT
ALU SLICE
Now
and the
ALU block. The ALU block requires two input ALU operations require two inputs
PP can receive
a
DATA PATHS
Input port
register.
XX marks
Registers block output AA or BB, or it can receive contents of the Buffer three-way junction whence input PP is derived.
Input port
way
junction
whence
the
YY marks
the two-
input
is
derived.
4-49
terface
Let us examine the external signals that will be required to support the inbetween the register and ALU blocks. If we assume that an addiis
ALU INPUT
IDENTIFIED
tional option
to input
at ports
PP
or
QQ
BB
BB
AA
as
-
BB
VV
it.
AA
BB BB
BB
Dl
Dl
Dl
Dl
VV
AA
BB
VV
BB
is
the
same
BB, so ignore
Since AA and BB can have the same value, ignore BB - BB which can be AA; ignore Dl -BB which can be made equivalent to Dl -AA.
-
made
equivalent to
BB
is
ignored since an
ALU
operation
will
inputs.
We will
use three input pins to identify the remaining eight possible PP-QQ input combinations. These three input pins will become the low order three bits of a 9bit microinstruction code and will be interpreted as shown in Table 4-9.
DATA
4-bit
IN
wide
16 x 4-bits of
unassigned
Register Block
4-bit
wide
shifter
4-bit
wide
Buffer Register
And
Slice
Logic Unit
From
To Meet
4-50
Table 4-9.
MICROINSTRUCTION
12
11
ALU INPUTS
|0
QQ
BB BB 00 00 00
PP
vv
AA
VV
o
1
AA
BB BB
DD DD DD
Bits 0,1,2.3
VV
00
Concatenated
chip slices
Bits 4,5,6.7
Bits 0.1,2.3
Bits 4,5,6,7
Figure 4-4.
Two
4-Bit
ALU
Slices
8-Bit
Concatenated
To Generate An
4-51
ALU
interface also requires four data data input to YY. Our DIP therefore looks like this:
in
AO
A1
DIO
Select Register
for Port
DM
DI2 DI3
A
f
A2
Data
in
A3
BZO
BZ1
<
Select Register
for Port
B or Z
j
BZ2
BZ3
10
Select
ALU
inputs
1
II
4-BIT
12
ALU
SLICE
Now move
on
to the Arithmetic
and Logic
Unit.
CHIP SLICE
leaving behind comple-
moved
ARITHMETIC
out,
logic.
Moving
shifter logic
AND LOGIC
UNIT
option of shifting data within a short recycle path through the Buffer
register
its
(RRSSUUVVXXPP)
or
we
can
shift a final
ALU
operation result on
way back
(RRSSTTZZ).
it
The Buffer
quires
register in Figure
did
in
Figure 4-1.
In
two inputs. In Figure 4-3 the ALU inputs PP and Q'Q. In Figure 4-3, the Buffer register has become
results of
ALU input whenever an ALU operation recome from the two Registers block output ports
a holding location for intermediate
ALU
operations.
We
CHIP SLICE will assign the next three bits of the microinstruction ALU OPERATION code (13, 14, 15) to define the ALU operations which are to IDENTIFICATION be performed. There are only five isolated operations: ADD, COMPLEMENT, AND, OR, XOR. We could add increment and decrement to the list; instead we generate the equivalent by providing an external carry
in:
4-bit
wide Complementer,
Block)
(ALU
Output RR
results
and Carry
in.
4-52
in
and the
five
ALU
operations allows us to
Table 4-10.
slice
DIP
will
Select Register
for Port
A1
A2
DI2
Data
in
A3
BZO
DI3
CI
Carry
in
Select Register
for Port
BZ1
B or Z
BZ2 BZ3
10
Select
ALU
inputs
-J
11
12
4-BIT
Define
*"
(
13 14
15
ALU
SLICE
ALU
Operation
Only the ALU destination remains to be specified; three microcode bits for this specification.
we will
use
CHIP SLICE
ALU
block out-
for
ALU
DESTINATION
2) 3)
The The
Data out.
its
SS and TT.
Data on
way
may
optionally be shifted
loft
or right
all
bewildering variety of output options could be selected since data can be output to any or
of
Table 4-10.
ALU
Bits
MICROCODE
15
FUNCTION
General
Carry In =
14
13
Carry
In
=
-
PP
QQ
PP
if
PP
QQ
is <s
PP
QQ
PP
Increment PP
i'
QQ =
;
QQ
1
if
Increment
1
if
DD
PP
QQ
iPP
(PPi
QQ
QQ
is
PP
PP
QQ
if
is
the
Ones complement PP
Tvvos complement PP
ones complement
of PPi
1
QQ
in
is
QQ OR PP QQ AND PP QQ XOR PP
1
Carry
plays no part
in
Boolean operations
currently
|
1
1
unassigned
4-53
two
will
Table 4-11.
ALU
Destinations Specified By
BUFFER REGISTER
18 17 16
REGISTER BLOCK
Data Out
Shift
Shift
No
1
Left
Right
1
No No No No
No
Yes
No No No No No
Left
Right
No
Bear
the temporary data in mind that we really have two types of ALU output which is heading for the Buffer register and permanent answers which are heading back to the Registers block. Based on this concept. Table 4-1 1 illustrates one way in which destinations could be specified.
left
to discuss
is
status.
CHIP SLICE
and Sign status flags are easy to generate, so these three first.
Every chip
slice will
us look at
STATUS
SIGN
be
built
assuming
that
it
slice in
will
assumes
STATUS
the eventual
bit:
ALU
word. The
Sign Status
bit
We
will
can generate the sign bit directly from the high order data out line of every single chip slice. Only the high order chip slice's Sign bit will be used; other chip slice sign bits
be ignored.
4-54
The overflow status can be generated from the two high order
lines of
OVERFLOW
STATUS
was gener-
Exclusive
OR
of
becomes
the
overflow status
^W-^
2,
As described
in
Chapter
OR
bits of a
BE
ZERO STATUS
DO.
Zero Status
DO
By tying the Zero statuses of
status:
all
CPU
etc
Chip
Slrce
1
Chip
Slice 2
etc
4-55
Carry and shift statuses are not nearly so straightforward. First of three sets of statuses: mr*^ Data In
all,
we
need
RS3
BSO
Data Out
will
must work
in parallel.
shift,
created using
two chip
slices:
HRS3
LRS3
Uilt
Ultt
HRSO
Vrm
D7 D6 D5 D4
High order
slice
If
Wm
Low
order
slice
D3 D2 D1 DO LRSO
the shift illustrated above is to occur as a single, parallel must become the high order slice shift in (HRSO).
step, the
low order
slice shift
out (LRS3)
4-56
If LRS3 and HRSO are both connected to DIP pins, these two pins and an 8-bit shift is created:
all
we
have to do
is
connect
HRS3
t t t t t
1*
t t.
\
D7
}) D6 D5
v
slice
D4
r H )))
so
D3 D2 D1
DO
LRSO
High order
Low
order
slice
But
when
it
comes
is
less straightforward.
is
When
at
shifting,
LRS3
is
progress.
When
generated
Here
is
shift,
we
have no problem:
CLOCK
D0,D1,D2,D3
LRS3
D4,D5,D6,D7
we
have a problem:
CLOCK
D0,D1,D2,D3
CARRY
D4.D5.D6.D7
4-57
We
in four-bit
in
increments,
could
and
CARRY STATUS
whole purpose of using chip slice products to gam instruction execution speed. We must therefore add logic which allows the ALU to forecast whether a binary addition is going to create a carry, or propagate one coming in.
But rippling binary addition defeats the
The
there
is
a carry
in
to binary addi
then there
:
ded
will
digits are
being ad
CARRY PROPAGATION
Two
digits
10
No
Carry
<
-^
'
Carry
in
propagated
10 10
1 1 1
11
1
Carries propagated
If
Pj
ALU
via ports
PP and
respectively,
we
con
propagate
OR Q
AND
(P,
OR
Q,)
AND
(P 2
OR Q 2 AND
)
(P 3
OR Q 3 =
)
order to determine whether a new carry will be generated, we must start at the high order end of the 4-bit unit and work back to the low order end. Both high order digits must be one or one high order digit must be with a carry propagated from the penultimate
In
1 1
CARRY GENERATION
digits:
XX X X
--
XX X X
--
XX---
XX--
Oxx
1>
Oxx
0*
1
Carry:
1>
1
0*
If
C,
bit
position
))
i,
then
if
C,
1.
generating a carry,
(P 3
AND Q 3 OR
)
(C 2
AND
(P 2
OR Q 2 =
For
C2
to
1.'
the
)
same
bit
positions shifted
down:
(P 2
In this
OR
Q,))
ALU
4-58
Finally, this is
the
way
pins
must be assigned:
DIP
-<
>
I
Select Register
for Port
Dll
DI2 DI3
Data
in
<
J
-Carry
in
Select Register
for Port
B or Z
-Carry -Carry
out
generated
in
--Carry propagated
Select
ALU
inputs
cz
^
4-BIT
-Buffer
shifter carry
out
in
ALU
SLICE
poo
DPI
Define
-Registers
ALU
Select
Operatio
-c
"!
J
ALU
Destination
D02 D03
Data out
|
Power Ground
Clock
slices;
Carry generate logic will usually be provided on a separate carry generate device. This device receives Carry Propagate (P) and Carry
Generate (G) signals, in the proper sequence, from the 4-bit generates and returns the correct Carry in (C) to each chip
CARRY GENERATE
DEVICE
ALU
slice:
it
ALU
3
c;
ALU
2
C2
ALU
C!
ALU
G 2>
P2
'
G '1
ph
P3
Carry Look
GO
Ahead
W
G3
^PO
slices, as we have described them, are driven by a 9-bit microinstructogether with binary data input and various status/control signals.
The control
unit
it
does
in
not, tor
reasons
we
wilf
soon discuss.
We
code
ROM
and
its
addressing
as discussed
We
can gain a
4-59
at the
in
4-8.
quentially Therefore,
Under normal circumstances microinstruction codes are accessed sethe Control Unit addressing logic must have a Microprogram Counter (MPC), the equivalent of a Program Counter which can be incremented after every microprogram access to
reference the next sequential microinstruction:
MICRO-
PROGRAM
COUNTER
nn ^
MPC
D11
rf
Incrementing
Logic
We arbitrarily assume a
a
2-bit
width
in
implying
maximum
of
4096 in microinstructions
ROM.
Any microinstruction sequence is going to begin at some initial address; therefore Control Unit addressing logic must be able to initialize the Microprogram Counter. Consider two
possibilities:
1)
Every macroinstruction object code is going to be implemented by a microinstruction sequence with its own initial address which must be loaded into the Microprogram Counter. We will therefore provide direct data access to the Microprogram Counter:
^ mi ^
2)
It
nn
MPC
Incrementer
Logic
would be
some
may have
We
w
where some
such per-
stored:
Incrementer
Logic
MPC
t
R0 Keg
Rii
fe.
must be able
to re-execute
one
instruction a
number
our example, a "No Operation" instruction was re-executed simply to keep the Conwill therefore add an increment inhibit Unit synchronized with external timing.
We
DO
MPC
D11
> .
Incrementer
Logic
R0
R11
Finally,
Increment
Inhibit
recall that there are frequently used microinstruction sequences which perform operations such as memory read or memory write. We can handle this situation in
of
one
two ways.
4-60
First
consider having a
number
-
Microprogram Counter
Buffer:
MPC Buffer
nn
D11
^
w
t
MPC
Incrementer
Logic
<
Register
A
A
no
=
A
Increment
Inhibit
Register B
E =
Register
E =
.
As
logic
illustrated
above,
the
address
of
the
in
first
microinstruction
B,
for
four
frequently
used
mrcroinstruction sequences
may be
stored
in
Registers A,
C and
can save
prior
contents of
MPC
MPC
<
Buffer
\
\
}
Incrementer
Logic
DO-^-..
MPC
D1
i
s J "
<
i
7'
'
RO
Register
The
last
Register B
/
i
Increment
Inhibit
Register
microinstruction
in
MPC
i
Buffer
i
nn^
mi M
Register
= =
MPC
i
^ ' *J
Incrementer
Logic
1
Increment
Inhibit
Register B
Register
.
4-61
case,
will
back up the
Buffer
Stack
The
access another frebuffer stack allows one frequently used microinstruction sequence to is a common quently used microinstruction sequence. This is sequence nesting. The stack microcomputer feature and is described in Chapter 6.
This
tion
1)
is
how
would work
for microinstruction
sequence
A
C:
accessing microinstruc-
sequence
which
in turn,
Microinstruction
sequence
reaches the point where microinstruction sequence B must be A address is saved on the stack, then the sequence B adBuffer
input:
Stack
Address
X /
Incrementer
Logic
Starting
address
MPC
Register
Increment
Inhibit
4-62
2)
Microinstruction
accessed. Step
is
repeated:
Buffer
Stack
Address B Address
N s
-*
Starting
address
DO
*-
<
[D11 -
MPC
Incrementer
Loaic
*J
RO
R11
>
Register
Increment
Inhibit
>
C completes
execution, so the saved Address B
is
3)
Microinstruction sequence
returned to
MPC:
Buffer
Stack
N
Address B
Address
DO
*
*
MPC
Incrementer
Logic
D11-*
RO
R11
*-
>
Register
*>
Increment
Inhibit
4-63
4)
Microinstruction
sequence
B.
in
turn,
is
returned to
MPC:
Buffer
Stack
Address B
Address A(
y
1++
Incrementer
Logic
DO-*-
MPC
Register
Increment
Inhibit
additional control signals will be needed: one will push the contents of MPC into the stack, as illustrated in Steps 1 and 2, the other will pop the top stack address into MPC, as illustrated in Steps 3 and 4. Our Control Unit address logic DIP pin assignments will now be as follows:
Assuming
two
RO
Ground
Clock
^, ^.
DO
Dl
R1
R2 R3 R4 R5 R6
R7
D2 D3
Register
Input
D4
snal
D5
<
R8
dress
D6 D7 D8 D9
R9
.R10
Bus
R11
D10
D11
Inhibit
._
Push
Pop
>.
4-64
slices
we are going to build a Central Processing Unit by combining ALU with Control Unit addressing logic and a microprogram in Read Only
as follows:
Memory
ALU
Slices
Control Unit
Microprogram
Address Logic
ROM
a very considerable amount of additional external logic will be required before the simple configuration illustrated above can perform as a Central Processing Unit. For example, nowhere have we addressed the problem of receiving or transmitting control signals. What about the microprocessor Read and Write
In practice
control signals?
would have been possible to add logic to the Control Unit that automatically senses and creates CPU-type control signals. However, that assumes chip slice products are going to be used as CPU building blocks only. The assumption is unwarranted.
It
By describing chip
slice
products
in
Chapter
4.
a chapter
CPU
building blocks,
in
devoted to Central Processing Units, we which makes them conceptually easy to undersis
which information
being presented
Control Unit
set. But.
in this
book.
slice
work and
extra logic
restrictions are
must surround the chip slice and Control Unit imposed on the way these products are used.
In terms of our current discussion, therefore, we must conclude without demonstrating the equivalent of an instruction fetch or a typical instruction's execution,
because the type of information which would have to be covered before necessary external logic could be adequately treated is beyond the scope of this book.
4-65
CPU
in
chapter we are going to identify the additional logic that must accompany a order to generate a microcomputer system that is comprehensive enough to
be useful.
We
must separately identify the logical components of a microcomputer system (e.g., CPU, RAM memory, ROM memory, etc.) but there is no fundamentally necessary correlation between logical components and individual chips. As you will see in Volume II, there can be wide variations between the type of logic which one microcomputer manufacturer will put on a single chip, as comby function
pared to another.
CPU
ROM
in
to a
CPU
3,
is
very simple.
words
of
As described
word.
Chapter
entire
memory
are
implemented on
a single
bit
ROM
chip.
By
contrast, read-write
of the
memory
The
1)
signals required by a
ROM
expect, a
ROM
device
of the
will require
device are quite elementary. As one would logically the following input signals:
being accessed.
The address
memory word
tells
2)
the
ROM
device
when
dressed
3) 4)
memory word.
ROM
and CPU
will
be synchronized.
signals which the ROM device must have are eight data lines (for an which the contents of the addressed memory word may be transferred back to the CPU. Figure 5-1 illustrates a hypothetical ROM device. This ROM device is connected to the CPU as illustrated in Figure 5-2.
Before describing a ROM access in detail, let us consider features of a microcomputer system.
some
of the non-obvious
Were
CPU and one ROM. EXTERNAL two devices could be directly connected. Since it must be DATA BUS possible for more than two devices to be present in a microcomputer system, signal connections are made via an External Data Bus, which may be likened to a common signal highway connecting chips of the microcomputer set.
a microcomputer system to consist of just the
pins from the
5-1
(Vdd
Vss
AO
A1
2 3
Vgg
Clock $
'
A2 A3
DO
D1
A4 A5
A6
A7 A8
>-
Address Select
D2
D3
Data
-<
D4
D5
A9
SO
S1
D6
D7
READ
S2
> Chip Select.
S3
S4
S5
Figure 5-1.
Read-Only
Memory
Notice that the 16 address signals of the CPU become ten ROM DEVICE signals and six device select signals at the SELECT ROM. This distribution of the address lines implies that the ROM has 1024 (2 10 words of memory, and a 6-bit select code. Providing the high order six address lines coincide with the 6-bit device code of the ROM, the ROM will decode the
word address
lines as representing
true,
If
one
of
its
READ
control signal
DO
D7.
will
goes
ROM
the six high order address lines do not coincide with the
ROM
select
ROM
Frequently a ROM chip will have no chip select logic; then there will be a single chip select signal, which must be generated by external logic. It is also very common for a ROM device to have two select inputs. For the ROM to be selected, one input must be low while the other input is simultaneously high.
If
the
ROM
chip has
If,
its
own
chip design.
for
example, a
into the
code is a permanent feature of the ROM ROM chip has the select code 001 100, then this select code will ROM chip when was created, with the result that the ROM chip will
select logic, then the select
it
:
respond only to
Code
,
001
1000000000000
Highest
Select
Code
memory
address
110
3 3
1111111111
F F
5-2
S
<<<<<<<<<<wSmo)woi
<h*
<Hfr
<Mt
^^+^
OOQQQQQQ>
cr
>>> w <<<<<<<<<<<5<<<
~o
</)
en
H*-
P o5>
t,
a>
en
5-3
In
other words, a
ROM
is
chip with one device select code must be looked upon as differing from
an identical
If
ROM
ROM
chip,
feature of the
ROM; merely
illustrated
ROM
device responds to
memory
may be
as follows:
A1
A? A3 A4 AR
Afi
Word
Address
Memory Address
w.
Memory
Address from CPU
A7 AR A9
to
ROM
Device
w.
A10
A11 A1?
n-of.-64
w Select
Select
.Device
Select
w Select 2.
>.,
A13 A14
AlfS
Logic
Select n.
is internal to a ROM chip will never be of any concern to you, as a microcomputer user. The way in which the ROM chip selects or deselects itself, the way in which responds to read control signals, the way in which extracts necessary data and places the data at pins DO D7. are all completely irrelevant since there is nothing you can do about
Logic that
it
it
it.
Consider a
in
memory
4,
is
reproduced here, as
it
it
appeared
Chapter
to link
to Figure 5-2.
AO
to
A15
INSTRUCTION
DATA
ADDRESS
ADDRESS
INSr
CODE
DO
to
D7
Instruction
Data
Fetch
Fetch
Memory Read
Instruction
5-4
CPU
is
concerned, there
is
no difference between an
address
A0
this
data at
DO
D7.
),
By the time
data on
DO
goes low and READ goes low (at (B) D7; data must stay on these lines until
ROM
<J>
RAM logic must System Bus and place this data in an addressed memory word; in addition, RAM logic must be able to extract data from an addressed memory word and place this data on the External System Bus data lines. Also, most RAM is implemented using a number of RAM chips, with each chip supplying one or more bits of the data word.
than
ROM
interface logic.
is
a simple
enough concept;
it
means
that
each chip
lines,
will
only have
one data
pin.
and
DO
D7.
for
As described
select
ROM,
RAM
A0
A15
into a
device
code and a memory address. However, there may be eight RAM chips (for an 8-bit word), each of which has the same device select code, but is connected to a different data line on the External System Bus. Figure 5-3 illustrates a single RAM chip with on-chip device select logic, and Figure 5-4 shows one way in which RAM memory may be added to the ROM-CPU
combination
illustrated in Figure 5-2.
Vdd Vgg
(J)
A0
A1
3 4
A2
___^. clock
-
A3 A4
A5 A6
A7
Address Select
Data
A8 A9
SO
S1
_^
READ
S2
Chip Select.
.^WRITE
S3
S4
S5
Read-Write
special
Figure 5-3.
Memory Chip
Pins
And
Signals
RAM
and/or provide device select logic. The Fairchild F8 needs special RAM interface devices because of its unique logic distribution. Figure 5-5 illustrates RAM controlled by a RAM interface device.
5-5
RAM
Q-
U
"O
<
o m
cc
< >
3 o
10
T3
5-6
CJ
O>
CC
Q,
Q<
(
<
<
>>
r
is
5 o CC
SgsKsas
>
> >
Q O 8
Q Q O ^
.*
<
<
1
<
<
<
f
i'
Q S s
o:
r> Q_
II
>
&c <
f
<
<(
1 T
< <
4.
.1
<
;?ssasss
u
<cc
CC LU \-
> >
>
c2
Q Q Q
SSoMSS ssss
'
t,
1
<
<
1
o 2 3 4 5
RAM RAM RAM
III
RAM
:
:
ra
E ^
5-7
between
logic that
put/Output
(I/O).
We
in
system,
boundary of the microcomputer been specifically designed to operate conjunction with the CPU. We will classify all other logic as
will
MICRO-
all
external.
The interface between the microcomputer system and external logic must be clearly defined; it must contain provisions for transfer of data, plus control signals
that identify events as they occur.
There are many ways in which data transfer between the microcomputer system and external logic can be accomplished; but they all fall into the following three categories:
1)
PROGRAMMED
I/O.
In this
case,
all
and external logic are completely controlled by the microcomputer program being executed by the microcomputer CPU.
There
will
more
precisely,
by a
evi-
been placed in a location where external logic can access or, alternatively, the microcomputer system will indicate in some predefined way that it is waiting for external logic to place data in some predefined location from which it can be input to the microcomputer system.
dence
it:
The key
2)
characteristic of
programmed I/O
is
does as
it
is
told.
INTERRUPT
nal logic.
means
microcomputer
is
currently doing
3)
DIRECT
MEMORY ACCESS.
This
is
form
of data transfer
to
move
data
CPU
in
The
in turn.
PROGRAMMED
Data are transferred between a either direction, via an I/O port.
I/O
logic, in
5-8
An I/O port will consist of an I/O Port Buffer, connected to the data lines of the External System Bus and to pins which access external logic:
I/O
PORTS
CO ^ Other
/Control
CN
; Lines
WRITE
READ
<
>
D7
Data
AO
f Lines
)
\ Address
^5/ Lmes
LU
LILI-
CO
When
microcomputer system,
in
it
whence
The
binary value
001001
DO
D1
D2 D3 D4 D5 D6 D7
I/O Pins
Data Lines
- .*
<
-*
.4
From
external logic
<
-
^
I/O Port Buffer
The I/O Port Buffer cannot be constantly communicating with the data lines of the External System Bus, as illustrated above, since the data lines of the External System Bus may be carrying data to or from memory. If the I/O port were permanently communicating with the data lines of the External System Bus, then every time external logic presented data at the l/O'pins. this data would be propagated down the shared data lines with unpredictable consequences. The microcomputer CPU will therefore select an I/O port and read the contents of the I/O Port Buffer, in much the same way as data gets read out of memory. This parallel between reading data out of I/O Port Buffers and reading data out of memory is appropriate, since most microcomputer systems transfer a great deal of data to and from external logic; therefore, they have more than one I/O port.
5-9
We
can develop a parallel I/O device with one or more I/O where the I/O Port Buffers have addresses, just as memory words have addresses. A simple scheme would be to take
ports,
line
is 0,
PORTS ADDRESSED
I/O
USING
MEMORY
ADDRESS
LINES ~ ~~ ~~" memory addresses of 7FFF 16 and below will access memory words, whereas memory addresses of 8000 16 and above will access I/O Port Buffers. Using the READ and WRITE control lines, Figure 5-6
this line
is
whenever
is
1,
memory module
is
selected, but
whenever
this line
selected.
In
other words,
~~
il-
one
port.
Vdd
Power and ground
Vss
DO
D1
Vgg
..clock
3 4
D2 D3
A0
A1
D4
D5
D6
D7
,
Data^_
-Microcomputer
System
A2 A3
A4 A5
A6
Address
W
R
WRITE
READ
I/O0
1/01
A7
JA 15 must
1
be
A8 A9 A10
A11
I/02
to select)
I/03
>l/0 Por
I/04 I/05 1/06
1/07
The device
in
Figure 5-6
is
because data
is
in
I/O device should have only one I/O port. The is purely a function of the number of pins that are economically available on a dual in-line package. The device illustrated in
is
no reason
why an
number
its
Sixteen pins are connected to the address lines of the External System Bus and provide the information needed to determine if this I/O Port Buffer has been selected.
2)
System Bus and are used to transfer information from the External System Bus to the I/O Port Buffer, or from the I/O Port Buffer to the External System Bus.
3)
Two
control lines,
(read), or
determine whether data will flow from the I/O Port from the External System Bus to the I/O Port
Buffer (write).
5-10
4) 5)
for
One
pin
is
That sums to 30
I/O device
illustrated in Figure
There
15
)
is.
of course,
I/O
is
unlikely.
about reducing the number of address lines to ten? Now 16 pins are available for I/O ports and our parallel I/O device can have two I/O ports, as illustrated in
Figure 5-7.
How
Powe ,(
Vdd
Vss
Vgg
<D
Ground
Clock
_
A0
A1
I/O0
1/01
A2
I/02
A3
I/O Port Address <
I/03
I/O
I/04
Port
A4 A5 A6 A7 A8
I/O Ports Selected
I/05 I/06
PARALLEL
I/O
I/07
External
INTERFACE
I/08
Devices
A15
DO
D1
I/09
I/O10
1/011
>l/0 Port B
D2
Microcomputer _^__^ Data System
<
D3
D4 D5
D6
D7
Figure 5-7.
W
R
Parallel
WRITE.
READ-
Two-Port,
lines in Figure
5-7
will
be divided as follows:
One
of the ten
address
lines will
be
A 15,
in
memory word,
Address
lines
AO
A8
lines
may be any
I/O ports'
A9-A14
are ignored
A15 must
be
1
000000 '111111111
In
the unlikely event that this arrangement provides insufficient I/O port addresses, address lines
A9-A14
parallel
I/O device.
The penalty
Buffers,
is
In
paid,
when
the high order address line (A15) is used to select I/O Port 1B rather than 65536 (2 16 words of memory can be ad(2
),
)
dressed.
memory can be
a severe
penalty
is
of addressable
memory
(or
few microcomputers require 32768 words anywhere close to that much memory). Typically, a
between 1024 and 4096 words
of
microcomputer application
will
require a total of
memory.
Nevertheless, many microcomputer systems use separate addressing logic to select I/O ports. Figure 5 8 illustrates one possible scheme which adds two control lines to the microcomputer CPU. One
control
line,
AO
A7
The other control line, IORW, high, indicates that the External Data Bus lines contain information which must be read into the I/O Port Buffer. If IORW is low, then the selected I/O Port Buffer contents must be output to the data lines of the External Data Bus.
just
As you will discover in Chapter 7, the two methods we have described for selecting I/O ports are two out of a bewildering array of possibilities. These two methods do, however, broadly cover the most common ways in which I/O ports are addressed.
ternal
Unfortunately, the blind transfer of data between a microcomputer system and exlogic will not always provide sufficient I/O capability. The following necessities are missing:
1
to
tell
external logic
when
data has
an I/O buffer and is therefore ready to be sampled. Conversely, external logic must have means of indicating to the microcomputer system that it has placed data in an I/O buffer and the data can now be read.
2)
The microcomputer system, and external logic, must each have some way of informing the other as to the nature of the data placed in an I/O buffer. Clearly data being transferred between the microcomputer system and external logic is subject to various
interpretations. For example,
it
may be
it
may be
code
all
identifying operations to
may
also be part, or
of
an address.
When
the microcomputer outputs signals to external logic as a I/O CONTROL means of identifying events or data, these signals are referred to as I/O controls. The same information travelling in the opposite direction, that is from external logic to the microcomputer, is referred to as I/O status. The differentia tion of information into controls and status, based upon the direction of the information, is logical since we are dealing with a situation where the microcomputer is at all
times
in
control of events.
In
I/O
STATUS
interpret
it
for the
microcomputer to
when
Minicomputer systems will usually have a whole set of I/O control and status lines that are separate and distinct from I/O ports. Microcomputers more commonly allocate one or more I/O ports to function as control and status conduits, while separate I/O ports transfer data.
I/O Port A in Figure 5-8 might be used to transfer data, while I/O Port B is used to transfer control and status information. So far as the microcomputer system is concerned, the same instruction sequences are used to handle data flow through either I/O port. It is the way the microcomputer system interprets a data word that determines whether the word is data, control or status information.
5-12
o o
en
'
!
Q<
<
1'
us
<~~
^ ^
00
Oi
""
in
in
O or
e DQ
\
Q Q Q Q Q Q ^
li
- *1
1
-" 1
<C
J
s 5 8 s
~t
-J
IOSEL
IORW
u
Cl)
Q 2 2
"^
r
n>
o
ti)
3 Q_ U
i_
O
CD
CO m
(1)
u
> > >
>1
< < < < < < < < < < < < < < <
0-
< O
en
tl
h*
'
00 in
en
p
(
_)
(
i
'
H
>
3
o o
1 _
''
o,
1'
cn
'7
*j
l>
r-
> > S
_ - cm o ^ Q S Q O O Q O O Q 5 Q O O Q Q
t.
i
xaod 0/
t!
1
iao d
0/1
1
fc
=
CD
5-13
INTERRUPT
Most microcomputer CPUs have a control
I/O
which external logic can demand the attention of the microcomputer system. This signal is referred to as an interrupt request signal because, in effect, the external logic is asking the microcomputer system to interrupt whatever is currently doing in order to service more pressing external logical needs.
signal via
it
We will
is
begin the discussion of interrupts with an example that too simple to be realistic, but contains all the key features of a meaningful application.
Suppose a microcomputer system is being used to control the temperature of shower water, as illustrated in Figure 5-9. A thermometer measures the temperature of the mixed hot and cold water issuing from the shower head and transmits this temperature, as a digital signal, to the microcomputer system. The microcomputer system compares this temperature to a set point, which is supplied by an appropriate control. Depending on the difference between the real and desired shower temperature, the microcomputer system outputs data which must be interpreted as a valve control signal, causing the valve to increase or decrease the hot water flow.
There are a number
of reasons
why
this
is,
in reality, far
from simple.
between the time you adjust a shower tap and the time that the water issuing from the shower head changes temperature. For this reason, a non-trivial program will have to be executed by the microcomputer to ensure that it does not attempt to make ridiculous adjustments. We will call this program ADJUST, and illustrate it residing in program memory as follows:
As experience
will
some
delay
MEMORY
0400
Arbitrarily
*
ADJUST
Start of
Program
selected
memory addresses
073E
Another program,
End
of
Program
called
RECORD,
will
readings.
The
in
only contact
in
between programs
Our memory
RECORD and ADJUST are that ADJUST memory and RECORD will place the data now looks like this:
will
in
correct format,
MEMORY
0080
Start of
Program
Data placed
in
data buffer
by
RECORD
End
of
Program
Program
by
ADJUST
End
of
Program
5-14
TEMPERAti.Jflf
TEMPERATURE
SELECT
DATA
IN
figure 5-9.
of
Shower Water
5-15
The way
which shower head temperatures are read and transmitted to is another feature of this problem which is not as straightforward as might appear. It will take approximately half a second
in
for
an inexpensive temperature sensor to record a temperature. Half a like very much time, but a microcomputer can execute approximately a
How
is
know when
tries to
transmit?
the temperature sensor has a new value to send data to an I/O port, the microcomputer
reading can easily get lost
in
system
is
very
One
a quarter of a
One way of resolving the problem is illustrated in Figure 5-10. step sequence allows the temperature sensor to microcomputer system's attention as follows:
(T)
three-
INTERRUPT
call
the
REQUEST
The temperature sensor transmits an interrupt request signal (IREQ) to the microcomputer system via an External System Bus control line.
The microcomputer system has the choice
rejecting the interrupt request;
it
<D
INTERRUPT
ACKNOWLEDGE
System Bus
control
line.
(D
interrupt
transmit data to I/O Port A. Also, request signal upon receiving an interrupt acknowledge since, clearly once the interrupt request has been serviced, the external device is no longer requesting another interrupt.
Timing
for this three-step
acknowdge signal as an enable signal, to the external device must remove its interrupt
sequence may be
illustrated as follows:
IREQ.
IACK
DATA
Note that although
we
have been
talking
to
the
microcomputer system, data flow could just as easily be in the opposite direction; in fact, there is no reason why any data flow need follow an interrupt. The program executed following an interrupt could, for example, simply output control signals.
The purpose of the interrupt is to tell the microcomputer that it must suspend whatever it is doing, process the data being input, then carry on with its suspended operations. With reference to programs RECORD and ADJUST, this is what happens:
^U
Interrupt requested!
<og ol
IQ<I ]<
I
"
ss
i8
o cc
S^
1
1
t
OO DOC
Q c
(I
<
t
1
^
1
? o *
~ - ~
S
cc
CD
JL
*I
*
5
"
a:
a 5 8 3
Q 2 2
D u
^
J
<
l~-
<
CO
O)
"~
> Q
S
a>
? o c
'
*
E o
en
uj
gj
x CD o
t
E
"
C
< < 5 O D
LU
Q Q Q O Q
O2
< <
CC
L.
--. c :
L t
O o 8 o o
o o O c o O O O
v xyod
(E
o/i
a iaod o/i
< X
zu
LU
LU
rV o ^
I H-
O-XJ
ell
5-17
and cause the interrupt request to be sensed by the microcomputer at above. The microcomputer CPU responds by suspending execution of ADJUST, while executing RECORD (to). While RECORD is executing, the data transmitted by the temperature sensor (in Figure 5-10) is read into the microcomputer system, since program
Refer again to Figure 5-10. Steps
RECORD
When RECORD
at
execution of
ADJUST
continues at
picking
up exactly where
left off
at
is that it is an unscheduled event. microcomputer system that can predict when or how often program RECORD will be executed. However, there is logic within the microcomputer system that can suspend any program's execution, later restarting execution from the exact point of suspension.
of
no
1)
What happens
was
being executed?
of the
2)
wants executed?
to the
Consider
first
what happens
The
program may have important information in the status flags, the Data Counter and Accumulator; this data is going to be wiped out by the new program, so that when the new program has finished executing, the old program will no longer be able to restart. This problem is resolved by
old
SAVING REGISTERS
AND STATUS
starting to
all
CPU
the
execute
new
is
program.
When
value
to
be executed
when
was
CPU
program can
pick
up where
it
left off.
This concept
is
illustrated as follows:
Data
Memory
0060
0061
is the situation when ADJUST is interrupted to execute RECORD (registers contents and memory addresses
This
0062
0063
0064
from Status
have been
arbitrarily
selected)
0065
0060
0061
This
is the situation when RECORD has finished executing and ADJUST must con-
0062
tinue
where
it
left off.
0063 0064
0065
C[0|S|Z|
to Status
5-18
until the current instruction has completed executing. This no need to save the contents of the Instruction register, since it contains an instruction code which has been processed. In other words, the interrupt directly precedes the
An
be acknowledged
is
arrival
of a
new
instruction code.
in
which the
old
may be
be
Unit),
saved, as
illustrated
program status flags and registers' contents new program starts execution. One way wouid
execution of a microprogram (stored in the Control which simply writes the contents of CPU registers into a data area of memory which has been set aside for this purpose. A microcomputer designer may be reluctant to use up precious Control Unit space in this way, and instead may require the programmer to write a short program which will do the same thing. Such a program is called an "Interrupt Service Routine."
for the interrupt request signal to initiate
new
reverse, to
and
status.
in
We
will
more
detail in
Chapter
6,
after
programming
more
detail.
Now
consider
of the program
We
will refer
the microcomputer CPU gets the address which the interrupting logic wants executed. to this as the Interrupt Address Vector.
of determining
how
INTERRUPT
ADDRESS VECTOR
which program must be executed following an inshower temperature control problem, there is an easy solution. The shower head temperature sensor is the only external device that can request an interrupt, and there is only one program it can want executed following the interrupt. This being the case, the microcomputer CPU could be built with internal logic that causes one program, origined at one specific memory address, to be executed following an
terrupt request as there are microcomputers. In the case of our
intermpt:
r-K
-*c
*
COMPLEMENTER
ACCUMULATOR
DATA COUNTER
PROGRAM COUNTER
h-
INSTRUCTION REG
ADDITION
AND BOOLEAN
LOGIC
CONTROL UNIT
BUFFER REGISTER
3*H
/
IREQ
/
IACK
it
Now
1)
every time the Control Unit receives an interrupt request (IREQ) and it does as follows:
interrupt
is
ready
acknowledge
signal, IACK.
2)
Save the contents of Status Flags, the Accumulator, the Data Counter and the Program Counter, or else allow the programmer some way of doing the same
thing.
5-19
3)
of the Interrupt
A minicomputer programmer would consider this method of responding to interrupts as laughably ridiculous. Who knows when and how the minicomputer may next have to respond to an interrupt? To specify that all interrupts will be serviced by a program origined at memory address 0400 16 (for example) would be an intolerable restriction, because it reduces the minicomputer programmer's ability to be flexible.
tain
microcomputer applications, having fixed interrupt address vectors makes a ceramount of sense. Remember that microcomputers are going to be used as logic components, not as general purpose computers. Most microcomputers are used in
In
dedicated, non-varying situations, where one, or a few specific interrupts will require equally specific responses from the microcomputer system.
Figure 5-11 shows how the parallel I/O interface device and the ROM device from Figure 5-8 could be modified to receive the interrupt request signal IREQ. Each device, as modified in Figure 5-11. contains a 16-bit register, in which an interrupt address vector is permanently stored. Upon receiving the interrupt acknowledge signal IACK. the device transmits an
interrupt address vector to the
CPU,
via
CPU
registers, the
CPU
Program Counter.
The
Parallel
its
A0
A7.
will
have to
transmit
CPU
in
two
is,
halves;
microprogram
Counter. This
Program
using the
bus
must be interpreted
in
different
same ways at
MULTIPLEXED
LINES
different times.
Notice that we have a problem with the Parallel I/O interface device, as illustrated we have run out of pins. IACK has to be input somehow in response to IREQO. The best way of resolving this problem is to replace the address pins A0 A7 with three chip select
pins CO. CI
five
unused
pins,
one
of
to IACK:
Two
of interrupt
address vector.
r^si
100
101
^^ ^
\
CO
CI
\
or B. or
C2
One
half of interrupt
addr
)SS
<
102
IACK
o o
00
D1
D2
D3
D4
108
109
'010 cr
\
PARALLEL
I/O
D5
D6
O Q_ O
I011
D7
IQSEL
1012
KD13
1014 1015
INTERFACE
The
First.
device changes
two
important ways.
CO, CI and C2 will be the product of additional chip select logic, which receives of the external system bus address lines as inputs.
some
or
all
5-20
is
now
it
may
ception
Having external chip select logic is the rule rather than the examong real microcomputer support devices. In reality,
in
the external select logic frequently does not exist. Since there are very
a typical
microcomputer system, and more than 32K bytes AND of A15 and any other address line:
>-
memory
is
rare,
A1
A? A3 A4 AR
Afi
A7 AR A9
CO
w
A1D
A11 A1?
AO
A1
C1
C2
A2 A3 A4 A5 A6 A7 A8 A9 A10
A11
12
11
10
9
|
I
~~x
Y
l
00
Port
Must
simultaneously selected
Must be
to select device
5-21
Upper
Lower
it
not a
real
problem;
memory
at the
Having the interrupt request signal arrive at memory or interface devices, rather than CPU, means that for every memory or interface device in the system, a different external device can have its own interrupt service routine identified for
post-interrupt execution. This concept
is
illustrated as follows:
PROGRAM
MEMORY
0200
ROM
device
provides this
02A0
Arbitrarily selected
I/O device
provides this
memory addresses
031A
ROM
device 2 provides
this
^ 04C0
ROM
device 3 provides
this
In
the above
illustration, interrupt
ROM
devices
1,
2 or 3
,
will
always
memory
031A 16 and
1
.
04C0 16 respectively. An interrupt request signal arriving at Parallel I/O Interface device will always specify execution of a program stored in memory with execution address 02A0 16 Each inis passed on to the CPU as IREQO. terrupt request arrives as a separate and distinct IREQ signal;
it
When
But a
the
CPU acknowledges
ROM
or I/O device
which
is
permanent feature
of the
ROM
or I/O device.
than one device capable of requesting an inWhat happens when more than one device simultaneously requests an interrupt? Which device is to be acknowledged, and how do we prevent the other devices from also acknowledg-
terrupt
included
in
a microcomputer system.
ing?
There are two parts to the answer. First, we must provide devices with a means of identifying themselves; we use select codes for this purpose. Next we must include interrupt priority arbitration logic.
two concepts.
5-22
H<
IH*
J
J li
a E
i
cl"^
0^-0 CO, ,<D^COO>0 <<<<<<<<<<W m """ m
\
gliiiiiiiiiJiiiiih;
\
5 > >
II-
Q Q Q
O Q Q o ^
IH-*!
II
'1
2 -\*k
-
2
\
1
f~~
1 1
<- ~ [
C3
S <
X "
<
QQ030Qoo5=
3 CL U
1 1
(HI
1
! <<<<<<
l
<
4<
<<<3<<
H
1
"~ Tih
I
H<
(1
"4
Iw f"
j|oa O
O x
<<<<<<<<DOQ
Q O Q Q Q
\
7
.V
< g
2
cr
//
1
W> &
o
SQQ2QQQ
Q Q
go
o Q Q Q
> D >
of
1
S
CO
V IHOd
0/1
iyod
o/i
,r
it
oo. G5
ro
E 3
5-23
<
>-
D
CD
iii
O" CO
B 5 g
<
^
CD cj CD
53
i? Q. 3
o O o
5-24
It would not be very economical or practical to require a new memory or I/O interface device to be added to the microcomputer system for every new shower to be
controlled. Many microcomputers will therefore require an external device, when requesting an interrupt, to accompany the request with an identification code. Figure 5-12 shows how an external device may connect directly to the External System Bus, placing its identification code on the data lines of the External System Bus when the CPU acknowledges its interrupt request with IACK. With
reference to Figure 5-12, events proceed as follows:
(T)
which
it
transmits to the
CPU
as
IREQ.
(2)
(3)
When
Upon
the
CPU
is
it
lines of
this
as an external device
(4)
Following protocol specified by the microcomputer system, the external device places
data at a Parallel I/O Interface device's I/O port.
its
of having external devices identify themselves with a code, as illustrated in Figure 5-12, makes a lot of sense to a minicomputer user (or designer), but to the microcomputer user it has one elementary flaw: it demands intelligence of the external device. Remember that a minicomputer may cost thousands of dollars and may be part of a system costing tens of thousands of dollars. Very few microcomputers cost more than $100, so we can only justify using a few dollars worth of logic to generate a device select
code.
The idea
have another reason why minicomputers and microcomputers are, and are remain, fundamentally different. The cost of providing external devices with the logic implied by Figure 5-12 may only be a few dollars, which is trivial in the
Here
likely to
we
world of minicomputers. But a ROM device, or a Parallel I/O interface device, also only costs a few dollars; therefore, every demand for dedicated intelligence in external devices is, comparatively, an expensive demand in the world of microcomputers. External device select codes, which are so obvious in the world of minicomputers,
must be justified on a case-by-case basis in the world of microcomputers. Chip costs increase very little with chip complexity, so economics demand that the microcomputer system does as much as possible, and demands as
little
as possible of external
logic.
minicomputers are priced at $3250 and $3640. Options that are compared make the two prices hard to evaluate, in determining which minicomputer is more expensive. one minicomputer system requires that an external device have $10
If
Two
expense
will
Two
for one very specific application, cost $53 and $61, need $10 worth of extra logic to request an interrupt on the $53 microcomputer system, but not on the $61 microcomputer system, then the $53 microcomputer system may well be eliminated for this single reason.
respectively.
an external device
will
5-25
INTERRUPT PRIORITIES
What happens when more than one
same time?
priorities,
external device requests an interrupt at the This problem can be resolved in two ways. First, logic within the microcomputer system can have a number of interrupt request lines with ascending
as follows:
Vdd
Power and Ground
Vss
DO
D1
Vgg
D2
Clonk
D3
AO
A1
D4
>
Data.
CPU
D5
D6
A2
A3
A4
A5
D7
W
R
WRITE
READ
IOSEI
A6
^Address <
A7 A8 A9
IORW
IACK
IRFD1
^ ^. ^ ^
^
Prinnty
1
Interrupt request
A10
A11
^ iRrm ^
IRFO?
Priority 2 Interrupt
request
A12
A13 A14
I
A15
A
in
fewer CPU
do the same job, using Consider the Interrupt Priority device illustrated
INTERRUPT
PRIORITY CHIP
Figure 5-13.
Before discussing how the Interrupt Priority device illustrated in Figure 5-13 works, we will define what is meant by interrupt
priorities.
INTERRUPT
PRIORITIES
AND WHAT
THEY MEAN
interrupt
Suppose more than one external device may request an interrupt. If two or more external devices request interrupts by SIMULTANEOUSLY sending IREQ signals that overlap in time, then WHICH external device gets the
(IACK)
is
acknowledge
determined by interrupt
priority:
Device
IREQ (second
priority)
A
Device
IREQ
(third priority)
MICROCOMPUTER SYSTEM
wrv
p4
Device
IREQ
(first priority)
5-26
Vdd
Power and Ground
Vss
DO
D1
vgg
D2 D3 D4 D5
INTERRUPT
PRIORITY
Clock
4>
>
Data^
10
11
12 13 14 15
D6 D7
IO0
101
16 Interrupt request
lines.
16 17
I02
with 16
priorities (0 highest,
I03
>-
15 lowest)
18
19
I/O Port
110
111
112
W
R
WRITE
READ
IREQO
IACK
Figure 5-13.
An
In
the above
illustration,
external devices A.
B and C
all
transmitting IREQ signals to the microcomputer system. By whatever priority arbitration technique the microcomputer system is using, it is determined that Device C has the highest priority, Device
has the second priority and Device B has the lowest IACK, must therefore be sent to Device C.
fact that
priority.
The
single
acknowledge
signal.
Devices A and B did not have their interrupt requests acknowledged does not imply must remove their IREQ interrupt request signals. They can do so they wish. If they do not, they will be acknowledged, in turn, when the microcomputer CPU is subsequently ready to acknowledge interrupts again.
The
that they
if
all
interrupt service
programs residing
memory, one
for
Acknowledge IREQ
Acknowledge IREQ
from Device B
Disable interrupts
5-27
is
First
Device C's
@ and,
executed
at.
Subsequently Device
and B's
interrupt service
respectively.
interrupt service
routines,
andare
to
be executed sequentially, as
illustrated
above,
dis-
then while
is
must be
point,
A and
after
re-enabled;
now
(^has resumed executing, the microcomputer system interrupt logic A is acknowledged. While is executing, the microcomis
again disabled
until
is
still
now
gets executed.
in
microcomputer systems.
7.
These
instructions,
and
how
in
Chapter
Suppose the microcomputer system did not disable its service routines such as and . This is how the
interrupts
would be
serviced:
Ths important concept to understand is that interrupt priorities determine which device receives the interrupt acknowledge IACK when more than one device is
simultaneously requesting an interrupt via IREQ.
Interrupt priorities
started executing. Device A has lower interrupt priority than Device however, once Device C's interrupt request has been acknowledged. Device C removes its interrupt request. Device A's interrupt request is still present and is the highest priority interrupt re-
Device
A once has
C;
quest. The instant program enables interrupt logic, it will immediately be interrupted, and program (A) will execute. If you do not want program (5)to be interrupted, then when you write program you must make sure it keeps interrupt logic disable. Instruction steps to do this are
described
in
Chapter
7.
Let us now return to the Interrupt Priority device illustrated in Figure 5-13, and explain how this device works. As illustrated, there are 16 separate and distinct lines via which external
devices can transmit interrupt request (IREQ) signals to the Interrupt
Priority device. Signals
priority,
INTERRUPT
PRIORITY
AND
MULTIPLE
REQUEST LINES
terminate at pins
priority.
10
through
115. 10
has highest
When one
device sets
arrive at pins 10
115,
CPU responds
5-28
When
it
sets
number on DO
15,
D3.
one IREQ
arrives at
16
0101
113,
is
output
is
via
DO
two IREQ
high.
and
01 10
output
at pins
If
Timing
is
as follows:
IREQ
IREQO
DO
D3
IACK
Once
The data
device to the
System
Bus, while the I/O pins interface the Interrupt Priority device with external
in
devices, as illustrated
Figure 5-14.
initially
microcom-
System
means
device
is
selected via
memory
chapter.
The important point to note is that any programs executed after an interrupt has been acknowledged use the same logic as programs executed before the interrupt was acknowledged. Interrupt logic applies only to the process of requesting and accepting an interrupt. If external devices connect to the microcomputer system
do likewise after the interrupt has external devices connect to the microcomputer system via the data lines of the External System Bus, they will do so before and after an interrupt is acknowledged.
via I/O ports before the interrupt, they will
been acknowledged.
If
there
system only has one interrupt line, or if more than one external device using the same priority interrupt request, then a method called "daisy chaining" must be employed to determine interrupt priorities.
If
a microcomputer
is
INTERRUPT
PRIORITY
AND DAISY
CHAINING
A number of
connect to the same interrupt request line IREQ. The interrupt acknowledge line. IACK, however, will terminate at one external device. This device must have internal logic which passes on the interrupt acknowledge if the device is not requestdevices
in
all
ing
an
interrupt,
but traps
it
in
same
5-29
>
<gcOOE<
~*
~*-^
!
SiQ
i2
I i i
Q<
<
1
mil
~"
^
-
1'
<
<
to
r-
00
0>
o a s a s
5 O cc
(>-*-II
> >
>
*
5.
Q 2 8 O O O Q ^
4 T
1
1111
i|
In
<M| H[
,
-_,
1
c 5
!
1 1
V5
3 3 Q 8JS 5 *
3 QU
a
^
51
> >
cm
co
in
(C
t->
*r
ui
r-
IMH<-" T"
-1
1
ixl
IN!
i.
_ _ " u J
,
^^
w
Ci
s <
W
o o o
O -M
n " U 8 S 5 =
f-i
*T
cJ
(J
m UD r^ U O O
a.
Dice cc
>
L_ CC
z,
> >
?e
^ 2
>
1
t1
"
Q Cl= O
0:
0)
>
E"S
5-30
logic,
last
device,
to
to.
Daisy chain-
ing
may be
illustrated
as follows:
IREO
Device
Device
3
Device
2
Device
1
To Microcomputer System
IACK
There are strengths and weaknesses associated with having separate priority lines, or daisy chains, in microcomputer systems. In either case, the question becomes somewhat academic
since, as described in Chapter 6, a microcomputer system that is being interrupted by a great multitude of external devices is probably being misused. Nevertheless, let us consider some of the strengths and weaknesses associated with separate interrupt priorities, and with daisy chains.
There are situations where separate interrupt priority makes sense, because the microcomputer CPU must attend to one external condition at the expense of all
others.
For example, most minicomputers- have a highest priority interrupt which is activated by a power failure. Whiie this may not at first make a lot of sense, consider what happens when power does go down.
Microcomputers typically use + 5 and/or + 12 volt DC power supplies POWER FAIL which are generated from the normal 110 volt AC power line. Power INTERRUPT failure might be detected when power falls below 90 volts. But may be a few thousandths of a second before power drops so low that + 5 and 12 volts cannot be maintained for the microcomputer. In these few milliseconds, a hundred or more microcomputer instructions may be executed to prepare for power failure in an orderly fashion, now when power comes up again, the power fail interrupted program can restart without loss of data.
it
We
have described one situation where separate sider the limits of daisy chaining.
will
Daisy chaining
the
if
all
of
which require
little
shower would get needs of the 99 showers that came before in the daisy chain. is quite conceivable that the microcomputer system will be so busy attending to devices situated at the beginning of the daisy chain that the tail-end devices would get little or no attention. The occupant of Room 100 will get scalded or freeze.
not
number does
become
how
respond
to the
it
Another problem with daisy chaining is that it demands intelligence of any external device in the daisy chain. Once again, we are dealing with microcomputer economics.
External devices
in
a daisy chain
must
identify themselves,
has no
way
of
it
went before
far
down
we
are back to
demand'ng
in
when an
code
to the
implemented
either.
for a
few
dollars,
but
remember
microcomputer system. Certainly this logic could be a microcomputer does not cost too many dollars
order to eliminate the cost of external logic required implement a daisy chain, some microcomputer manufacturers provide this logic on support devices. Consider daisy chain logic on an I/O interface device;
In
DAISY CHAINING
to
WITH
I/O
INTERFACE DEVICES
5-31
Here
is
one possible
Parallel
Vdd
Vss
SO
SI
<-> Device
select
<>
><->
signals
Vgg
$
100
101
'
|^
address vector
DO
D1
D2
Interrupt
CO
D3
D4
D5
<
1
Q-
I02
I03
I04 I05 I06
3 CO < < Q
D6
D7
><->-
<
PARALLEL
I/O
<->
I07
<-> 108
109
CD 1 cc
IOSEL
INTERFACE
IO10
1011
WITH
INTERRUPT LOGIC
IACK
IREQ
O Q. o
-<->
1012 1013
1014
1015
In order to acquire the extra pins for needed signals, we have replaced 8 device select pins (AO - A7 in Figure 5-12) with two pins, SO and S1. For the device to be selected, a low signal must be input at SO. A simultaneous low input at SI will select Port A. A
at
S1
will
select Port B.
You can
usually choose
two address
lines
and
is
tie
them
could
directly to
SO and SI,
lot of
without using a
how you
Parallel
I/O
A7
A6
A5
A4
A3
A2
5-32
A7
A6
1
A5
X
A2
1
A1
AO
1
Could be
or
1.
We
arbitrarily select
Must be
to select device 3
selects Port
1
selects Port B
Thus 45 16
selects device
3, 3,
Port A.
65 16 selects device
Port B.
This device select logic has nothing to do with interrupts we are currently discussing.
which
is
the subject
A number
follows:
would be used as
REQO
I
i i
A
I/O Device
TO
MORE
DEVICES
I/O Device
I/O Device
TO MICROCOMPUTER SYSTEM
'
IA(:k
IACK
IREQ
IACK
IREQ
ACK
IREQ
\
This
1)
f
I
4
device
- External
interrupt requests
is
_/
what happens:
one or more external devices request an
interrupt,
When
line "true".
2)
on
to the
CPU
via
3)
a "true"
is
IREQO
input.
CPU
logic
now knows
that
some
device
it
does
requesting an interrupt.
4)
5)
When CPU
The
"true",
it
be acknowledged
it
first Parallel
I/O device
in
it
traps the
IACK
If
signal,
it
the
in-
SO and S1
put,
it
select lines.
the
first Parallel
The
traps IACK.
5-33
6)
traps
its
allows the I/O device to be identified. Note that select logic associated with SO and S1 not involved. The interrupt request/acknowledge logic has
its
own
select logic
is
is
it
it
on.
Now
used
If
data
is
to be input or output,
SO and S1
are
Parallel I/O with interrupt logic device introduces a very important concept putting more than one function on a single chip. Parallel I/O logic and Interrupt logic have nothing in common. They happen to be on the same chip, so they share the data bus pins DO D7.
The
MULTI-
FUNCTION
DEVICES
External logic can request an interrupt via one I/O device; then after the interrupt has been acknowledged, the external logic can transmit or receive data via I/O ports of the same I/O device, another I/O device, or via no I/O device.
Following an interrupt, there
device which trapped IACK.
is
no reason
I/O logic
and interrupt logic happen to share a chip; they have no other connection.
DIRECT
The shower temperature
controlling
MEMORY ACCESS
to
microcomputer system will spend a lot of its time simply receiving data from the temperature sensor and storing the data in a RAM buffer.
have described
is
We
how
interrupts
may be used
execute program
perature sensor
scheme.
Remember
approximately.
A cheap temperature
sensor is not going to transmit exactly two temperature readings per second. In fact, there could be considerable time period variations between temperature transmittals. As a result, we cannot predict, with any degree of accuracy, the time delay between consecutive ASYNCHRONOUS data transmittals from the temperature sensor to the microcom- EVENTS
puter system. Therefore, data transmittals from the temperature sensor to the microcomputer system constitute asynchronous events:
Readings transmitted by temperature sensor to microprocessor
Because data transmittals from the temperature sensor to the microcomputer system are somewhat unpredictable (or asynchronous), program RECORD must be executed every time the temperature sensor transmits a data item. Program
will
RECORD
move
in
the
RAM memory
sequence
5-34
5-35
cannot be part of program ADJUST, since the logic of program ADJUST cannot detect the arrival of data from a temperature sensor. Any scheme that executes the RECORD instruction execution sequence at fixed time intervals is bound to miss a large number of the
is
an example:
@
it
ADJUST.
sequence which records data transmitted by the temperature sensor to the microcomputer system. If transmitted data does not reach the microcomputer system during (R)
of the instruction
may be
missed.
The only safe way of catching all data transmitted by the temperature sensor is to have the temperature sensor request an interrupt when it is ready to transmit a
will
In response to the temperature sensor's interrupt request, the microcomputer system execute the data sensing instruction sequence, characterized in the illustration, above by (R) The illustration must now be modified as follows:
data item.
(A)
Each time the temperature sensor transmits data to the microcomputer system, it notifies the requesting an interrupt. In response to the interrupt request, program logic suspends execution of program ADJUST while executing program RECORD (). Program RECORD reads the data input by the temperature sensor, then program ADJUST continues executing from
CPU by
Even This
1
this
method
is
by the temperature sensor is not very efficient. interrupt and executes RECORD:
)
The CPU
and
executing program
it
an interrupt request,
status;
executes
above.
When
the
the contents of
interrupt.
then
it
2)
Program RECORD in the illustration above) is executed. This program contains tions which load a memory address into the Data Counter, read data from an I/O port
Accumulator, then output the data from the Accumulator to the
the Data Counter.
instrucinto the
3)
Step
is
reversed.
Saved contents
of registers
continues execution.
Out of
all the instructions that get executed to implement the above three steps, the only change, each time the temperature sensor transmits a reading and (r) is re-
executed,
is
in
Step
2.
The contents
of the Data
5-36
Counter
will
it
was
last time,
and one
this
is
less than
it
will
Fifty
to repetitively
se-
quence of events. Before we can decide whether we must ask two questions:
1
Are operations
The answer
In fact,
is
common,
or
is
this an isolated
that
is
not only
it
will a
operations performed by
microcomputer.
from an exter-
nal device,
will
from
RAM
buffers to
external devices.
2)
If the microcomputer did not spend 50 microseconds every time it input data from an external device (or output to an external device), what else would it do with the time?
is nothing, in which case the wasted time is irrelemicrocomputer application starts to get more complex, the waste of time starts to become more serious. If it takes 50 microseconds to read a data item from an external device, and another 50 microseconds to transmit a data item to the same external device, then one microcomputer system could perform one hundred data transfers per
In
many
second
but there
would be no time
left
to
do anything
else.
be intolerable.
CYCLE STEALING DIRECT MEMORY ACCESS Direct memory access (DMA) provides a solution. We will create a new device for our
this device we will place a small amount of CPU-type dedicated to the sole task of moving data between I/O ports (or the data lines of the External System Bus) and memory.
logic,
The
DMA
it
while
device will accomplish its task by suppressing or bypassing CPU logic creates signal sequences that enable the appropriate data transfer.
in
Given the microcomputer system architecture that has been described chapter, the task of designing a DMA device is really quite straightforward.
this
INHIBIT Temporarily suppressing CPU logic is easy, since the CPU is CONTROL driven by an external clock signal. If we can stop the clock signal, we can stop the CPU. Therefore, as illustrated in Figure 5-15, we will add an INHIBIT control line to our External System Bus, and an INHIBIT control pin at the CPU device.
The INHIBIT
signal will normally
CPU
chip
will
com-
bine the clock signal with the INHIBIT signal, to generate the internal clock signal which drives
CPU
chip
logic:
INHIBIT-
-CPU $
All
the
DMA
device has to do
is
low
in
CPU
chip:
J
INHIBIT
cpu
<t
5-37
Memory
devices and
Parallel Interface
devices have no
the
way
of
signals
DMA
more
detail.
The
DMA
An Address
memory word
to
be accessed,
A Counter, A
Status
which
initially
is
to
be
filled
during a
to
be read during
a write operation.
DMA
few
logic
is
DMA
options.
We
will
look at a
of these
options
later.
registers of the
Initially,
DMA device
memory words.
programmed I/O
may appear as I/O ports or addressable instructions will be used to set values in
is
an example:
0080
007 F
03
This simple
filled
[
Address Register
Counter Register
Status Register
example
and ongined
at
0080]5.
is
to
be
Memory
Access.
The Status
for the
moment
6 5 4 3 2
10
1
Bit
Number
Q3TTTTT
"
( (
= =
= DMA = DMA
register,
specified,
the
CPU
to
initialize
DMA
DMA DMA
DMA
INITIALIZATION
will
have
no other way for data device Address, Counter and Status registers.
In
order to
initialize
DMA
operation, a
DMA
device.
2)
DMA
device.
3)
DMA
device.
4)
illustrated
above)
DMA
device.
The
control
code must
DMA
device on.
DMA
device has
control lines.
The WRITE
used by the
DMA
RAM.
5-38
The READ
used by the
DMA
RAM
or
ROM.
at
DMA
DMA
device
DMA CAUGHT
ON THE FLY
how
far a
operation
operation
is
program that adjusts its logic to the current said to be catching DMA on the fry.
level of
completion of a
DMA
Of course, an executing program can turn a DMA operation of f aft any time by simply writing new data into the DMA device's
register to
DMA BEING
TURNED OFF
progress.
Status register. As described above, setting the would immediately stop any DMA data
bit of
the Status
transfer that
was
in
What happens
after a operation has started? Notice that external devices are connected directly to the data lines of the EXECUTION External Data Bus. In addition, the external device has a request signal (DMAREQ) which it pulses high to the device. If data is being read from the external device, the following signal sequence occurs:
DMA
DMA
DMA DMA
D0-D7
WRITF
The
entire
DMA
as the
As soon
edge
DMA
DMAREQ
is
line,
it
immediately lowers
the second rising
kept low
until
2)
The CPU
suspend operations for one clock cycle because INHIBIT line low ((3) above). The CPU will also apply high resistances at its connections to the address and data busses, effeckeeps the
FLOATING
CPU
(J)
BUSSES
tively
disconnecting
itself
is
3)
low and <t> rising above) causes the DMA device to output Address register on the address lines of the External System Bus (above). Also the DMA device acknowledges the DMA request by pulsing the DMACK response control line high (above).
The combination
the contents of
of INHIBIT
its
5-39
The
bit
of the
DMA
DMARW
high or low.
As
illustrated
above,
it
is
external device to
must transmit The combination of DMACK high and place its data on the data lines of the External
the
DMA
WRITE
control
line. All
RAM
DMA device to output a high on the decode the address on the address lines
on sensing the WRITE control high, the selected RAM interis on the data lines of the External System Bus and will write this data into the addressed memory word. RAM interface logic neither knows nor cares where data, address and control signals originated. It simply responds to any situation and one
will find itself will
selected;
face device
which activates
its
internal logic.
As
terminates DMA operations. In reality, some rising edge of scheme would be used, since the one illustrated, though ve ry simp le, would c ause jitter in the leading edge of CPU 0. CPU goes high only because INHIBIT goes high. INHIBIT going high for a s econd goes high because just went high for a second time. Clearly,
illustrated
other
(J)
CPU
(J)
in
INHIBIT
,r
!
CPU
Thus, as
practical.
illustrated,
the
is
realistically
im-
As soon
Bus.
it
as the
DMA
its
Address
will
RAM
data
buffer.
Simultaneously the
is
DMA
chip
will
Counter
register.
Here
DMA write
5-40
Notice that the write operation differs from the read operation only in that the device sets the READ control signal high when it places the contents of its Address register on the address lines of the External Data Bus. This causes the memory module which is selected by the memory address to place the contents of
DMA
DMA
DMA
the addressed
memory word on
DMARW,
DMA
Once
chip,
again the
DMA
it
device
will
decrement
its
Address
register,
so that
is
DMA
operation.
One
of
two
things
register
decrements to
zero:
The
is
DMA device may signal the fact that the DMA operation
DMA device may simply start the whole process over again,
Counter register and Address
register,
DMA END
is
rupt
2)
over by sending an interrupt request to the CPU. This inter would be handled according to whatever interrupt processing logic the CPU
using.
origi-
The
by saving the
so that
it
original
until
The two options available when the First the "end of DMA interrupt":
Cycles stolen by
DMA
device counts
down
Last
DMA
Interrupt request follows
last
DMA
stolen cycle
///
Main program executing
Next consider a
length count:
DMA cycle
DMA
initial
Initial Initial
Address
Current Address
Current Count
Status
Count
When
dress"
0, "Initial Count" is loaded into "Current Count", and "Initial Adloaded into "Current Address": Status remains unchanged (unless modified by the CPU),
and the
DMA
same
buffer,
One
MULTIPLE EXTERNAL DEVICES DMA device can control DMA operations for many external devices. Since a DMA device does not actually transfer any data, does not need any I/O ports
it
it
DMA WITH
5-41
hit
CD
i
Hi
>
CD
LO
mi
t-
CD
>
<M
CD
or
<
\fvym u
OQQQQQQQ
in
^
<y)
fc
rs,
CO
5
<.
^r
Ln
<J)
a)
C/)
< O
00
<<<<<<<555
55
5-42
Many schemes
DMA
device to control
DMA
access
for
more
than one external device; Figure 5-16 illustrates just one possibility.
The
DMA
device illustrated
in
DMA
own DMA
request
line
DMAREQ5). Common
DMA
DMA
(DMARW)
lines are
used by
devices.
DMA
when
it
is
own DMA
request
line high.
The
DMA
registers,
3,
based on the
DMA
DMAREQ3
When
the multidevice DMA device illustrated in Figure 5-16 steals a cycle and transfers a data word via DMA. the signal sequence is identical to that which we have already described for a single external device. However, external devices in Figure 5-16 must contain their own select logic. In other words a device which raises its DMA request line must be the only device to respond to DMACK, DMARW and the External Data is Bus; no other device attached to the multidevice DMA device must respond to these lines. the responsibility of the external device, not the multidevice DMA device, to ensure that only one
It
itself
selected for DMA at any time, data transfers. Memory modules merely respond to address and control signals output by the DMA device. Memory modules neither know nor care where this information had its origin. Only the selected external device is active at the other end of the External System Bus, so the two ends of the data transfer are clearly
then there
no possibility of confusion
in
DMA
defined.
Let us consider an
External device 2
is
example
in detail.
it
raises
DMAREQ2
high:
INHIBIT
IREQ
End-of-DMA
interrupt
IACK
DMACK
DMARW
DMAREQ5 DMAREQ4 DMAREQ3 DMAREQ2 DMAREQ1
\f
V
1
If
U V
External
External
External
Device
Device 2
Device
3.
5-43
The
first
thing
DMA device
is
logic will
If
do
is
DMAREQ2,
in
the enable
bit (bit 0)
it
0,
DMA
If
device logic
will
ignore the
DMA
re-
quest. Since
will
DMAREQ2
a pulse signal,
will
go away.
steal a
the enable
bit is 1,
DMA
de vice
logic
acknowledge the
interrupt
on
DMACK
DO
D1
and
CPU
Vdd VSS
Vgo.
Address
Counter
D2
D3
D4
AO
At
Status
Address 2
Counter 2
Status 2
| t
PS
06
"I
|
A2 A3
D7
A4
A5 A6 A7 AS A8
Address3
Counter 3
Status 3
W
R
^"ipman
Address 4
Counter 4
Status 4
Address 5
Counter 5
>-
Status 5
DMAREQ2 DMAREQ1
1
External
Externa.
Device
Devce
DMA
end
of
DMAREQ2
pins:
from
To Address
lines of
JNHIBIT
JREQ
_IACK
End-of-DMA
interrupt
External
Data Bus
:'-'.
u.
Tl
DMA
dress
ft
of
device logic
2.
will
Ad-
Since
dress,
DMAREQ2
identifies
no confusion can
result
Address 2 as the DMA register containing the required memory adfrom the fact that four other addresses, in four other address
5-44
DMAREQ2
and
The W. R
DMARW
2:
DO
D1
Address
Counter
Status
1
D2
D3 D4 D5 D6
;
AO
Al
Address
A2
Counter 2
Status 2
A3
A4 A5
D7
Address 3
Counter 3
Status 3
A6
A7
IREQ
Address 4
End-of-DMA
interrupt
IACK
A8 A9 A 10
All
Counter 4
Status 4
DMARW
DMAREQ5 DMAREQ4 DMAREQ3 DMAREQ2 DMAREQ1
' 1
Address 5
Counter 5
Status 5
'
'
'
External
External
Device
Device
data transfer
2.
now
device
Signal
occurs between the memory word addressed by Address 2 and external sequences associated with the data transfer are exactly as described for the
DMA
chip.
SIMULTANEOUS DMA
Observe
of the
CPU
on a
DMA really involves nothing more than reproducing a limited amount DMA device A DMA device may be likened to a CPU which is capatwo
instructions:
2)
memory
to an external device.
Because of the very limited number of operations which the DMA device can perform, nearly all of the time-consuming sequences associated with CPU operations (for example the instruction
fetch)
can be eliminated.
But
ing
we can take DMA logic a step further. By duplicating part of the External System Bus, we can eliminate the need to steal cycles from the CPU. Look again at the timdiagram for a memory read operation:
AO
to
A15
DO
to
D7
Memory Read
Instruction
5-45
To
RAM
Devices
<
Notice that even though the External System Bus is constantly busy, neither memory nor external devices will be busy during the <t> high portion of instruction cycles. These periods, shaded above, represent the time required by the CPU's Control Unit to generate appropriate control signals.
By creating a second External System Bus, DMA logic can access while the CPU is not doing so. This is illustrated in Figure 5-17.
External devices will be connected to the data lines of the
memory modules
shown
in
DMA System
Bus. as
Figure
5-17, for
all
DMA
data transfers.
If
using
nal
programmed
must be
shown
in
Figure 5-17.
At the memory modules, the must communicate with two busses and
of T-junction. This T-junction
is
pins
some form
TRI-STATE BUFFER
tri-
state buffer,
is,
in
effect,
[To Bus
To Device
TRI-STATE
BUFFER
,To
Bus B.
DMA? We
buffers.
must pay
tri-state
What we buy
it
little
is
very small;
in fact,
is
memory modules
be provided with
them.
We
performance improvement.
microcomputer designer is therefore more likely to select one DMA method or the other based upon which method is best suited to the architecture of the microcomputer system.
The External System Bus represents one of the most varying features of any microcomputer system. Indeed, the only constant feature you will find from bus to bus is the
presence of eight data
lines (for 8-bit
will also
have 16 address
lines.
The greatest
variation is seen in the control signals generated by the CPU. Basically there are two philosophical extremes. One extreme calls for a complex set of control signals to which other devices passively respond. The other extreme calls for elementary control signals which must be interpreted by devices that contain a considerable amount of internal chip logic.
Consider
this
the CPU that totally dominates a microcomputer system. Devices that interface to not receive any clock signal inputs. Instead they will receive numerous control sigSemiconductor and Signetics nals which identify events on the Data Bus in detail. The National microcomputers are the best examples of this philosophy.
first
CPU
will
5-47
just
one
control signal
MCS6500 CPU
receive this
this
controf signal, plus the system clock signal. Devices contain internal logic to
bination of
decode
com-
two
MCS6500 microcomputer
system.
The philosophy behind National Semiconductor and Signetics type microcomputers is special devices are needed to support the CPU. By having a very complete set of control
standard off-the-shelf logic can be used.
that
no
signals,
The philosophy
that support the
of
microcomputers with very elementary sets of control signals is that since it add extra logic to an LSI chip, you are far better off generating devices
in
CPU
SERIAL INPUT/OUTPUT
transferred over telephone lines serially. There are also some slow I/O devices, such as the common teletype and magnetic tape cassettes, which transmit and receive data serially. If a CPU is to transmit or receive serial data, then it must have interface logic capable of converting serial data to parallel data, or parallel data to serial data:
Data
is
101 10101
1
10101
'
10010001
k
10
'I: -J
10
1
J1
1
1
1
Jo
1
[o
\1
\1
lo
is
transferred
between a telephone
line
and a
Telephone
Line
MODEM
SERIAL
MICRO-
INTERFACE
COMPUTER
A modem
is a device which can translate telephone line signals into digital logic levels, or digital logic levels into telephone line signals. Some microcomputer manufacturers provide modems as a single logic device, but we do not consider the modem to be part of the microcomputer system; therefore modems are
MODEM
not described
in this
book.
A magnetic
any other
serial
SERIAL
MICRO-
DEVICE
INTERFACE
COMPUTER
transmitted and
Transmitting
Device
^j^
Transmitting
pin
Serial
Receiving
tltE
Receiving Device
Data
Signal
Like
1.
any other
digital signal,
the
011100100. This
I I I I I I
is its serial
data signal
Ul "TT-|_Ln
i
I
I
I
l
I
Interpretation:
n n O'l'l M'O'O'I'O'O
i
I
'
Whereas
it
is
easy
for
you
and
interpret
it
CLOCK
SIGNAL
will
require
more
use a clock signal to identify the instant at which the receiving device must interpret the data
boundaries.
We will
signal:
Clock Signal
Serial
Data
Interpretation.
illustrated above, the falling edge of the clock signal identifies the instant at which the serial could just as easily clock on the rising edge of the signal. data signal must be sampled.
As
We
Clock Signa
Serial
Data
Interpretation
serial
it
receiving device. Let us look into the implications of this simple necessity.
5-49
If the receiving device uses a clock to interpret the serial data signal, then the transmitting device must use a clock with the same frequency to create the serial data signal:
Transmitting
Clock Signal:
Serial Data:
rarmt
SriJri-JrLJrLJrLjf^^
1
Receiving
Clock Signal:
Interpretation:
1
The
is
because
in reality,
it
takes
change
state.
Now
it
makes
if
3
But
in reality,
finite settling
time:
Look
at
what happens
if
and receive
serial data:
Single Clock
Signal:
Serial Data:
"0"
will
be received
when
" 1"
was
in
"1"
will
be received
when
a "0"
was
in
the
process of being
transmitted
5-50
We
SERIAL DATA
The transmitting
binary
digit:
Transmitting
Clock Signal:
Serial Data:
During
this
time interval
The
to
happens
show
digits.
CLOCK SIGNAL
Transmitting
Clock Signal:
c
Serial Data:
Receiving
Clock Signal:
Interpretation:
Jn
Fl
SIGNAL SETTLING DELAY
The
illustration
above shows the transmitting clock signal active on its trailing edge, whereas the is active on its leading edge: there is nothing significant in this use of signal
edges.
The receiving device must wait for the Serial Data signal to settle, presuming it has changed state, before trying to read the signal level. A signal's settling delay is a characteristic of the
5-51
is
is
an
Transmitting
Clock Signa
Serial
Data
Interpretation
Settling Delays
single serial
digit
time interval
Single
Clock Signal:
Settling Delays
Look
carefully at
how
is
received:
End
of digit time
interval
and
start
Single
Clock Signal
Serial data
Read
signal level
shortly before
end
of digit time
interval
5-52
The time
ted.
interval during
is
which the
Serial
BAUD
RATE
binary digit
speed
which data
is
being transmitthis
for:
is
Suppose
com-
mon
then endure
we measure
if
stream is not the way in which serial data transfers "bits per second", and refer to this number as the
this
is
BAUD
RATE.
For example,
equivalent to a baud
rate of 110.
Our microcomputer system already has a clock signal, used to time inCLOCK CPU. Do not confuse the microcomSIGNALS puter system clock with the serial data clock; the only thing these two signals have in common is that they are both clock signals. The serial data clock signal may or may not be derived from the microcomputer system clock.
struction execution within the
*^
From
a microcomputer user's point of view, speed is the most striking difference between the microcomputer system clock and the serial data clock. A typical microcomputer system clock may have a period of 500 nanoseconds (2 MHz) whereas serial data transfer rates typically range from
between
rate
is
10 Hz to 9.6 KHz.
In
CPU
clock.
The
SERIAL
actly the
baud
rate,
does:
CLOCK SIGNAL
Single
Clock Signal:
V
for the clock rate to
Serial Data:
Interpretation:
It is
quite
common
SERIAL
x 16
rate:
CLOCK SIGNAL
Data
15
1
Serial
10 11
12
13
14
15
Clock Signal
Serial Data:
Interpretation:
rate
is
SERIAL x 64
CLOCK SIGNAL
Data
Clock
Signal:
Serial
62 63
31 32
33 62 63
31 32
33 62 63
Data:
Interpretation
5-53
The reason
possible to the for having x16 and x64 clocks is to get as close as signal. center of a single digit time interval when sampling the serial data clock signal does not necessarily The fact that serial data needs a companion mean that all serial I/O requires two signal lines. The accompanying clock signal does you set up a serial data communicanot actually have to be transmitted on a companion wire. not have to tions interface, with a predefined baud rate, then receiving device logic does
If
logic
can create
its
own.
synchronizing
it
with a transition
in
line:
Synchronize here
i; Serial
Data
Clock Signal:
Serial Data:
Interpretation:
Special synchronizing
In
digit
is
permanently high
when
MARKING
Note that
when using a x 16 or x64 clock signal, the receive clock can be one or two pulses out of phase with the transmit clock and no harm will be done. The receive sampling point will simply
be skewed a
little
off center.
is
If
insufficient,
how about
tern?
We
bit
sequence and
set
up
rules
which
must be preceded by
this
synchronization pattern:
Clock Signal:
Serial Data:
"^j
i_m
illustrated above does
r
Synchronization
bit
Interpretation:
pattern
exist,
in
the
and is referred to a
serial
SYNC
character.
serial
many rules that we must impose on order to ensure that the receiving device correctly interprets the transmitted data. This set of rules is referred to as "communications protocol".
just the first of
SERIAL
data streams
in
DATA
Every
serial
I/O data
link
must have
communications
must be
parallel I/O,
which
tell
how
TELEPHONE LINES
dealing specifically with telephone lines, consider the fact that the transmitting and receiving devices may continuously switch roles, as happens in any voice telephone conversation. While talking, you are the transmitter; while listening, you are the
receiver.
When
5-54
Similarly,
when
telephone
lines
two-way communication
will
almost
always be required.
If a single telephone line is used to transmit data in both directions then communication is said to be half duplex. If
HALF DUPLEX
FULL
two telephone
lines
line
one
direction
DUPLEX
in
then communication
of
full
said to be
full
duplex.
is
The advantage
proceed
in
parallel.
ERROR DETECTION
Whether
serial
data
is
lines,
or directly
between
a transmitting
we must
check
for errors
in
transmission.
way
some means
At
have crept
does
this job.
bit
has
PARITY
BIT
all
been set
the data unit is either odd or bits will be detected. Here are some examples, assuming odd
parity bit
is
illustrations,
the
shaded and
Transmitted
Received
101101106
10110110:
100101 10i
100101108
1
Even
parity, error
detected
-1010110
Odd
Even
parity,
no error-detected
detected
100101 101
parity, error
parity,
100101101
01101001$
Odd
no error detected
An
additional technique used to check for errors in transmission is to append a "cyclic redundancy character" at the end of data stream segments. The cyclic redundancy character is a numis
CYCLIC
REDUNDANCY CHARACTER
Here
digit divisor:
11000000000000101
The
result of dividing this divisor into the transmitted data stream, treating the transmitted data
stream as one continuous binary number, becomes the Cyclic Redundancy Character. The receiving device multiplies the received data stream
If
the result
is
divisor,
The
Redundancy Character is just one rather simple method used to track down errors in complex methods have been devised not only to track down errors, but also to determine exactly what the error is can be corrected. Entire books have been written so that on the subject of error detection and correction, therefore we are not going to discuss the subject
Cyclic
transmission. Very
it
any
further.
now
tie
serial
scribed thus
far.
Generally stated, serial data communications protocol can be divided into synchronous and asynchronous categories. You will find protocol easier to understand you
if
5-55
approach synchronous and asynchronous data communications as two separate and not minor variations of a single concept. tities
distinct en-
principal characteristics of synchronous, serial data transfer is that the data signal. Having once established a serial data transfer baud rate,
MUST
transmit a data
bit at
device
knows
exactly
how
data signal:
I
Serial
Data
Is
Interpretation:
For example,
if
300 baud
the
serial
synchronous data
device can
slice
serial
transfer has been specified, then the receiving 3333 microsecond segments, interpreting each seg-
ment as
We
with freguencies
1,
How
is
know
the bounds
100101
1
of
---01
Where
Clearly our
>
101 1000101
1--
and must
used
for this
some way to synchronize on data unit boundaries. The SYNC purpose Every synchronous data stream begins with either
one or two
SYNC
characters:
SYNC
SYNC
01101001011010011011...
+
First
character of data
The data
unit in a synchronous, serial data stream usually consists of data bits without parity; but a parity bit may be present. Here is an example of a 9-bit data unit; eight data bits and a parity bit:
xxxxxxxxP
t_
Either
Parity Bit
odd
or
even
parity
may be
specified.
Eight data bits need not always be transmitted; options allow 5, 6, 7 or 8 of the data bits to be meaningful. If less than eight data bits are meaningful, then the balance of high order bits are ignored. Here is an example of a data unit in which only 6 data bits are signifix x x x x x
t_
Parity Bit
(if
present)
Two
While waiting for synchronous, serial data to start arriving, a receiving device will enter a "hunt" mode, during which
it
SERIAL
serial
your protocol
calls
one Sync character, then the receiving device will start matched a single Sync pattern. More frequently, protocol will which case the receiving device will not start decoding data Sync characters.
for
interpreting data as
call for
two
until
it
if
characters until the next real character is ready to transmit. To illustrate this concept, consider an operator entering data at a keyboard; the keyboard transmits data using very slow, synchronous serial I/O. The operator has to key enter the message:
Good#morning)!$l\/lrj5Smith.
)6
be entering data
at variable
is
speed, keyboard
serial
data transmission
will
follows:
Go^o#d#6#mom2ing)&#M2r###Sm#ith
$ represents Sync characters.
When
in
it
will
ignore
will
remain
in
Assuming
that the
message
illustrated
above
is
being- transmitted
r
in
^
Sync Char 2
The
may be
illustrated as follows:
Sync
Char 3
1
Sync
Char 4 Char 5
1
Char
Char 3
101---
M
9
If
digit
bit
are illustrated.
ASCII characters only are being transmitted, 8-digit characters, including 7 data digits and a parity digit may be used.
some
all.
additional information
to consider the
link
must be present.
of
we need
needs
is
two-way communication.
the transmitting
If
a serial data
communication
to work,
SERIAL DATA
HANDSHAKING device must be able to transmit commands and receive responses in dialog with the receiving device; this is the BISYNC only way of insuring that the transmitting device is ready PROTOCOL for the transmitted data or to tell the transmitting device that it must stop transmitting and start receiving. Following the Sync characters that begin and end any data stream, therefore, there will usually be some well defined control
5-57
characters which
must be transmitted in both directions. This dialog is referred to as handshaking IBM 2770 Bisync protocol uses this handshaking sequence:
enquiry
character
to
determine
is
ready
to
Assuming
that
it
is
ready,
the
nifymg that
it
and
is
ready to receive.
The
transmitter
now sends
it
is
|starting|
followed by a character
and
following
know
if
transmission errors.
If
no
errors
lMMMr
S
-
S
*-~
transmitter sends
its
receiver
sends
[character!] this
one
block,
says.
"Yes.
received
your
OK.
checked
it,
ECC
ECC
Characters
sent tram
found
it
TDATATRR
X
and
now
have
text
T X
DATA TRR
received
an
odd-nu nber
of
BCC
XCC T
Transmute
blocks from you".
tllll
The
usualptart*
of-text| character,
[text.j lf this is
followed by the
block of data to
the
last
be
transmitted,
is
an |end-of-tex t|
by
cycli-
character
cal
sent, followed
redundancy|check characters'!
D
L
1
(Characters
sent from
Receiver)
Assuming
that the
it
receiver found
no
errors,
sends
back
an
"Your
last
I
block
was
received
OK
T.
Upon
receiving this response and
and now
number
of text blocks."
Recognizing
the
special
end-of-
5-58
DATA
will
chronous
X
ES
N
ECCS
DATA
T
B
R
FCCE
DATA
V
T X
T"" ~Y~"'
V
^^C' "Y""'
T X
T
Strictly
serial
synchronous
data
Mark
Serial Data:
own
is
in an asynchronous data stream must carry its synchronization information. An asynchronous data unit therefore "framed" by a single Start bit, and one, one and a
FRAMING
START
STOP
BIT
half, or
two Stop
bits:
BIT
single
asynchronous
serial
data unit
Stop bit(sU
Parity bit
Data
Framing
bits
bits
Start bit
Having a single
There
of
is
start bit
is
a similarity
between the synchronous data stream's SYNC characters and the framing
SYNC
bits
frame every
data character
7 or 8
may be
less than eight data bits are meaningful, the leftmost, high-order bits are
if
will
single
asynchronous
serial
data unit
x x x x x
T.
Stop
Data
bit(s)
Parity bit
bits
5-59
Thus a The
is
actually transmitted.
parity
parity
may be
PARITY
BIT
specified.
1's are
stop
bits;
always used
one stop
serial 8-bit
will
be two
bits,
STOP
BITS
bit is
then every
data
sometimes specified. If you have two stop word will contain twelve bits:
OxxxxxxxxPI
*T_
Stop
Data
bits
Parity bit
bits
Start bit
If
bit,
then every
serial 8-bit
data word
will
consist of eleven
bits.
start bit,
.1
seven data
bits,
a parity bit
--
for a total of
bits
TELETYPE SERIAL
10 Baud.
DATA FORMAT
bit
Some transmission
and one
half
width
is
one
width.
Consider even
unit.
This
is
how
asynchronous serial data using two stop bits, with 6 data bits in each data sequence of parallel data will be converted into a serial data stream:
IU
II
iu
(
|o
[o
(o
some form
synchronous serial data communications is occurring over telephone lines, then of handshaking protocol, as illustrated for synchronous telephone communications, is going to be required. In fact, there is nothing to prevent the identical
If
is
simply a
method
of transmitting informa-
via a single
telephone
line.
Notice that during asynchronous data transfer the receiving device has an
additional
means
The
first
binary digit
FRAMING ERROR
must be a representing the start bit; the last two binmust both be representing the stop bits. If the receiving device does not detect appropriate start and stop bits for any data unit in an asynchronous serial data stream, then it will report a framing error.
1
A SERIAL
Let us
I/O
COMMUNICATIONS DEVICE
SIZE
now
DUAL
First
IN-LINE
how
PACKAGE
some
of
all,
We
rationale
which leads us to a
have been using 40-pin DIPs indiscriminately for all of larger or smaller package
size, or are
we better off simply standardizing on the 40-pin DIP, pins remain unused?
5-60
even
if
half the
we would like to use DIPs with as few pins as and they use up more space on a printed circuit card. Using a 40-pin DIP, where a smaller one would do, can have a snowballing cost effect: Fewer DIPs on a PC card can mean more PC cards. More PC cards can mean a larger backplane, a bigger power supply and a more expensive enclosure.
The answer
is
that
all
more
to build
On
to insure that
makes no economic sense to have a bewildering variety of DIP sizes simply no DIP ever wastes a pin. For example, you are better off using a standard 40-pin DIP with two unused pins, rather than building an odd-ball 38-pin product.
the other hand,
it
this
For our serial I/O communications device we are going to select a 28-pin DIP since is one of the standard package sizes. We can get away with this smaller number of pins
serial
because our
LOGIC DISTRIBUTION
two
Our
Synchronous and asynchronous serial I/O logic is going to share a single chip. The sets of logic have enough in common for this to make a lot of sense.
serial
faces:
communications I/O device may be visualized as having three interfor the microcomputer CPU and one each external asynchronous and synchronous serial I/O. Each interface will, as usual, have data lines and control signals. For the serial I/O interface, control signals can be grouped into general controls and modem controls. General controls apply to any external logic, whereas modem controls meet the specific needs of industry standard modems which does not prevent you from using modem controls for other external logic if you can.
One
THE CPU
Since the
We
SERIAL
is
I/O
DEVICE INTERFACE
to synchronous and asynchronous I/O, this
is
CPU
interface
common
where
The
bus data
buffer:
we
will begin.
is
serial
I/O device
lines
going to communicate
in parallel
with the
pins,
DO
\
External
U2
System Bus
Data Lines
D3
CO
ro
w
CO
D4 D5 D6 D7
the
CPU
interface are
no
different
from those
we
included
in
the
operation
progress and
IORW
selects either a
IOSEL and IORW. IOSEL identifies an I/O 'read to' the CPU or a 'write from' the CPU.
5-61
Add
clock,
serial
like this:
DO
D1
1
External
D2
\
a
CD
._
System Bus
Data Lines
-*-H
D3
D4
.Q
CO
D5 D6
D7
SEL
*
*"
Vdd
Vss
Vtjg
<l>
RW
THE SERIAL I/O INTERFACE We are going to use separate pins to transmit and receive serial data. Some devices
use a
Since
single, bidirectional data pin.
we have separate transmit and receive data pins, we will also need to input separate transmit and receive clock signals. Both clock signals are input by external logic to control
is
Receive Clock:
Jl_rL_TL
\
\
DO
D1
l
Receive Data:
i
2
D2
External
il
< >\ (
1 J
[
D3
D4
D5
d /
en
D6
D7
IOSEL
*
*Vdd
Vss
1
IORW
)i
RD
RC
1
<
<
Receive
serial
data data
^ ^
'
Vgg
<t>
Receive clocks
serial
TD
TC
Transmit
"Transmit
clocks ._
^
\
\
J
Transmit Clock
_rL_n_rL
i
/ 'i y /
Transmit Data:
5-62
If
same
CLOCK
SIGNALS
serial
two
serial data
baud
I/O inter
Consider a synchronous data stream where every Receive Clock signal rising edge will strobe the Receive Data signal level, as a binary digit, into the Receive Data buffer Whenever the receive data buffer contains
SERIAL
DATA
INPUT
its
Bus
buffer. Here
is
an
illustration of serial
Serial
1
Data
(o
Data Clock
Receive
Serial
Interpretation:
RD -
5-63
buffer
is
now
over again.
trailing
edge
will
strobe out a
bit
from the
SERIAL
bits will
bit 7
be
has
output
in
bit 0. As soon as
DATA OUTPUT
to continue the serial
been output, the Transmit Data buffer will be considered empty, so the Data Bus buffer contents will be loaded into the Transmit Data buffer,
transmit process. Here
is
an
illustration of serial
data output:
V-,
DO*
'
Serial
'
J
Data Clock:
Transmit
Serial
Data
Interpretation:
*_
r
22 \
v^
DO
L\
no
^
Dl
\tt
JU*
Vgg
RD
"rc"
If
asynchronous
serial
data
were being
serial
or
32nd pulse
in
5-64
SERIAL
I/O
CONTROL SIGNALS
assembled data bytes and to Control logic and control signals which we are now going to describe determine which of the possible operations is occurring at any time. The serial I/O interface device will simply ignore the clock signal internal control logic has not been programmed to recognize Also, the Receive Data buffer contents will simply be lost the Data Bus buffer is not ready to receive an assembled byte.
transmit data bytes for disassembly
if
it.
if
Let us consider the control signals which must be present to support serial data being transmitted and received.
consider transmit logic; it will need two control SERIAL one to indicate that the Transmit Data buffer is TRANSMIT empty, the other to indicate that the Data buffer is ready to CONTROL receive another byte of data. We will call these two signals TE and SIGNALS TRDY. The two signals are not identical. For example, when serial data is being output synchronously, TE will be high while a SYNC character is being output; yet TRDY
First of
all,
signals,
will
be low
is
is
way
that
TE and TRDY
signals will be
Transmit
Serial
Data
DGEEX
U
SYNC
DATA
Tl TRDYTl
will call
L__
now
be read.
3CDC U IT U IT
SERIAL RECEIVE
Receive logic uses a single Receive Ready signal which we RRDY. This signal tells the CPU that a byte of data has been
CONTROL
SIGNALS
Frequently, the RRDY signal will be used to generate an interrupt request. The interrupt can be acknowledged by a very simple instruction sequence that moves the received data byte into an appropriate microcomputer system
read-write
memory
location.
is
When
serial
synchronous data
being received,
remember
that the
SYNC
must
SERIAL RECEIVE
know when
characters.
serial
SYNC
SYNCHRONIZATION CONTROL
We will therefore add a SYNC control signal, which will be output true as soon as the SYNC characters have been detected. Some serial I/O devices allow the SYNC control line to be bidirectional. In this case, rather than preceding synchronous data with SYNC characters, external logic can input the SYNC
control signal true; then the synchronous data:
Serial
serial
Data
In
SYNC,
nfM^-r^
First bit
Receive Clock.
of
first
byte
5-65
MODEM CONTROL
Only the
DSR
data.
SIGNALS
be described. There are these four
whenever
in-
modem
--
The
modem
it
is
ready to receive
The
signal
is
Any
ter-
minal could generate this signal. This allows the microcomputer system to test external logic
it.
DTR
it
--
is
the
serial
is
output by the
tell
is
cate.
Under program
it
control
this signal
high to inhibit
all
serial
low
to initiate serial
--
I/O operations.
t
Wh en
he
serial
I/O device
will
is
modem
device
4)
both be low.
Now
is
Remember
may be
CTS
(Clear
if
receiver;
full
duplex data
the
link,
RTS from
becomes CTS
at
the
of
must be a
modem
at the line
en d capable
receiving.
In
modem
receiving
millise-
conds
later.
The interaction of DSR, DTR, RTS and CTS may be gram flow chart:
Set
illustrated
DTR
low
Output RTS
5-66
This
is
how
now
looks:
Externa
^RTS
System Bus
Data Lines
OSR
-sync
J*-TRDY
K-
Receive
serial
dala
Transmit clock
I/O
INTERFACE DEVICE
Given the many options available when using the serial I/O interface device, we are going to need a Control Register in order to select options and in some cases to determine the conditions of control signals being output.
First
we must
select
synchronous or asynchronous
SERIAL
I/O
identifies the
trol
We
fundamental decisions we must make under program conwill refer to Table 5-1 variables as mode parameters,
MODE
of
any
serial
I/O operation.
FUNCTION
Clock frequency
ASYNCHRONOUS
Baud
rate x1.
SYNCHRONOUS
Usually baud rate x1
5,
x16 or x64
Data
Parity
bits
per byte
6,
7,
or 8
Stop
bits
Viz
or 2
Sync characters
2 or external
Sync
Mode
Parameters
Asynchronous I/O using a x1 clock is sometimes called isosynchronous I/O; equivalent to transmitting data using is
it
ISOSYN-
CHRONOUS
SERIAL SERIAL
I/O
bits) in
an otherwise
Within any selected set of mode parameters, the Serial I/O Interface device must still receive commands. Commands must
identify the direction of serial data flow (transmit or receive), or terminate
I/O
COMMANDS
mode
to
be modified.
to
Commands must
error conditions.
of,
the
control signals,
and respond
any
What
is
commands must
them?
take care
and
how
SERIAL
I/O
We
we
ERROR CONDITIONS
we
conditions.
can read a combination of eight input signal statuses and error must be able to read are: The input signals whose level
5-67
1)
DSR
CTS
for
2)
To Send. This
I/O interface
register; Serial
sometimes left out of the Status device logic must then automatically wait
signal
is
SERIAL INPUT
I/O
CONTROL
SIGNALS
CTS
3)
SYNC
TE
External synchronization.
4)
5) 6)
TRDY
RDY
Transmit Receive
and
CPU.
may be connected
to in-
terrupt logic
left
may be
in
reported:
a serial data unit.
bits
Parity error.
The wrong
parity
was detected
start
2)
Framing
Overrun
error. In error.
asynchronous mode,
were not
correctly detected.
3)
Bus
buffer,
lost.
Normally an error condition does not cause a Serial I/O Interface device to abort
operations. The
error
is
reported
in
Using commands,
1)
we
will react to
a
an error condition
in
In
NAK
source.
2) 3)
In
to
its
"break" signal
4)
To our
TRDY
Receive
serial
data
data
Transmit clock
I/O
INTERFACE DEVICE
of the serial I/O Interface device that we have not covered is how going to be selected, and how its buffers and registers are ad-
far as the CPU logic is concerned, the device consists of the Data Bus buffer, the Control register and a Status register.
So
The Receive Data and Transmit Data buffers lie passively in the path of received and transmitted communicate with the Data Bus buffer, therefore do not need additional
In reality
the Control and Status registers can be looked on as a single addressable unit, since you
into a Control register
register.
Thus,
we
is
which
register:
in
order to access a Serial I/O Interface device we only have two pins left. One pin (CS) will constitute
a chip select, while the other pin (RS) selects either the Data
/ 1 1
DO
D1
_^
1
External
1 D2
System Bus <
Lines
W
I
D3 D4
\ |co ^
1 D5
1
1
1
'cr
a
T
D6
D7
c
W
^
RD
TF
TRPY
Receive
serial
Vdd
Vss
o
<_>
^
w
data
"D
Vgg
*
Since
CO
RC
.
TD
TC -^
Transmit
serial dat.
Transmit clock
we
only have
two
some
order
CS and RS
select signals.
Use
this
of
as
we
indicated earlier
in
may be
Figure 5-18 we can now illustrate one way in which a serial I/O interface device integrated into our hypothetical microcomputer system.
REAL-TIME LOGIC
The concept of vious example
easy enough to understand. The most obtime of day by a microcomputer system that is driving an employee badge reader, and must therefore record the exact time when each employee enters and leaves his place of work.
real-time logic
is is
one that
is
the maintenance of
real
mrcrocomputer may
measures the
of revolutions
speed
of a
thousands
per minute.
microcomputer will have no difficulty keeping track of real time of day since the whole microcomputer system is driven by a clock signal. All that is needed is to add some logic which counts clock signals and generates an interrupt request after a specified num-
if
is
going to be used to
500 nanoseconds, then a one 2000 clock periods. Of measure real time of day, then a
is
required.
When
used
in
an application that
not time-sensitive, a
5-69
microcomputer may have a very inexpensive crystal generating its clock signal. Indeed, cases a resistor-capacitor network may be used in the place of a crystal:
in
.some
Some
of the
microcomputers described
in
Volume
II
When
to the
that
is
needed
is
some form
of pulse
number
of
tradeoff is power versus number of devices. At any given time semiconductor manufacturers can implement a certain number of gates worth of logic on one chip. What this logic should be is the chip designer's business. Nothing but tradition says that a Central Processing Unit and memory must be implemented on separate chips. There is no economic or scientific reason defining
The
chip/logic relationships.
What happens,
in reality,
is
is faced with an important tradeoff; presuming that technology has advanced to the point where he can now put 30% more logic on his chip than the last, time around, what is this extra 30% to be? Should the new CPU have a more powerful instruction set with a lot of minicomputer-like addressing modes, or should the instruction set remain the with the extra logic being devoted to read-write memory? Or how about using the exsame tra logic to put some parallel I/O on the CPU chip?
In reality
It
the
amount
of logic
a single chip
is
we are likely to see an equally rapid evolution in microcomputers, with a diverging trend At one end of the spectrum we have already reached the one-chip microcomputer, where a minimum representation of all the different logic devices described in this chapter have been crammed onto a single chip. At the other end,
is
for this
reason that
we
therefore, conclude this chapter with a caution: The segregation of logic on different devices, as described in this chapter, is nothing more than a very approx-
We,
imate guideline; and as time goes by, you will see more microcomputers merging logic onto a very few, or even one device.
5-70
ID
"D .C
Sl^imO:
,r-
<
<
I<<<<<<<<<
tou)wl
iiiiiiiiiiiJiiiiifT^C
(1)
T!
tl)
(/)
C_
>
C)
(I)
<
_) LL
5-71
CPU's Accumulator register or move data from the Accumulator to a memoword or output data via an I/O port.
To use
a microcomputer, therefore, you must first select the devices that will give you sufficient logic capability; then you must sequence the logic to meet your needs, by creating a sequence of instructions which, taken together, select chip logic capabilities that satisfy the needs of your application. The instruction sequence is a program, and programming is the creation of the instruction sequences.
THE CONCEPT OF
A PROGRAMMING LANGUAGE
The concept
microcomputer program was introduced instruction, binary addition program was described.
of a
in
Chapter 3, where a
five-
This chapter discusses the types of instructions which a real microcomputer system will need, and how programs are really written. In fact, a discussion of how programs are written must precede the discussion of instruction types, since we are going to use programming terminology in order to describe instructions.
There
is nothing to prevent you from creating a computer program as a sequence of binary instruction codes, just as they will appear in memory, or in the Instruction register. The addition program described in Chapter 4 can be written out in binary or hexadecimal digits as
follows:
Program As
10011100 00001010 00110000 01000000 10011100 00001010 00110001 10000000 01100000
Hexadecimal
Version of Program 9C
Binary Matrix
0A
30 40 9C
0A
31
80 60
Were you
is
to generate your
chances of misplacing a
unfortunate since
is
it
or a
microcomputer program directly as a sequence of binary digits, the are very high; and the chances of spotting the error are low. This 1
for a
is
not
enough
program
to
it
is
absolutely
accurate, there
an inopportune
moment, with disastrous consequences. is this inherent necessity for perfection that causes programmers to grasp at any device which makes errors harder to create and easier to spot.
a sequence of binary digits, the first and to code the program using hexadecimal
6-1
digits,
binary equivalent.
Writing the program
in
hexadecimal
digits
is
one hexadecimal
digit for
On
down
wrong, programming
of errors,
generate
of digits.
in
hexadecimal
digits also
makes
digit,
wrong
or
mesmerizing binary pattern. The binary and hexadecimal programs are reproduced below,
error.
See
how
long
it
Program As
10011100 00001010 00110000 01000000 10011100 00001010 00011001 10000000 01100000
In
Hexadecimal
Version of Program
Binary Matrix
9C
0A
30 40 9C
A0
31
80 60
the end, however, the program must be converted into a binary sequence, because
is
that
how
in
it
is
going to be stored
in
memory
and
that
is
how each
instruction
must be
repre-
sented
SOURCE PROGRAMS
teletype, or any other terminal with the appropriate keyboard, generates ASCII character codes in response to keystrokes; therefore, let us assume that a program written in hexadecimal digits will initially be generated as a sequence of ASCII character codes.
Hexadecimal
digits are
letters
through
F.
The
Hexadecimal
Digit
ASCII
Code
00110000 00110001 00110010 00110011 00110100 00110101 00110110 00110111 00111000 00111001 01000001 01000010 01000011 01000100 01000101 01000110
of paper, using hexa source program.
2 3
4
5 6
7
8
9
A
B
D
E F
as illustrated
in
is
9C
OA
30 40
9C
OA
31
80 60
Figure 6-1.
On Paper
This source program must be converted into a form that can be loaded into and executed. One way of doing this uses paper tape.
memory
PAPER has eight "channels", representing the eight binary digits of a byte. A hole punched in any channel represents a 1, TAPE while the absence of a hole represents a 0. Ten bytes are represented by one inch of paper tape. In other words, every 0.1" of paper tape represents one byte, as follows:
A paper tape
One
Usually a line of sprocket holes appears
to a toothed
Byte
3;
wheel
to
OBJECT PROGRAMS
Our goal is to convert the source program, illustrated in Figure 6-1, into a paper tape, as illustrated in Figure 6-2. The paper tape in Figure 6-2 is an exact representation of the binary instruction codes that will be stored in memory; digits are represented by holes, and
1
digits are
The program
is
called
Binary Equivalent
Figure 6-2.
An
Object Program
On Paper Tape
6-3
the hexadecimal digits illustrated in Figure 6-1 are entered at a keyboard. We it is a teletype keyboard. Each digit becomes an ASCII code on paper tape, as illustrated in Figure 6-3.
will
assume
Source Program
As Written on Paper
9C
OA
30
40
9C
OA
31
80 60
CD
CD
CD_CD_CD_C_D_cp_CD_
M U ^
Figure 6-3.
Ol
si
You could create the paper tape illustrated in Figure 6-3 by simply turning a teletype punch on, then depressing appropriate
keys at the keyboard.
EDITORS
a little more fancy by attaching the teletype to a computer, which executes a program to read keyboard data and punch paper tape. This program is called an EDITOR.
Using an Editor program to create source programs is a good idea. For example, the Editor program could be written to ignore any key that is not a valid hexadecimal digit (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F). Since a teletype can read as well as punch paper tapes, the Editor can read
old source
let
you make corrections, then punch out the corrected version you would otherwise spend rekeying the error-free
Having tised an Editor to create a source program on paper tape, as illustrated in Figure 6-3, you will execute another program which automatically reads the source program and creates an object program equivalent; for the moment we will refer to
this as a
CONVERTER
program.
6-4
program
is
quite simple
and
is
Combine
the rightmost (low order) four bits of every pair of source program bytes into one
Channels
1,
Channels 4 through
3)
If
Channels
bits
and use
Channels 4 through
as follows:
7.
These three
logic steps
may be
illustrated
Source Program
40
0A
=A
directly into
II
tape, as created
memory to be executed. Chapter 20 of "An Introduction To Microcomputers: Volume Some Real Products" describes how this is done for microcomputer systems.
in
to
medium
for creating
Usually a magnetic used to store source and object programs (or any
will
ASSEMBLY LANGUAGE
Why are
hexadecimal
digits digits
more
efficient
medium? Because
hexadecimal
make
the programmer's job easier, leaving the hard job to the computer.
by making
is
and easier
to spot
is
program
by
will
execute
in
seconds, or
(at
digits,
language which
grammer to comprehend.
The programming language source will be very unlike a binary digit object program, so the Converter program, which converts the programming language source program into a binary object program, becomes more complex; but that remains an insignificant penalty.
6-5
What
rors
a programming language tries to do is eliminate syntactical programming erdigit, the wrong instruction code leaving only logic errors, specific to the application, as the programmer's responsibility.
the misplaced
is
Assembly language
by the
the
first
human programmer.
or
microcomputer consists
of a set of instrucline
line of
may be
Mnemonic
LIM
Operand
DC0.ADDR1
H'OF'
Comment
LOAD THE SOURCE ADDRESS INTO DC LOAD DATA WORD INTO ACCUMULATOR MASK OFF HIGH ORDER FOUR BITS JUMP OUT IF RESULT ISO STORE MASKED DATA INCREMENT THE DATA COUNTER
RETURN FOR NEXT BYTE NEXT INSTRUCTION
HERE
LMA
AIA BZ
OUT
DCO HERE
SRA
INC
JMP OUT
MNEMONIC
FIELD
Consider
Label
first
the mnemonic
field,
follows:
Mnemonic
LIM
Operand
DCQ.ADDR1
H'OF'
Comment
LOAD THE SOURCE ADDRESS INTO DC LOAD DATA WORD INTO ACCUMULATOR MASK OFF HIGH ORDER FOUR BITS JUMP OUT IF RESULT ISO STORE MASKED DATA INCREMENT THE DATA COUNTER
RETURN FOR NEXT BYTE NEXT INSTRUCTION
HERE
LMA
ill
mm
OUT
The.
only
OUT
DCO
HERE
field is the most important field in an assembly language instruction, and is the This field contains a group of letters which constitute which must have something in a code identifying the source program instruction. field
it.
mnemonic
ASSEMBLER The converter program used to convert assembly language source programs into binary object programs is called an ASSEMBLER. The Assembler reads the mnemonic field, as a group of ASCII characters, and substitutes the instruction ary code in order to generate an object program.
Consider the instruction specified by the
bin-
mnemonic SRA.
Chapter
4,
same where is
it
shown
using the instruction code 60 16 The Assembler must therefore have logic which gener.
in
the
mnemonic
field of a
source program
Binary form of
Binary form of
Source
ASCII
mnemonic
Program
S R
seen by Assembler
by Assembler
Assembler
logic
00110000
6-6
Note carefully that only the binary instruction codes of a microcomputer, that is, the object code, are sacred and unalterable. The source program mnemonics are arbitrarily selected and can be changed at any time simply by rewriting the Assembler to recognize the new source program mnemonic.
Every microcomputer's programming manual
will
is
define
instructions
using
is
source program
mnemonics. The
the fact that only
mnemonics
different
demonstrated by
to
rare
cases
will
two
identify instruction
mnemonics
can
become
a very
set of instruction
emotional issue. Many Intel 8080 users, for example, have created their own mnemonics and have gone to the trouble of writing their own Assemblers to
recognize their
new mnemonics.
mnemonic
is
to represent the
same
instruction.
We
have
.
just
shown how
.
the
mnemonic SRA
60 16 Another Assembler could be written to convert the mnemonic XYZ to the object program instruction code 60 16 A third Assembler could be written to convert either SRA or XYZ to 60 16
.
in
this
real
The mnemonics LIM, LMA, AIA, BZ, SRA, INC and JMP come from the hypothetical microcomputer instruction set which is created in Chapter 7.
Next
Label
we
is
highlighted as follows:
Mnemonic
LIM
Operand
DC0.ADDR1
H'OF'
Comment
LOAD THE SOURCE ADDRESS INTO DC LOAD DATA WORD INTO ACCUMULATOR MASK OFF HIGH ORDER FOUR BITS JUMP OUT IF RESULT ISO STORE MASKED DATA INCREMENT THE DATA COUNTER
RETURN FOR NEXT BYTE NEXT INSTRUCTION
it. If
HERE
LMA
AIA BZ
OUT
DCO
HERE
SRA
INC
JMP
OUT
The
label field
field,
may
it
or
the label
is
may not have anything in there is anything in means of addressing the instruction. In other words,
its
LABEL
FIELD
you do not
identify
an instruction by
location
in
program memory
(as
we
in
did
in
Chapter
4),
because
at the
may
not
know where
memory
the instruction
label.
HERE must be
identified,
because
later
on
an
instruction
which
specifies a
change
of execution
sequence. The
instruction:
HERE
specifies that the instruction labeled
instruction:
it
HERE
is
is
Jump
may be used
to illustrate
what
means by drawing
Mnemonic
I
Operand
DC0.ADDR1
H'OF'
Comment
LOAD THE SOURCE ADDRESS INTO DC LOAD DATA WORD INTO ACCUMULATOR MASK OFF HIGH ORDER FOUR BITS JUMP OUT IF RESULT ISO STORE MASKED DATA INCREMENT THE DATA COUNTER
RETURN FOR NEXT BYTE NEXT INSTRUCTION
LIM
HERE-
-LMA
Al^ BZ
OUT
DCO HERE
SRA
INC
JMP
OUT
6-7
The Assembler is going to have to keep track of where because the Assembler is going to have to replace every
in
memory
label with
an actual
memory
is
address.
Suppose the object program form of the above assembly language source program occupy memory words as follows:
Object
going to
Program
Memory
Locations
03FF.0400. 0401
Label
Mnemonic
LIM
Operand
DC0.ADDR1
H'OF'
Comment
LOAD THE SOURCE ADDRESS INTO DC LOAD DATA WORD INTO ACCUMULATOR MASK OFF HIGH ORDER FOUR BITS JUMP OUT IF RESULT ISO STORE MASKED DATA INCREMENT THE DATA COUNTER
RETURN FOR NEXT BYTE NEXT INSTRUCTION
.
HERE
LMA
AIA
BZ
OUT
DC0 HERE
SRA
INC
JMP
OUT
will
0402
to
binary instruction
value
0402 16
code for the JMP instruction happens to be BC, 6 the label HERE has the then the Assembler will convert the source program instruction:
If
JMP
to the three object
HERE
program bytes:
BC
04
02
If
code
for:
HERE
LMA
^
now
occupied
program memory byte with address 0C7A 16 then the Assembler would convert:
JMP
to the three object
HERE
program bytes:
BC 0C 7A
The Operand
Label
field
may be
highlighted as follows:
OPERAND
FIELD
Mnemonic
LIM
Operand
QC&,ADDR1
H'OP-
Comment
LOAD THE SOURCE ADDRESS INTO DC LOAD DATA WORD INTO ACCUMULATOR MASK OFF HIGH ORDER FOUR BITS JUMP OUT IF RESULT ISO STORE MASKED DATA INCREMENT THE DATA COUNTER
RETURN FOR NEXT BYTE NEXT INSTRUCTION
HERE
LMA
AIA BZ
Oti?
SRA
INC
JMP
wmm
DCO
OUT
6-8
H'OF'
in
operand
field
will
use to
create the second byte or second and third bytes of an instruction that requires
byte of object program code. For example, suppose the source program instruction:
LIM
DC0.ADDR1
illustrated in
is
instruction
program
Chapter
3.
The Assembler
will interpret
Address
of
Memory Word
0400
0401
Memory Word
9C
0A
30
LIM
DCOADDR1
Instruction
0403 0403
There
is
40
that the
no
rule
which says
operand must specify or can only specify second and third The Intel 8080 microcomputer, for example, has seven ac-
cumulator-type registers and a single instruction which moves data from one register to another.
This source program instruction
is
written as follows:
MOV
where
and
But the
D.S
D
S
MOV
7
byte:
10
-Bit
No.
|6|1|D|D|D|S|S|S|
These three
These three
bits identify
H
the
These two
bits identify
the instruction as a
MOV
instruction.
Now
we
are illustrating
in this
chapter.
DC0.ADDR1
DC0 identifies the Data Counter into which immediate data must be loaded. ADDR1 is a label representing the address which must be loaded into the Data Counter. The Assembler will convert ADDR1 into a 6 -bit binary data value.
1
H'OF'
specifies
immediate,
for
The
instruction
AND
mnemonic and
has the effect of
is in
the Accumulator to be
ANDed
field. In this
operand
field is
0F, 6
it
OUT
and
appearing
instruction:
in
operand
with labels
OUT and
HERE. The
HERE
BZ
OUT
;JUMP OUT
IF
RESULT
IS
ZERO
specifies that
if
AND
Immedinor-
must be the
instruction
SRA
The
would
HERE
states that the next instruction to
tion
with the label HERE, not the instruction with label OUT, which, following se-
quentially,
DCO
to
be incremented.
The comment field contains information which makes the program easier to read but has no effect on the binary object program created by the Assembler. In other words, the Assembler ignores the comment field.
is the Assembler going to tell where one field ends and the next begins? Usually space codes are used to separate fields, and the Assembler uses these rules:
1)
COMMENT
FIELD
How
FIELD
IDENTIFICATION
All
first
first
label
field.
If
the
first
character
is
label field
is
presumed
to
be empty.
2) 3)
Contiguous space codes are treated as though they were one space code.
All
characters
between the
first
(or
in-
terpreted as the
4)
If
mnemonic
field.
the
the mnemonic does require an operand, then the Assembler assumes that all characters between the second and third space codes (or contiguous space codes) constitute the
operand
6)
field.
Sometimes comment
for this purpose.
fields are
We
Space code
Label
field delimiters
may be
Operand
illustrated,
rules,
as follows:
Mnemonic
:
Comment
LOAD THE SOURCE ADDRESS INTO DC LOAD DATA WORD INTO ACCUMULATOR MASK OFF HIGH ORDER FOUR BITS JUMP OUT IF RESULT IS STORE MASKED DATA INCREMENT THE DATA COUNTER
RETURN FOR NEXT BYTE NEXT INSTRUCTION
LIM
>'DC0.ADDR1.
HERE.
:: :
LMA-: AlA
::
BZ
: :
H-OFvXv OUT
:::-.
SRA
INC
::
:::
DCO
herf
:::
JMP-:
:::
:::
OUT
6-10
ASSEMBLER DIRECTIVES
An assembly language
illustrate
we
in
assembly language
cannot be assembled as
told
it
stands.
To
give fixed,
bi-
OUT
where
eventually reside.
There
is
Assembler
Directives,
itself.
which you
will
use to provide
cannot deduce
in
for
explaining
how
the labels
OUT
and HERE
the operand
field
would
be interpreted by the Assembler, we illustrated the program sequence occupying program memory locations beginning at 03FF. You would
specify this origin to the
ORIGIN DIRECTIVE
directive as follows:
Label
Mnemonic
Operand
H'G3FF'
Comment
LOAD THE SOURCE ADDRESS INTO DC LOAD DATA WORD INTO ACCUMULATOR MASK OFF HIGH ORDER FOUR BITS JUMP OUT IF RESULT ISO STORE MASKED DATA INCREMENT THE DATA COUNTER
RETURN FOR NEXT BYTE NEXT INSTRUCTION
Its
ORG
Lirvi
'DC0.ADDR1
H'OF'
HERE
LMA
AIA BZ
OUT
DCO HERE
SRA
INC
JMP OUT
The
the
origin
sole purpose
in
the program
is
to
tell
be located
that
in
how
to
memory addresses
must be substituted
END is the only assembler directive that is absolutely mandatory. DIRECTIVE Another assembler directive that is always present, because it makes the job of creating an Assembler easier, is the END directive. This is the last instruction in a program and tells the Assembler that there are no more executable instructions.
The END assembler
Label
directive
may be
illustrated
as follows:
Mnemonic
ORG
LIM
Operand
H'03FF'
Comment
LOAD THE SOURCE ADDRESS INTO DC LOAD DATA WORD INTO ACCUMULATOR MASK OFF HIGH ORDER FOUR BITS JUMP OUT IF RESULT IS STORE MASKED DATA INCREMENT THE DATA COUNTER
RETURN FOR NEXT BYTE
DC0.ADDR1
H'OF'
HERE
LMA
AIA
BZ
OUT
DCO HERE
SRA
INC
JMP END
The Equate assembler directive is one more that is universally present because it makes assembly language programming much easier. You use the Equate assembler directive to assign a value to a symbol or a label.
Consider the instruction.
AIA
H'OF'
EQUATE
DIRECTIVE
BITS
6-11
symbol which
is
is
il-
Label
Mnemonic
:
Operand
Comment
VALU
ORG
LIM
Mm H03FF'
DCO.ADDR
HERE
LMA
AIA BZ
VALUE OUT
DCO
HERE
SRA
INC
LOAD THE SOURCE ADDRESS INTO DC LOAD DATA WORD INTO ACCUMULATOR MASK OFF HIGH ORDER FOUR BITS JUMP OUT IF RESULT IS STORE MASKED DATA INCREMENT THE DATA COUNTER
RETURN FOR NEXT BYTE NEXT INSTRUCTION
be used to assign a value to the address labeled ADDR1 did not exist as an instruction label some-
JMP
OUT
An Equate assembler
ADDR1. However, you would only do where else within the program.
There are two mnemonics that appear
Constant and Define Address.
if
in
DEFINE
These
CONSTANT
DEFINE
The Define Constant mnemonic is used to specify a single byte of actual data. The Define Address mnemonic is used to specify two bytes of actual data. Here is an example of how these two mnemonics would be used. The instruction sequence:
ADDRESS
ADDR1 VALUE
would cause the Assembler
ORG DC DA DC
H'0700' H'3A'
K27AC
H'OF'
memory map:
0700
0701
3A
27
0702
AC
OF
MEMORY ADDRESSING
addressing has already been introduced in Chapter 4, where some discussion of the subject was needed in order to define the registers which a CPU will require. We are now going to cover the subject of memory addressing thoroughly as a precursor to defining a microcomputer's instruction set.
Memory
perspective.
6-12
The forerunner of all microcomputer instruction sets is the instruction set of the 8008 microcomputer and the Datapoint 2200 minicomputer. These two devices
the
Intel
have
same
2200 executes
Mr. Vic Poor (and associates) at Datapoint developed this instruction set for the limited data processing environment of "intelligent terminals." Discrete logic replacement was not what they had in mind. Vic Poor's instruction set was deliberately limited, to accommodate the confines of
fast.
large scale integration (LSI) technology as it stood in 1969-1970. The instruction set's ory addressing capabilities were primitive out of necessity, not desire.
Intel,
mem-
who
initially
market
for the
product
developed the 8008 microcomputer at Datapoint's reguest. found a significant in discrete logic replacement a market for which the instruction set was
never intended.
result of
two competin
Microcomputer designers incorporated minicomputer features as fast as advances technology would allow while there was no definable microcomputer user base.
LSI
b)
Now that a definable microcomputer user base designers are responding directly to users' needs.
is
Influences (a) and (b). above, do indeed differ. Microcomputer users' needs are not always well suited by minicomputer instruction sets, a fact to which we will continuously return in this chapter.
IMPLIED
An
MEMORY ADDRESSING
in detail in
instruction that uses implied memory addressing specifies the contents of a Data Counter as the memory address.
Implied
memory
this
Chapter
4; therefore,
we
will
simplyx
summarize
addressing mode.
memory
is
a two-step process:
First,
the required
memory
Next, a single-byte
tains the
address
first
Consider the
two
in
this
two
instructions
may be
illustrated
as follows:
Program
Memory
6-13
first
instruction (LIM
DC0.ADDR1) occupies
three program
memory
bytes,
memory
arbitrarily selected.
067A
DC0.ADDR1
instruc-
mnemonic. This
in
bytes are to be loaded, as a 16-bit value, into Data Counter DCO. Recall that the actual binary
code appearing
will
The second
memory
instruction, with mnemonic LMA, specifies that the contents of the location which is addressed by Data Counter DCO is to be loaded into the
Accumulator. We call this IMPLIED memory addressing, because the memory reference instruction, in this case LMA, does not specify a memory address; rather, it stipulates that the memory location whose address is implied by Data Counter DCO is the memory location to be referenced.
DIRECT
Simple direct
addressing.
In
MEMORY ADDRESSING
directly specifies the address of the
in
memory
we
are using
chapter, the
LIM and
LMA
instructions could
be combined
into
one
direct
memory
Program
Memory
Address Register
067A
067B
43
2F
Accumulator
067C
3C
067D
067E
067F
2F3A
2F3B
2F3C
4A
2F3D
An Address
same
it
does so
transiently.
direct
memory
memory
This
becomes
memory
location to be
mode used
by minicomputers. Implied
memory
ad-
dressing
is
a microcomputer
phenomenon.
register
is
referred to as a
Address
register or
register's contents.
in
The process
of
memory
reference instruction.
6-14
in a
microcomputer
is
programmable.
into the
In fact,
every microcomputer
will
have a number of instructions that simply load data Counter contents, but do nothing else.
Some microcomputers provide both implied and direct memory addressing. These microcomputers have one or more Data Counters for implied memory addressing, plus an additional Address register for direct memory addressing.
The
first
into the
CPU
microcomputers used implied memory addressing only, because it was simple to design Control Unit; there was no other reason. The penalty incurred by the use of implied
addressing
is
do what one direct memory addressing inwhere microcomputer designers could do away with implied memory addressing, but they have not done so. Today most microcomputers include a limited number of instructions with direct memory addressing, but implied memory addressing remains the standard; why? Because some necessary variations of direct
that
it
memory
takes
two
instructions to
advanced
to the point
memory ROM.
when programs
are stored
in
VARIATIONS OF DIRECT
MEMORY ADDRESSING
We
A
will first consider variations of direct memory addressing as they apply to minicomputers with 12-bit and 16-bit words. This is a good beginning, since direct memory addressing variations evolved as minicomputer memory addressing features.
16-bit
word allows a minicomputer to have 65,536 different instructions in its instruction set. A word allows a minicomputer to have 4096 different instructions in its instruction set. These are ridiculously high numbers. Minicomputers therefore separate instruction words into instruction code bits and address bits.
12-bit
Consider first a minicomputer with a 12-bit word. Digital Equipment Corporation's PDP-8, the world's first popular minicomputer, uses a 12-bit word. The PDP-8 CPU is now manufactured by Intersil on a single chip, called the IM6100. The 12-bit word may be used as follows:
o o o o x x|x x|x x x|x|
i
12-BIT
WORD
DIRECT
ADDRESSING
PDP-8
INTERSIL
r-
*
Address
bits (2
8
256 10
IM6100
Instruction
code
bits
Eight address bits allow this instruction to directly address up to 256 memory words; 256 words constitutes a very small memory, so we will have to seek ways of expanding our memory addressing range, without using more addressing bits.
Will four instruction
tion of
code
is
twelve
the above separacode bits and eight address bits only applies to memory how the PDP-8 and IM6100 interpret memory reference instruc-
bits
III
J
'
^-1
Ixlxlxlxlxlxlxlxl
Address
Indirect
bits,
if
memory
reference instruction
we
will
if
describe
later)
Only a
memory
reference instruction
these three
(for
bits
memory
non-
reference
instructions);
110 and
111
specify
memory
reference instructions
6-15
These 9
bits
allow 5 1 2 non-
memory
reference
instructions, for
instruction
a total of
These 3
specify a
instruction
code
if
bits
non-memory
they
10 or
1 1
reference instruction,
contain
1
1.
16-bit
bits of
an instruc-
tion word:
m. Q|o|x|x|x|x|x|x|x|x|x|x|xTx]
T
The
Address
bits (2
12
= 4096 10
bits
>
Instruction
code
16-bit computer could offer more instruction code options, and a smaller addressing range, as follows:
loioiolololololo X|X|X|X|X|X|X|X|
i
8 address
bits (2
256)
8 instruction code
bits
Most minicomputers divide their single word instructions into eight address bits and eight instruction code bits, as illustrated above. An 8-bit microcomputer can easily
achieve the
same
result,
using
two
8 instruction code
X X X X X X X X
8 address bits
(2
8
256)
instruction:
2-bit
X X X X X X X X X X X X
>
.~>
12 address bits"
(2
12
= 4096 10
6-16
Although two
12-bit
words per
instruction
is
very feasible,
all
PDP-8
word
If
instructions.
a 16-bit of
words
instruction,
it
nstruction
code
bits
X X X X X X X X X X X X X X X X
16 address bits
(2' 6
65.536,
The microcomputer programming examples we have used earlier 16-bit memory addresses via three 8-hit wnrH f n ii<-.,o-
in this
book specify
8 instruction code
bits
2 3
X X X X X X X X X X X X X X X X
16 address
bits
clear that
one way or another, instructions can have anybits. What is the optimum number?
ADDRESS
BITS
minicomputer applications, statistically we find the 80% to 90% of Branch instructions only need an addressing range 128 words (addressable with eight address bits):
THE
Jump and
OPTIMUM NUMBER
XXXX -
128
Instruction
here, at
Most frequently
y addressed
Address
XXXX
127
Memory Words
XXXX +
instruction
word format,
including
two
Format
(limited
|o|o|oio|o|ofo|ojx|x|x|x|x|x[xTx|
.
addressing
range)
8 Address
bits
8 Instruction code
bits
Format 2
(limited
|o|Q|o|o[x|xlxixix|x|x|xlxix]x|x]
addressing
range)
2 Address bits
4 Instruction code
bits
Format 3
(extended
addressing
range)
16 Instruction code
bits
x X X X X X X X X X X X X X X X
16 Address
bits
6-17
'
SHORT FORM
any word
instruction.
LONG
FORM
in
memory.
To
illustrate
is
paging, consider a
12-bit
into
Memory
effectively
segmented
bits
'
per instruction.
Hex
Memory
Address
Page Count
_0000 _0100 16
0300
_0200, 6
1R
.0900, 6
Page 10
.OAOOir
Etc.
bits of
digits of a
memory
address; the
digits are
the instruction:
would be coded
|1|0
i
f
in
JMP
H'3C
one
3C 16
(H'
'(specifies a
hexadecimal value
between quotes.
Jump,
direct instruction.
in
memory
computed using
address
word.
6-18
Suppose the jump instruction is stored in a memory word with the ad0709 ie After the jump instruction has been fetched from memory, the Program Counter will contain the value 070A The effective
dress
.
EFFECTIVE
MEMORY
ADDRESS
16
is given by the two high order digits of the Program Counter, plus the two low order digits from the instruction, as follows:
memory
address, therefore,
2-Bit
Program Counter
1
|o|i|iniololo|oli|o|o|i|
|o|
lololol
ilol oi
Effective Address:
073C
digits, taken from the Program Counter, are PAGE page number. The low order digits, supplied by the inNUMBER struction code, are the address within the page. Combining the two portions of the address yields the effective memory address. The term "effective memory address" applies to any memory address that must be computed in some way using information provided by the instruction.
As
illustrated
JMP
will
H'3C
Program Counter, so the next
instruction will
into the
fetched from
memory
be
location
073C 16
Memory
(12
bit
Memory
Address
words)
Instruction Register
Program Counter
e specified by
gits of
two
high order
Program Counter
as follows:
This illustration
is
keysQ, and,
6-19
(T)
The Program Counter addresses memory word 0709 16 The contents of this memory word, A3C 16 is fetched and stored in the Instruction register. The Program Counter is incremented
.
to
070A 16
thus,
it
memory word.
(2)
The
instruction
code
is
(3C 16 are
)
.
moved
digits of the
Program
Counter, which
now
contains 073C, 6
The next
instruction will
LMA
H'6C
located on Page 2F 16 would cause the contents of memory location 2F6C 16 to be loaded into the Accumulator. The same instruction on Page 1C 16 would cause the contents of memory location
1C6C 16
to
be loaded
into the
Accumulator.
With many paged computers a devious error occurs at the page boundaries. Recall that the Program Counter is incremented
an instruction has been fetched. Therefore the page number is acquired from the high order digits of the Program Counter, AFTER the
after
PAGE
BOUNDARY
ERROR
instruction:
LMA
H'6C
this instruction
were located at a memory word with address 2FFF 16 After Program Counter will contain 3000, 6 Now the contents 306C 16 would be loaded into the Accumulator, instead 2F6C, 6
. . .
of the
of the
restriction
is
instruction
cannot
memory word
instruction
page boundary:
Page 06
noperable
memory
a
Page 07
<
Page 08
Paging is wasteful of computer memory, because it requires programs to access data on, or via addresses stored on the program's page. Thus numbers used com monly by programs on many different pages must be stored repeatedly on each page, or else we must add some new flexibility to paged addressing.
all
6-20
Also,
when
fills
exactly
writing program modules and subroutines, is difficult to contrive that every module one page. As a result, a small portion of memory at the end of each page is wasted,
it
since it is too small to accommodate even the smallest subroutine. Thus a programmer must frequently waste a lot of time juggling the sizes and memory locations of his program modules and subroutines.
Program
Size (words)
MAIN
SUB1 SUB2
88 16
22 16 78 ;6
52 16
38 16
50, 6
66 16
as follows:
We
can
map
memory
Program
Memory
0300,6 0388, 6 0400,6 0452,6
-
Location
0387,6 03FF, 6 0451,6 0489,6 04FF, 6 0565, 6 0585,6
MAIN
SUB2 SUB3 SUB4 SUB5 SUB6 SUB1
But beware of an error
tions, say).
will
0490 !6
0500,6 0566,6
in subroutine SUB3 that requires you to increase its size (by two instrucSubroutines SUB3. SUB4. and SUB5 no longer fit on one page, and correcting SUB3
require
in
memory.
One method
This
is
some
of the restrictions
imposed by
paged addressing
option, the
BASE PAGE
what the PDP-8 does, so let us look at this specific case. In order to give itself one more PDP-8 uses just seven of the eight address bits to compute addresses within a pagein other words, the PDP-8 page is not 256 words long, is 128 words long. However, the eighth bit allows you to address either the current page, that is, the page on which the instruction is located, or you can address the base page, that is. one of the first 128 words of
it
memory
This
is
illustrated
as follows:
|p|p|p|p|p|p|p|p|p|p|p|p|
|o|o|o|o|d1x|x|x|x|x|x|x|
Effective
address,
memory D =
1
Effective
memory
address,
D =
|010|0|0|Q|X|X|X|X|X|X|X|
6-2
In
the
above
illustration,
bits of
computed by this bit is 0. then the effective memory address is the page select bit. in the five moving the X bits into the low order bits of an Address register and inserting 0's to 127 from order bits of the Address register; in other words, memory locations high may be addressed. This is referred to as the base page of memory. the D bit is 1. then
If
high order bits of the the five high order bits of the Address register are taken from the five which the instrucProgram Counter; only memory locations within the 128 word page in
tion resides
may be
referenced.
A more flexible
ing,
in
an instruction repreadded to the Program sent a signed binary displacement, which must be
which
it
is
PROGRAM RELATIVE
bits of
pag-
PROGRAM
RELATIVE
PAGING
Counter contents.
program
relative
page may be
illustrated
as fellows:
Instruction
Range
-
of
Memory
Address B
Directly
Addressable
Range
Directly
of
Memory
Instruction
by Instruction B
Addressable
-Address
by Instruction A.
in a forward Program relative addressing allows an instruction to address memory each direction of half a (positive) or backward (negative) direction with a range in
word:
8 Address
,
bits
bits
8 Instruction code
is
Assume that the high order address bit is a sign bit; 24AE 16 and .the eight address bits contain 7A 16 then
. .
if
the instruction
the effective
1
24AE _ 7A
2528
bits
Sign
bit is
6-22
memory
addressing
may be
illustrated
Memory
Address
Object
Code
24AD
BC7A
JMP
HERE
2528
In
HERE
LMA
THERE
the above
is
illustration,
LMA
instruction's object
code
dress
bits of
the
JMP
instruction
The Assembler will compute the adby subtracting the value in the Program Counter, after the JMP
out.)
instruction has
label
HERE:
HERE
is
equivalent to
2528
PC
= 24AE = 007A
instruction
is illegal,
If
the Assembler
will
computes
JMP
and an
error
message
be transmitted
to the errant
instructions
were
reversed;
we would now
have:
Memory
Address
Object
Code
24AD
HERE
LMA
THERE
2528
BC84
bits of the
JMP
HERE
in
The Assembler
the value
in
will
compute address
JMP
instruction
the
same way, by
subtracting
JMP
instruction has
HERE:
Label
HERE
is
equivalent to
24AD
PC contents
Difference
= 2529 = 7C
-7C
is
stored
in its
7C
ones complement
= 111110 = 10
1
twos complement
10000100=
JMP
instruction
is
84
follows:
The
effective
memory
computed as
2529 FF84
24AD
bits.
DIRECT
IN
MEMORY ADDRESSING
MICROCOMPUTERS
Variations of direct addressing which are useful in minicomputer applications are not useful, and are frequently not even viable, in microcomputer applications. Let us carefully examine why this is the case.
Consider
first
a three-byte, direct
memory reference
instruction,
EXTENDED
DIRECT
which
we
ADDRESSING
Instruction
Two
16-bit address
will certainly
memory
location to
otherwise manipulate data, or to change program execution sequence by executing a jump or branch instruction. There are, however, two
tions: first, the
be addressed
problems associated with the use of three-byte, direct memory reference instructwo address bytes cannot be changed; second, three-byte instruc-
memory.
Here
is
another buffer:
buffer
starting address
Load
buffer length
first
Accumulator
YES
the above program logic sequence would be executed by a microcomputer that has two Data Counters (DCO and DC1) and two Accumulators, (AO and A1). Assume that Buffer 1 begins at memory location 0470 , Buffer 16 2 begins at memory location 08C0 16 , and each buffer is eight bytes long. Illustrating CPU Data register contents, this is what happens:
Consider
how
6-24
< <
000Q00
O O
*3"
oooooooo
^T
OOOOOOOO oooooooo
cocococococococo
O O u
CO
K s
c_>
< o o -
^
I
o ^ O
u o
o r
u u o - _ ~ U U Q Q u u <
-
^
CO
^ S S Q
CD
00000
oooooooo
OOOOOOOO oooooooo
r- 5 o
o o o
o o & o
6-25
0000
o o
oooooooo
T s u < o o -
UUUUUCJUU
oooooooo
cocococococoooco
o o u
00000
O 8 o u o
oooooooo
s 3
C_>
UOCJCJOOUU
oooooooo
< 3 o '
(_)
a.
o -- o < < u u
6-26
q q y o <
TD
"D
00000
oooooooo
J
H^
o
UUOUUUUCJ oooooooo
COCOCOCOOOCOCOCO
e
1
o o o ^r co o o
r-~
^r CM
oo
^ T3
o
c ;
Q po
GJ
0000
oooooooo
oooooooo
CJ
o o
s o
<->
o - o < < U
<-J
6-27
y 8 u < a a u
E E
CO
W i Q
0000
o o
o o U
Is
1
oooooooo
^ K s u < o o
-t
^r
u o o
^r
o
-
u o
q y y <
E
<<??E
o
CO
.
^ D
CO
<3-
e 00000
o o o o
o
O o o o o o o o
*3"
u u u o u CO o o o o o o o
s u < o o -
o o
^r
o U
CL
< <
(J
6-28
0000
UUUCJUUUO oooooooo
D-
< < U U
Q Q u u <
003
OOOOOOOO
111
I
I
I
C_l
o o o
-
6-29
Observe that the program, as illustrated, fits into 15 program memory bytes. Instructions 4 through 9 are re-executed eight times. This is possible, since with each re-execution, the part that changes, data memory addresses, changes in the Data Counters. This is the virtue of implied memory addressing.
How would
the
same program
consist of a pair
be implemented by a minicomputer that has If the program is in ROM, it will have to of three-byte instructions repeated eight times:
logic
o <
CD
<
(J
o <
o o
CD
o
CO T3
CO ~o
Total program length will be 48 bytes. Implied memory addressing has saved memory by allowing a set of instructions to be re-executed, and by allowing memory reference instructions
to
occupy
Implied
a single byte:
Memory
Direct
Memory
Reference Instruction
Reference Instruction
Load
into
accumulator
data addressed by
DC
/data addressed by
'
Addressing problems associated with microcomputers become more severe if you try to use any type of paged direct addressing. Minicomputer designers use
PAGED
DIRECT
paged
direct addressing
in
order to
ADDRESSING
relative,
is that it can only be used for form of addressing simply cannot be used for instructions that write into memory. ROM usually comes in 1024-byte
instructions. This
be
ROM
or
modules. Pages are either 128 or 256 bytes long. Therefore, an entire page will either RAM. It is not possible to have the program area of a page in ROM and the data area
in
of the
same page
RAM:
6-30
One 1024
byte
ROM
Module
PageO
Page
No
can
Page 2
Page 3
high order
half of
\
page
" can
relative,
is
paged addressing
next page
RAM
It
would
certainly
be possible to have
th S
'
memory
d
'
dir^^f
WOU d
'
reqU
'
re
Vld
'
ng UP mem0rV
One 1024
byte
ROM
/
Module
data
PageO
program
data
Page
program
data
data
Page 2
program
Page 3
program
data
memory mapping greatly increases the cost of creating microcomputer oro grams, plus the potential for introducing programming errors. As a result microcoZte grams are almost always written with separate program and data areas of
n^ me^TlSlo^"
6-31
Memory
Program Area *
Data Area
So
universal
specify separate
dresses a dresses a
memory into program and data areas that some microcomputers admemories for programs and for data. This means that the Program Counter Counter adwhich the Data Counter cannot address; and conversely, the Data memory memory which the Program Counter cannot address.
is
this division of
adstarts at the other end of a data buffer, so the memory is easy to imagine program logic that can create a In either case, dress must be decremented after every memory access.
It
we
memory
d
re
AO AO
via vih
DCo\ DC1 \
nl
DCO
DC1
IS
THE STACK
nt
.tncril
DC1
which has existed in many There is a variation of implied memory addressing another in almost every minicomputers and is implemented in one form or of a stack was introduced microcomputer; it is known as Stack addressing. The concept
at the
end
of
Chapter
4,
in
logic.
MEMORY STACKS
The more common Stack
architecture sets aside some area of addresses. The data memory for transient storage of data and register, called the Stack is addressed by a Data Counter type of
STACK
POINTER
Stack Pointer.
writing to the top of the Stack Only two Stack operations are usually allowed: top of the Stack (referred to as a Pop, (referred to as a Push), and reading from the
or a Pull).
stack of data words, where the fact that it may be visualized as a data word at the top of the stack. entered into the stack, or the first empty only the last data word Pointer. via an address stored ,n the Stack may be accessed. In either case the Stack is accessed
its
name from
6-32
A Push
word
operation,
(or
which writes
other
Accumulator
some
CPU
PUSH
I
'
currently addressed by the Stack Pointer (SP); the Stack Pointer contents is then automatically incremented to address the next free word, at the new top of the Stack, as follows-
After Push
Stack
0C40
0C41
4A
62
7 7 ?
->
0C42
0C43
0C44 0C45
0C46
0C47
Pull or
Pop operation
is
is
contents
POP
decremented
word written into the top of memory word addressed by the Stack
is
cumulator or
some
moved
other
CPU
to the
Ac
register. This
may be
illustrated
as follows-
Before Pop
Stack
After
Pop
Stack
Observe that
data
at the
end
of a
Pop
memory word
word
is
is
first
unused
he
assumed
to
be empty.
between implied memory addressing, using a Data Counter, and Stack memory adS n9 3 " 9 the only difference between the two is inter is self ev dent ln fa that ^p the Stock Pointer contents MUST be incremented after a write,
parallel
'
The
fhfr
h ere
tlo n
'
'
and
MUST
be decremented
after
C UrS
th
that^
h u
bove
mow
the%"
nmhing ch"
m T" VT
thln
r
th
be nQ lm P lemented in mory - the opposite direcaCC8SSed r8ther than the t0p In the se e '"^trated f deCr6mented after a Wnte and ^remented after a read. Otherwise
*
'
StaCk
^
"
'
6-33
is
P^ SH
number
is
of registers
commonly 8
it
or 16)
the CPU.
When
a byte of data
cascades
down
as follows:
Before Push
After Push
Stack
When
a byte of data
is
pulled or
POP
cascades up as follows:
Before Pop
After
Pop
Stack
Stack
CA
Pointer, since at This Stack architecture requires no Stack read out of the top of the Stack.
all
times data
is
being written
into, or
HOW A STACK
The Stack
is
IS
USED
it
Consider the
users; a great convenience to minicomputer necessity in microcomputer applications. are use of subroutines. Most programs, whether they
is
an absolute
SUBROUTINES
program
consist of a number of written for a minicomputer or a microcomputer, which is recorded once, somewhere in frequently used instruction sequences, each of routine is then accessed as a subroutine.
memory. The
An
application
may
require arithmetic to
Byte
single, 32-bit
number
6-34
The most
efficient
way
is
programs to
perform addition (for example), you will subroutine. A call may be illustrated as follows:
Now every time you want to use an instruction which CALLS the
division.
SUBROUTINE CALL
Program Memory Used by Main Program
Program
Memory used
by 32-bit binary
addition subroutine
Suppose you did not use subroutines; the instruction sequence needed to perform 32-bit, binary would have to be repeated every time program logic specified 32-bit, binary addition. The program would now appear as follows:
addition
Most programs, whether they are written for minicomputers or microcomputers, eventually become nothing more than a large network of calls to subroutines. Providing the importance of subroutines in all microcomputer programs is accepted at face value, you need not understand any more about subroutines at this point. However, let us consider what happens when a subroutine is called, and how program logic handles a return from a subroutine.
The PDP-8 minicomputer, and a number of other old minicomputers use the first memory word of a subroutine as the location where the return address is to be stored. For example, suppose our 32-bit, binary addition subroutine instructions occupy memory locations
Memory word 4C2 16 is the first word of the subroutine, and must be left empty. subroutine is called from memory location 72A 16 the following sequence of events occur:
dresses.
the
6-35
of the
in
memory
location
4C2 16-
2)
3)
first
memory
location
4C3 16
This
may be
illustrated
as follows:
Before Call
After Cal
Subroutine
?
Subroutine
04C2 04C3 04C4 04C5 04C6
04C7
72C
Cc Ming Progra
m
0728 0729
Ccailing
Program
0728
72C
PC
4C3
PC
0729
CALL
4C2
072A
072B
CALL
4C2
072A
072B 072C
072C
072D
072E 072F
072D
072E
072F
0730
The
last instruction executed within the subroutine must be a return instruction. This instruction moves the address (72C 16
)
SUBROUTINE RETURN
in the first word of the subroutine (at 04C2, 6 back into the Program Counter, thus causing program execution to continue at the instruction following the
stored
subroutine
call.
cannot work in a microcomputer apthe subroutine is going to be stored in read-only memory; this being the case, the return address cannot be stored in the first word of the subroutine. Microcomputers store subroutine return addresses in the Stack. The 32-bit binary addition subroutine call would be executed as follows:
This
scheme
plication, since
6-36
Before Call
After Call
Subroutine
Subroutine
04C2 04C3 04C4 04C5 04C6 04C7
04C2
H
04C3
04C4
04C5
04C6
04C7
1 1
i i
1 1
ailing Progre
m
0728
0729
c ailing Program
0728
0729
CALL
04
072A
072B PC SP
04C2
CALL
04
072A
072B
C2
072C
0C45
C2
072C
072D
072E 072F
072D
072E
072F
Stack
Stack
I 1
1
1
21
0C40
0C41
21
OC40
0C41
4A
62
? ? ?
4A
0C42
0C43
0C44
^^ Top
62
of stack
~^
0C42
07
2D
0C45
In
the above
illustration,
bits long,
memory words are assumed. Since addresses are are required to store each address.
all
16-
In order to return from a subroutine, it is only necessary to pop the top two bytes of the Stack into the Program Counter. Execution will then proceed with the instruction following the call to the subroutine.
NESTED SUBROUTINES
subroutine.
There
is nothing at all unusual about one subroutine calling another. In subroutines are frequently nested to a level of five or more. There are even certain mathematical routines in which the most efficient way to write the program is for the subroutine to call itself.
fact,
RECURSIVE SUBROUTINES
call itself is re-
So
nested
StacT
Were
this
illustrations.
is being used to preserve return addresses, subroutines can be any way. or can call themselves; and providing the return path follows the eXaCt V the C rreCt retUm address wi always oe at the cu "*nt
' '
"
top of the
book a programmer's guide, we would now prove the above statement with extensive However, in order to understand microcomputer concepts and microcomputer programming, you can take at face value the fact that the Stack will
insure that the return path
is
the
6-37
yourShould you still be curious, you can prove this or exact inverse of the subroutine call path. Arbitrarily selec located in various areas of memory. self by defining a number of subroutines a piece of other subroutines exist. Draw a Stack on locations within subroutines where calls to return, pop the return adperform a push of the return address. For each
paper and
for
in exactly that you come out of nested subroutines dress ,nto the Program Counter. You will find however complex the subroutine call sequences may the same sequence as you entered them,
each
call
be.
INDIRECT ADDRESSING
An INDIRECT ADDRESS
specifies a
is
assumed
to
INDIRECT
ADDRESS
Memory
Jump
indirect object
code
Address
XXYY
provided by
Jump
instruction
The
first
of these
two memory
bytes has address XXYY, and the two bytes contain AABB.
This
memory byte has the memory address AABB. and the addressed memory
location.
is
AABB
is
INDIRECT
EA = [XXYY]
where:
ADDRESS COMPUTATION
EA
[
signifies the
address
is
enclosed by the
brackets.
A PAGED COMPUTER'S
INDIRECT ADDRESSING
since it is the only an absolute necessity on a paged computer, own page. location outside an instruct.on s way a program can access a memory instruction: on a paged computer, the direct address Thus,
Indirect addressing
is
LMA
XXYY
6-38
must,
if
XXYY
is
beyond the
instruction's page,
be replaced by the
indirect
address instruction:
LMA
"HERE
HERE
In
DA
HERE
XXYY
provides the address of the indirect address
the
LMA
Memory
location
HERE
contains'an address
the effective
memory
address.
With an absolute, paged microcomputer, an instruction with indirect addressing will only occupy two bytes. The effective memory address is now computed as follows:
Memory
Any
indirect instruction's
Memory
address of instruction
object code
code bytes
The
first
two
bytes,
on the
same
required
memory addresses
AABB
which can memory, has the memory address AABB, and is the addressed memory
This
byte,
memory
be anywhere
in
location.
6-39
Memory
These three
identify the
instructor!
bits
These seven
bits
provide an
12-bit
memory
address of instruction, a
are binary digits.
and b
digit.
aaa aabbbbbbb
An
indirect addressing
instruction
These two
both be
indirect
1
bits
must
to specify
address on
current page.
12-bit
aaaaannnnnnn
memory
address of word, on same
stored, a
digits.
is
This 12-bit
the indirectly
addressed
memory word.
a base
INDIRECT VIA
page, will use a large part of the base page to store addresses; these addresses will be referenced indirectly. For ex
ample, suppose
BASE PAGE
aaaaabbbbbbb is in the above illustration the object code at memory location HUOnnnnnnn. instead of being 1111 Innnnnnn. Now the address stored in memory location OOOOOnnnnnnn would be chosen, not the address stored in memory location aaaaannnnnnn.
6-40
Another variation of indirect addressing sets aside certain memory locations as auto increment or auto decrement locations. For example, the PDP-8 minicomputer sets aside memory locations 008 16 through 00F 16 on the base page, as auto increment locations. If an address is stored in any auto increment location, then the address will be incremented whenever it is referenced indirectly.
,
INDIRECT AUTO
INCREMENT
AND DECREMENT
With reference
to the
most
recent, illustration,
if
then after the indirect addressing instruction had executed, memory location 008 would contain" 16 PUH+ i; on the next execution of the indirect addressing instruction. PQR + 1 would be the effective memory address, not PQR.
)
(i
008
An
auto decrementing
indirect
PQR-1
**'* ***
rather than
PQR + 1.
if
S'
be ,m P |emented
read-write
memory
addresses
Memory
Memory
address of
Any
instruction
code
indirect instruction's
bytes.
.PPQQ
object code
PPQQ +
YY
-(PPQQ + D+YY
(PPQQ+1 )+YY +
1
AA
AABB
This
memory
be anywhere
in
addressed
memory
location.
6-41
INDIRECT ADDRESSING
In
Memory
Indirect addressing instruction
object code
XX YY
Address
XXYY
provided by
indirect instruction
XXYY yyyY +
AABB
that
TPQQ
RRSS
Why
indirect address
AABB
to
PPQQ
or
RRSS?
Many minicomputers are time-shared. This means that a single minicomputer may be executing many programs, attending to each one for a few milliseconds before going on to the next. Each program will use parts of memory to store programs and data that are needed for immediate execution, while the bulk of programs and data will remain on disk. A program or data table may occupy completely different areas of memory on each re-execution. This is because the area of memory that is free for use may be impacted by totally unrelated programs that were executing in preceding milliseconds by the time-sharing system. Variable indirect addressing is one of the ways in which minicomputers are able to cope with the fact that programs and data tables may occupy different areas of memory from one execution of the pro-
gram to the next. is only necessary to change a few addresses, such as AABB, in order to change the location of a data table or a program. While this justification for indirect addressing makes a lot of sense in complex minicomputer applications, it makes absolutely no sense in microcomputer applications. When an entire microcomputer system, complete with memory, costs a hundred dollars or less, it will be cheaper to give each user his own CPU and memory, rather than go to the extra programming expense required to
It
6-42
Non-time sharing applications can also make effective use of variable indirect addressing. For example, a single data area may be used by a number of data tables of variable
length. Consider a simple telecommunications application. Data
is
arriving over a
telephone
line at
some random
memory. At fixed intervals, a microcomputer program is executed to process the most recent chunk of raw data. Observe that each time the microcomputer program is executed, the data on which it must operate will reside in a different area of read-write memory. If the microcomputer program references read-write
it
rate;
is
stored
in
read -write
memory via indirect addressing, then by simply loading the new beginning address of the data area into the indirect address space, the microcomputer program can access the next segment of data wherever it may be:
Memory
One
of
many
indirect addressing
instructions,
all
of
object code
same
data.
Address
XXYY
provided by
indirect instruction.
XXYY XXYY+1
processed data
Raw data
currently begins
1.
XXYY
and
XXYY + must
1
be read-write
memory
location.
6-43
microcomputer that has only implied and direct addressing would have to simulate This could be done indirect addressing to perform the operations described above.
follows: using three instructions for each indirect addressing instruction as
Memory
Load
XX
from
XX YY
direct into
YY
Load
low order byte
XX YY +
of Data
1
Counter
1
fromXXYY +
object code
XXYY XXYY +
INDEXED ADDRESSING
A number
implied memory addressing as of microcomputer manufacturers describe the same. indexed addressing; the two are similar but they are not address. This may be ilAn indexed address is the sum of a direct and an implied follows: lustrated as
Memory
Data Counter
Indexed addressing
instruction
code
to
XXYY
AA
|
XXYY +A ABB
-This
is
the addressed
memory
location
6-44
is
called an Inin-
Some minicomputers do
1
INDEX REGISTER
dexed addressing; most do. Minicomputers that do have indexed addressing may have from to 15 index registers. 16-bit minicomputer indexed addressing may be
illustrated
16-Bit
Memory
Index
Register
code
Base Address
XXYY+AABB
-This
is
the addressed
memory
location
16-bit
illustrated
16-Bit
Memory
code
Base Address
XXYY
+ OOBB
This
is
the addressed
memory
location
6-45
The index
while
bit
it
register derives
its
indexes an area of
name from the fact that its contents is likely to change (for example, memory being treated as a data table). This may be illustrated for a 16-
minicomputer as follows:
16-Bit
Memory
Index
Register
code
AABB
AABB-
First
memory
table
DISP+AABB.
.This
is
memory
Indexed addressing
gives
rise to
may be combined
this
PRE-INDEXING
two
possibilities;
the index
may be
When
the index
we
illustrated
as follows:
16-Bit
Memory
Index
Register
Pre-indexed addressing
instruction
code
Base Address
This
is
the
memory
location
indirect
PPQQ-
This
is
the addressed
memory
location
6-46
is
given by the
EFFECTIVE
ADDRESS
EA = [BASE + INDEX]
The square brackets denote "contents
of". In the
above
illustration:
is
413C 16
given by:
is
memory word
When
the index is applied to the indirect address, we talk of post-indexed addressing. This may be illustrated as follows:
16-Bit
POSTINDEXING
Memory
Index
Register
I
Post-indexed addressing'
instruction
code
XXYY
Base Address
This
is
the
memory
location
indirect
This
is
the addressed
memory
location
is
given by the
EFFECTIVE
ADDRESS
=i
EA
[BASE]
INDEX
of." In the
above
illustration:
register contains
213A 16 and
is
413C 16
the effective
given by:
EA
= [413C 16 ] + 213A 16
6-47
is
memory word
with address
413C
lfi
plus
213A 16
how much
index-
ed addressing,
microcomputer, this
may be
Hlustrated as follows:
Memory
Index
Register
Indexed addressing
instruction
code
Base Address
This
is
the addressed
location
memory
Clearly there
is
some redundancy
sum
valid
XXYY + AABB
cannot
to
in indexed addressing, as illustrated above. more than FFFF ]6 since this is the largest value that a 16-bit ad,
Any
Memory
Index
Register
Indexed addressing
instruction
code
Base Address
This
is
the addressed
location
emory
This
is
EA = XXYY + AAOO
= XXYY + AABB
6-48
We
have saved a byte in our indexed addressing instruction, and given up nothing. dexing data tables, this representation of indexing may be illustrated as follows:
In
terms of
Memory
Index
Register
-Indexed addressing
instruction
lAAYYl
code
'Base Address
AABB-
-First
memory
location
AABB
+ OOYY
-This
is
memory
Since
effect,
we
is
a 16-bit index register, but only an 8-bit memory word, what we are doing in creating the table base address out of the index register high order byte, plus the base
have
address byte. The index register low order byte becomes the table index.
Effective index
Index Register:
In
sent. This
many
the world of microcomputers, straightforward indexed addressing is rarely preis because we are dealing with an 8-bit instruction code, and if we try to specify too
addressing options,
we
will
bits.
6-49
Chapter 7
AN INSTRUCTION SET
We are now ready to create a hypothetical instruction set. The instruction set we are
now
Rather,
justify
going to create will not copy any existing microcomputer's instruction set. them; what we must do is it will contain features representative of all of
each feature.
CPU ARCHITECTURE
The first prerequisite, before we can discuss individual instructions, is to select the number and type of registers, plus the number and type of addressing modes that
our hypothetical miocrocomputer will have.
We
will start
with re gisters.
number We cannot simply select a enough for any situation. Remember, every
large
logic,
of
registers
we
more than
have many
NUMBER OF
REGISTERS
is
register
using up limited
real
estate on the
CPU
chip; also,
bits,
registers,
we
will
use up
many
instruction
code
referenced. Therefore
we must
to be
We
rather than one, simplifies 16-bit data operations, since the as the upper and lower bytes of a single 16-bit unit:
0.
Bit
No.
15
14
13
12
11
10 9
10.
.16-Bit
Representation
to justify having
two Accumulators.
also useful
easier
and
faster with
when data from two tables must be read and processed two Accumulators, which, in effect, provide two indepen-
transfer.
sufficient?
or
equivalent
DATA COUNTERS
used as Data Counters or memory address registers of three 16-bit Data some form We are going to provide our microcomputer with Accumulators, or Counters (DCO, DC1 and DC2); therefore, we do not need more than two
equivalent registers.
greatly simplifies processing data out of ta-
Why
bles.
is
that
it
(the most obvious examFrequently data from two source tables are combined in some way third table. Microcomputers with less than ple is multi-byte addition) and the result is stored in a addresses between temporary three Data Counters, or equivalent address registers must shuffle of having only one (or two) Data storage in memory, or must otherwise circumvent the limitations
Counters.
7-
Consider the simple case of multibyte addition. Having three Data Counters,
similar operations, are easily
this operation,
and
handled as follows:
Memory
XXXX
DCO
DC1
XXXX YYYY
zzzz
.
YYYY
DC2
'ZZZZ
Original
DC
contents;
will
all
these addresses
be incremented
after
we would
have to
move one
XXXX
or
YYYY)
into the
answer
buffer,
Memory
XXXX
YYYY
DCO
DC1
YYYY
ZZZZ
Step
1
\
/
zzzz
I
XXXX
ZZZZ
n
DCO
DC1
4+ Tic1
Step 2
microcomputer with only one Data Counter would have to store the three table addresses in read-write memory, then load each address into the Data Counter before accessing each table.
somewhere
7-2
microcomputer with indirect addressing could store the three memory, then access tables indirectly via the three addresses:
Memory
Address
Base Page
will
table access.
YYYY
ZZZZ
7-3
11
We
will
Counter
CPU
REGISTERS
Our complement
SUMMARY
8-bit 8-bit
Accumulator
ACO
Data Counter
Accumulator AC1
16-bit 16-bit 16-bit
DCO
DC2
16-bit 16-bit
Stack Pointer SP
Program Counter PC
STATUS FLAGS
Chapter 2 we described status flags, and microcomputer w,th the four status flags Z
In
how
(Zero).
(Carry).
We
r 6a T!tI?c registers
of
^ ^ ^ ^ ^S^JSS^T ^
aTan^tTmativT'^^T^^
Since
access,n9 a
C Unter S " kely t0 proV(de ndirect addressing number of data areas; th,s was "
ited
we
'
we
will
^l^S^
follows:
1)
^ Y memor
'
save on instruction code bits, and CPU chip logic bv Wl11 nClUde 3Ut0 inCrement 3nd au
will
- Se-men
instructions
flexible set of
addressing options.
'
2>
w T
rnX^^g^:r
b
Cti nS
'
"
=^^
01
1
^ "^ ^ ^ *
eSS
offered
*"
Address specification
bits for a
Load or Store
instruction.
DC2
The next two bytes provide the
direct
memory address
If bits and 1 are } 1. these two bits are unused. are not 11. then interpret bits 2 and 3 as follows:
If
bits
and
00
01
at
conclusion
7-4
Memory
reference instructions, other than Load and Store, will offer this limited
bits for
memory
reference instructions
10
I I
M M
II
Simple, implied
memory
addressing only
DC2
The next two bytes provide the
direct
Direct addressing.
memory
address.
A DESCRIPTION OF INSTRUCTIONS
There are two competing perspectives which we must maintain while evaluating the instructions that are to constitute our microcomputer's instruction set. First, we must decide what instruction types are vital, very useful, or simply desirable; next, we must select instructions that use the 256 possible combinations provided by an 8-bit instruction code; we cannot have more than this number of options.
In order to balance our two perspectives in the following discussion, we are going to create a complete, but hypothetical, microcomputer instruction set. This means that we must justify each instruction, or instruction type, and we must specify the object code pattern which is to be interpreted by the CPU Control Unit as identifying the specified instruction.
INPUT/OUTPUT INSTRUCTIONS
A
microcomputer system would be useless
if it
means
is
is
input/output and
An input/output
1)
Is
the instruction reading data from an external device ting data to an external device (output)?
transmit-
2)
As we discussed in Chapter 5, most microcomputer systems have, or at least allow, more than one port through which data can be transferred between external devices and a microcomputer system. We must identify the I/O port via
which the input or output operation
is
to occur.
3)
What is the source (for input) or destination (for output), within the microcomputer system, for data being transferred via I/O instructions?
in
Input/output operations are so frequently used in microcomputer applications, that order to save memory, it is a good idea to include a few single-byte I/O instruc-
tions.
We
could use just four of the 256 object code options, two for input (one for each Accumulator two for output (one for each Accumulator as the source), then
one
of
in
Byte Byte
1:
2:
7-5
This
scheme
7
is
better:
6 5 4 3 2
10
IpIpI
Bit
No.
Mojo IQM
in
specifies output
An
We
is
have used up eight object code options, without specifying which Accumulator involved in the data transfer. These are the eight object code options used by I/O instruc-
tions:
00001000
00001001
by next byte
via
via via
I/O Port
I/O Port
1
00001110
00001
1
via
It is going to take an additional bit to specify one of the two Accumulators as the data source or destination in I/O instructions. The eight object code options illustrated above would have to be repeated (perhaps with bit 4 set to 1) in order to represent two sets of I/O instructions, one set accessing Accumulator A0, the other set accessing Accumulator A1 As a result, 16 object code options would be consumed by I/O instructions; and that is unnecessarily extravagant Instead we will stipulate that Accumulator A0 will always be the source or destination of data for I/O instructions.
This preferred use of Accumulator AO will occur frequently in PRIMARY our instruction set, since it is an easy way of reducing the ACCUMULATOR number of object code options used up by any instruction type. By making one Accumulator always more accessible, rather than spreading preference between the two Accumulators, the programmer can think and program in terms of a pnmarv Accumulator (A0) and a secondary Accumulator (A
1
).
We
will
INPUT SHORT
is the instruction operand, and must be 0, 1 or 2 to specify one of the three I/O ports allowed by a single byte I/O instruction. The Assembler will flag any other
value
in
il-
INPUT LONG
IN
7-6
This time P
follows:
value from
through 255.
two-byte instruction
will
be generated as
Input to
AO
OUTPUT SHORT
OUTS
P
will
This
is
or 2 only).
And
for
Output Long:
OUTPUT LONG
OUT
P
This instruction
is
cumulator
AO
Long instruction, except data will be transmitted from Acany I/O port from through 255.
transfer,
By making I/O instructions access only Accumulator AO as the source or destination for a data we have decided that it is more important to specify a limited number of ports within a
instruction,
one-byte I/O
or destination.
Referring to the shower temperature controlling example, let us assume that temperature readings arrive through I/O Port 0, while controls are output to the hot water valve via I/O Port 1 I/O Port 2 is used as a common status port for inputs and outputs. Information at these I/O ports will be interpreted as follows:
.
I/O Port
0:
millivoltage, ranging
from
mv
F
in F,
may be
ap-
proximated as follows:
=30
+ 0.45 mv.
I/O Port
signed binary number, specifying the hot water valve must be opened (positive) or
amount
of valve
movement
will
through 127.
I/O Port
2:
be interpreted as follows:
I/O Port
7
I/O Port
6 5 4 3 2
hliloi Hi
l
10 loM
1
Bit
No.
\ k_
= New data at I/O Port = No new data at I/O Port = New data has been read = New data has not been read
Not, Used
1
= New data at I/O Port = No new data at I/O Port = Retransmit last data value = Last data value read and OK = Ready to receive data at I/O Port = Not ready to receive data at I/O Port
1
1
1
Not Used
In
the Port 2
illustration,
represents
bits
output by
the CPU.
7-7
11
into
memory
program
will
have
to con-
perform
basic architecture of any computer, mini or micro, provides a very limited data storage in CPU registers, and a (relatively) enormous data storage capacity in memory external to the CPU. This makes memory reference instructions the next most vital, after I/O instructions. Recall from Chapter 5 that some microcomputers treat I/O instructions as a subset of memory reference instructions, by assigning specific memory addresses to I/O ports.
The
capacity
As might be expected, the two most commonly used microcomputer memory reference instructions merely move data to or from memory; these are the Load and Store instructions.
to
an Accumula-
LOAD
tor.
I 1
Store instruction
moves
memory
loca-
I
*
tion.
STORE
These being the two most commonly used memory reference instructions we will spend the bits needed to include in the Load and Store instruction very flexible addressing modes.
Load and Store instruction object codes
will
appear as follows:
^6543210
1
Bit
No
01
DC2
The next two bytes provide the
direct
Direct addressing.
memory
address.
If
If Bits and 1 are 1 1, these two bits are unused. are not 11. then interpret bits 2 and 3 as follows: 00 Specifies simple, implied memory addressing.
bits
and
01
at
conclusion
A0
Reference Accumulator
Load
1
Store
Load or Store
instruction
now look at the complete addressing capabilities offered by the Load and Store instructions, starting with the simplest.
Let us
After describing
are.
we
will justify
each one.
DIRECT
in bits
and the
be provided
in
the
two bytes
ADDRESSING
must both
that follow.
Observe that
We
will
be
for a direct
now
Byte
0/
Load
into
Accumulator
or
Byte 2
memory
Byte 3
two bytes
Byte
1"
or
Byte 2 Byte 3
memory
two bytes
The following
7
do with Load
or Store instructions:
6 5 4 3 2
1
10
lilil
Bit
No.
lohl
J
I
k
-Direct addressing
if
bits 2
these two
10 or
1.
.These two
can have any value and not represent Load or Store instruction if bits 2 and 3 are not both 0.
bits
There
from Load and Store instruction object codes. Twelve of the combinations do not represent Load or Store instructions, as illustrated above (3
are
resulting
combinations of
bits 2
and
3,
times 4 combinations of
bits
4 and
5.
equal
12 combinations). Therefore, there are 52 variations of the Load and Store instructions.
memory addressing
can
IMPLIED
ADDRESSING
6 5 4 3 2
I
10
| |
lohj
lolol
00 Address
01
implied by
DC0
Simple, implied
memory
addressing
Reference Accumulator
1
A0
Reference Accumulator A1
__0 Load
1
Store
or Store instruction
-Load
7-9
The
effective memory address for the Load or Store instruction DCO, DC1 or DC2, whichever has been specified by bits and
is
1.
Introducing the auto increment and auto decrement feature is quite easy to understand; the auto increment feature says that the implied
will
AUTO
INCREMENT
memory
address, that
1
be incremented by
will
the contents of the specified Data Counter, at the conclusion of the memory reference inis.
Counter contents
struction.
auto decrement feature specifies that the Data be decremented by at the conclusion of the in1
AUTO DECREMENT
for
3 and
2.
2.
which
will
will differ from the implied addressing be 01, the equivalent auto decrement in-
have 10
in bits
3 and
1 's in
bits 2
and
3, is
INCREMENT
We
AND SKIP
/Load
7
6 5
?1
3 ?
1
or Store, then increment contents of the Data Counter specified by bits and 1; then check contents
Byte
Jnjl}
ofDataCounte
<
Byte 2
\jtrW
the last 6 bits of the Data Counter contents are 000000, increment the Program Counter to bypass (and ignore) this byte. If the last 6 bits of the Data Counter have any other value, treat this byte as a signed binary number, to be added to the Program Counter contents,
forcing a Branch.
The most effective way of illustrating the necessity for the various addressing modes is with short program sequences. Let us therefore first describe the instruction mnemonics which will be used for the Load and Store instructions.
Load and Store
Direct will use these
mnemonics:
LOAD DIRECT
LRA
LRB
SRA
SRB
Load Load
A0
|
STORE DIRECT
A1
A0
A1
ADDR
data
digits
is
will
instruction
any symbol representing a memory location from which data will be read or to which We use the letter A to represent A0 and B to represent A1; we could use the and 1, but it is too easy to confuse and O. and with therefore, use of and 1 within
be written.
1
I;
mnemonics
is
unpopular.
will
LOAD IMPLIED
memory
location
LMA
LMB
Load
into
A0
from the
STORE IMPLIED
|
addressed by
DCX
memory
location
Load
into
from the
addressed by
DCX
SMA
SMB
DCX
specifies
A0
into the
memory
location
addressed by
DCX
A1
into the
memory
location
addressed by
DCX
and therefore must be DCO, DC1 or DC2.
one
7-10
The Load
will
or Store with
Auto Increment
will
or
Auto Decrement
instructions
be
identical to
be incremented or decremented.
We
for Load with Auto Load with Auto Decrement, SNA and SNB for Store with Auto-Increment and SDA and SDB for Store with Auto Decrement.
will
Increment,
for
Load and Store instructions with Auto Increment and Skip mnemonics:
will
be
LSA
LSB
DCX, LABEL
Load Load
into
AO
A1
AND SKIP
AO
into
SSA
SSB
A
memory
will
DCX
DC1
identifies the
address;
it
or
DC2.
is
LABEL
symbol
last six
which
be executed next
if.
after
DCX
is
incre-
mented, the
In
all
zeros.
at a simple problem
starting
power of the Load and Store instructions, let us look which moves data from one buffer to another. Assuming that the the source and destination buffers are in Data Counters DCO and DC1, and
is
assuming
follows:
stored
in
illustrated
as
Data
Memory
XXXX
Move raw
zz <
data input
by thermometer
*^
AO
A1
ZZ
DCO
DC1 DC2
XXXX YYYY
YYYY
ZZ<
To data
buffer
where data
is
held
XXXX YYYY
ZZ
is
is
is
7-11
The following
instruction
sequence
will
LOOP
LMA SMA
DCO
DC!
Decrement A1 contents
If
A1 contains
which
0.
branch to
LOOP
in
Instructions
we
familiar instruction
mnemonics.
this
is
Now we
will
what hap-
pens to our
sequence:
LOOP
LNA
DCO
DC1
1
byte.
SNA
Store
in
Decrement A
If
contents
0,
A1 contains
branch to
LOOP
six instruction
Two
instructions have been removed from the program code have been saved.
that the destination buffer
of object
Now assume
the
last six
ends
at
memory
zeros:
location
08C0
all
08C0 16 = 000010001100*3000
We
can
now compress
our data
move program
to these
two
instructions:
LOOP
LNA
SSA
DCO DC LOOP
1,
These two
instructions
occupy three
C
We
A
,0
1
Q
1
Load A0
1
via
via
Store
A0
Twos complement
Increment and Sk,p instrucfionmcrements the destination buffer address, it tests the incremented value; if the incremented value does not end in six binary zero digits, execution will return to the Load instruction- this twoinstruction loop will be continuously re-executed until the Store, Increment and Skip instruction does increment the destination address to 08C0 16 at this point the branch will be bypassed and the instruction which immediately follows the above data movement loop will be executed.
;
no longer need to hold the buffer length in Accumulator A1. Nor do the buffer, length, or increment memory addresses. After the Store,
we need
to
decrement
minicomputer programmer would recoM at an addressing scheme such as the auto increment and skip. The idea that data tables must be
placed at
six binary
in
it
offers advantages.
7-12
While the minicomputer programmer may see the neatness of instruction loops that require no special end-of-loop logic, problems associated with data relocation would be horrible; if a program were to be re-used in another application, or if it were part of a time-sharing system, the programmer would constantly have to worry about ensuring that data tables ended at correct
memory boundaries
or else the
We
minicomputer programmer's axiom: "Remember return once that whatever you do today may impact tomorrow." But remember that in the world of microcomputers there is no tomorrow. Whatever you do today becomes a ROM chip and minor will never again change. Mapping data tables onto memory address boundaries is only a inconvenience, since memory mapping will be a significant part of every microcomputer programming assignment anyway. When the ROM chips that result from your program may be
again to the old
reproduced thousands of times, you
the fewest, smallest chips possible.
will
want
to
in
skip feature offers very significant advantages in a it saves on object program bytes, while the is part of a job having to map data tables onto address boundaries
must be done
in
any event.
instruc-
DIRECT
ADDRESSING
JUSTIFICATION
There
done with an
tions use less
certain cases,
buffer length
which
in
we were
the end
we
movement
many
which
this
How
length, or
any
Accumulator?
Program
Memory
01000011
Load
direct into
A0
location with this
To A0-
7-13
bytes and
will
temporarily
Program
Memory
Load immediate
1
into
DC0
01000000
AO
via
DCO
This byte
addressed
To AO
instruction
it
which
is
needed
when
Counter
is
an un-
is
followed by a s.ngle
memory
an address
in
the address
If
we have seen earlier in this chapter, the three bytes needed Counter result in a great subsequent memory savings, but only if the Data Counter is going to be re-used many times.
into a Data
is
microcomputer
the
more
,s
of the Intel
8080 has
to
Most programs load single values (such as counters and indexes) make direct addressing justifiable.
G C er 0r ndeX t0 be l09ded mt0 9 reg Ster h9S a value that Wl change, " use neither , direct nor implied addressing to load the value into a register. You would use immediate addressing:
^1", t would
you
'
'
Program
Memory
Load
into
A0
of this byte.
The contents
7-14
1 1
With the exception of the Store instruction, microcomputer instructions memory since that implies the presence of read-write, memory.
will
avoid modifying
We
will include
these secondary
memory
reference
in-
AND
OR XOR
structions:
7
6 5 4 3 2
10
COMPARE
00 Use Data Counter DCO
Simple, implied
memory
_01 Use
Data Counter
10 Use Data 1 Direct addressing. The next two bytes provide the direct
DC Counter DC
addressing only
memory
address.
AND
OR
Exclusive
100
101
OR
we
will use:
ABA
or or or or or or or
ABB
Add
Binary to
ADA
DSA
ADB
DSB
Add Decimal
Decimal
A0 or Al A0 or A1 Subtract from A0
to
or
ANA ORA
XRA
ANB ORB
XRB
AND
OR
with
A0
or
CMA
CMB
7-15
in bits 7 and 6 specifies that the remaining six bits represent secondary reference instructions. However, only seven of the eight combinations possible for bits
memory
2,
secondary
only 56 of the 64
bit
3 and 4 combina-
be written out
like this:
MNEM
where
DCX
is
MNEM
one
of the
mnemonics
listed
above
(e.g.,
ADA), and
DCX
is
one
of the
Data
The
direct
memory
will
look
like this:
MNEM
where
ADDR
the direct address.
ADDR
is
ABA
DC
d A USmg binarv addlt,oa the contents of the memory location whose address !l ' ?f 1X1. This by is the object code generated:
7
is
implied
6 5 4 3 2
10
olololololofT]
^pL_
is
-Add
.To
A0
is
.This
a secondary
memory
reference instruction
The following
a direct
memory
referencing instruction:
XRB
ADDR
'
h C n f A1 S XCluS e - Red Wlth the contents of the memory location addressed by ^ mb olTn nR These three object program bytes will : symbol ADDR. Th be created:
This
is
secondary
memory
reference instruction.
Reference
Exclusive-OR
7
1
5*4 3 2
1
1
XjF
1 1
1
These two bytes contain the 16-bit address represented by the symbol ADDR
Only two of the seven secondary memory reference instructions described above auvc need any comment.
Add and subtract decimal perform decimal addition two binary steps, as described for binary-coded
7-16
decimal arithmetic
Chapter
2.
We
We
perform decimal subtraction using a separate instruction, since the logic sequence
is
suffi-
ciently different
do not provide
BINARY
Chapter
2.
SUBTRACT
DECIMAL ADJUST
majority of
Note
and subtraction
instructions are
not the
same
takes the contents of a register and re-arranges the bits to create the
this
is
explained
in
Chapter
2.
microcom-
puters offer a decimal adjust instruction; a minority offer decimal arithmetic instructions.
The Compare
dressed
result
instruction subtracts the contents of the ad- | COMPARE | location from the specified Accumulator; the it is not stored in the specified Accumulator. However, of the subtraction is discarded
memory
the Z status
tion since
it
bit is set
is
of data items.
in
instructions, described later in this chapter, take advantage conjunction with the Compare instruction.
SECONDARY
MEMORY
memory
reference
REFERENCE INSTRUCTIONS
JUSTIFICATION
instructions necessary?
memory
addition. Boolean logic and compare, are such basic steps in any The operations described logic sequence that a microcomputer that did not offer these logic capabilities, one way or another, would be worthless.
There
however, no reason why these operations have to be part of memory reference instrucexample, it would be possible to load the two operands into Accumulators AO and Al, then to perform the same operations, register-to-register. Microcomputers which have many Accumulators, such as the Intel 8080, favor register-to-register instructions over register-to-memory
is,
tions. For
instructions;
register-to-memory instructions as
Let us look at a simple example.
microcomputers with fewer Accumulators, such as the Motorola M6800. use we have described.
buffers beginning at
single,
XXXX
and
YYYY
(in
the preceding
in
each hold a
multibyte number.
buffer beginning at
XXXX
could be added to
the
MULTIBYTE ADDITION
buffer
beginning at
YYYY
as follows:
Initially
ABA
SSA
DC1
Add
binary from
answer
buffer
DC 1, LOOP
7-17
The above
stored
will
in
This
program assumes that the buffer beginning at YYYY (this address is contains one of the numbers to be added, but at the end of the addition this buffer contain the answer. This logic works, since the answer is going to over-store the byte which
three-instruction
DC 1)
information
follows:
is
it
will
not be needed
in
the future
Second Source
Source
And
Destination
Another three instruction loop can perform a binary addition where the result buffer, which we will assume is addressed by DC2. The three instructions
is
stored
in
a third
this
will
looTl^e
LOOP LNA
SSA
DCO
DC2.LOOP
ABA DC1
Add
Store the
An example
of the usefulness of the Boolean secondary memory reference mstructions is to test switches for setting changes.
BOOLEAN
LOGIC JUSTIFIED
Suppose the status of eight switches are input to I/O Port settings for these eight switches are stored in memory
4-
the previous
dressed by the symbol SWITCH. The following instruction sequence identifies which switches have changed settings and how the settings have
at a location
ad-
SWITCH CHANGE
TESTS
,N
Input
XRA SWITCH
Save contents
Identify
of
AO
A1
switches that turned on
ANA SWITCH
This
is
Identify
instructions do;
The
first
new
01100101
7-18
Where
memory
symbol
now
"off".
Switch 6
was
"off",
and
is
now
"on". Switches
and
The XRA
settings
in
EXCLUSIVE-OR
A0:
Old Settings
New
Settings:
10101101 01100101
1 1
XRA
The changed switches
are identified by
1
00 000
1
bits,
in
A1.
^___
\
AND
AND
Changed
Settings:
Old Settings
11001000 10101101
10001000
gives on-to-off switches.
ANA
addressing requires a Data Counter to already hold an address. Direct addressing could do the job. A base address stored in two memory bytes could be directly addressed, and
memory
IMMEDIATE INSTRUCTIONS
JUSTIFICATION
Load
direct into
DC0
XX XX
DC1
xxxx
7-19
But the above illustration clearly has some redundant bytes; the address being loaded into the Data Counter could just as easily be stored in the two direct memory address bytes as follows:
Load immediate
into
DCO
DC1
YY YY
Immediate instructions are not absolutely vital to a microcomputer instruction set, but they are certainly a great convenience; we will therefore include eight immediate addressing instructions: to load data into the three Data Counters, the Stack Pointer, the Program variations) or the two Accumulators. These will be either two- or three-byte instructions; since the Accumulators are only one byte long, immediate instructions that load data into an Accumulator will be followed by just one byte of immediate data. The Data Counters the Program Counter and the Stack Pointer are all two bytes long; therefore, immediate
instructions
data.
that load data into any of these registers will be followed by two bytes of immediate following object code patterns will specify immediate instructions:
The
JL
7
6 5 4 3 2
jl 10
I
I 1
No.
hlol I1I1I1I
000 Load immediate DCO 001 Load immediate DC 1 010 Load immediate DC2 011 Load immediate SP
100 Load immediate PC (Jump) Load immediate PC (Jump to subroutine) 110 Load immediate A0
101 111
Load immediate A1
Since there are eight immediate instructions, and there were eight unused object code combinafrom within the secondary memory reference instruction group, we use these eight unused combinations for immediate instructions, as illustrated above.
tions
Special attention must be given to the two instructions which load immediate data into the Program Counter; unlike the other immediate instructions, these two modify the program
JUMP
INSTRUCTION
execution sequence; the next instruction executed is going to be fetched from the memory location whose address was loaded immediately into the Program Counter
7-20
In its
is
an Unconditional
Jump
(or
Branch) instruction:
Program
Memory
0401
0402
10111100
41
Load immediate
into
PC
PC
St
^s
0405
if 0403
1^0404
/
0405
I
2A
This instruction
will
be executed next.
V.
4129
^>412A
412B
412C
412D
Jump-to-Subroutine instruction differs only in that the curProgram Counter contents must be saved before the new immediate data is loaded into the Program Counter; since our
rent
JUMP TO
SUBROUTINE INSTRUCTION
is
will
be pushed
described earlier
in this
immediate data
Program Counter:
Stack
04
05
~*
New
top of stack
Jump to
PC
subroutine
This instruction wi
be executed
next.
Most microcomputers' instruction set descriptions do not include Jump and Jumpto-Subroutine instructions in the immediate instruction category; instruction logic is, however, almost identical.
7-21
Instruction
mnemonics
for
immediate instructions
will
be different
for
Jump and for the straightforward Load Immediate instructions. For Load Immediate we will use the following mnemonics:
LIM
LOAD IMMEDIATE
R.DATA
R must be AO, A1. DCO, DC1, DC2 or SP. DATA must be a number, or a symbol representing a number; it must be equivalent to an 8-bit value if R is AO or A1, it must be equivalent to a 16-bit
value otherwise.
The Jump
JUMP
JMP
ADDR must
be the
ADDR
label of the instruction
which
is
to
be executed next.
The Jump-to-Subroutine
JSR
JUMP TO
SUBROUTINE
SNAME
label of the
first
SNAME
must be the
instruction
We
will
now
create a subroutine.
move program
fully, this
SUBROUTINES
BUFA
BUFB
EQU EQU
XXXX YYYY
LIM LIM
DCO.BUFA
DC1.BUFB
Load Source
initial
address
Load Destination
initial
address
LOOP
LNA SSA
DCO
Move
DC LOOP
1,
to Destination
directive.
it
an Assembler directive
is
generates
EQUATE ASSEMBLER
DIRECTIVE
no object code; instead it provides the Assembler with information without which the Assembler could not generate an object program.
EQU
identifies
an Equate directive;
in
number
must be
substituted. For
example
'
it
tells
XXXX
We
LIM
LIM
DCO.XXXX
DC 1. YYYY
LOOP
LNA
SSA
DCO DC 1, LOOP
7-22
The advantage of having the Equate is that the symbol BUFA (or BUFB) may appear many times within a program. the value assoIf
ASSEMBLER
DIRECTIVES
THEIR VALUE symbol changes, all you have to do is change one Equate in the source program. When you re-assemble the source program, every reference to the changed symbol will be corrected in the new object program which the Assemciated with the
bler creates.
directive,
program
instruction that
references the changed symbol, then you would have to correct each source program instruction,
with no guarantee that you found
them
all.
moving program into a subroutine, all we do is give a label to the instruction which is to be executed first, and to add an instruction which executes a return from the subroutine:
To
JUMP TO
SUBROUTINE
MOVE
LOOP
LIM LIM
DCO,
BUFA
Load source
initial
address address
DC1.BUFB
Load destination
initial
LNA
SSA
DCO
Move
DC 1, LOOP
destination
The Return-from-Subroutine
the Return logic for now.
instruction
is
we
will
ignore
call
JSR
Subroutine
MOVE
MOVE
instructions:
J^
7
6 5 4 3 2
I
T?T
10
hi liMI
An immediate
operate instruction
is
specified
lohl
Select
~1
A0
Select
.00
01
Add immediate
AND
immediate
10
1
OR immediate
Compare immediate
7-23
11
Each
instruction describes
an operation that
will
Program
One
Accumulator
Memory
t
Immediate Operate
instruction
The status
tion.
flags C, O,
Z and S
will
be set or reset to
reflect
Observe that we have used eight of the twelve unused object code combinations from the 64 Load/Store patterns 01XXXXXX. These four combinations still remain unused within this pattern:
01XX01
1.
We
will
for the
Immediate
Operate instructions:
AIA
AIB
NIA
NIB
OIA
01B CIA
CIB
In
Add immediate
to
A0
COMPARE
IMMEDIATE
A0
each case.
number
will
(or a symbol) that becomes an 8-bit value. In each case, two be generated. For example, the OIB instruction will create this object
code: Byte
1 1
ill
OR immediate
the data
in this
with
byte
Byte 2
I
at
We
2
will
IMMEDIATE OPERATE
INSTRUCTIONS
JUSTIFIED
was defined
These two
INS
instructions determine
there
is
new
Input status
NIA
H'OV
Mask out
all
but the
bit
7-24
The NIA
instruction resets to
all
bits in
bit 0:
INS
A0 Contents XXXXXXXX
0000000X
NIA
HOT
X
If
represents either
the result
is
or
zero, bit
must have been zero, and no new data is at I/O must have been 1, so there is new data at I/O Port 0.
zero, bit
Port 0;
if
the result
is
not
Z status
will
0,
bit
and can
set
to
1.
INS
2 H'FE' H'02'
2
Input status
NIA
Clear
bit
1
OIA
Set
bit
to
OUTS
This
is
INS
2 H'FE' H'02'
2
NIA
OIA
OUTS
digit (0 or
how
the
AND
and
OR
ANDing I/O
work, refer again to Chapter 2. All we are doing ORing the result with 00000010.
is
BRANCH ON
CONDITION INSTRUCTIONS
to this point, status flags Zero (Z), Carry (C), Overflow (O), and Sign (S) have been useless curiosities, because the microcomputer provides no way to take advantage of the status flags.
Up
What
is
the logical
way
The answer is to provide instructions which allow program execution sequence depend on the condition of a status flag.
to
We have already seen two examples of how status flags can determine the subsequent course of
for a zero or
program's execution. In the Immediate Operate instruction description, bit of I/O Port 2 is tested non-zero value. If this bit has a zero value, program execution must branch to some instruction sequence which does not attempt to read new data from t/O Port 0. If this bit is 1, the program execution sequence must branch to a routine which will input data from I/O Port 0.
The discussion
the
last
Load and Store instruction categories started out with a routine that loads Accumulator A 1, then decrements the contents of A 1 as a means of testing if program buffer byte has been moved; so long as A1 has not decremented to zero,
of
7-25
execution returns to the beginning of the data move loop; as soon as the contents of A1 decrements to zero, program execution must continue and not branch back:
AO.LENGTH
DCO.BUFA
address address
DC1.BUFA
starting
LOOP
LNA SNA
AIB
If
DCO
DC1
H'FF'
byte,
increment
DCO
DC1
Add
decrements
0, return to
LOOP
If
While the AIB instruction (which has already been described) in effect decrements the contents of A1, a Register Operate instruction (which has not yet been described) does the job in one byte,
instead of two.
Branch on Condition instructions are vital to a microcomputer because they are the means of testing status flags; status flags in turn are vital to a microcomputer because they are the means for determining what happends when an instruction executed with more than one
possible result.
BRANCH ON
CONDITION INSTRUCTION
JUSTIFICATION
There are two philosophies concerning Branch on Condition instructions; one uses Branches, the other uses Skips.
Branch on Condition instruction, as the name implies, has a one- or two-byte displacement following the instruction code
(just like
BRANCH
PHILOSOPHY
immediate
is
data).
If
a specified condition
is
placement
added
is
a program branch
executed.
If
Program Counter as a signed binary number, and thus is not met, the Program Counter is increinstruction
is
executed.
may be
illustrated
as follows:
Memory
Address
142 A
Program
Memory
142B
142D
PC
142C
Branch on condition
142D
142E
3A
Displacement byte
/.
is
142F
if
142D + 003Aif
condition
is
not met.
met.
SKIP
states that if the specified status conditions are met, then the next sequential in-
PHILOSOPHY
7-26
'
if
instruction will
the specified status conditions are not met, then the next sequenillustrated as follows:
Memory
Address
142 A
Program
Memory
142B
142D
PC
142C
142D
142E
142F
Skip on condition
J Next instruction
/
2D
if
i r
condition
142F
if
condition
is
not met.
is
met.
In
the
it
illustration
were
dition
was
met.
Were "Next
if
if.
incremented to 1430 16
the condition
was met.
on condition
instruction,
By including an Unconditional
Jump
you
Memory
Address'
142 A
Program
Memory
142D
Skip on condition
142B
142C
PC
142D
142E
Jump
\ to this
unconditional
address
if
/
1
f
142F
1430
1430
condition
142D, then
contents of 142E
is
met.
and 142F
condition
is
if
not met.
is
Observe that the auto increment and skip form of Skip on Condition instruction.
instructions
Should our microcomputer include Branch on Condition or Skip on Condition instructions? will choose Branch on Condition instructions because they are a little more economical with this type of two-way execution sequence:
We
Data
LOOP
LNA SNA
AIB
DCO
DC1
H'FF'
if
LOOP
LNA SNA
AIB
DCO
DC1
H'FF'
if
Branch to Loop
A =
1
is
not
equal to
JMP
LOOP
Branch Logic
Skip Logic
7-27
What
which
we will
branch?
We will
choose
BRANCH ON WHAT
CONDITIONS?
Branch on Zero
Branch on Zero
(Z) (Z)
(C)
(C)
Branch on Overflow (O) equals Branch on Overflow (0) equals Branch on Sign Branch on Sign
(S) (S)
1
equals
equals
Branch on Condition instructions will be followed by single-byte displacements, which means that a forward or reverse displacement of +127 or -128 bytes is possible. This is reasonable since 90% or more of all branches will be served by this range, so to provide twobyte displacements would be wasteful of memory. Of course, you can always generate a longer
range branch by combining an Unconditional
follows:
Jump
Branch on Z
Branch to HERE on Z
JMP
HERE
The JMP memory.
THERE
Next instruction
instruction
is
it
in
instruction
sequence
illustrated
logic as a Skip
on
We
will
for
Bit
No.
X X X
.000 Branch on Z 001 Branch on Z 010 Branch on C
011 100
101
110
1 1
1
will
OP
LABEL
is
LABEL
if
OP
is
met.
7-28
The Assembler
the Assembler
will
convert
1
LABEL
into a
LABEL;
if
the result
is
out of range,
an error message.
OP
will
be a mnemonic as follows:
BZ
Branch on Zero
(Z
=
(Z
BNZ
BC
Branch on No Zero
= 0)
1
Branch on Carry (C
BNC
BO BNO
BP
Branch on Overflow (0
Branch on No Overflow
1)
(0=0)
Branch on Positive
(S
BN
Branch on Negative
(S
= 0) =
The Compare
instruction causes novice programmers a great deal of confusion. "Branch on zero" and "Branch on carry" are not nearly as meaningful as "Branch if greater" or "Branch if
less."
Recall that the
Compare
instruction subtracts
Ac-
cumulator, and sets status flags based on the result of the subtraction. The following conditions
can therefore be
identified:
(BLE).
(BL).
operand
(BE).
Branch on Accumulator and operand not equal (BNE). Branch on Accumulator greater than operand
(BG).
Depending on whether the Accumulator contents is being interpreted as signed or unsigned binary data, the qualitative conditional branches can be determined by using the following Boolean logic:
Branch
Condition
BLE
BL BE
Z
Boolean Condition
Signed Data
Unsigned Data
1
OR
S
XOR 0) = = XOR Z =
(S
1
1
C =
OR Z =
C =
Z
BNE
Z Z
=0
C =
Z =
1
BG
BGE
In
OR
S
OR Z =
1
C =
some
case,
subtract or
In
compare
operation.
In that
and C =
0.
look at
order to illustrate the use of Branch on Condition instructions, we will take another how the shower temperature controller might read data being input by the
thermometer.
When
this bit is 1, of I/O Port 2. tests bit the thermometer is ready to output a byte of .data, thermometer logic assumes that any previous data it sent has been read and processed; therefore thermometer logic transmits a byte of data to I/O Port and signals this event by setting bit of
it
If
7-29
I/O Port 2 to
Port
1.
Thermometer
Data
in
I/O Port 2
|_
I | |
V
read as
__ ^
is
I/O Port
I/O PortO
Data
ready to transmit
to I/O Port
bit
1 1
'Test
It
of I/O Port 2
is
so reset to
to
1
Set
bit
Data
in
I/O Port
There
is
new
data
in
I/O Port
In
order to read data input by the thermometer, the microcomputer program must keep testing
of I/O Port 2 until this bit
is
1
.
bit
Then the microcomputer must read the data in I/O Port 0; but at the same time the microcomputer must reset bit of I/O Port 2 to since, as soon as data is read out of I/O Port 0, becomes old data. The program must now set bit of I/O Port 2 to 1; this tells thermometer logic that the data in I/O Port has been read.
it
1
The following instruction sequence performs the operations described above; in addition, this instruction sequence assumes that the data byte read out of I/O Port will be stored in a memory location addressed by Data Counter DCO. Auto increment addressing is used with DCO so that
this
Data Counter automatically addresses the next free byte of the input data buffer, ready for the
LOOP
INS
Input status
NIA
H'OV
Clear
all
bar
bit
if
BZ
INS
LOOP
2
H'FE'
Return to
LOOP
is
bit is
New
Set
data
bit
1
NIA
Reset
bit
OIA
H'02' 2
to
OUTS
INS
Restore the
new
SNA
DCO
Store
in
memory
A number of microcomputers have Jump-to-Subroutine instructions akin to the Branch on Condition instructions we have just
described. Our microcomputer has one Jump-to-Subroutine which was described as an Immediate instruction.
instruction
JUMP TO
SUBROUTINE ON CONDITION
may
if
well reside
in
The
logic of Conditional
memory a long way away from the Jump-to-Subroutine inJump-to-Subroutine instructions is otherwise similar to the
is
Branch on Condition:
next instruction
is
if
not, the
executed.
Many minicomputers also have a set of Conditional Return-fromSubroutine instructions. These instructions restore to the Program Counter the address which the Jump-to-Subroutine instruction saved. have no
CONDITIONAL
We
we
will
7-30
REGISTER-REGISTER
MOVE INSTRUCTIONS
There are two types of instructions that reference two CPU registers: instructions that move data from one register to another, and instructions that perform secondary memory reference type operations, but entirely within the CPU.
Register-to-register data
movement
REGISTER TO REGISTER
MOVE
INSTRUCTIONS
JUSTIFIED
We
must be able
to
move
data between
is
AO and
move
plied addressing.
Moving data
in
in
assumes
Counter
in
question
is
There
is
rarely
any need
ability to
However, the
to move data from one Data Counter to another. move data between the Stack Pointer and Data
MULTIPLE
STACKS
Counters, or between the Stack Pointer and Accumulators is useful, since this allows a program to have more than one Stack. DC2 could be used as a buffer for the Stack
Pointer, for
DC2 and
SP,
ac-
cessed.
Moving data between the Accumulators and the Program Counter allows program logic to compute jump addresses. This is very useful in branch tables, which are illustrated later in this chapter.
COMPUTED JUMP
We
will therefore
7
provide Data
instructions as follows:
6 5 4 3 2
1
10
Bit
.000 X 001 X
=A0
010 X
011 X 100 X
101
=A =A
=A0
=A
_00 Move
01
11
contents of
Move
contents of Y to X
10 Exchange contents of
Y and X
instruction
of the
is
Not Used
.A
In
register-to-register
Move
specified
X =A
formed out
two Accumulators as
follows:
7
A0
6 5 4 3
2
1
A1
7
15 14 13 12 11 10 9
7-31
This instruction:
MOVE
MOV
S.D
Will
move the
by S
1
Moves
are legal:
A AO AO. A
1
.
Move A
Move
AO Move AO contents to A
contents to
Stack Pointer contents to
SP.DC 1
DC
Move
is
illegal:
MOV
DC1.DC0
two
legal
Moves:
MOV MOV
Recall the switch
DC1.A
Move DC
contents to Accumulators
to
A.DCO
test
Move Accumulators
it
DCO
Move
instruction as follows:
change
program:
used a register-to-register
IN
Input
new AO
switch settings
XRA
SWITCH
A0.A1
Identify
changed switches
contents
in
MOV
ANA
Save
A1
on
SWITCH
will be:
EXCHANGE
S.D
X
The same
rules apply to
S and
as described for
MOV.
REGISTER-REGISTER
OPERATE INSTRUCTIONS
tions,
Because our microcomputer has a number of secondary memory reference instrucseven it needs very few Register-Register Operate instructions; the following instructions, which parallel the secondary memory reference instructions, will do:
7
5 4 3 2
1 1 1
10
010
011 100
101
Subtract decimal
AND
OR
Exclusive -OR
110 Compare
111
Not Used
7-32
an
A0-A1 Exchange
instruction,
is
where AO
will
use
AO
binary
AD
SD
Add A1
to
AO
decimal
Subtract A1 from
AO
decimal
AND
OR
EXCLUSIVE OR
AND
OR
XOR
COMPARE
CMP
None
of the Register-Register
These three
struction:
A1
to
be the destination
-of
in
A0.A1
AB
X
A0.A1
Add
is
in
AO
Register-Register Operate instructions are convenient to have, but not vital, since they do nothing that could not be done using Load, Store and secondary memory reference instructions.
Register-Register Operate instructions
will
REGISTERREGISTER
OPERATE INSTRUCTIONS
JUSTIFICATION
and
that takes time.
secondary
memory
reference
instructions,
secondary
memory memory -
There is one further set of Register-Register Operate instrucACCUMULATOR tions which will prove very useful; we will allow the contents of DATA COUNTER Accumulator AO to be added, as a signed binary number, to any ADDITION one of the Data Counters. This allows a data address displacement to be computed, then added to (or subtracted from) a Data Counter.
This instruction
is
where doubly
ADDRESSING MATRICES
VAL
(X.Y)
may be used. If the dimension of Y is known, each increment of X may be handled by adding the dimension of Y to the Data Counter which is addressing VAL. This is illustrated as follows:
7-33
VAL
Data Table
VAL(I.I)
VAL (1.2)
VAL (1.3)
VAL (1.4)
1
To extend this type of matrix handling, we will also allow unit, to be added to any Data Counter.
AOand
We now
10
Bit
No.
11
'"X
.00 DC0
01 DC1
10
1
is is is
destination
destination
DC2
SP
destination
destination
is
_0
1
Add A0 Add A
to
.Add
Address
A0
7
A1
3
2
10
8
10
Bit
No. (8
bits)
15 14 13 12 11 10 9
10
Bit
No. (16
bits)
We will
DAD
S
is
S.D
may be A0
or A;
is
7-34
is
also
BRANCH
TABLES
one
of
branch table
is
list
of addresses, identifying a
logic.
number
of programs, just
which must be
we
will
is
we
will illustrate
real,
ADDR1
EQU
H'1247'
Program
ADDR2 ADDR3
EQU EQU
etc.
H'183C
Program
K28CA'
H'0800'
Program 3
ORG
BTBL
DA DA DA
etc.
ADDR1
ADDR2 ADDR3
The EQU mnemonic, recall, is an Assembler directive; it tells the Assembler what values to assign to the symbols ADDR1, ADDR2, ADDR3, etc. The DA mnemonic is a "Define Address" Assembler directive; tells the Assembler to place the 16-bit value provided by the operand in the next two currently identified memory locations.
it
EQUATE
DIRECTIVE
DEFINE
ADDRESS
DIRECTIVE
ORIGIN DIRECTIVE
The
ORG mnemonic
address.
in
;
is
memory
0800 16
six
In this
memory address
in
as
terms of
memory map,
.
above
instructions result
these
data bytes:
Memory
Address
Memory
07FF
BTBL
n ^ OoOO
~
~
12
ADDR1
0801
47
18
0802
0803
ADDR2 ADDR3
3C
28
0804
0805 0806
The
label
CA
Now
Accumulator A0;
we
DC0.BTBL
for
program addresses
into
DC0
DAD DAD
LNA
AODC0
A0.DC0
Add
the table
number
twice,
two bytes
DC0 DC0
A,PC
identified
by
DCO
LMB
MOV
Move
this
address to PC
7-35
Look
1)
at
what happens:
instruction loads
The LIM
0800, 6
into
2:
DCO.
the
2)
two
DAD
instructions
3)
The LNA
DCO.
memory
location
.
0804, 6
into
Now A0
LMB
CA, 6
DCO
contains 0805, 6
4)
The
tains
memory
location
0805, 6
into
A1.
Now A1
con-
5)
The
MOV
instruction
memory
location
value
28CA, 6
into the
to
is
given
in
Some Register Operate instructions are absolutely necessary, whereas others are nothing more than conveniences. We will therefore identify the ways in which a register's contents may be modified, and determine whether the operation is necessary, or just a convenience.
to increment and decrement registers' contents is universal; whenever a register contains a counter or index, there is the probability that it will have to be incremented or decremented. To some extent, the auto increment and auto decrement variations of implied addressing makes the need to increment and decrement the Data Counters
The need
INCREMENT
AND DECREMENT
less
vital; still
it
it
is
not
always.
Since we have no binary subtract instructions, it is vital that j COMPLEMENT | there be an instruction to complement at least one of the Accumulators. Complementing the Data Counters serves no useful purpose. See Chapter 2 for a discussion of twos complement subtraction.
It
this
is
a frequent prestep.
CLEAR
REGISTER
an
initialization
SHIFT AND
ROTATE
SHIFT
shift
operation
is linear:
o.o.o.o
KJ
lost-*-
in
KJ >u
will
lost.
Thus a simple
order
will
bit
shift left,
bit
as illustrated above,
left, will
having no
to.the
be
move each bit to the next bit to the left; the high There being no bit to the right of the low order bit,
be moved
into the
low order
bit.
7-36
rotate operation
is
circular;
assumed
adjacent:
A
and
i^
AA
would be
ROTATE
(J~
Numerous
variations of shift
shift or rotate left:
<b KJ KJ
rotate operations are possible;
J
you can
SIMPLE SHIFT
AND ROTATE
c
Simple Rotate Left
^3
Simple
Shift Left
You can
D
Simple
2.
Shift Right
A
A
is
equivalent to dividing by
while the
left
is
equivalent to
itself.
multiplying by
of a register to
shift or rotate
shift
and
rotate
SHIFT
AND
ROTATE
THROUGH CARRY
high order
bit
becomes new
value of Carry
low order
bit
left
is
illustrated
right shift
through Carry
is
self
evident.
Another
variation
branches a
bit into
SHIFT
AND
CARRY
The
shift
=FFF =f
7TRotate with Branch Carry
with branch-carry
is
Shift
first in
where an
initial
value of
must be assumed
The
shift
may
also
(sign
bit)
ARITHMETIC
SHIFT
to the right:
6 5 4 3 2
10
Bit
No.
^unchanged
>
7-37
An
arithmetic shift
left will
bit,
6 5 4 3 2
10
Bit
No.
unchanged
i
data.
w
in
is
very useful
microcomputer
applictions,
SHIFTING
As was discussed
four
bits;
in Chapter 2. binary-coded decimal digits each occupy each byte holds two BCD digits. A four-bit shift is therefore equivalent
is,
it
__
to a single
decimal
is
The
four-bit
and
makes
it
easy to pack and unpack ASCII characters. Recall that appears as follows:
2 3
4
5 6
7
8
9
= = = = = = = = = =
00110000
00110001
00110010
00110011
00110100
00110101
00110110
00110111
00111000
00111001
port
Suppose a string of ASCII digits are being read through an I/O format, two digits per byte as follows:
Data as read:
in
BCD
0011 0010
0011 0110
0011
1000
0011 0101
Data as packed:
0010 0110
1000 0101
The
four-bit shift
is
we
will settle
on some
shift
mnemonics, then
BCD
packing operation.
How
Shift
we
have?
in
microcomputer
instruction sets.
We
will
have such instructions for the two Accumulators only, but without Carry (simple), with Carry, and with branched Carry.
it
we
will
a luxury
will
we
would provide
We
In
include
two
left
of either
will
and right shift. One will operate on the contents operate on the combined unit as a 16-bit number.
Accumulator
will
we
shift operation.
We can
now summarize
7-38
For the operations which are confined to the Accumulators, these are the instructions and their object codes:
7
1
6 5 4 3 2
1
10
Bit
No.
A
.
0000
0001
001
Simple
shift left
0010 Simple
0100
0101
rotate right
left
Simple rotate
Shift right
through Carry
Shift left
through Carry
with branch Carry with branch Carry
0110
0111 1000
1001
Shift right
Shift left
1010 Clear
register
AO
contents contents
Operate on
The
shift
and
rotate instructions
status.
may modify
The Complement
instruction will
affect the
Zero
No
The two
ject
codes
4-bit shift instructions can operate on AO, A1, for these instructions will be as follows:
A(A0
W
Address
registers;
6 5 4 3 2
Bit
No.
.1
1101
1110 Operate on
contents
and on the The Increment and Decrement instructions operate on the Accumulators
they
will
6 5 4 3 2
1.1
10
No.
000 Operate on AO
001
01
Operate on
010 Operate on A
Operate on DCO 100 Operate on DC1 101 Operate on DC2
Increment register contents Decrement register contents
7-39
will
SHIFT
AND
ROTATE
INSTRUCTIONS
SRAA
SRAB SLAA
SLAB SR4A SR4B SL4A
SL4B SR4 SL4
CONTENTS RIGHT SIMPLE CONTENTS RIGHT SIMPLE CONTENTS LEFT SIMPLE SHIFT A1 CONTENTS LEFT SIMPLE ROTATE AO RIGHT SIMPLE ROTATE A RIGHT SIMPLE ROTATE AO LEFT SIMPLE ROTATE A1 LEFT SIMPLE SHIFT AO RIGHT THROUGH CARRY SHIFT Al RIGHT THROUGH CARRY SHIFT AO LEFT THROUGH CARRY SHIFT A1 LEFT THROUGH CARRY SHIFT AO RIGHT WITH BRANCH CARRY SHIFT Al RIGHT WITH BRANCH CARRY SHIFT AO LEFT WITH BRANCH CARRY SHIFT A1 LEFT WITH BRANCH CARRY SHIFT AO RIGHT ARITHMETIC
Al
1
SHIFT A1 RIGHT ARITHMETIC SHIFT.AO LEFT ARITHMETIC SHIFT A LEFT ARITHMETIC SHIFT AO RIGHT FOUR BITS SHIFT A1 RIGHT FOUR BITS SHIFT AO LEFT FOUR BITS SHIFT A1 LEFT FOUR BITS SHIFT AO AND A1 RIGHT FOUR BITS SHIFT AO AND A LEFT FOUR BITS
1 1
we
will
in-
INCREMENT
REGISTER
INC
may be
DC2
DECREMENT
REGISTER
DEC
Complement and
and
will
two Accumulators
only,
I
'
COMPLEMENT vmrixmtnt
CLEAR
|
CLA
CLB
Clear
AO
Clear
COA
COB
These four
instructions
Complement AO Complement Al
have no operand.
7-40
We will
ples of
now illustrate the value of Register Operate how these instructions may be used.
shifts;
instructions with
some exam-
Consider multibyte
SHIFT
and divided.
status,
ple,
rotate
through Carry
propagate a
shift
down
number
MULTIBYTE
sim-
bit of
may be
three-byte
start
C
Stepl:
assumed
l
initial
status
|0[1|1|0|1|Q|1|11 /Il|0|lill0llf
0r\ l^
>
Step
2:
J0I1I1I0I1I0I1TTI |0IH1|Q|1|0|1|0|
ll
Ml MIOlHOlol
Step
3:
I1I1I0I1I0I1I1I1I
I1I0I1I1I0I1I0I0I
The program
to
perform
this
operation
is
as follows:
LIM
DCO.
starting
address
in
DCO
LMA
SDA
DCO
DCO DCO DCO DCO DCO
into
AO
via
DCO
branch carry
DCO
LMA
SLCA
into
ACO
DCO
SDA
LMA
SLCA
Load
last
byte
SMA
The LIM
address of the
last
7-41
step 1. First. LMA loads the low but does not modify the address in DCO, since we will want to same address. The SLBA instruction is very useful at this point because it performs a branch carry; we do not know what the Carry status is before enterinq this routine, but with the SLBA instruction we do not care; this instruction loads into the low order VeS the high rder bit f A0 Int0 the Carr sta ready to be^hrfted into the V ?k next byte. Tu SDA mstructioa stores the The shifted contents of AO back into the memory byte from which the unshrfted source came; then the address in DCO is decremented to point to the second byte
instructions.
AO
'T
^.
The next three instructions. LMA. SLCA and SDA perform step 2. These three instructions differ from the previous three instructions only in that a shift left with carry must now be performed since the Carry status represents the high order bit of the previous byte, which must become the low order bit of the current byte.
Step 3
is
ts dress
differ
in
accomplished via the last three instructions. LMA. SLCA and SMA; these three instrucfrom the three step 2 instructions only in that we do not bother to decrement the adDCO. since there are no more bytes to be shifted.
Observe that since only three bytes are to be shifted, we do not use an instruction loop The whole of the program above only occupies 12 bytes, three for the Load Immediate into DCO instruction, one each for the remaining instructions. We could condense the three steps into one set of three repeated instructions so long as we can change the SLBA to a SLCA instruction and so long as the final SMA instruction becomes an SDA instruction. The program now appears
as
which must
initially
be
!^ LIM
,
LOOP
LMA
SLCA
DCO
DCO
A1
Load buffer startin 9 addres s m DCO Load byte count into A1 Load next byte into AO, via DCO
Shift left
with Carry
SDA
DEC BNZ
DCO
LOOP
a program with e.ght instructions versus the previous ten. But these eight instruc going to occupy 12 bytes; three for the Load Immediate into DCO. two ach or the Load Immediate into A1 and the Branch on Non-Zero, and one each for the emamder
We now -have
ions are
st,H
t structure offers
Thi
is
'
as
lterat ' nS
we described reference instructions could be tested for "on" or "off" status in a program loop as follows:
when justifying secondary memory
1)
SWITCH
TESTING
T ^
A
k" branch carry
into
A1
in
been performed.
AO.
aS 3 SW tCh COunter * contents will be the Carry status, which will indicate 'nuicaie that mat
'
AO one
bit right in
bit
of
AO
is
now
bit
in
4)
Save
AO and A1
reflects the
low order
of
AO
Move
program
"
"^ **"
"^
n " Program
"
therWISe
COntinue Wlth
"
sw *ch off
7-42
6)
When
Shift
the "switch on" or "switch off" program has completed execution, reload
AO and A1
from DC2.
7)
A1
left
one
bit
If
Carry
is
set,
we
are done.
If
Carry
is
step 3 above.
above
LIM
IN
A1.1
4
Load 01
into
A1
LOOP
SRBA
AO
right
MOV
BC
A.DC2
Save AO and A1
DC2
SWON
MOV
SLBB
DC2.A
Restore
Shift
AO and A1
left
from
DC2
Now
PACKING
ASCII DIGITS
bits (low order four bits) of ASCII numeric digit representations; two numeric digits will be packed per byte, as described directly before
shift
object codes
illustration.
to
pack
digits:
in
Step 2
Step 3
move
read
in
one ASCII
four
bits.
digit
and store
Accumulator AO.
shift left
the contents of
AO
to
A1. A1
ASCII
now
digit:
00
XXXX
After four
XXXX0000
Step 4
Step 5
mask out
follows:
AO now
digit:
bits:
ASCII
After masking high order
0011YYYY 0000YYYY
as follows:
Step 6
Add A1
store the
to AO.
AO now contains the high and low order digits 0000YYYY + XXXX0000 = XXXXYYYY
digits in
Step
two packed
memory (we
two ASCII
will
assume the
correct buffer
is
addressed
byDCD.
Step
8
will
return to step
digits.
We
assume
5,
and
bit
of
I/O Port 6
5.
is
set to
by the
inputting device
whenever
it
digit to
I/O Port
7-43
LOOP1
IN
Input status
Shift bit
SRBA
BNC
LOOP1
6
of
is
AO
If
Carry Carry
0.
1,
OUT
IN
If
is
output
AO
to I/O Port 6
SL4A
bits
MOV
LOOP2
IN
A0.A1
Save
in
A1
first
Repeat
five instructions
SRBA
BNC
LOOP2
6 5
H'OF'
.
OUT
IN
NIA
Mask out
AB LDA JMP
Add A1
to
AO
digits
DCO
LOOP1
Store the
two packed
STACK INSTRUCTIONS
Since our microcomputer has a Stack, it must have Push instructions to move registers' contents onto the Stack; it must also have Pop instructions to move data off the Stack, and into registers.
the Jump-to-Subroutine init pushes the Program Counter contents onto the Stack before loading a new address into the Program Counter.
list
JUMP-TO SUBROUTINE
Push instructions will be used primarily for interrupt processing; programming examples are given along with interrupt
handling
instructions.
I
'
PUSH
I
'
Pop instructions are used in interrupt processing, and in order to return from a subroutine; examples of the latter use are
given
shortly.
POP
RETURIM-FROMSUBROUTIIME
Push and Pop instructions are sometimes used to pass data (parameters) to subroutines; we will illustrate this use of Push and Pop instructions later.
SUBROUTINE
PARAMETER
PASSING
Our microcomputer
will have Push and Pop instructions that reference the two Accumulators, and the four Address registers; object codes will be as follows:
6 5 4 3 2
Bit
No.
nun
t
in
k
000 AO selected
001
01
selected
DC
selected
110 PC selected
Push
1
Pop
Stark instruction Rf
OP
OP
R
represents the instruction mnemonic;
it
R
be
will
PUSH
or POP, for a
Push
or
Pop
instruction,
respectively.
will
data
Stack. R
whose contents is to be pushed onto the Stack, or which is to receive may be A0, A1, DCO, DC1, DC2 or PC. No oth er symbol is allowed
RETURN
INSTRUCTION
The
instruction:
POP
will
PC
move
the
two bytes
at the
top of the Stack into the Program Counter, thus effecting a return
RET
will
mnemonic
perform the same operation, and generate the same object code; will generate the one object code byte:
7
1
in
RET
6 5 4 3 2
1
10
1
As an example of Stack instructions' use. return to the data movement subroutine which was described along with Immediate instructions; the subroutine was listed like
this:
MOVE
LOOP
LIM
DC0.BUFA
DC1.BUFB
Load source
initial
address
LIM
Load destination
initial
address
LNA
SSA
DCO
Move
DC 1, LOOP
to destination
7-45
addition to adding a Return instruction, this subroutine can be made useful if the beginning addresses for the source and destination buffers (BUFA and BUFB) are variable. Stack instructions provide one way (but not the best way) of making this possible.
In
more
PARAMETER
PASSING
MOVE,
its
BUFB onto
BUFA and
LIM
DCO.BUFX
PUSH
LIM
DCO
DCO.BUFY
PUSH
JSP,
'
DCO
MOVE
The top
of the Stack
now
looks
like this:
Stack
address of
instruction following
JSR
Address BUFY
Address BUFX
I
Subroutine
MOVE
must be modified as
follows:
MOVE
-
DC2
DC1
in
DC2
initial
address
DCO
DC2 DCO DC 1, LOOP
initial
address
LOOP
PUSH LNA
SSA
RET
at
top of stack
Move
Pop
to destination
at instructions
move
subroutine which
we
this po.nt.
data from a source buffer with a dedicated address, to a destination buffer with another dedicated address.
Next,
the
first
moved
when
Pop
instructions
we
improved on the
subroutine by allowing the calling program to specify the PARAMETERS source and destination buffer beginning addresses. These two addresses are called "parameters", which the calling program passes to the subroutine. Parameter passing is a very important feature of subroutine handling; by making parameter passing easy a microcomputer becomes a significantly more powerful device.
versatility of this
SUBROUTINE
7-46
Parameter passing instructions are, in fact, quite simple to specify. What we will do is to allow parameters to follow the Jump-to-Subroutine instruction, then we will provide the microcombecome the puter with a form of indirect addressing, where the two bytes at the top of the Stack
data
will
be fetched.
But before we explain this concept with pictures and examples, let us define the parameter passing instructions which our microcomputer will include.
First,
6 5 4 3 2
10
I
Bit
No.
ololol
01
Pass parameters to
to
A0
A1
Pass parameters to
Pass parameters to
Pass parameters to
DC0 DC DC2
1
The
as follows:
PASS PARAMETER
INSTRUCTION
SPP
SPP
is
the instruction mnemonic, and R identifies one of the registers A0, A1, DC0.
is
DC1
or
DC2
no other symbol
allowed for
R.
PASSING
PARAMETERS TO
SUBROUTINES
be called as follows:
JSR
MOVE
BUFX BUFY
Call
data
move
subroutine
DA DA
DA mnemonic
in
instructions reside
memory
as follows:
Program
Memory
-
04C0
PC.
^04C1
04C2 04C3 04C4 04C5 04C6
04C7
0478
10111101
20
tl^
80 08
> BUFX
00 08
>
BUFY
40
7-47
After the
JSR
instruction
has executed, PC
will
is
subroutine
MOVE. The
04C4 16
will
be
at the
Stack
SP 04
C4
The
MOVE
MOVE
LOOP
SPP
SPP
DCO
DC1
Load source
starting
address into
DCO
Load destination
starting
address jnto
DC
LNA
SSA
RET
DCO DC 1. LOOP
Move
Pop
to destination
The
1)
first
SPP
instruction
causes the
CPU
logic:
at the
2)
by
this
address
is
then
.
contains 08, 6 Therefore, at the end of this step, the high order byte of value 08, 6 and the memory address has
a memory address. The contents of the memory location memory address are loaded into the high order byte of DCO The memory incremented. The memory address was 04C4 and memory location 04C4 16
16
DCO
contains the
been incremented
to
04C5 16
3)
Step 2 is repeated, with the data fetched from memory going to the low order byte of At the end of this step DCO contained 0800 16 and the memory address is now
,
DCO
.
'
04C6 16
4)
Instruction execution
is
is
which
now
04C4 16
The second SPP instruction ,s a repeat of the first SPP instruction, except that DC1 is specified as the destination: therefore, at the conclusion of the SPP instruction. 0840 16 will be stored in DC1 and the top two bytes of the Stack will hold the value 04C8 16 This is the address of the next instruction to be executed following the two parameters. BUFX and BUFY. At the conclusion of the Move subroutine, the RET instruction will pop the value 04C8 16 back into the Program Counter tnus allowing normal program execution to continue.
.
INTERRUPT INSTRUCTIONS
In reality we are going to talk about more than interrupt instructions. There are only three interrupt instructions; one disables all interrupts, the second enables all interrupts, and the third is a Retum-from-lnterrupt instruction.
How
is
similarities between processing an interrupt and entering a each case, program execution temporarily branches from a mam program to a secondary logic sequence, at the conclusion of which program execution returns to the main program. The difference between a subroutine and an interrupt is that a Jump-to-Subroutine is part of the scheduled mainstream logic:
Main Program
2\
^SubroutineX
An
interrupt on the other hand, is an unscheduled event, and the main program has no way knowing when the interrupt will occur:
of
Interrupt!
Main
Program
We
Chapter 5. the various ways in which external devices can interCPU's interrupt protocol becomes more minicomputer-like, and more sophisticated, so also the cost and complexity of the external logic needed to meet the reInquirements of CPU interrupt protocol goes up. We will therefore adopt a very simple scheme. when the CPU terrupting devices will be daisy-chained on a single interrupt request line, and sends out an acknowledge signal, the interrupting device will output a single byte of data to an
discussed at
some
length,
in
rupt the
CPU.
CPU
will interpret
the data
in
in-
terrupting device.
interrupt,
it
will automatically
do three things:
interrupt from being processed before the First, it will disable interrupts, thus preventing another must be executed by current one has been adequately handled. An Enable Interrupt instruction
Next the
CPU
will
flags'
Finally the
CPU
will
and
memory
location 0.
instruction can be executed at any time to prevent any interrupts from being acknowledged; this condition will last until the Enable Interrupt instruc-
A Disable Interrupt
tion
is
re-executed.
first
Let us
look at the object code for the Enable and Disable Interrupt instructions:
Interrupt procesing instruction specified
t
7
6 5 4 3 2
JL 10
Bit
No.
MiliMMiM
Enable interrupts
.1
Disable interrupts
7-49
The mnemonics
Dl
for
ENABLE INTERRUPT
DISABLE INTERRUPT
and
El
for
Enable Interrupts.
The Return-from-lnterrupt
First
it
instruction will
do three
things:
RETURN
will
matically
when
the interrupt
FROM
INTERRUPT
Then
it
will
pop the
Program Counter.
enables interrupts.
The Return-from-lnterrupt
7
instruction's object
No.
code
will be:
6 5 4 3 2
1
1 .1 1
10
1
1
Bit
X
The
instruction
RTI
mnemonic
will be:
To
illustrate
we
will
show
In-
terrupt
Acknowledge.
We
will also
show
the program steps which must be present at the end of the interrupt service
routine.
INTERRUPT
ACKNOWLEDGE Acknowledge, the CPU logic saves the status flags at the top of the Stack, pushes the Program Counter contents onto the top of the Stack, then disables interrupts. The Program Counter is zeroed, which means that program execution jumps to memory location 0.
At the time of the
Interrupt
2)
memory location 0. there is a short program #sequence which saves the contents CPU registers by pushing registers' contents onto the Stack. This is necessary, since the registers may be used in any way by the program which is about to be executed.
Starting at
all
of
3)
After
read,
all
registers'
is
and
contents have been saved on the Stack, the contents of I/O Port FF 16 is used to compute the starting address of the particular program which will service
7-50
4)
optionally contain
an Enable
Inter-
this instruction
is
may be
First Interrupt
Main Program
Second
interrupt
service routine
If
until their
Retum-from-
Interrupt instruction
executed-.
This
is
the instruction sequence which, given our interrupt service logic, must be present begin-
ning at
memory
location 0:
ORG
PUSH
PUSH PUSH PUSH
AO
A1
Save
all
registers'
contents
on the stack
DCO
DC1
PUSH
IN
DC2
H'FF' Input device ID from I/O Port FF
LIM
DCO.BTBL
SHLA
AO
left,
simple, to multiply by 2
DAD
LNA
AO.DCO
Add AO
Load the
starting
to
DCO
DCO DCO
A,PC
LMB
address
MOV
This
is
Move
the address to PC
the
current
tells
memory address
for
SAVING REGISTERS
creating object
memory
location 0.
ON STACK We
in
The five Push instructions save the contents of aH registers on the Stack.
The
IN instruction will receive a device ID at
are
CPU
to execute the
at
Push
ID
number
number
7-51
will
be
Accumulator AO.
The instructions from LIM to MOV constitute a branch table. Branch tables BRANCH were described along with the DAD Register-Register Operate instruction. TABLE Notice in the branch table instruction sequence above that a Shift instruction has been used to multiply the contents of AO by 2 before adding to DCO; in the previous
ample, the
ex-
DAD
instruction
was executed
same end
result.
The address computed by the branch table becomes the beginning address of the interrupt service routine, which will now be executed to service the specific device which requested an interrupt. Once the interrupt service routine has completed execution, will call a subroutine that reverses the interrupt acknowledge steps as follows:
it
RINT
DC2
DC1
Restore
all
registers'
contents
DCO
A1
AO
Observe that registers are popped from the Stack in the reverse order to which they were pushed, since the Stack is a last-in-first-out storage unit.
RESTORING REGISTERS
The
final
RTI instruction
will
is
on the Stack
will
FROM STACK
acknowledge.
Counter the
If
interrupts are
Program execution
now
STATUS INSTRUCTIONS
we have four status flags. Sign (S). Carry (C), Overflow (O) and Zero (Z), it must be possible to set or reset these flags individually. The most common situation in which
Since
program logic will rquire a flag to be set is just before entering a program loop which contains a Branch on Condition instruction at the beginning of the loop. In the normal course of events, status flags will be set later in the loop to be tested when program logic comes back to the beginning of the loop. It must be possible to set status conditions before entering the loop, so that can get by the Branch on Condition on the first pass.
we
There are also many multibyte arithmetic algorithms which require the Carry and Overflow statuses to be either cleared or set before starting the algorithm; subsequently, after each byte of
the multibyte
number
is
processed, carries are passed from one byte to the next via these
in
two
Chapter
2.
We
6 5 4 3 2
i
10.
i i
Bit
No.
loioiohni
00
Select Sign
(S)
__0 Reset
1
status to
1
Set status to
7-52
STATUS SET
SET
STATUS RESET
J
RES
each case. X may be
C. O.
X
one
of the four status flags.
In
or S, to identify
No
other symbol
is
allowed.
As an example
addition routine, described along of status instruction use. the multibyte. binary status: reference instructions, starts out by clearing the Carry
memory
RES
LOOP
LMA
ABA
SSA
DCO
DC1
Add
binary from
answer
buffer
DC 1, LOOP
addition
Once
in
the
loop.
the.
binary
instruction
ABA
sets
and
resets
the
Carry
status
appropriately.
HALT INSTRUCTION
Every microcomputer has a Halt instruction.
When
this
instruction
is
executed, the
microcomputer that has a front panel, microcomputer simply stops. In a minicomputer, or in a on the panel. So far as the CPU is conprogram execution is restarted by hitting a restart button described in Chapter 4) must be signal which is input to the CPU (and was
cerned, the reset
pulsed
In
in
order to
start
the Halt instruction object code conour microcomputer, and in many other microcomputers, since unused memory words frequently contain bits This is done with good reason, all while being debugged, makes a wild jump and tries to exbits In the event that a program, all no instructions exist, there is a very good in some area of memory where ecute instructions which will cause the pronext instruction object code
sists of
chance
that
it
will pick
gram
to simply stop,
The
Halt instruction
mnemonic
appropriately:
HALT
when any
instruction
is
executed.
We
instruction set with summary Table are going to summarize our hypothetical the instruction sets for real 7-1. In Volume 2 similar tables will summarize
microcomputers.
7-53
In
ACO
AC1
ACO
address
Accumulator AC1
ADDR
C
A
An
16-bit
memory
Carry status
8-bit binary data unit
DATA
DCO
DC1
Data Counter
DCO
DC2
DC2
OCX
DISP
Any
data counter
An
displacement
DST
I
Any
Any
destination register
status indicator
Overflow status
An
Any
PC
R S
Program Counter
register
Sign status
SP
Stack Pointer
SRC
Any source
Statuses
register
SW
z
Zero Status
Contents of location enclosed within brackets. If a register designation is enclosed within the brackets, then the designated register's contents are specified If an I/O port number is enclosed within the brackets, then the I/O port contents are specified If a memory address is enclosed within the brackets, then the contents of the addressed
memory
[[]]
Implied
memory
memory
contents of a
register.
A
V
Logical
Logical
AND
OR OR
in
V
*~
<
logical Exclusive
Data
is
is
transferred
Data
STATUSES
in
Table 7-
course of the instructions' execution. If there it had before the instruction was executed.
the
is
no
X.
it
means
7-54
c
03
skip
ment
03
skip
in
1
^
skip
X u Q
^ 1
^
1
\3
_ O
03 " c i O CO D
O.
Cl.'-
:'s^
cnO $
x
i
S^2
b
X o ^u5 - Q ^
CO,!,
"3
XrX> o >
.^
x
>
en
03
*
O)
o UJ 2 cc O u.
CC UJ a.
_ co
z
i-
3 O
o
Q o_ _ "Q
CO
03,1, 03,1,
03
X-CX-C
"o
a)
X
-o
t5
O
"~
T-
o
c
o
a-
o
>-
f
$
en
s |
<>
c-qC-qC Scwc.cn
S
<
J -o 7 o. c .9
E
Q-
= cl
en
^2^S"Om^7
ii=
ro
7 t
CO
en
O)
Q3
7 .9 Q.
fCO
cn^--"
i_i
o o 3
00
5
cc UJ a.
O
t
o
-
(D
^'
X U D) y -n< ro
e
Q-
Si, 8
r
|s ES ~
t
Q.
'
?-
c
03
^
o
^g--03^03^0)><|2l j|
i-iU^'G
Q. O-
<
O
o o b
Q-
<O
gliliSS888^ 5< 5^ 5
I
CJ
CD
8li.|
05 UJ 0)
03
<^<i2
03 <"
Q.
Q.rin-Ori,T3ri,-OX
co
S O
"5
03
CO
_c
o
Q.
(0
1M
1-
O
2co
< O
(0
E E 3
O
0) UJ
CM
CN
<
-7
r~-
CM
CM
_
..
03
to
5 z
<
CO
Q_
Q_
O
o z o
2
UJ
EC UJ a.
QOxXXXXX 88888
DC
DC
CC
Q Q < X u a
CC
O Q < X y o
o
oo
Z
UJ a. >-
3 O
<"
<
f 1
Z
2
Q S
CO.
^ 1
& a
CO co _1
CD
i-5
CO
<
CO _J
< CO
CO
33U3J3J,ati
0/1
AJOUJSI/VI
AJBUIUd
7-55
en
Q Ul
oc oc UJ CL
x
77
"
x
__
oc
"
ra x ?
O)
Q_
CO
o u.
T 6lEV "
;
T3
en I
'
,_
ra^TS^. <^ *c
"
to
-n :=
o
< oc
"5 5^<
s~
<
*JL
O.JL
0)1
o
<
II
U Q U Q O u Q
II
CN
UJ Ol
g^glglS^x-g^X^x.cgogoO
^.i^i^'lj,'!^ E" E" S ^-^ - l*" f o So So o OnOnoQoQ oo o rr*o ny >u >u y 5y y o<u< youougog
o
E
2r
cc
QC
o c
CD
B
T3
CO
^<^<^<^c7^^UU*U*E
(/)
CD
E E
T3
03
UJ
z> i-
w X N
XXX
X X
X
oo
X
'
X
X
X
X
X
X
< o X
X X ^
o X
</)
X ^
Ul
>
03
co-
cr>
^-
co
<
co
co
<
CN
CO
^^
(0
'
Z5
z
<
DC UJ 0.
oc
cr
cc
cc
tr
< 1< O
cc
< r< Q
<r
O o z o
Ul
z 2
< <
:
<<<<QQ<<OOXXU
:
2
_i
2
_i
> 1.....
Ul 0.
Ajouja|/\|
aieipauiuj|
7-56
^" < <u- O _. < < o< < O + o" o" o < <<"o
I
a: 1
Q
-
Q-
Q
SD.
.2
t;
S <^<
< H-
0)
<
a
32 CD
^ Q <
i
CD
O u
^3
co
co
U
73
" " "
u
"
u
" "
a ^a
Q* > 5 _ O ^ ^
?
tu
l-|oI-|o|-iolo|^
Q-Q. Q or
O) 11
u
II
u
II
c!<l
111
-ill
X
'
'
'
'
'
II
II
II
II
II
88 < <
<-
n^m5u2u2o2o2co2co2
i
X
X
X X X
(0
z <
EC
O
< < < z < z
UJ Q.
o < o
c_>
<
ai&iedo
e^eipeuiuii
dump
i*0
UOIlipUOQ qouBjg
7-57
o u.
DC
oc
Ol
<->
.-.
cd
II
y to
5
co
a
E
oj
^-
O C O CD c
CD
Q._g>
'55
g-
r3
E a>.E E ~ m
J"?
fe
,-,,-,<,-,
o<o
C )
I
o|
<
II
I
g,
c x
0)
to
^ en CO g
UJ
>o> <j^ ig* So o > ^ ^ UU > < < E< Q o <^ c s %\< JUJL 3 si < o o o u |og o o U Q.H- D O o<u< << E ^ < < < < oQ
**> cd *-.
<r
O
I )
oc
t- CO
2r
*-
co
ca
CD
en
II
T3
X! "O
en
LU
T3 CC CO
CD .Ji' CD
<<
j;
j;
CD
03
XXX
X
pp no
mm
oq co oo
COCOOCOC
O X
8AO|/\|
CC
CJ
Q 5< Q
Or
CO CO CO CO
XlOOccJjar-j
alejado
jaisiBau-jaisiBau
aiejado
ja^siBay
QaU-Bsy
7-58
TO
Q_
<0)
2
H3
CD
oo <^
E
(D
B
<B
M" -
_c
V> <2
'
'
n
oo
IM
ii
i
o*
-c
^
<o
~^ ^
-H-
cU
u
II
'
-Eir .O)^
00 DC
1-1
a3
i
-^^<<^
+ _ ^ o o o o O Oi
fe O O O O
<<<<-DT3 ->-'- c
c
CO
a 00 g 1Q "=&
*
4- Q. -^ oo
u Q.
E^~
2
en
.Z,
o)<r o_
Q-Q. u oo
2 =
CO
<
fc
<<<<<<
<C
^
5
(Dpi,
ro
2
or
>
00 00 00 00 CO 00
X X
X X X X
XX XX
X X
5
z <
DC
(0
IU o.
o
tr _j cc _j oo 00 00 00
<<3S
55<<
cc _j cc _i cc _i oo oo oo oo oo oo
y ^
SSBJ
>|0BS
(penuiiuoo)
9)8J9dO J8|Sl6SU
uiejed
idrujaiui
snms
7-59
APPENDIX A
ASCII
(7 bit)
EBCDIC
(8 bit)
Hexadecimal
Representation
3F
ASCII
<7bit)
?
EBCDIC
(8 bit)
40
2 3
@
A
B
blank
41
4
5
6
7
8
9
42 43 44 45 46 47 48
49
C D
E
F
G H
I
A
B
4A
4B
,4C
K
L
<
(
D
E
F
4D
4E
4F
M
N
P
+
1
10
11
50
51
&
12
Q
R S
13
14 15 16
17
52
53 54 55 56 57 58 59
U V
18 19
w
X
Y z
[
1A
IB
5A
5B 5C
1C
$
*
1D
1E 1F
\
) I
5D
blank
l
20
21
5E 5F 60
61
a
22
23 24 25
#
$
62 63 64
b
c
%
e
(
d
e
f
26 27 28 29
65 66 67 68 69
g
h
i
2A
2B 2C
+
I
6A
6B 6C
k
1
2D
2E
%
> ?
6D
6E 6F
m
n
2F 30
31
o
1
70
71
P
q
r
32 33
3
4
5
72
34 35 36 37 38 39
73 74
75
s
t
6
7
u V
76
77
8 9
w
X
78 79
3A
3B
V
z
7A
<
3C
3D
3E
>
7B 7C
# @
7D
A-1
APPENDIX A
Hexadecimal
Representation
7E 7F
(continued)
ASCII
(7 bit)
EBCDIC
(8 bit)
Hexadecimal
Representation
BF
ASCII
(7bit)
EBCDIC
(8 bit)
CO
C1
a
80
81
A
B
82
b
c
83 84 85 86 87 88 89
d e
f
C2 C3 C4 C5 C6
C7
D
E F
G
H
I
g
h
i
C8 C9
CA
CB
8A
8B 8C
CC
CD
CE CF
8D
8E 8F
DO
D1
J
90
91
]
D2
k
I
K
L
92
93 94 95 96 97 98 99
m
n
P
q
r
D3 D4 D5 D6 D7 D8 D9
M
N
P
Q
R
DA
DB DC DD
DE DF
EO
E1
9A
9B 9C
9D
9E
9F
AO
A1
E2
s
t
A2 A3 A4 A5 A6 A7 A8 A9
u V
E3 E4 E5 E6
E7 E8 E9
S T
w
X Y
z
w
X y
z
EA
EB EC
AA
AB AC
ED
EE EF FO
F1
1
AD
AE AF
BO
B1
F2 F3
2 3
B2
B3 B4 B5 B6 B7 B8 B9
F4
F5
4
5
F6
F7 F8
6
7
8 9
F9
FA
FB FC
BA
BB BC
FD
FE
FF
BD
BE
A-2
AN INTRODUCTION TO MICROCOMPUTERS
\WFil
BY
ADAM OSBORNE
SYBEX
PUBLICATIONS DEPT.
313 Rue Lecourbe
75015
relex:
PARIS, FRANCE
200858 Sybex
LIST
LfSte
\&&
Mil