Computer Architecture and Organization
Computer Architecture and Organization
1.0 Introduction :
The input and output modules play very important part in a computer system. These are
the modules through which the computer interacts with the external environment. The users feed
in programs, data, and commands and the computer provides the results/ reports for use by the
user.
As computers have a wide variety of applications and they are used in different kinds of
environments there are wide variants of input/ output devices with vastly differing characteristics
found in use in computer systems. These devices may vary in their speed of operation, in the
format of the data they input/ output, in the size of the data unit they exchange, in the way they
interact with the computer system etc. Not to speak of devices differing in functionality, devices
with the same functionality may also differ in their mode of interaction. The architecture of the
computer system must be flexible enough to accommodate devices widely varying in
characteristics. The input/ output modules have to be organized incorporating mechanisms such
that these devices can be connected to it and can exchange data. To the same computer system it
should be possible to connect a keyboard transferring one character at-a-time at a rate of a few
characters per second, a storage device transferring data in large blocks at a rate of several
megabytes per second, or a network interface transferring data in even larger blocks at rates that
may go beyond gigabits per second. On top of it there are also variations within the I/O devices
with the same functionality but produced by different manufacturers.
1. Speed of Data Transfer: Ranging from a few bytes per minute in telemetry devices or a
few bytes per second in a keyboard to some gigabits per second
for data communication devices or high speed storage devices.
2. Interface:
a. Serial/ parallel: Single bit at-a-time or multiple bits at-a-time.
b. Connector: Type of connector.
c. Protocol: Steps involved in the transaction of data.
It is difficult for a processor to deal directly with devices having widely varying
characteristics and interfaces. Therefore the computer systems add a buffer set of interfaces,
called I/O Interface, between the processor and the I/O devices. These interfaces provide a
uniform interface to the processor on one side while on the other side each of these provides an
interface as appropriate for the device(s) it serves.
The I/O interfaces are often connected to the processor and the memory unit by a
common set of data and control signal lines referred to as the Bus or the System Bus as shown in
Figure-1. The uniform side of the I/O interface is connected to the bus. The processor and the
memory also have compatible interfaces to the bus to enable transfer of data and control
information.
PROCESSOR MEMORY
SYSTEM BUS
o o o
INTERFACE INTERFACE INTERFACE INTERFACE
I/O
I/O DEV
I/O
DEV DEV I/O I/O
DEV DEV
I/O I/O
DEV DEV
I/O BUS I/O I/O
DEV DEV
I/O I/O I/O
DEV DEV DEV
The other side of an I/O interface is connected to one or more I/O devices using an I/O Bus that
is compatible to the interface on the device(s) concerned.
The system bus consists of a common set of signal lines shared by the interfaces for exchange of
data and control information. These signal lines can be categorized in the following groups:
1. Address Lines,
2. Data lines,
3. Control lines.
3. Device Interface : Interface with the I/O device possibly as per an I/O bus standard.
The collection of the addresses of the registers in the I/O interfaces constitutes the I/O Address
Space. The I/O address space is organized in one of the two ways-
1. Memory mapped I/O: In this organization the addresses of the registers in the I/O
interfaces are mapped to an area in the memory address space
itself. As a result read/write operations on the I/O interface
registers can be performed as in case of memory locations. There is
no need for separate control signal lines in the bus for I/O read/
write operations. All the processor instructions available for
memory operands can also be used for I/O operands.
Memory
Locations I/O
Memory
Registers
Locations
I/O
Registers
Memory mapped I/O Isolated I/O
2. Isolated I/O: In this the I/O address space is totally independent of the memory
address space. For the read/ write operations on the I/O interface
registers there is a separate set of control signal lines provided in
the bus. There is also a separate set of instructions provided in the
instruction set for these operations. The disadvantage is lesser
flexibility in programming. The advantage is that the memory
address space is not fractured and the entire space is available for
memory purpose.
code_seg segment
-
-
-
mov si, offset data
mov cx, data_size
mov dx, printer_sr
mov bx, printer_dr
print_loop: and [dx], ready_mask
jz print_loop
mov al, [si]
mov [bx], al
inc si
dec cx
jnz print_loop
-
-
-
code_seg ends
The problem with this mode of data transfer is due to the speed mismatch between the
processor and the I/O devices. For example, a printer with a speed of 150 cps (say) each
character takes about 7 ms. It will be possible for the interface to transfer a character to the
printer once in every 7 ms. Even if we assume that each m/c instruction requires 1 μs the print
loop will require only 7 μs. After completing the transfer of one character in 7 μs the processor
has keep checking for the printer interface to become ready for about 7 ms in what is known as
the Busy Wait loop doing nothing useful. This is rather wasteful.
Interrupt driven I/O tries to do away with the inefficient Busy Wait loop of the processor. Here
the processor transfers one data unit and than goes on to carryout some useful work in the form
of executing another program. Once the data unit is transferred to/ from the I/O device and the
I/O interface is ready to receive/ deliver the next data unit it sends a signal to the processor
indicating its readiness. This signal is called an Interrupt Request. The interrupt request signal
is sent through a signal line meant for the purpose also known as the Interrupt Request Line.
On receiving the Interrupt Request signal the processor interrupts the process under execution
and gives its attention to the I/O interface that raised the interrupt request. This it does by
transferring control to a routine maintained for the purpose called the Interrupt Service
Routine(ISR). There is one ISR maintained for every device or the devices of the same
category. The ISR checks if the data transfer is complete. If not, it transfers the next data unit
and then returns control to the interrupted program to resume its execution.
As can be seen, in this mode of data transfer the processor does not waste time in a busy wait
loop. This mechanism works fine for the slow I/O devices. For faster I/O devices that require
transfers at rates of megabytes per second, however, transfer of one data unit per execution of
the ISR is not efficient as a good number of instructions are required to be executed in every
unit of data transfer. For that matter, involving the processor for every byte of data transfer
itself becomes very inefficient. This is because in the process of the processor transferring the
data there are two bus cycles involved. In one the processor transfers the data from the memory
to a processor register and in the other it transfer the data from the register to the I/O interface.
In DMA the I/O interface is made to perform the actual transfer of the individual bytes of the
data to/from the memory unit. The processor through the ISR initiates the I/O operation by
supplying the start address of the data block in memory and the size of the data block to be
transferred to the I/O interface and specifying the operation to be performed. The interface than
performs the transfer of the data units in the data block one by one on its own by directly
accessing the memory unit without involving the processor. While this I/O data transfer
operation is carried out by the I/O interface the processor makes itself busy in the execution of
some other process. After the entire data block transfer is completed the interface raises the
interrupt request signal to intimate this information to the processor. The processor, on receipt
of the interrupt request, interrupts the process under execution and checks for the next
command to be given to the interface raising the interrupt and after giving the command to the
interface it resumes execution of the interrupted process.
The DMA mechanism brings in efficiency in the following ways-
1. It reduces the number of bus cycles required for a block of data transfer to/from an I/O
device to half.
2. Reduces the overhead of instruction execution in the ISR per unit of data transfer as the
ISR needs to be executed only once for a large block of data instead of every byte/word of
data transfer.
3. Frees the processor from I/O data transfer activity and allows it to devote its time in useful
process activities and makes multiprogramming possible.
To allow more than one interface in the computer system to have interrupt capability there are
different possibilities:
1. Provide one IRQ signal line for each interface,
2. Let multiple interfaces share one IRQ signal line.
In the first case the IRQ signal line itself identifies the interrupting device interface. Therefore
the processor can chose the appropriate ISR for servicing of the interrupt request raised. In the
second case, however, there is need for mechanism to resolve the identity of the interrupting
device. The following are the mechanisms for interrupt identification:
Polling: In this one of the bits in the status register is used to indicate that the interface has raised
an interrupt. The processor on receipt of an interrupt request reads the status registers of the
interfaces one by one and thus identifies the interrupting interface.
Vectored Interrupt: An interrupt vector consists of the Start Address (PC) & Processor Status
(PS) pair for the ISR of an interface. The interrupt vectors of the interfaces are typically
maintained in an Interrupt Vector Table. Each interface is assigned an identification code which
basically acts as a pointer to the interrupt vector of the interface in the table. When the processor
raises the INTA signal the interrupting interface places its identification code on the data bus.
The processor reads this code and uses this to extract the interrupt vector (PC & PS) of the
interrupt and then transfers control to the ISR of the interface. The interrupt vectors are usually
maintained in a table called the Interrupt Vector Table (IV-table). The interrupt identification
code acts as a pointer to relevant entry in the IV-table.
When there are multiple I/O interfaces capable of raising interrupt request there is possibility
that more than one interface raise interrupt request at the same time. In such a situation the
processor has to decide to which interface it will service first. While one interface is serviced
the other ones have to wait for their turn. Hence there is a question of priority that comes up.
The system must therefore have an Interrupt Priority mechanism. Some of the possible
mechanisms are-
4.4.2.1 Priority Levels: In case there are different interrupt request lines each interrupt
request line is assigned a priority level. When more than one interface raises interrupt
requests simultaneously the processor compares the priority levels of the
corresponding interrupt request lines and responds to the interface using the IRQ with
higher priority by sending INTA to that interface.
4.4.2.2 Daisy Chaining of Interrupt Acknowledgement: When more than one interfaces share
an IRQ signal line they also share the same INTA signal line. The INTA signal line is
however daisy chained through the interfaces, that is, the INTA signal line enters one
interface, goes through its logic circuits, comes out to enter the next interface . . . .
The INTA signal can therefore propagate through the interfaces. An interface,
however, does not allow the signal to propagate through it if it is one of the interfaces
raising interrupt request. Thus, the first interface in the chain among the interfaces
raising IRQ receives the INTA signal and gets the chance to place its identification
code on the data bus to obtain service from the processor while the rest have to wait
for their turn. Hence the sequence of the interfaces in the daisy chain defines the
interrupt priority among the interfaces sharing the IRQ, INTA pair. The priorities of
the interfaces are as per their position in the daisy chain and the one nearest to the
processor has the highest priority.
IRQ
Processor
INTA
Interface1 Interface2 Interface N
Daisy Chain
The I/O interfaces are used for different devices serving wide variety of applications. Some
devices have a higher urgency in receiving the attention of the processor than the others. For
example, an interface involved in a real-time control system has a deadline before which it has
to respond to certain input from the system. Similarly, an interface for a high-speed storage
device needs to transfer data blocks to/ from the device as per time constraints of the device. In
contrast, some of the other devices, particularly the slower ones such as printer, keyboard, etc.
do not have any hard time constraints. Thus it is possible to order the devices in terms of their
urgency in receiving attention/ service from the processor. In case the ISR of a device with
lower urgency is under execution and a device with higher urgency raises an interrupt request,
it may be necessary that the execution of the current ISR is interrupted to allow execution of
the ISR of the device with higher urgency. Once execution of this ISR is complete the control
has to be returned to the previous ISR so that the servicing of that device can be completed.
Such execution of an ISR during execution of another ISR is referred to as nesting of
interrupts. From execution point of view this nesting is similar to that of subroutines.
Therefore, here too stack is used for saving the PC & PS of the current ISR before transferring
control to next ISR. As in case of nesting of subroutines here too several levels of nesting is
possible for interrupts.
There is however another important aspect to this nesting of interrupts. The processor should
attend to an interrupt request only if the device raising interrupt request is of higher urgency
than the one that is currently being served. To ensure this the processors use an interrupt
priority mechanism. As per the urgency of the devices their interfaces are assigned interrupt
priority codes. The device interfaces with the same priority codes are grouped together and
they share the same IRQ, INTA pair while those with different priority codes are assigned
IRQ1
INTA1
IRQ2
INTA2
Processor
IRQ3
INTA3
different IRQ, INTA pairs. Some designated bits in the processor status register are used to
hold the priority of the process under execution. The interrupt priority of the device being
served is assigned to this process priority. This is done through the Interrupt Vector while a
new interrupt vector (PC & PS value pair) is loaded before execution of an ISR begins. When
the code under execution is not an ISR the priority bits in the PS are normally set to 0(zero) so
that the processor can respond to any interrupt that may occur.
The steps involved in the process of interrupts in case of Vectored Interrupt mechanism are as
follows:
Repeat
If Interrupt Request raised Process Interrupt
MAR ← PC
PC++
Read
IR ← MDR
Execute
Until IR = Halt
At the beginning of the loop the control unit checks the interrupt request lines made available
at its inputs. If it finds any of the IRQs raised it jumps to a routine that processes the interrupt
and then returns to the repeat loop for normal instruction execution. Note that interrupts are not
recognized during the execution of an instruction.
After an interface raises an IRQ the processor has to recognize it and then respond to it. The
state or the transition in the IRQ signal that causes the processor to recognize the occurrence of
an interrupt request is called triggering of the interrupt. Some interrupts are triggered by the
IRQ signal being in the active state (High- in case of active high, Low- in case of active low).
This is called Level Triggering. In others the triggering is caused by a transition in the IRQ
signal, either from low to high or from high to low. This is called Edge Triggering.
Triggering becomes important when nested interrupts are supported. In case of level triggering
after an interrupt request is recognized and the processor goes on to start execution of its ISR,
just before it executes the first instruction of the ISR the execution loop will check for interrupt
requests. If the interrupt is level triggered the control unit will find the IRQ currently under
process active and shall respond to it again. This will lead to an infinite loop of interrupt
response.
One way to overcome this problem is Edge Triggering of interrupts. The control unit will
respond to an interrupt request only once. Basically the relevant edge of the IRQ signal will set
a flip-flop in the control unit. After the control unit checks the IRQ line it also resets this flip-
flop so that is does not cause a response to the IRQ second time.
The other possibility is that the control unit disables the interrupts by masking all the IRQ lines
at its input on recognition of an IRQ. The interrupts are enabled again by executing an
Interrupt Enable(IE) instruction provided in the instruction set. The IE instruction can be
placed at the beginning of the ISR if interrupt nesting is to be allowed.
4.5 Exceptions:
Exceptions refer to an event occurring internal to the processor that causes an interruption to
the execution of the current program. Some examples of exceptions are-
When an exception occurs a routine provided for handling the specific condition gets executed.
1. The program causing the software interrupt does not provide the address of the routine.
This is obtained from the Interrupt Vector.
2. Before transferring control to the IRS the Processor Status Register (PSR) content is
changed with that provided in the interrupt vector.
The usefulness of software interrupt also lies in these. Normally software interrupts are used by
application programs for obtaining operating system services. The OS services are encoded in
routines within the OS. The memory addresses of these routines are not known to the
applications. Therefore these routine cannot be executed by the application programs through
subroutine calls. However these addresses can be made available to the ISR for a software
interrupt and thus provide access to these routines to the application programs.
There is another important aspect associated with execution of OS service routines. The OS
service routines can be executed only with a higher privilege level than that of an application
level program. That is because an application level program should not be allowed direct
access to the system resources. This restriction is required to protect these resources from
unauthorized malicious access as well as faulty access by untested and defective code.
Therefore only tested OS service routines are allowed access to the sensitive resources in the
system. The privilege level of a process is encoded in some of the bits in the processor status
register. When a new PS value given in the interrupt vector is loaded to the PSR before
transferring control to the ISR of the software interrupt, the process assume the privilege level
required for execution of the OS service routine. This change in privilege level of the process
from application or user level to that of OS or Supervisory level is called a Context Switch- a
switch of context from application or user context to an OS or supervisory context. This
context switch occurs is case of all interrupts as well as exceptions. At the completion of
execution of the ISR a reverse switch from supervisory context to user context occurs.
1. Identification of the interrupt is automatic from the interrupt instruction. Hence the
interrupt vector can be readily extracted from the IV-table.
2. In software interrupt the task performed by the ISR is initiated by the process under
execution and is very much a part of it. In case of hardware interrupt the task
performed by the IRS executed due to the interrupt may be caused by an event not due
to the interrupted process under execution and may in no way be related to it.
4.7 Direct Memory Access (DMA)
In DMA the I/O interface needs to access the memory unit by itself. Therefore it requires the
capability of driving the bus. This includes the ability of becoming a bus master, to generate a
memory address and place it on the bus and issue a read or write command to the memory unit.
To become a bus master there are protocols and mechanisms that shall be discussed later.
Normally, a DMA interface is used in devices that require transfer of data in blocks. Therefore
it needs to generate the addresses of consecutive locations in a block of memory starting at a
given location. For this it needs to know the start address of the block and the size of the block.
A counter can be used to generate the consecutive addresses. For this a DMA interface
typically has the following:
• The ISR for the interface running on the processor transfers the start address of the
memory block for data transfer and the size of the data to be transferred to the start
address register and the word count/ block size register respectively in the interface and
then writes the command in the command register of the interface. After that the ISR
transfers control of the processor to the interrupted program.
• On receiving the command the interface performs the data transfer as follows:
A DMA interface performs data transfer operations in one of the two following modes-
1. Cycle Stealing Mode: In this mode normally the processor is assumed to be the bus
master. When the bus is not in use by the processor, the DMA interface gets hold of
the bus, performs one bus cycle for memory operation and then releases the bus.
This mode is normally used in interfaces for slower devices.
2. Burst/ Block Mode: In this mode the interface obtains bus mastership, performs a
burst of data transfers to/from memory and then releases the bus. This is normally
used in high speed devices. To operate in this mode the interface maintains a data
buffer capable of holding several bytes/ words of data instead of a single data
register.