Module 4 IO ORGANIZATION
Module 4 IO ORGANIZATION
MODULE 4
INPUT/OUTPUT ORGANIZATION
These variety of I/O devices exchange information in varied format, having different
word length, transfer speed is different, but are connected to the same system and
exchange information with the same computer. Computer must be capable of handling
these wide variety of devices.
ACCESSING I/O-DEVICES
A single bus-structure can be used for connecting I/O-devices to a computer. The
simple arrangement of connecting set of I/O devices to memory and processor by
means of system bus is as shown in the figure. Such an arrangement is called as Single
Bus Organization.
• The system bus enables all the devices connected to it to involve in the data
transfer operation.
• The system bus establishes data communication between I/O device and
processor.
• Each I/O device is assigned a unique set of address.
• When processor places an address on address-lines, the intended-
device responds to the command.
• The processor requests either a read or write-operation.
• The requested data are transferred over the data-lines
• same address space is used for both memory and I/O interface. They have
only one set of read and write signals.
• All memory related instructions are used for data transfer between I/O and
processor.
• In case of memory mapped I/O input operation can be
implemented as, MOVE DATAIN , R0
Source destination
Source Destination
I/O INTERFACE
The hardware arrangement of connecting i/p device to the system bus is as shown in
the fig.
This hardware arrangement is called as I/O interface. The I/O interface consists of
3 functional devices namely:
4) Data Register:
o The data bus carries the data from the I/O devices to or from the processor.
The data bus is connected to the data/ status register.
o The data register stores the data, read from input device or the data, to be
written into output device. There are 2 types:
DATAIN - Input-buffer associated with keyboard.
DATAOUT -Output data buffer of a display/printer.
DATAIN register: is a part of input device. It is used to store the ASCII characters read from
keyboard.
DATAOUT register: is a part of output device. It is used to store the ASCII
characters to be displayed on the output device.
STATUS register stores the status of working of I/O devices –
• SIN flag – This flag is set to 1, when DATAIN buffer contains the data
from keyboard. The flag is set to 0, after the data is passed from DATAIN
buffer to the processor.
• SOUT flag – This flag is set to 1, when DATAOUT buffer is empty and
the data can be added to it by processor. The flag is set to 0, when
DATAOUT buffer has the data to be displayed.
• KIRQ (Keyboard Interrupt Request) – By setting this flag to 1, keyboard
requests the processor to obtain its service and an interrupt is sent to the
processor. It is used along with the SIN flag.
• The program checks the status of I/O register and reads or displays data.
Here the I/O operation is controlled by program.
WAITK TestBit #0, STATUS (Checks SIN
flag) Branch = 0 WAITK
Move DATAIN, R0 (Read character) [
*Code to read a character from DATAIN to R0]
This code checks the SIN flag, and if it is set to 0 (ie. If no character in DATAIN
Buffer), then move back to WAITK label. This loop continues until SIN flag is set
to 1. When SIN is 1, data is moved from DATAIN to R0 register. Thus the program,
continuously checks for input operation.
Interrupt
• It is an event which suspends the execution of one program and begins the
execution of another program.
• In program controlled I/O, a program should continuously check whether the
I/O device is free. By this continuous checking the processor execution time is
wasted. It can be avoided by I/O device sending an ‘interrupt’ to the processor,
when I/O device is free.
• The interrupt invokes a subroutine called Interrupt Service Routine (ISR),
which resolves the cause of interrupt.
• The occurrence of interrupt causes the processor to transfer the execution
control from user program to ISR.
Program1 ISR
The following steps takes place when the interrupt related instruction is
executed:
The following steps takes place when ‘return’ instruction is executed in ISR -
• It transfers the execution control from ISR to user program.
• It retrieves the content of stack memory location whose address is stored in SP
into the PC.
• After retrieving the return address from stack memory location into the PC
it increments the Content of SP by 4 memory location.
Interrupt Latency / interrupt response time is the delay between the time
taken for receiving an interrupt request and start of the execution of the ISR.
Generally, the long interrupt latency is unacceptable.
INTERRUPT HARDWARE
• The external device (I/O device) sends interrupt request to the processor by
activating a bus line and called as interrupt request line.
• All I/O device uses the same single interrupt-request line.
• One end of this interrupt request line is connected to input power supply by
means of a register.
• The another end of interrupt request line is connected to INTR (Interrupt
request) signal of processor as shown in the fig.
• When switch is closed the voltage drop on the interrupt request line is found
to be zero, as the switch is grounded, hence INTR=0 and INTR=1.
• The signal on the interrupt request line is logical OR of requests from the
several I/O devices. Therefore, INTR=INTR1 + INTR2 + + INTRn
The arrival of interrupt request from external devices or from within a process,
causes the suspension of on-going execution and start the execution of another
program.
• Interrupt arrives at any time and it alters the sequence of execution. Hence
the interrupt to be executed must be selected carefully.
• All computers can enable and disable interruptions as desired.
• When an interrupt is under execution, other interrupts should not be
invoked. This is performed in a system in different ways.
• The problem of infinite loop occurs due to successive interruptions of active
INTR signals.
VECTORED INTERRUPT
• A device requesting an interrupt identifies itself by sending a special-code to
processor over bus.
• Then, the processor starts executing the ISR.
• The special-code indicates starting-address of ISR.
• The special-code length ranges from 4 to 8 bits.
• The location pointed to by the interrupting-device is used to store the staring
address to ISR.
INTERRUPT NESTING
• A multiple-priority scheme is implemented by using separate INTR & INTA lines for
each device
• Each INTR line is assigned a different priority-level as shown in Figure.
INTR 1 I NTR p
Processor
Priority
arbitration
• The interrupt acknowledge line is connected in a daisy fashion as shown in the figure.
• This signal is received by device 1. The device-1 blocks the propagation of INTA
signal to device-2, when it needs processor service.
• The device-1 transfers the INTA signal to next device when it does not require the
processor service.
• In this technique, devices are organizes in a group and each group is connected
to the processor at a different priority level.
• With in a group devices are connected in a daisy chain fashion as shown in the
figure.
.
Word-Count register:
The format of word count register is as shown in fig. It is used to store the no of
words to be transferred from main memory to external devices and vice versa.
a) DONE bit:
• The DMA controller sets this bit to 1 when it completes the direct data
transfer between main memory and external devices.
• This information is informed to CPU by means of DONE bit.
b) R/W (Read or Write):
• This bit is used to differentiate between memory read or memory write
operation.
• The R/W = 1 for read operation and
= 0 for write operation.
• When this bit is set to 1, DMA controller transfers the one block of data
from external device to main memory.
• When this bit is set to 0, DMA controller transfers the one block of data
from main memory to external device.
• The DMA controller requests the CPU to transfer new block of data
from source to destination by activating this bit.
• The DMA controller connects two external devices namely disk 1 and disk 2
to system bus as shown in the above fig.
• The DMA controller also interconnects high speed network devices to system
bus as shown in the above fig.
• Let us consider direct data transfer operation by means of DMA controller
without the involvement of CPU in between main memory and disk 1 as
indicated by dotted lines (in the fig.).
• To establish direct data transfer operation between main memory and disk
1. DMA controller request the processor to obtain 3 parameters namely:
1)Starting address of the memory block.
2)No of words to be transferred.
3)Type of operation (Read or Write).
• Actually the CPU generates memory cycles to perform read and write
operations. The DMA controller steals memory cycles from the CPU to
perform read and write operations. This approach is called as “Cycle
stealing”.
• An exclusive option will be given for DMA controller to transfer block of data from
external devices to main memory and from main memory to external devices.
This technique is called as “Burst mode of operation.”
BUS ARBITRATION
• Any device which initiates data transfer operation on bus at any instant of
time is called as Bus- Master.
• When the bus mastership is transferred from one device to another device,
the next device is ready to obtain the bus mastership.
• The bus-mastership is transferred from one device to another device based
on the principle of priority system. There are two types of bus-arbitration
technique:
The following steps are necessary to transfer the bus mastership from CPU to
one of the DMA controller:
• The DMA controller request the processor to obtain the bus mastership by
activating BR (Bus request) signal
• In response to this signal the CPU transfers the bus mastership to
requested devices DMA controller1 in the form of BG (Bus grant).
• When the bus mastership is obtained from CPU the DMA controller1 blocks the
propagation of bus grant signal from one device to another device.
• The BG signal is connected to DMA controller2 from DMA controller1 in as daisy
fashion style is as shown in the figure.
• When the DMA controller1 has not sent BR request, it transfers the bus
mastership to DMA controller2 by unblocking bus grant signal.
• When the DMA controller1 receives the bus grant signal, it blocks the signal from
passing to DMA controller2 and enables BBSY signal. When BBSY signal is set to 1
the set of devices connected to system bus doesn’t have any rights to obtain the bus
mastership from the CPU.
• Registers: The fastest access is to data held in registers. Hence registers are part of
the memory hierarchy. More speed, small size and cost per bit is also more.
• At the next level of hierarchy, small amount of memory can be directly
implemented on the processor chip.
• This memory is called as processor cache. It holds the copy of recently accessed
data and instructions.
There are 2 levels of caches viz level-1 and level-2.
Level-1 cache is part of the processor and level-2 cache is placed in
between level-1 cache and main memory.
• The level-2 cache is implemented using SRAM chips
Locality of Reference
• Many instructions in the localized areas of program are executed repeatedly during
some time of execution
• Remainder of the program is accessed relatively infrequently
• There are 2 types of locality reference:
1) Temporal
➢ The recently executed instructions are likely to be executed again and again.
• This number of blocks is small compared to the total number of blocks available
in main-memory.
• Correspondence b/w main-memory-block & cache-memory-block is specified by
mapping-function.
• If the cache memory is full, one of the block should be removed to create space
for the new block, this is decided by cache control hardware.
• The collection of rule for selecting the block to be removed is called the
Replacement Algorithm.
• The cache control-circuit determines whether the requested-word currently exists in
the cache.
• If data is available, for read-operation, the data is read from cache.
• The write-operation (writing to memory) is done in 2 ways:
1) Write-through protocol &
2) Write-back protocol.
Write-Through Protocol
➢ Here the cache-location and the main-memory-locations are updated
simultaneously.
Write-Back Protocol
➢ This technique is to
→ update only the cache-location &
→ mark the cache-location with a flag bit called Dirty/Modified Bit.
During Read-operation
• If the requested-word currently does not exists in the cache, then read-miss will
occur.
• To overcome the read miss, Load–through/Early restart protocol is used.
Load–Through Protocol
➢ The block of words that contains the requested-word is copied from the
memory into cache.
➢ After entire block is loaded into cache, the requested-word is forwarded
to processor.
Prof. Anitha C S, Dept. of CSE(Data Science), 22
Digital Design &Computer Organization(BCS302) MODULE -4
➢
During Write-operation
• If the requested-word does not exists in the cache, then write-miss will occur.
1) If Write Through Protocol is used, the information is
written directly into main-memory.
2) If Write Back Protocol is used,
→ then block containing the addressed word is first brought
into the cache &
→ then the desired word in the cache is over-written
with the new information.
Mapping functions
There are 3 techniques to map main memory blocks into cache memory –
1. Direct mapped cache
2. Associative Mapping
3. Set-Associative Mapping
DIRECT MAPPING
• The simplest way to determine cache locations in which to store memory blocks
is the direct mapping technique as shown in the figure.
• The main memory block is loaded into cache block by means of memory address. The main memory
address consists of 3 fields as shown in the figure.
• Each block consists of 16 words. Hence least significant 4 bits are used to select one of the 16
words.
• The 7bits of memory address are used to specify the position of the cache block, location. The most
significant 5 bits of the memory address are stored in the tag bits. The tag bits are used to map one of
25 = 32 blocks into cache block location (tag bit has value 0-31).
• The higher order 5 bits of memory address are compared with the tag bits associated with cache
location. If they match, then the desired word is in that block of the cache.
• If there is no match, then the block containing the required word must first be read from the main memory
and loaded into the cache. It is very easy to implement, but not flexible.
2. Associative Mapping:
• It is also called as associative mapped cache. It is much more flexible.
• In this technique main memory block can be placed into any cache block
position.
• In this case , 12 tag bits are required to identify a memory block when it is
resident of the cache memory.
• The Associative Mapping technique is illustrated as shown in the fig.
• In this technique 12 bits of address generated by the processor are compared with
the tag bits of each block of the cache to see if the desired block is present. This
is called as associative mapping technique.