UNIT 4 LoC 2
UNIT 4 LoC 2
In computer architecture, input-output devices act as an interface between the machine and the
user.
Instructions and data stored in the memory must come from some input device. The results are
displayed to the user through some output device.
The following block diagram shows the input-output configuration for a basic computer.
Note: FGI and FGO are corresponding input and output flags which are considered as control
flip-flops.
1. Two decoders: a 3 x 8 operation decoder and 4 x 16 timing decoder
2. A 16-bit common bus
3. Control Logic Gates
4. The Logic and Adder circuits connected to the input of AC.
Addressing Modes
An instruction contains an operation field, an address field, and a mode field. The operation field
indicates what operation is to be performed, for example, addition, subtraction, multiplication,
etc. The mode field indicates how the memory address of the operand, which is to be used in an
operation, is determined. To understand the various types of addressing modes, it is important to
understand how the computer deals with instruction. The instruction cycle of a computer goes
through the following three phases:
Implied mode
In this mode, the instruction contains an indirect definition of the operand. An example of an
implied mode instruction is CMA (complement accumulator). Here, the operand (complement) is
implicitly specified in the instruction.
Immediate addressing mode
In this mode, the instruction contains both the opcode and the operand. It can be said that an
instruction that uses the immediate addressing mode contains an operand field in place of an
address field. The operation, as well as the operands, are mentioned in the instruction. An
example of immediate addressing mode instruction is ADD 10. Here, ADD, which is the
operation, and 10, which is the operand, are specified.
Register mode
In this mode, the instruction specifies a register. This register stores the operand. An example of
register mode instruction is:
AC = AC + [R]
This will add the operand stored at register R to the operand stored in the accumulator.
In this mode, the instruction specifies a register. This register stores the effective address of the
operand. An instruction that uses register indirect addressing mode is:
AC = AC + [[R]]
Here, the contents which reside in the memory location specified by the register R will be added
to the contents of the accumulator.
In this mode, the instruction specifies an address. This address is the address of the operand. An
example of a direct addressing mode instruction is:
AC = AC + [X]
This will add the operand stored at address X with the operand stored in the accumulator. This
mode is also referred to as absolute addressing mode.
In this mode, the instruction specifies an address. The memory location specified by the address
contains the address of the operand. An example of an indirect addressing mode instruction is:
AC = AC + [[X]]
This will add the operand stored at the address specified by the memory location X with the
contents of the accumulator.
Auto-increment/decrement mode
In this mode, the instruction specifies a register which points to a memory address that contains
the operand. However, after the address stored in the register is accessed, the address is
incremented or decremented, as specified. The next operand is found by the new value stored in
the register.
In this mode, the contents of the address field are added to the constant stored in the program
counter. The result of the addition gives the address of the operand. For example, suppose the
address field contains 850, and the program counter contains 20, then the operand will be at
memory location 850 + 20 = 870.
In this mode, the address of the operand is determined by adding the contents of the address field
and the contents of the index register.
In this mode, the address of the operand is determined by adding the contents of the address field
and the contents of the base register.
Immediate addressing mode: Used to set an initial value for a register. The value is usually a
constant
Register addressing mode/direct addressing mode: Used to implement variables and access
static data
Register indirect addressing mode/indirect addressing mode: Used to pass an array as a
parameter and to implement pointers
Relative addressing mode: Used to relocate programs at run time and to change the execution
order of instruction
Index addressing mode: Used to implement arrays
Base register addressing mode: Used to write codes that are relocatable and for handling
recursion
Auto-increment/decrement addressing mode: Used to implement loops and stacks
To provide users with programming versatility by providing facilities such as counters, pointers,
indexing, and program relocation
Conclusion
The addressing mode is one of the fields in an instruction. This field determines how and where
an operand is fetched from the memory. The various types of addressing modes are:
Input-Output Interface
Interrupts
The interrupt is a signal emitted by hardware or software when a process or an
event needs immediate attention. It alerts the processor to a high-priority
process requiring interruption of the current working process. In I/O devices one
of the bus control lines is dedicated for this purpose and is called the Interrupt
Service Routine (ISR).
When a device raises an interrupt at let’s say process i, the processor first
completes the execution of instruction i. Then it loads the Program Counter
(PC) with the address of the first instruction of the ISR. Before loading the
Program Counter with the address, the address of the interrupted instruction is
moved to a temporary location. Therefore, after handling the interrupt the
processor can continue with process i+1.
While the processor is handling the interrupts, it must inform the device that its
request has been recognized so that it stops sending the interrupt request
signal. Also, saving the registers so that the interrupted process can be restored
in the future, increases the delay between the time an interrupt is received and
the start of the execution of the ISR. This is called Interrupt Latency.
Software Interrupts:
Hardware Interrupts:
In a hardware interrupt, all the devices are connected to the Interrupt Request
Line. A single request line is used for all the n devices. To request an interrupt,
a device closes its associated switch. When a device requests an interrupt, the
value of INTR is the logical OR of the requests from individual devices.
The sequence of events involved in handling an IRQ:
1. Devices raise an IRQ.
2. The processor interrupts the program currently being executed.
3. The device is informed that its request has been recognized and the device
deactivates the request signal.
4. The requested action is performed.
5. An interrupt is enabled and the interrupted program is resumed.
Handling Multiple Devices:
When more than one device raises an interrupt request signal, then additional
information is needed to decide which device to be considered first. The
following methods are used to decide which device to select: Polling, Vectored
Interrupts, and Interrupt Nesting. These are explained as following below.
1. Polling: In polling, the first device encountered with the IRQ bit set is the
device that is to be serviced first. Appropriate ISR is called to service the
same. It is easy to implement but a lot of time is wasted by interrogating the
IRQ bit of all devices.
2. Vectored Interrupts: In vectored interrupts, a device requesting an
interrupt identifies itself directly by sending a special code to the processor
over the bus. This enables the processor to identify the device that
generated the interrupt. The special code can be the starting address of the
ISR or where the ISR is located in memory and is called the interrupt vector.
3. Interrupt Nesting: In this method, the I/O device is organized in a priority
structure. Therefore, an interrupt request from a higher priority device is
recognized whereas a request from a lower priority device is not. The
processor accepts interrupts only from devices/processes having priority.
Processors’ priority is encoded in a few bits of PS (Process Status register). It
can be changed by program instructions that write into the PS. The processor is
in supervised mode only while executing OS routines. It switches to user mode
before executing application programs.
2. Interrupt—Driven I/O:
To overcome the disadvantage of Programmed I/O,i.e., keeping CPU busy
needlessly, Interrupt — Driven I/O is used. In this approach, when a
peripheral sends an interrupt signal to the CPU whenever it is ready to
transfer data. This indicates that the I/O data transfer is initiated by the
external I/O device. The processor stops the execution of the current
program & transfers the control to interrupt the service routine when
interrupted. The interrupt service routine then performs the data transfer.
After the completion of data transfer, it returns control to the main program to
the point it was interrupted.
6. Used for small data transfer. Used for large data transfer.