You are on page 1of 14

INPUT/OUTPUT PROGRAMMING

 A very important part of assembly language programming deals with


the input and output of information to and from peripheral devices.
 The programming techniques of Chapter 4 deal mainly with the
computing aspect of programming, but this aspect is useless unless
data can be input for computation and the results of computation can
be output for examination and use. In this chapter, we present some
of the basic techniques for input/output programming.
The specific instructions or instruction sequences for
coding these techniques will vary with the instruction set,
input/output system and devices available on a given
computer. Each computer and each problem will need to
be considered for its own properties.
5.1 BASIC I/O PROGRAMMING
CONCEPTS
Input/output for most modern computers is asynchronous.

This means that the timing of the operation of the central processor and each
I/O device is independent. The central processor is internally synchronous;
each action is controlled by the control unit and each action is performed at
exact specific times as determined by a central clock in the CPU.
Every operation in the CPU occurs at well-specified times and the duration of each
operation is exactly specified in terms of the number of ticks of the clock needed for that
operation.

This is caused by the physical nature of the I/O


devices and the necessity of mechanical operation in
order to perform I/O functions

With input/output devices, this is


not true. The input/output
instructions (IN, OUT, IOC) only
initiate an operation; the actual
operation takes an indeterminable
time depending on the nature of the
I/O device, its state, and the
operation.
Mechanical operations simply
cannot be built to the rigid
timing specifications that
electronic circuits can be built
to.

This uncertainty requires careful


consideration of the way in which
I/O devices and the CPU interact.
Physically, this is done by
building, for each device, a
controller.
A controller is a piece of electronic circuitry which controls the attached I/O
device for the CPU. A controller may well be a small computer (a
microcomputer or minicomputer) programmed exclusively for this purpose, or
it may be a special-purpose device designed and built specifically as a
controller.
The CPU
sends
commands to
the controller to
perform I/O,
and the
controller sees
that it is
actually done.
The actual input/output instructions for the MIX
computer are limited to only three: IN, OUT, and IOC.

The IN instruction initiates the input of information into memory, storing in the memory locations beginning with the
effective address and continuing for one record.

The previous contents of the memory locations used by an IN instruction are destroyed by the storage of the new
information.

The OUT instruction sends information to an output device. The information is transferred from memory,
beginning at the address specified by the effective address of the OUT instruction. Since the contents of memory
are simply read and sent to the I/O device, the contents of memory remain unchanged.
For both the IN and OUT instructions, the amount of memory transferred is determined by the
I/O device selected. Each IN or OUT instruction begins the transfer of one record of
information. A record is the (physical) unit of information which is naturally handled by a
device. The record for a card reader or card punch is one card; for a line printer, one line. Thus
the size of a record for a card reader or card punch is 80 characters long; for a line printer, 120
characters long. Since 5 characters can fit in one word on the MIX computer, this requires 16
words of memory for a record of a card reader or card punch, and 24 words for a record of a line
printer. The magnetic tape, disk, and drum devices for MIX computers all have records of 100
words. The typewriter and paper tape unit has 70-character (14-word) records
FIGURE 5.1 The relationship between
an I/O device and an I/O buffer.

Note that these record lengths


need not be true for all card
readers, punches, line printers,
tapes, disks, drums, or
terminals.

There exist card readers and punches which deal with cards of 51 or 96 characters instead
of 80. Line printers have been built to handle lines of 80,12 0,132, or 136 characters
(among others). Many teletypewriters, CRT terminals, and paper tape devices handle data
one character at a time, with line lengths of 70, 72, 80, 120, 132, or 136 characters.
In this text we will consider only the standard MIX input/output devices. If your
installation has non-standard peripherals, special attention may be necessary on your part
in their programming, but the concepts presented here will still be applicable.
Since an IN or OUT instruction only starts an operation, at any time each device may
be in either of two states: ready for a new command, or busy with a previous one.
Each device alternates between these two states. Initially, the state of the device is
ready; it is waiting for a command to do something. When the CPU executes an I/O
instruction which selects this device, the device begins work on the task which it is
assigned, becoming busy. After as long a time as needed to perform the task requested
of it by the CPU, it finishes and becomes ready again, able to perform another I/O
command. One bit for each device records the state of the device, as ready or busy.
The setting and clearing of this bit are controlled completely by the device.
The ready/busy bit is used in several ways. First, it may be tested by the JRED and JBUS instructions which
can be used to control the execution of the CPU. The JRED and JBUS instructions specify a device unit
number in their F field, and will jump to the effective address if the device is ready (JRED) or busy (JBUS).
The state of the device is not affected in any way.

The other use of the busy/ready bit is in controlling the IN, OUT, and IOC instructions.
When an IN, OUT, or IOC instruction is decoded by the control unit, it will mean that a
new I/O command is to be issued to the (controller of the) device specified by the unit
number given in byte 4 of the instruction. If that device is ready, the new command can be
issued and the CPU can continue to the next instruction. If the device is busy, however, the
new command cannot be issued. I/O devices (and their controllers) are generally rather
simple devices and so they can only do one thing at a time. Because of this, it is only
possible to have one outstanding I/O request per device at a time
If the control unit decodes an I/O command (IN, OUT, IOC) for a busy device, it must wait until that device becomes
ready before it can issue the new command.

Thus, if a device is ready when an I/O instruction is executed for that device, it only takes one time unit to
execute. If, however, the device is busy, the execution time for that instruction can take an arbitrarily long and
unpredictable length of time, however long it takes until the device finishes its last command and becomes
ready (only to become busy again with the new command). This extra time is called interlock time.

The IOC instruction is used to provide special-purpose control functions for some I/O
devices; its use and meaning is entirely dependent upon the device with which it is used.
It is the instruction which allows all of the special device-dependent functions we may
need to do but do not really need a separate instruction for. We would like to be able to
tell the tape units to rewind, but a rewind command would not make much sense for most
other devices.

You might also like