Professional Documents
Culture Documents
Module 2
By
Sharmila Chidaravalli
Assistant Professor
Department of ISE
GAT
Basic I/O operations
• I/O operations are essential, the way they are performed can
have a significant effect on the performance of the computer.
Program-Controlled I/O Example
Read character input from a keyboard and produce character output on a display screen.
Difference in speed between processor and I/O device creates the need for mechanisms
to synchronize the transfer of data.
Solution
Output : the processor sends the first character and then waits for a signal from the
display that the character has been received.
It then sends the second character.
SIN SOUT
- Registers
- Flags
- Device interface Keyboard Display
Bus connection for processor keyboard and display
To inform the processor that a valid character is in DATAIN, a status
Control flag SIN is set to 1.
A program monitors SIN & when SIN is set to 1, the processor reads the
contents of DATAIN.
When character is transferred to processor SIN is automatically cleared to
0. If a 2nd character is entered at the keyboard, SIN is again set to 1 and the
process repeats.
An Analogous process taken place when character are transferred from the
processor to the display.
A buffer register DATAOUT, & a status control flag, SOUT are used for
this transfer.
Bus connection for processor keyboard and display
When SOUT = 1, the display is ready to receive a character under program control,
the processor monitors SOUT & when SOUT = 1 the processor transfer a character
code to DATAOUT. The transfer of a character to DATAOUT clears SOUT=0.
When the display device is ready to receive a second character SOUT is again set
to 1.
The Buffer register DATAIN & DATAOUT and the status flags SIN & SOUT are
part of circuitry commonly known as device interface.
Machine instructions for read/write operation
READWAIT Branch to READWAIT if SIN=0
Input from DATAIN to R1
(Or MoveByte DATAIN, R1)
SIN & SOUT are cleared automatically when the buffer registers DATAIN &
DATAOUT are referenced
Read operation
READWAIT Testbit #3,INSTATUS
Branch=0 READWAIT
Movebyte DATAIN,R1
Write operation
WRITEWAIT Testbit #3,OUTSTATUS
Branch=0 WRITEWAIT
Movebyte R1,DATAOUT
A Program that reads a line of characters and display it
Processor Memory
Bus
•Multiple I/O devices may be connected to the processor and the memory via a bus.
•Bus consists of three sets of lines to carry address, data and control signals.
•Each I/O device is assigned an unique address.
•To access an I/O device, the processor places the address on the address lines.
•The device recognizes the address, and responds to the control signals.
Accessing I/O Devices
I/O devices and the memory may share the same
address space:
Memory-mapped I/O.
Any machine instruction that can access memory can be used to transfer data to
or from an I/O device.
Simpler software.
Control lines
Input device
•I/O device is connected to the bus using an I/O interface circuit which has:
•Address decoder decodes the address placed on the address lines thus enabling the
•Data register holds the data being transferred to or from the processor.
•Status register holds information necessary for the operation of the I/O device.
•Data and status registers are connected to the data lines, and have unique addresses.
Recall that the rate of transfer to and from I/O devices is slower
than the speed of the processor. This creates the need for
mechanisms to synchronize data transfers between them.
Program-controlled I/O:
Processor repeatedly monitors a status flag to achieve the necessary
synchronization.
Processor polls the I/O device.
• Processor can perform other useful tasks while it is waiting for the
device to be ready.
Interrupts
•Processor is executing the instruction located at address i
when an interrupt occurs.
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 return from interrupt
service routine.
Interrupts
Saving and restoring information can be done automatically by
the processor or explicitly by program instructions.
In other cases, the data transfer that takes place between the device and the processor can be
used to inform the device.
Interrupt Hardware
Interrupt Hardware
Several devices can request an interrupt
Since the closing of one or more switches will close the line voltage to drop to 0
the value of INTR is logical OR of the requests from individual devices.
How are interrupts enabled and disabled?
Interrupt-requests interrupt the execution of a program, and may alter the intended
sequence of events:
Sometimes such alterations may be undesirable, and must not be allowed.
For example, the processor may not want to be interrupted by the same device while executing
its interrupt-service routine.
Processors generally provide the ability to enable and disable such interruptions as
desired.
One simple way is to provide machine instructions such as Interrupt-enable and
Interrupt-disable for this purpose.
To avoid interruption by the same device during the execution of an interrupt
service routine:
First instruction of an interrupt service routine can be Interrupt-disable.
Last instruction of an interrupt service routine can be Interrupt-enable.
Mechanisms to solve the problem of successive interrupts
First Option
Processor h/w ignore the interrupt-request line until the execution of the first
instruction of ISR has been completed
Using interrupt disable instruction as the first instruction in ISR
Typically interrupt-enable instruction will be the last instruction in the interrupt
service routine before the return-from-interrupt instruction
Second Option
Third Option
Processor has a special Interrupt-Request line for which the interrupt–handling circuit
responds to only the leading edge of the signal, such a line is said to be edge triggered
Processor will receive only one request, regardless of how long the line is activated.
Control unit which performs these transfers is a part of the I/O device’s
interface circuit. This control unit is called as a DMA controller.
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
I/O operation involving DMA
•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
control information are duplicated.
Direct Memory Access
DMA Operation
To start DMA transfer from main memory to one of the disks,
a program writes the address, word count and function (read or write) information into the
registers of the corresponding channel of the disk controller
DMA device request have the higher priority than the processor requests for using the bus
Top priority is given to high speed peripherals such as disk, high speed network interface or
graphics display device.
Direct Memory Access
Processor and DMA controllers have to use the bus in an
interwoven fashion to access the memory.
DMA devices are given higher priority than the processor to access the bus.
Among different DMA devices, high priority is given to high-speed peripherals such as a
disk or a graphics display device.
The device that is allowed to initiate transfers on the bus at any given time is
called the bus master.
When the current bus master relinquishes its status as the bus master,
another device can acquire this status.
The process by which the next device to become the bus master is selected and bus mastership is
transferred to it is called bus arbitration.
Centralized arbitration:
A single bus arbiter performs the arbitration.
Distributed arbitration:
All devices participate in the selection of the next bus master.
BUS Arbitration
Centralized Bus Arbitration
B BS Y
BR
Processor
DMA DMA
controller controller
BG1 1 BG2 2
BUS Arbitration Centralized Bus Arbitration
Bus arbiter may be the processor or a separate unit
connected to the bus. BBSY
BBSY
BR
Processor
DMA DMA
Controller1 Controller2
BG1 BG2
BUS Arbitration Centralized Bus Arbitration
BUS Arbitration Distributed Arbitration
All devices waiting to use the bus share the responsibility of carrying out the arbitration process.
Arbitration process does not depend on a central arbiter and hence distributed arbitration
has higher reliability.
All the devices are connected using 5 lines, 4 arbitration lines to transmit the ID, and one line
for the Start-Arbitration signal.
The pattern that appears on the arbitration lines is the logical-OR of all the 4-bit device IDs
placed on the arbitration lines.
BUS Arbitration Distributed Arbitration
BUS Arbitration Distributed Arbitration
Arbitration process:
Each device compares the pattern that
appears on the arbitration lines to its
own ID, starting with MSB.
A bus protocol is the set of rules that govern the behavior of various
devices connected to the bus, as to when to place information on
the bus, when to assert control signals, etc.
Buses
Bus lines may be grouped into three types:
Data
Address
Control
Bus protocol: set of rules that govern the behavior of various devices connected to the bus as to
when to place information on the bus, assert control signals and so on.
Master: device that initiates data transfers by issuing read or write commands on the bus, also
called as initiator
•In case of a Write operation, the master places the data on the bus along with the
address and commands at time t0.
•The master strobes the data into its input buffer at time t2.
Buses : Synchronous bus
Once the master places the device address and command on the
bus, it takes time for this information to propagate to the devices:
This time depends on the physical and electrical characteristics of the bus.
Also, all the devices have to be given enough time to decode the
address and control signals, so that the addressed slave can place
data on the bus.
•Signals do not appear on the bus as soon as they are placed on the bus, due to the propagation delay
in the interface circuits.
•Signals reach the devices after a propagation delay which depends on the characteristics of the bus.
•Data must remain on the bus for some time after t2 equal to the hold time of the buffer.
Buses : Synchronous bus
Data transfer has to be completed within one clock
cycle.
Clock period t2 - t0 must be such that the longest propagation
delay on the bus and the slowest device interface must be
accommodated.
Forces all the devices to operate at the speed of the slowest device.
Asserts the Master-ready signal to indicate to the slaves that the address and
command information has been placed on the bus.
Address slave performs the required operation, and informs the processor it has
done so by asserting the Slave-ready signal.
Master removes all the signals from the bus, once Slave-ready is asserted.
If the operation is a Read operation, Master also strobes the data into its input
buffer.
Buses : Asynchronous bus
t2 - Addressed slave places the data on the bus and asserts the Slave-ready signal.
Data Path:
The registers, ALU and
interconnecting bus are
collectively referred to as the data
path.
Instruction Execution
• Fetch Phase
• Execute Phase
Internal processor
b us
Register Transfers R i in
Ri
Y in
• Ri-in: Allow data to be transferred into Ri
Constant 4
Select MUX
A B
ALU
Z in
Z out
Register Transfers R i in
Ri
A B
• Riout is set to1 – the contents of ALU
register are placed on the bus.
Z in
Z
• Riout is set to 0 – the bus can be
used for transferring data from Z out
other registers .
Input and output gating for the registers .
Register Transfers
Data transfer between two registers:
Example:
Transfer the contents of R1 to R4.
1. Enable output of register R1 by setting R1out=1. This places
the contents of R1 on the processor bus.
R3 [R1]
Clock 1:
R1-out, R3-in
•Set R1-outto 1
•Set R3-into 1
•Set all others to 0
Clock 2:
•Reset R1-outto 0
•Reset R3-into 0
Arithmetic or Logic Operation
• ALU is a combinational Circuit that has no internal
storage
R3 [R1] + [R2]
Sequence of Steps:
1. R1out, Yin
3. Z out, R3in
What is the sequence of steps for the following operation?
R6 [R4] –[R5]
Fetching a word from memory
• CPU transfers the address of the required information word to the MAR. Address of the required
word is transferred to the main memory.
• Meanwhile, the CPU uses the control lines of the memory bus to indicate that a read operation is
required.
• After issuing this request, the CPU waits until it receives an answer from the memory, informing it
that the requested function has been completed. This is accomplished through the use of another
control signal MFC (memory function completed)
• The memory sets this signal to 1 to indicate that the contents of the specified location in the memory
have been read and are available on the data lines of the memory bus.
• We will assume that as soon as the MFC signal is set to 1, the information on the data lines is loaded
into MDR and is thus available for use inside the CPU. This completes the memory fetch operation.
Fetching a word from memory
MAR: Memory Address Register
1. MAR[R1]
2. Start a Read operation on the memory bus
3. Wait for the MFC response from the memory.
4. Load MDR from the memory bus
5. R2[MDR]
These actions are carried out as separate steps, but some can be combined into single
step.
Each action can be completed in one clock cycles, except action 3 which may require
several clock cycles, depending on the speed of the addressed device
Fetching a word from memory
R/W
Control signals which are necessary to perform given action are MFC
Address
1. R1out,MARin,Read (start to load a word from memory) Lines
3. MDRout,R2in
Timing Sequence:
2. MDR-inE ,
WaitMFC(wait until the loading is completed)
1. R1out,MARin
1. PCout,MARin,Read,Select4,Add,Zin
2. Z out, PC in, Yin, WMFC
3. MDR out, IRin
4. R3out,MARin,Read
5. R1out,Yin,WMFC
6. MDRout, SelectY, Add, Zin
7. Zout,R1in,END
Execution of a complete instruction
1. Fetch operation is initiated by loading the contents of PC into the MAR and sending a
read Request to the memory. select signal is set to select4, this is added to the operand
at B, which is the contents of the PC & the result is stored in register Z.
2. The updated value is moved from register Z back into the PC while waiting for the
memory to respond.
3. The word fetch from the memory is loaded into the IR (Execution phase). Enables the
control circuitry to activate the control signals for step 4-7 which constitute the
execution phase.
4. Contents of register R3 are transferred to MAR, and memory read operation is initiated.
5. Contents of R1 are transferred to Y to prepare for the addition operation.
6. When read operation is completed the memory operand is available in register MDR,
addition operation is performed, result is stored in Z
7. Result Z transferred to R1. End signal causes a new instruction fetch cycle to begin by
returning to step 1
Execution of Branch Instructions
• A branch instruction replaces the contents of PC with the branch target address,
which is usually obtained by adding an offset X given in the branch instruction.
• The offset X is usually the difference between the branch target address and the
address immediately following the branch instruction.
• For example if the branch instruction is at location 1000 and if the branch target
address is 1050, the value of X must be 46.
Execution of Branch Instructions
Control sequence for an unconditional Branch instruction
1. PCout,MARin,Read,Select4,Add,Zin
4. Offset-field-of-IRout, Add,Zin
5. Zout,PCin,End
Execution of Branch Instructions
Control sequence for a conditional Branch instruction
1. PCout,MARin,Read,Select4,Add,Zin
5. Zout,PCin,End
Multiple Bus organization of the data path
Control sequence for the instruction Add R4,R5,R6 for the three-bus
organization
2 WMFC
• Buses A & B are used to transfer the source operands to the inputs of the ALU, where an
ALU operation may be performed
• If needed ALU may simply pass one of its 2-i/p operands unmodified to bus C by
generating control signals called as R=A and R=B
• Incrementer unit, eliminates the need to add 4 to the PC using the main ALU.
• Constant 4 at the ALU input multiplexer is used to increment other addresses, such as the
memory addresses in Loadmultiple and Storemultiple instructions.