Input/ Output Organization: Accessing I/O Devices
Input/ Output Organization: Accessing I/O Devices
MODULE 3
With the memory mapped I/O any machine instruction that can access memory can be
used to transfer data to or from an I/O device.
Move DATAIN, R0
Reads data from the DATAIN and stores into processor register R0. Similarly
Sends the contents of register R0 to location DATAOUT which is the output data
buffer of a display unit or a printer.
Processor Memory
1
Krishna Teja, Asst. Prof, Dept of ECE, CMRIT
Computer Organization & Architecture
Address lines
Control lines
Input Device
Fig 2 illustrates the hardware required to connect the I/O device to the bus. The address
decoder enables the device to recognize its address when its address appears on the address
lines. The data register holds the data being transferred to or from the processor. The status
register contains the information relevant to the operation of I/O device. Both status and data
registers are connected to the data bus and assigned unique addresses.
The address decoder, data & status registers and the control circuitry required to
coordinate I/O transfers constitutes the device interface circuit.
Let us consider a simple example of I/O operation involving a keyboard and a display
device in the computer system. The four registers shown are used for data transfer operations.
Register STATUS contains two control flags SIN and SOUT which provide status
information for keyboard and display unit. The two flags KIRQ and DIRQ are used in
conjunction with interrupts. Data from the keyboard are made available in DATAIN register
and data sent to the display unit are stored in the DATAOUT register.
2
Krishna Teja, Asst. Prof, Dept of ECE, CMRIT
Computer Organization & Architecture
DATAIN
DATAUOT
The program reads the line of characters from the keyboard and stores it in the memory
buffer starting from the memory location LINE.
3
Krishna Teja, Asst. Prof, Dept of ECE, CMRIT
Computer Organization & Architecture
Interrupts
The other tasks can be performed by the processor while waiting for the I/O device to
become ready. When the I/O device becomes ready, it sends a hardware signal called
interrupt to the processor. Using the interrupts waiting periods can be eliminated.
Consider a task that requires some computations to be performed and the results to be
printed on a line printer. This is followed by more computations and output and so on. Let the
program consists of two routines COMPUTE and PRINT. Assume COMPUTES produces a
set of ‘n’ lines of output to be printed by PRINT routine.
Program 1 Program 2
interrupt
occurs
here
If COMPUTE takes longer to generate ‘n’ lines than the time required to print them,
then the processor will be performing useful computations all the time.
4
Krishna Teja, Asst. Prof, Dept of ECE, CMRIT
Computer Organization & Architecture
Saving registers also increases the delay between the time the interrupt request is
received and the start of execution of interrupt service routine. This delay is called interrupt
latency.
Interrupt Hardware
I/O device requests an interrupts by activating a bus line called interrupt request. A
single interrupt may be used to serve ‘n’ devices.
To request an interrupt device closes its associated switch. Thus if all the interrupt
request signals INTR1 to INTRn are inactive, the voltage on the interrupt request line is Vdd.
This is the inactive state of the line. When the device requests the interrupt by closing its
switch, the voltage line drops to zero causing the interrupt request line INTR received by the
processor to go to 1. The value of INTR is the logical OR of the requests from individual
devices, that is
INTR=INTR1 + . . . .+ INTRn
R is the pull up register because it pulls line voltage up to high voltage when the switches
are open.
5
Krishna Teja, Asst. Prof, Dept of ECE, CMRIT
Computer Organization & Architecture
The enabling and disabling interrupts must be available to the programmer. A simple
way is to provide machine instructions such as Interrupt-enable and Interrupt-disable that
performs these functions.
When the device activates interrupt request signal, it keeps this signal activated until
it learns that the processor has accepted its request. It is essential to ensure that this active
signal does not lead to successive interruptions causing the system to enter an infinite loop
from which it cannot recover. There are three ways to avoid this problem.
The first option is that processor must ignore the interrupt request line until the
execution of first instruction of interrupt service routine (ISR) has been completed. Then by
using the Interrupt disable instruction as the first instruction in the ISR, programmer can
ensure that no further interruption will occur.
The second option is to have processor automatically disable the interrupts before
staring the execution of Interrupt service routine. After saving the contents of PS on the stack
with Interrupt enable bit equal to 1, the processor clears the Interrupt enable bit in PS register
thus disabling further interrupts. When a return from interrupt instruction is executed, the
contents of PS are restored from the stack setting the Interrupt enable bit back to 1. Hence
interrupts are again enabled.
In the third option, processor has a special interrupt request line for which the interrupt
handling circuit responds only to leading edge of the signal. Such a line is said to edge
triggered.
The sequences of events involved in handling the interrupt request from a single
device are as follows.
4. The device is informed that the request has been recognized and in response
deactivates the interrupt-request signal.
5. The action requested by the interrupt is being performed by the interrupt service
routine.
6. Interrupts are enabled and the execution of interrupted program is being resumed.
6
Krishna Teja, Asst. Prof, Dept of ECE, CMRIT
Computer Organization & Architecture
KIRQ, DIRQ are the interrupt request bits for keyboard and display. The polling
scheme ha the disadvantage that the time spent interrogating the IRQ bits of all the devices
that may not be requesting any service. An alternate approach is to use vectored interrupts.
Vectored Interrupts
A device requesting an interrupt can identify itself by sending special code to the
processor over the bus. The code supplied by the device represents the starting address of the
interrupt service routine. The code length is 4 to 8 bits. The processor reads this address
called the interrupt vector and stores it in to the PC. The interrupt vector may also include a
new value for a processor status register.
The interrupted device must wait to put on the bus only when the processor is ready to
receive it. When the processor is ready to receive the vector interrupt code, it activates the
interrupt acknowledge line INTA. The I/O device responds by sending its interrupt vector
code and turning off INTR signal.
Interrupt Nesting
I/O devices should be organized in a priority structure. An interrupt request from a high
priority should be accepted while the processor is serving another request from the lower
priority device.
We can assign priority level to the processor that can be changed under program
control. The priority level of the processor is the priority of the program that is currently
being executed. The processor accepts interrupts from devices that have priorities higher than
its own.
7
Krishna Teja, Asst. Prof, Dept of ECE, CMRIT
Computer Organization & Architecture
Fig 6: Implementation of interrupt priority using individual interrupt request & acknowledge
lines
Simultaneous Requests
If several devices share one interrupt request line, some other mechanism is needed.
When several devices raises interrupt request and line is activated, the processor
responds by setting the INTA line to 1. The signal is received by device 1. Device 1 passes
the signal onto device 2 only if it does not require any service. If device 1 has pending
request for interrupt, it blocks the INTA signal and proceeds to put its identification code on
to data lines. In daisy chain the device that is electrically closest to the processor has the
highest priority.
8
Krishna Teja, Asst. Prof, Dept of ECE, CMRIT
Computer Organization & Architecture
Devices can be organized in groups and each group is connected at a different priority
level. Within group devices are connected in daisy chain.
It is important to ensure that interrupt requests are generated by only those I/O devices
that are being used by the given program. Consider a program that uses vectored interrupt
scheme where the staring address of interrupt service routine is stored at the memory location
INTVEC. Interrupts are enabled by setting Interrupt enable bit to 1in processor status register
which we assume is bit 9.
Assume that at some point in the program called Main we wish to read an input line
from keyboard and store the character in successive byte locations in memory locations
starting at location LINE. To perform this operation using interrupts, we need to initialize
interrupt process.
2. Load the address LINE in memory location PNTR. The Interrupt-service routine uses
this location as pointer to store the i/p character in memory.
4. Enable interrupts in processor by setting to 1 the IE bit in processor status register PS.
9
Krishna Teja, Asst. Prof, Dept of ECE, CMRIT
Computer Organization & Architecture
Once this initialization is completed, typing a character will cause an interrupt request to
be generated by keyboard interface. The interrupt service has to perform following tasks:
1. Read the input character from keyboard input data registers. This cause the interface
circuit to remove interrupt request.
2. Store the characters in memory location pointed to by PNTR and increment PNTR.
3. When end of line is reached, disable keyboard interrupt and inform the program Main.
Main Program
Interrupt-Service Routine
Branch ≠ 0 RTRN
Return-from-interrupt
10
Krishna Teja, Asst. Prof, Dept of ECE, CMRIT
Computer Organization & Architecture
To transfer large blocks of data at high speeds, an alternate approach is used. A special
control unit may be provided to allow transfer of block of data directly between external
device and main memory without intervention by processor. This approach is called direct
memory access or DMA.
DMA transfers are performed by control circuits that are part of I/O interface called
DMA controller. The DMA controller performs functions that would normally be carried out
by processor when accessing main memory.
The R/ bit determine the direction of transfer. When this bit is set to 1 by a program
instruction, the controller performs read operation that is it transfers data from memory to I/O
device. When transfer is complete, it sets done flag to 1. When IE is1, it causes the controller
to raise an interrupt after it has completed transferring block of data. Finally IRQ bit is set to
1 when it has requested interrupt.
Requests from DMA devices are given high priority than processor requests. Among
different DMA devices high priority is given to high speed peripherals such as disks, high
speed network interface or graphic display device.
The processor originates most memory cycles, the DMA controller is said to steal
memory cycles from processor. This technique is called cycle stealing. DMA controller is
given access to main memory to transfer a block of data without interruption. This is called as
block or burst mode.
11
Krishna Teja, Asst. Prof, Dept of ECE, CMRIT
Computer Organization & Architecture
Assignment Questions
12
Krishna Teja, Asst. Prof, Dept of ECE, CMRIT