CO Module 2 - Part1
CO Module 2 - Part1
Special hardware is necessary to interface the I/O devices with the microprocessor. The
address decoder enables the device to recognise its address when this address is available in
the address bus. The data register holds data being transferred to or from the processor. The
status registers contain the information relevant to the operation of the I/O device. The address
decoder, data and status registers and the control circuitry required to coordinate the I/O
transfer constitute device’s interface circuit
MEMORY MAPPED I/O
When the I/O devices and memory shares the same address space, the arrangement is
called memory mapped I/O. With memory mapped I/O, each instruction that can access
memory can be used to transfer data to or from an I/O device. For example, if DATAIN is the
address of the input buffer of a keyboard, the instruction MOVE DATAIN, R0 will read the
DATAIN and stores them into R0. Similarly, MOVE R0, DATAOUT will store the content of
R0 at the location DATAOUT, which may be the output data buffer of a display unit or printer.
Most of the computer uses Memory mapped I/O.
Some processors have special instructions IN and OUT for performing I/O transfers.
For example, Intel family processors have special I/O instructions and separate 16bit address
space for I/O devices. When designing a computer system with these processors, the designer
has the option for connecting I/O devices to the special I/O address space or as part of the
memory address space. One advantage of separate address space is that the I/O devices deals
with fewer address lines. While using the same address lines for this fewer I/O address signals,
a separate special signal is used to confirm that it is an I/O operation. When this signal is active,
the memory unit ignores the requested transfer. This technique, which uses separate address
space for I/O devices is termed as I/O mapped I/O.
PROGRAM CONTROLLED I/O
In program controlled I/O, the processor repeatedly checks a status flag to achieve the
required synchronisation between the processor and I/O device. W say that the processor polls
the device.
Consider the example of I/O operations involving a keyboard and a display device. The
four registers are used in the data transfer operations. STATUS register contains two flags, SIN
and SOUT, which provide the status for the keyboard and display. Two flags KIRQ and DIRQ
are for interrupts. Data from the keyboard are made available in DATAIN and the data sent to
the display are stored in DATAOUT register.
To control the keyboard and display, we need a program. The program should read character
from the keyboard, and stores it in the memory buffer. Then it calls the subroutine PROCESS
to process the input line.
As each character is read, it is displayed in the display. Register R0 is used as a pointer to the
memory buffer area. The contents of R0 are updated using the autoincrement addressing mode,
so that the successive character is stored in successive memory locations. Each character is
checked to see if it is the Carriage Return (CR), which has the ascii code of 0D. if it is, a line
feed character (ASCII code 0A) is sent to move the cursor one line down on the display and
subroutine PROCESS is called. This example illustrates program-controlled I/O.
INTERRUPTS
In polling method, the processor waits for the response form the I/O device. During this wait
period, processor not able to perform useful computation. This causes wastage of effective time
for processing. This can be solved by the technique called Interrupt. In this method, the I/O
device alerts the processor when it becomes ready. It can do so by sending a hardware signal
called Interrupt request to the processor.
Example: Consider a task that requires continuous computations to be performed and the results
to be printed on a printer.
COMPUTE produces a set of n lines output. PRINT routine is executed to send the first line of
text to the printer. At this point, instead of waiting for the line to be printed, the PRINT routine
may be temporarily suspended and execution of COMPUTE routine continued. Whenever the
printer becomes ready, it alerts the processor, by sending an interrupt request signal. In
response to this, processor interrupts the execution of COMPUTE routine and transfers the
control to the PRINT routine. The PRINT routine sends the second line to the printer and is
again suspended. Then the COMPUTE routine resumes the execution and this process
continues until all lines have been printed.
The routine executed in response to the interrupt request is called the Interrupt Service Routine,
which is PRINT in this example.
INTERRUPT HARDWARE
A single interrupt request line may be used to serve n number of devices. All devices are
connected to the line via switches to ground. To request an interrupt, a device closes the switch.
If all the interrupt request lines are inactive, the voltage level is Vdd. When a device closes the
switch, the voltage becomes zero, causing an interrupt request signal received by the processor.
ENABLING & DISABLING INTERRUPTS
The arrival of an interrupt signal from an external device, causes the processor to
suspend the execution of one program and start the execution of another. A fundamental facility
found in all computers is the ability to enable and disable such interruptions.
By using an Interrupt disable instruction, we can disable the further interruptions.
Likewise, interrupt enable instruction will enable the interrupts. The interrupt disable
instruction clears the interrupt-enable bit of the flag register, and the interrupt enable instruction
sets the interrupt- enable bit.
Another method for enabling and disabling the interrupt is the use of edge triggered
signals. Here, the processor’s interrupt request line responds only to the leading edge of the
signal. In this case, the processor receives only one request, regardless of how long the line is
active. Hence there is no danger of multiple interruptions.
The sequence of events involved in handling an interrupt request from a single device
is as follows
1. The device raises an interrupt request
2. The processor interrupts the program currently being executed
3. Interrupts are disabled by changing the control bit in the flag register (except in the case
of edge triggered interrupts)
4. The device is informed that its request has been recognised, and in response, it
deactivates the interrupt-request signal.
5. The action requested by the interrupt is performed by the interrupt service routine.
6. Interrupts are enabled and execution of the interrupted program is resumed.
HANDLING MULTIPLE INTERRUPTS
Another method for implementing multiple interrupts, with priority is the daisy chain method.
Here all the interrupt request lines are connected to the INTR pin of the processor. The INTA
signal is connected in daisy chain manner. The INTA signal is first received by device 1, then
device 1 passes it to device 2, and it goes on. If any device has pending requests, that device
blocks INTA signal, and proceeds to put the identifying code on the data bus. Therefore, the
device that is closest to the processor has the highest priority, the second device in the chain
has second priority and so on.
We can combine these two techniques to form a general structure in which devices are
organised in groups, each group is connected in different priority level. Within a group, devices
are connected in daisy chain.