MODULE-3 - Input-Output-Organization
MODULE-3 - Input-Output-Organization
MODULE-3 - Input-Output-Organization
and Architecture
Carl Hamacher, Zvonko Vranesic, Safwat
Zaky,
Computer Organization, 5th
Edition,
Tata McGraw Hill, 2002.
Module-3
INPUT / OUTPUT ORGANIZATION
Introduction
One of the basic features of a computer is its ability to
exchange
data with other devices.
Enables a human operator to use a keyboard and a display
screen to process text and graphics.
Computers are an integral part of home appliances,
manufacturing equipment, transportation systems,
banking and point-of-sale terminals.
Input to a computer may come from a sensor switch, a digital
camera, a
microphone, or a fire alarm.
Output may be a sound signal to be sent to a speaker or a
digitally coded command to change the speed of a motor,
open a valve, or cause a robot to move in a specified manner.
In short, a general-purpose computer should have the
ability to exchange information with a wide range of
Accessing I/O
Devices
Accessing I/O devices
A simple arrangement to connect I/O
devices to a computer is to use a single
bus arrangement.
The bus enables all the devices
connected to it to exchange
information.
It consists of three sets of lines used to
Processor Memory
Bus
For example,
Move DATAIN,R0
Move R0,DATAOUT
Accessing I/O devices..
When I/O devices and the memory have
different address spaces, the arrangement is
called I/O-mapped I/O.
Special In and Out instructions to perform I/O
transfers.
I/O devices may have to deal with fewer
address lines.
I/O address lines need not be physically
separate from
memory address lines.
In fact, address lines may be shared between
I/O devices and memory, with a control signal
to indicate whether it is a memory address or
Accessing I/O devices..
Address lines
Bus Data lines
Control lines
Input device
Accessing I/O devices..
Figure 4.2 illustrates the hardware
required to connect an I/O device
to the bus.
I/O device is connected to the bus
1
2
Interrupt
occurs i
here
i+1
M
Interrupts..
Processor is executing the instruction located at
address i when an interrupt occurs.
Routine executed in response to an interrupt
request is
called the interrupt-service routine.
When an interrupt occurs, control must be
transferred to
the interrupt service routine.
But before transferring control, the current
contents of
the PC (i+1), must be saved in a known location.
This will enable the return-from-interrupt
instruction to
Example..
Consider a task that requires some
computations to be performed and the results to
be printed on a line printer.
Let the program consist of two routines,
COMPUTE and
PRINT.
Assume that COMPUTE produces a set of n lines
of
output, to be printed by the PRINT routine.
First, the COMPUTE routine is executed to
produce the
first n lines of output.
Then, the PRINT routine is executed to send the
Example..
At this point, instead of waiting for the line to be
printed; the PRINT routine may be temporarily
suspended and execution of the COMPUTE
routine continued.
Whenever the printer becomes ready, it alerts
the
processor by sending an interrupt-request
signal.
In response, the processor interrupts execution
of the COMPUTE routine and transfers control
to the PRINT routine.
The PRINT routine sends the second line to the
printer
Example..
This process continues until all n lines have been
printed and the PRINT routine ends.
The PRINT routine will be restarted whenever the
next
set of n lines is available for printing.
If COMPUTE takes longer to generate n lines
than the time required to print them, the
processor will be performing useful
computations all the time.
Example..
Interrupts..
When a processor receives an interrupt-
request, it must branch to the interrupt
service routine.
It must also inform the device that
it has recognized the interrupt
request.
This can be accomplished in two
ways:
Some processors have an explicit
interrupt-
acknowledge signal for this purpose.
In other cases, the data transfer that takes
place between the device and the processor
Interrupts..
Treatment of an interrupt-service routine is very
similar to that of a subroutine.
However there are significant differences:
A subroutine performs a task that is required by the calling
program.
Interrupt-service routine may not have anything in common
with the
program it interrupts.
Interrupt-service routine and the program that it interrupts may
belong to
different users.
As a result, before branching to the interrupt-service routine,
not only the PC, but other information such as condition code
flags, and processor registers used by both the interrupted
program and the interrupt service routine must be stored.
This will enable the interrupted program to resume execution upon
Interrupts..
Saving and restoring information can be done
automatically
by the processor or explicitly by program instructions.
Saving and restoring registers involves memory
transfers:
Increases the total execution time.
Increases the delay between the time an interrupt request
is received, and the start of execution of the interrupt-
service routine. This delay is called interrupt latency.
In order to reduce the interrupt latency, most
processors save
only the minimal amount of information:
This minimal amount of information includes Program
Counter and processor status registers.
Any additional information that must be saved, must be
saved explicitly by the program instructions at the
Interrupts..
An interrupt is more than a simple
mechanism for coordinating I/O transfers.
The concept of interrupts is used in operating
systems and in many control applications
where processing of certain routines must be
accurately timed relative to external events.
Real-time processing.
Interrupt Hardware
An I/O device requests an interrupt by
activating a bus line called interrupt-request.
Most computers are likely to have
INTR1 to
Thus, if all interrupt-request signals
go to 1.
Interrupt Hardware..
Since the closing of one or more
IN T R INTR
1 p
Processor
INTA1 INTA p
Priority arbitration
Simultaneous Requests
Consider the problem of simultaneous
arrivals of interrupt requests from two or
more devices.
The processor must have some means of deciding
which request to service first.
Using a priority scheme such as that of Figure
4.7, the solution is straightforward.
The processor simply accepts the request having the
highest priority.
If several devices share one interrupt-request
line, as in Figure 4.6, some other mechanism is
needed.
Simultaneous Requests..
Polling scheme:
If the processor uses a polling mechanism
daisy-chain fashion.
When devices raise an interrupt request, the
INTR is activated.
interrupt-request line
INT
Processor
Device Device
INTA1
Processor
IN T R
p
Device Device
INTA p
Priority arbitration
circuit
Controlling Device Requests
Only those devices that are being used in a program
should
be allowed to generate interrupt requests.
To control which devices are allowed to generate
interrupt requests, the interface circuit of each I/O
device has an interrupt-enable bit.
If the interrupt-enable bit in the device interface is
set to 1, then the device is allowed to generate an
interrupt-request.
Interrupt-enable bit in the device’s interface circuit
determines whether the device is allowed to generate
an interrupt request.
Interrupt-enable bit in the processor status register or
the priority structure of the interrupts determines
Controlling Device Requests..
For example, keyboard interrupt-enable,
KEN, and display interrupt-enable, DEN,
flags in register CONTROL in Figure 4.3.
If either of these flags is set, the interface
circuit generates an interrupt request
whenever the corresponding status flag in
register STATUS is set.
At the same time, the interface circuit sets bit
KIRQ or DIRQ to indicate that the keyboard or
display unit, respectively, is requesting an
interrupt.
If an interrupt-enable bit is equal to 0, the
interface circuit will not generate an interrupt
Controlling Device Requests..
To summarize, there are two
independent mechanisms for controlling
interrupt requests:
At the device end, an interrupt-enable bit
Line).
This variable is initially set to 0.
We assume that it is checked periodically by
Example..
Direct Memory
Access
Direct Memory Access
A special control unit may be provided to transfer
a block of data directly between an I/O device
and the main memory, without continuous
intervention by the processor.
This approach is called direct memory access, or DMA.
DMA transfers are performed by DMA controller,
which is a control circuit that is a part of the I/O
device interface.
DMA controller performs functions that
would be normally carried out by the
processor:
For each word, it provides the memory address
and all the control
signals.
Direct Memory Access..
DMA controller can transfer a block of data from an
external device to the processor, without any
intervention from the processor.
However, the operation of the DMA controller must be
under the control of a program executed by the
processor. That is, the processor must initiate the DMA
transfer.
To initiate the DMA transfer, the processor informs
the DMA controller of:
Starting address,
Number of words in the block.
Direction of transfer (I/O device to the memory, or
memory to the I/O
device).
Once the DMA controller completes the DMA
transfer, it
informs the processor by raising an interrupt signal.
Direct Memory Access..
While a DMA transfer is taking place, the
program that requested the transfer cannot
continue, and the processor can be used to
execute another program.
After the DMA transfer is completed, the processor
can return
to the program that requested the transfer.
For an I/O operation involving DMA, the OS puts
the program that requested the transfer in the
Blocked state, initiates the DMA operation, and
starts the execution of another program.
When the transfer is completed, the DMA controller
informs the processor by sending an interrupt
request.
Direct Memory Access..
Direct Memory Access..
Figure 4.18 shows an example of the DMA
controller registers that are accessed by the
processor to initiate transfer operations.
Two registers are used for storing the starting
address
and the word count.
The third register contains status and control
flags.
The R/Wഥ bit determines the direction of the
transfer.
When this bit is set to 1 by a program instruction,
the controller
performs a read operation.
Direct Memory Access..
When the controller has completed transferring a
block of data and is ready to receive another
command, it sets the Done flag to 1.
Bit 30 is the Interrupt-enable flag, IE.
When this flag is set to 1, it causes the controller to
raise an
interrupt after it has completed transferring a block of
data.
Finally, the controller sets the IRQ bit to 1
when it has
requested an interrupt.
Direct Memory Access..
An example of a computer system is given in
Figure 4.19, showing how DMA controllers
may be used.
DMA controller connects a high-speed
network to the computer bus.
Disk controller, which controls two disks
also has DMA capability.
It provides two DMA channels.
It can perform two independent DMA
operations, as if each disk has its own DMA
controller.
The registers to store the memory
address, word count and status and
Direct Memory Access..
Main
Processor memory
System bus
Disk/DMA DMA
Printer Keyboard
controller controller