Professional Documents
Culture Documents
Several alternative strategies for input and output for microprocessors are described, with
examples for 8080 machines and the S·100 bus. The strategies are compared in terms of cost,
complexity, flexibility, and speed in typical psychology laboratory tasks. Flag testing, interrupt
processing, and direct memory access are considered in both parallel and serial modes.
The recent proliferation of microprocessors has device "borrows" the system memory to make the
made computing power available to more psychologists actual transfer. Like interrupt processing, the main
than ever before. As machines are installed in labora- program is unaffected, but there is no software support
tories, the need for implementing various input and in DMA. Instead, logic wired into the DMA device
output devices will become more apparent. Since many itself determines how the transfer is to be accomplished.
microcomputer systems are designed around standard Output processing is handled similarly. Usually the
bus structures (such as the S-lOO), peripherals from computer outputs to a relatively slow device such as a
many manufacturers may be used with a single main printer. Consequently, the computer must wait for the
computer. In addition, blank prototype boards for device to complete each operation before sending it the
custom circuits are available at low cost. Many psych- next command. A flag-polled output driver waits in a
ologists, then, will need to evaluate a variety of loop for the peripheral to send a "done" signal, indicat-
peripherals, and some will design circuits for their own ing readiness for the next command. An interrupt-driven
needs. output interface sends a command and is free to execute
The purpose of this paper is to present an overview a main program while waiting for the peripheral to
of some alternative strategies for implementing input complete its operation. When the peripheral is ready, it
to and output from microprocessors. These strategies interrupts the processor, which in turn sends the next
are compared in terms of cost, speed, complexity, and command.
flexibility for use in typical laboratory tasks. Examples Serial and parallel I/O modes are distinguished in
are taken from a system using the 8080 microprocessor terms of the hardware that actually transfers the data. In
and the S-100 bus configuration. Although other serial I/O, the data are available one bit at a time on one
machines may vary in details, much of the conceptual Wire, ordered in a precisely timed series. A group of
material cuts across various microcomputers. 8 bits (called a "byte") is preceded by a start bit. The
serial interface (often implemented around an LSI chip
MICROCOMPUTER INPUT AND OUTPUT called a UART, for universal asynchronous receiver-
transmitter) looks for each data bit at a specified interval
There are basically three strategies for accomplish- after receipt of the start bit. The data word is usually
ing input and output (I/O) in microcomputers (Smith, terminated by one or more "stop" bits as well.
1977): flag testing, interrupt processing, and direct Parallel interfaces, by comparison, are composed of a
memory access (DMA). Flag testing and interrupt pro- series of separate wires (eight in most microprocessors)
cessing can each be subdivided into serial and parallel where each bit of the data is made available simultan-
modes. In flag-testing input, the program tests a "flag" eously. A ninth wire often serves as either a "flag" or
bit while waiting in a loop. When data from a peripheral input to an interrupt circuit depending on the type of
becomes available, the flag bit changes state and the I/O being used.
program exits from the loop to accept the data. In
interrupt-processing input, a main program is free to FLAG TESTING
execute until the data is available. At that point, an
"interrupt" line on the processor is activated by an Figure 1 illustrates a portion of an assembly language
external device, and the program branches to a separate program written for the 8080 that implements a flag-
"interrupt service routine" to accomplish the transfer. testing algorithm for input (Scelbi, 1976).
When the transfer is complete, the main program The S-100 hardware for this application is shown in
resumes at precisely the point at which it was inter- Figure 2 (Lancaster, 1974). The interface consists of a
rupted. DMA devices accomplish I/O by sharing the series of eight simple switches that represent alternative
memory with the processor. When data is available, a responses from a subject (SI-S8). (The switches are
processor line called "hold" is activated, and the DMA assumed to be "bounceless.") These are connected to a
249
250 GOLDBAND
Figure 1. Assembly language subroutines for flag testingand interrupt for the 8080 processor.
*+ 5
R1: Rt;>R3~ > R4 R5: R6. R7· >R8.
• >
> • 5.6K
51
~f2
~~
~IS!l
7430 E10
NAND
1.0..
r- E1
PORTO
Decoders
~~6
~S7
~_~.~<S8 PORT 1
Decoders
-=-. ~ 010
~ 011
~
E1-9:74367
~
v:::: 012
E10 7430
R1-8 5.6K ~ 013
~ 014
W
V::: . 015
~ 016
~
~
017
Figure 2. Parallel port hardware for flag-poUed input for the 5-100 bus and 8080 processor.
INPUT AND OUTPUT FOR MICROPROCESSORS 251
~+5
>-
Rl: .~ ~IB' ~IM
>-
R~ ~; ~~>
R7:>R --
'I
•> •~ • ?
~
'I
SINTA
~~+5
Sl RiO'
~P2 ~
o CLR Q
~S3 7474
~P4 E1 Ei9
SI NT
~IS5
I-..
7430 ~ C SET Q pORT1
~~6 0ecoders
1_/}7 SINTA
J~8 *+5 ~
R9~ POBIN
.
-...:- »:
?::: 010 ~ 010
Ri-RiO 5.6K ~
z»: OI1"~~
L.--:::: 011
E17430 ~
~
012 ~~ 012
E2-E17 l.--:::
1/6 74367 ~ 013 E~ 013
E 1/4 7408
18
E19 112 7474 ~ 014
~
....L.--;::: 014
E20 1/ 67404 ~ 015 ~
....v:::: 015
~ 016.. ~ 016
~ OI7 ....... ~ 017
-'-
Figure 3. Parallel port hardware for interrupt-processed input for the S-IOO bus and the 8080 processor.
252 GOLDBAND
cutes the RST instruction by jumping to one of eight DIRECT MEMORY ACCESS
contiguous locations on page 0 of memory, where an
interrupt service routing (ISR) must exist. SINTA is The third class of I/O devices commonly used in
also inverted by E20 and clears flip-flop E19 in readi- microcomputers is DMA. These are complex peripherals,
ness for the next interrupt. usually designed to accomplish a particular job very
Note the increased complexity in the interrupt efficiently. DMA devices are often actually other micro-
compared to the flag-polled software presented in processors that share the same memory as the main
Figure 1. This is necessitated by the fact that the ISR processor. Although many high-speed peripherals avail-
must maintain the integrity of all registers by first able to psychologists use DMA, such as floppy disk
PUSHing them on the stack, and then POPing them off controllers and video interfaces, it is unlikely that many
before relinquishing control. In addition, the 8080 psychologists will design custom DMA devices for their
always disables further interrupts when it is interrupted labs. Note that no software is used in DMA, since the
(to avoid confusion of signals), so that the programmer peripheral itself "knows" what to do with the data
must remember to enable interrupts somewhere in the according to its circuitry or, in the case of a micro-
ISR to await further signals. Other cautions in using processor, its program.
interrupt software arise from the fact that many
programs (especially BASIC interpreters) ordinarily COMPARISON OF STRATEGIES
begin on the first memory page, so that the programmer
must patch them around to use interrupts with the As in most computing applications, there are trade-
8080. Furthermore, some BASIC interpreters use the offs among these approaches that make some more
"stack" in such a way as to make interrupt processing suitable for a given application than others. The trade-
virtually impossible; check with the manufacturer of offs are on dimensions of cost and complexity, flexibili-
your software to be sure it is compatible before adopt- ty in performing a variety of tasks simultaneously,
ing an interrupt interface. speed, compatibility across systems, and ease of imple-
Some advanced systems are structured around many mentation. Figure 4 summarizes the author's subjective
interrupt devices, each of which has a priority and can ratings of the various I/O strategies for each of these
interrupt other devices of lower priority. Both the dimensions.
hardware and software complexity of such systems rise In the hardware aspect of I/O, parallel interfaces are
considerably above the simple example presented here. often the least costly, least complex electronically, and
However, these applications of interrupts can dramatical- have adequate speed and flexibility for most applica-
ly increase the processing power of a microcomputer in tions. They are commonly found on plug-in modules
a complex laboratory environment at relatively low cost. such as analog/digital converters, real-time clocks, relay
Flag polled
Interrupt
interfaces, speech synthesizers, some printers, and other cheapest to implement. Its primary disadvantage is that
medium-speed devices. Parallel I/O has the drawback of it monopolizes the CPU while waiting for a peripheral,
requiring at least 8, and as many as 20, separate wires drastically reducing potential throughput. In many situa-
for the connection (if both input and output are tions this may be quite acceptable, though, since the
needed). Furthermore, because the signals are logic machine may be dependent on a slow peripheral device
level (TTL), it is not good practice to extend them such as a person. Operating systems that require user
more than a few feet from the CPU. Thus, parallel commands often use flag polling, as do programs that
devices are best suited for peripherals that are installed simulate terminals, and text editors.
in or near the computer's cabinet and for those that In many real-time applications the computer may
require moderate speed. have to continue processing while waiting for random
Serial I/O methods are typically slower than parallel, events from the lab environment. In such cases, inter-
and require somewhat more complex and expensive rupt I/O may be the best alternative despite the com-
hardware. Their primary advantage is that they require plexity of hardware and software implementations. For
only one signal wire in each direction and one ground instance, if a computer must monitor a subject's
wire. As a result, it is feasible to convert the TTL level to responses on several dimensions while at the same time
a more robust signal or frequency modulated tone (using presenting stimuli based on those responses. flag polling
a MODEM) and transmit it over a distance without would tie up the machine most of the time. An interrupt
degrading. Most timesharing systems on large computer system would allow computation for stimulus presenta-
systems use serial interfaced terminals. Another advan- tion while always being available for input. In complex
tage of serial I/O is that a standard exists (RS-232) interrupt systems, one machine might even service
for connectors and signal levels which facilitates inter- several such experiments.
connection of microcomputers to peripherals made by a Programming for interrupts can be difficult, since it
large number of manufacturers, including those of mini must be carried out at the machine language level, and
and full-size computers. Serial I/O is frequently used in requires careful attention to all possible sequences and
relatively low-speed devices such as terminals, Teletypes, priorities of events and to links between high-level
printers, and cassette storage systems. programming languages and machine language.
DMA interfaces are electronically complex. However,
they are extremely fast and require no management REFERENCES
from the CPU. They must be tailored to the specific
LA DAGE. D. Interrupts exposed: Using microprocessor interrupts
task and system on which they are used, and so suffer
effectively. Kilobaud, 1977. 4, 18-21. (a)
from relatively poor compatibility across systems. Be- LA DACE. D. Interrupts exposed: Implementing an interrupt-
cause of cost and complexity, they are best suited to driven system. Kilobaud, 1977. S, 78-80. (b)
critical and demanding tasks that would otherwise LANCASTER. D. TTL Cookbook. Indianapolis: Howard W. Sams ,
burden the processor with their service, such as video 1974.
SCELBI COMPUTER CONSULTING INC. 8080 Software guide and
displays and floppy disk controllers. gourmet cookbook. Milford, Conn: Scelbi, 1976.
Flag-polled I/O software is probably the simplest and SMITH, M. L. Build your own interface. Kilobaud, 1977,6,22-28.