You are on page 1of 102

Computer Organization and Architecture

Module 2

By

Sharmila Chidaravalli
Assistant Professor
Department of ISE
GAT
Basic I/O operations

• The data on which the instructions operate are not already


stored in memory.

• Data need to be transferred between processor and outside


world (disk, keyboard, etc.)

• 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.

Rate of data transfer (keyboard, display, processor)

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.

 Input : sent from the keyboard in a similar way


Bus connection for processor keyboard and display
Bus

Processor DATAIN DATAOUT

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)

WRITEWAIT Branch to WRITEWAIT if SOUT=0


Output from R1 to DATAOUT
(Or MoveByte R1,DATAOUT)
read and write operation
 Computers use memory –mapped I/O in which some memory address values
are used to refer to peripheral device buffer registers such as DATAIN,
DATAOUT

 Movebyte DATAIN,R1: contents of keyboard character buffer DATAIN can


be transferred to register R1 in the processor

 Movebyte R1,DATAOUT: contents of R1 can be transferred to DATAOUT

 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

Address Contents LOC = 3000, R0=3000


Move #LOC,R0 3000 h
READ TestBit #3,INSTATUS 3001 e
3002 l
Branch=0 READ
3003 l
MoveByte DATAIN,(R0) 3004 0
ECHO TestBit #3,OUTSTATUS 3005 \n
Branch=0 ECHO
MoveByte (R0),DATAOUT compare ‘\n’, (Ro)
R0=3001
Branch != 0 Read, True
Compare #CR,(R0)+
Branch!= 0 READ
Input/Output Organization
Accessing I/O Devices

Processor Memory

Bus

I/O device 1 I/O de vice n

•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.

I/O devices and the memory may have different


address spaces:
 Special instructions to transfer data to and from I/O devices.
 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 an I/O address.
Accessing I/O Devices
Address lines

Bus Data lines

Control lines

Address Control Data and I/O


decoder circuits status registers int erface

Input device

Hardware required to connect an I/O device


Accessing I/O Devices

•I/O device is connected to the bus using an I/O interface circuit which has:

- Address decoder, control circuit, and data and status registers.

•Address decoder decodes the address placed on the address lines thus enabling the

device to recognize its address.

•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.

•I/O interface circuit coordinates I/O transfers.


Keyboard Control Example
Reads one line from keyboard, stores it in memory buffer
and echoes it back to the display

Move # LINE,R0 initialize memory pointer


WAITK TestBit #0,STATUS test SIN
Branch=0 WAITK wait for char to be entered
Move DATAIN,R1 read character
WAITD TestBit #1,STATUS test SOUT
Branch=0 WAITD wait for display to become ready
Move R1,DATAOUT send char to display
Move R1,(R0)+ store char and advance pointer
Compare #$0D,R1 check if Carriage Return
Branch!= 0 WAITK if not get another char
Move #$0A,DATAOUT otherwise send linefeed
Call PROCESS call a subroutine to process the input line
Accessing I/O Devices

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.

Two other mechanisms used for synchronizing data transfers


between the processor and memory:
 Interrupts.
 Direct Memory Access.
Interrupts
• In program-controlled I/O, when the processor continuously
monitors the status of the device, it does not perform any useful
tasks.

• An alternate approach would be for the I/O device to alert the


processor when it becomes ready.
• Do so by sending a hardware signal called an interrupt to the processor.
• At least one of the bus control lines, called an interrupt-request line is
dedicated for this purpose.

• 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.

•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


resume execution at i+1.

•Return address, or the contents of the PC are usually


stored on the processor stack.
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 return from interrupt
service routine.
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 beginning of the
interrupt service routine.
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 control signal for this purpose.

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

Single interrupt request line may serve n devices.

All devices are connected to line via switches to ground

To request an interrupt device closes its associated switch

Inactive – if all switches are open


voltage on the interrupt request line is equal to Vdd

Device requests an interrupt closing its switch –voltage on line drops to 0,


causing an INTR(interrupt request signal) received by processor to go to 1.

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

 Processor automatically disables interrupts before starting the execution of ISR


(simple processor with one IR line)
 processor performs equivalent of executing an interrupt-disable instruction
 One bit in the PS register called Interrupt-Enable (IE) indicates whether interrupts are
enabled
 Processor clears IE bit in PS register disabling further interrupts
 After return from ISR, PS is restored by enabling the IE bit
Mechanisms to solve the problem of successive interrupts

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.

 Hence there is no danger of multiple interruptions and no need to explicitly disable


interrupt requests from this line
Sequence of events in handling interrupt request from single device, Assuming
that interrupts are enabled

1. The device raises an interrupt request


2. The processor interrupts the program currently being executed
3. Interrupts are disabled by changing the control bits in the PS (except in case of
edge-triggered interrupts)
4. The device is informed that its request has been recognized and in response it
deactivates the interrupt-request signal
5. The action requested by the interrupt is performed by the interrupt-service routine
6. Interrupts are enabled and execution of the interrupted program is resumed
Direct Memory Access
Direct Memory Access (DMA):
 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.

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.

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.
 To transfer a block of data, it increments the memory addresses and keeps track of the
number of transfers.
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
I/O operation involving DMA

OS puts the program requested to transfer in the blocked state

Initiates the DMA

Starts the execution of another program

Completion: DMA controller informs the processor by sending


interrupt request

OS puts the suspended program in the running state.


Direct Memory Access
 R/W bit determines the direction of transfer

 Controller performs read operation when R/W


bit is set to 1(transfer data from memory to I/O
device) else write operation (I/O device to
memory)

 After the block is transferred ,controller is ready


to receive another command, it sets the Done flag
to 1

 Bit 30 is the IE flag, when this flag is set to 1, the


controller raises the interrupt after the block is
transferred

 Controller sets the IRQ bit to 1 when interrupt is


requested
Direct Memory Access

•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
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.

Processor originates most memory access cycles on the bus.


 DMA controller can be said to “steal” memory access cycles from the bus. This
interweaving technique is called as “cycle stealing”.

An alternate approach is the provide a DMA controller an exclusive


capability to initiate transfers on the bus, and hence exclusive access
to the main memory. This is known as the block or burst mode.
BUS Arbitration 
Processor and DMA controllers both need to initiate data transfers on the
bus and access main memory.

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

 Normally, the processor is the bus master, unless it grants


bus membership to one of the DMA controllers. BR

 DMA controller requests the control of the bus by asserting Processor


the Bus Request (BR) line.
DMA DMA
 In response, the processor activates the Bus-Grant1 (BG1)
controller controller
line, indicating that the controller may use the bus when it
BG1 1 BG2 2
is free.

 BG1 signal is connected to all DMA controllers in a daisy


chain fashion.

 BBSY signal is 0, it indicates that the bus is busy. When


BBSY becomes 1, the DMA controller which asserted BR
can acquire control of the bus.
BUS Arbitration  Centralized Bus Arbitration

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.

Each device is assigned a 4-bit ID number.

All the devices are connected using 5 lines, 4 arbitration lines to transmit the ID, and one line
for the Start-Arbitration signal.

To request the bus a device:


 Asserts the Start-Arbitration signal.
 Places its 4-bit ID number on the arbitration lines .

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.

If it detects a difference, it transmits


zeros on the arbitration lines for that
and all lower bit positions.

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
•Device A has the ID 5 and wants to request the
bus:
- Transmits the pattern 0101 on the arbitration
lines.

•Device B has the ID 6 and wants to request the


bus:
- Transmits the pattern 0110 on the arbitration
lines.

•Pattern that appears on the arbitration lines is


the logical OR of the patterns:
- Pattern 0111 appears on the arbitration lines.
BUS Arbitration Distributed Arbitration
Arbitration process:
•Each device compares the pattern that appears on the
arbitration lines to its own ID, starting with MSB.

•If it detects a difference, it transmits 0s on the


arbitration lines for that and all lower bit positions.

•Device A compares its ID 5 with a pattern 0101 to


pattern 0111.

•It detects a difference at bit position 0, as a result, it


transmits a pattern 0100 on the arbitration lines.

•The pattern that appears on the arbitration lines is the


logical-OR of 0100 and 0110, which is 0110.

•This pattern is the same as the device ID of B, and


hence B has won the arbitration.
Buses
Processor, main memory, and I/O devices are interconnected by
means of a bus.

Bus provides a communication path for the transfer of data.


Bus also includes lines to support interrupts and arbitration.

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

Control signals specify:


 Whether it is a read or a write operation.
 Required size of the data, when several operand sizes (byte, word, long word) are
possible.
 Timing information to indicate when the processor and I/O devices may place data
or receive data from the bus.
Schemes for timing of data transfers over a bus can be
classified into:
 Synchronous,
 Asynchronous.
Buses
 Provides communication path for the transfer of data

 Bus includes lines needed to support interrupt and arbitration

 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.

 Data, address and control lines.

 Control signals – R/W (read or write operation), timing information.

 Master: device that initiates data transfers by issuing read or write commands on the bus, also
called as initiator

 Slave or target: device addressed by master


Buses : Synchronous bus

All device derive timing information from common clock line

Equally spaced pulses : equal time intervals

Each time interval constitutes a bus cycle during which one


data transfer can take place.

Crossing points : times at which pattern change


Buses : Synchronous bus

•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.

Width of the pulse t1 - t0 depends on:


 Maximum propagation delay between two devices connected to the bus.
 Time taken by all the devices to decode the address and control signals, so that
the addressed slave can respond at time t1.
Buses : Synchronous bus
At the end of the clock cycle, at time t2, the master strobes the
data on the data lines into its input buffer if it’s a Read
operation.
 “Strobe” means to capture the values of the data and store them into a buffer.

When data are to be loaded into a storage buffer register, the


data should be available for a period longer than the setup
time of the device.

Width of the pulse t2 - t1 should be longer than:


 Maximum propagation time of the bus plus
 Set up time of the input buffer register of the master.
Buses : Synchronous 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.

Processor just assumes that the data are available at


t2 in case of a Read operation, or are read by the
device in case of a Write operation.
What if the device is actually failed, and never really responded?
Buses : Synchronous bus
Most buses have control signals to represent a
response from the slave.

Control signals serve two purposes:


 Inform the master that the slave has recognized the address, and is ready to
participate in a data transfer operation.
 Enable to adjust the duration of the data transfer operation based on the
speed of the participating slaves.

High-frequency bus clock is used:


 Data transfer spans several clock cycles instead of just one clock cycle as in
the earlier case.
Buses : Synchronous bus
Buses : Asynchronous bus

Data transfers on the bus is controlled by a handshake between the


master and the slave.

Common clock in the synchronous bus case is replaced by two timing


control lines:
 Master-ready,
 Slave-ready.

Master-ready signal is asserted by the master to indicate to the slave


that it is ready to participate in a data transfer.

Slave-ready signal is asserted by the slave in response to the master-


ready from the master, and it indicates to the master that the slave is
ready to participate in a data transfer.
Buses : Asynchronous bus

Data transfer using the handshake protocol:


 Master places the address and command information on the bus.

 Asserts the Master-ready signal to indicate to the slaves that the address and
command information has been placed on the bus.

 All devices on the bus decode the address.

 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

t0 - Master places the address and command information on the bus.

t1 - Master asserts the Master-ready signal. Master-ready signal is asserted at t 1 instead of t0

t2 - Addressed slave places the data on the bus and asserts the Slave-ready signal.

t3 - Slave-ready signal arrives at the master.

t4 - Master removes the address and command information.

t5 - Slave receives the transition of the Master-ready signal from 1 to 0.


Buses : Asynchronous bus

Advantages of asynchronous bus:


 Eliminates the need for synchronization between the sender and the receiver.
 Can accommodate varying delays automatically, using the Slave-ready signal.

Disadvantages of asynchronous bus:


 Data transfer rate with full handshake is limited by two-round trip delays.
 Data transfers using a synchronous bus involves only one round trip delay, and hence a
synchronous bus can achieve faster rates.
Basic Processing Unit
Overview

• Instruction Set Processor (ISP)

• Central Processing Unit (CPU)

• A typical computing task consists of a series of steps specified by a


sequence of machine instructions that constitute a program.

• An instruction is executed by carrying out a sequence of more


rudimentary operations.
Basic Processing Unit: Processor
• Executes machine-language instructions.
• Coordinates other units in a computer system.
• Often be called the central processing unit (CPU).
• The term “central” is no longer appropriate today.
• Today’s computers often include several processing units.
E.g., multi-core processor, graphic processing unit (GPU), etc.
Main Components of a Processor
Fundamental Concepts

• The processor fetches one instruction at a time and performs


the operation specified.
• Instructions are fetched from successive memory locations
until a branch or a jump instruction is encountered.
• The processor keeps track of the address of the memory
location containing the next instruction to be fetched using
Program Counter (PC).
• Instruction Register (IR)
Executing an Instruction

• Fetch the contents of the memory location pointed to by the PC.


The contents of this location are loaded into the IR (fetch phase).
IR ← [[PC]]

• Assuming that the memory is byte addressable, increment the


contents of the PC by 4 (fetch phase).
PC ← [PC] + 4

• Carry out the actions specified by the instruction in the IR


(execution phase).
Processor Organization
• ALU
• Registers for temporary storage
• Various digital circuits for
executing different micro
operations.(gates, MUX, decoders,
counters).
• Internal path for movement of
data between ALU and registers.
• Driver circuits for transmitting
signals to external units.
• Receiver circuits for incoming
signals from external units.
PC:
 Keeps track of execution of a program
 Contains the memory address of the next
instruction to be fetched and executed.
MAR:
Holds the address of the location to be accessed.
I/P of MAR is connected to Internal bus and an O/p
to external bus.
MDR:
Contains data to be written into or read out of the
addressed location.
IT has 2 inputs and 2 Outputs.
Data can be loaded into MDR either from memory
bus or from internal processor bus.

The data and address lines are connected


to the internal bus via MDR and MAR
Registers:
The processor registers R0 to Rn-1 vary
considerably from one processor to
another.
Registers are provided for general
purpose used by programmer.
Special purpose registers-index & stack
registers.
Registers Y,Z &TEMP are temporary
registers used by processor during the
execution of some instruction.
Multiplexer:
Select either the output of the register Y
or a constant value 4 to be provided as
input A of the ALU.
Constant 4 is used by the processor to
increment the contents of PC.
ALU:
Used to perform arithmetic and
logical operation.

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

Input and output of register Ri are controlled by


switches ( ): Ri out

Y in
• Ri-in: Allow data to be transferred into Ri

• Ri-out: Allow data to be transferred out from Ri Y

Constant 4

Select MUX

A B
ALU

Z in

Z out

Input and output gating for the registers .


Internal processor
b us

Register Transfers R i in

Ri

• The input and output gates for


register Ri are controlled by Ri out

signals is Rin and Riout . Y in

• Rin is set to1 – data available on Constant 4

common bus are loaded into Ri.


Select MUX

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.

2. Enable input of register R4 by setting R4in=1. This loads the


data from the processor bus into register R4.
Example :

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

• Performs arithmetic and logic operation on the two


operands applied to it’s A and B inputs

• In the previous diagram,


• One of the operands is the output of the
multiplexer MUX and the other operand is
obtained directly from the bus.
• The result produced by the ALU is stored
temporarily in register Z.
Sequence of operations to add the contents of register R1 to those of
register R2 and store the result in register R3

R3 [R1] + [R2]

Sequence of Steps:

1. R1out, Yin

2. R2out, SelectY, Add, Zin

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

Uni-directional bus ().

Connect to the external address lines directly.

MDR: Memory Data Register

Bi-directional bus ().

MDR connections to both internal and external

buses are all controlled by switches.

Connection and control signals for register MDR


Fetching a word from memory
 Consider the instruction Move (R1),R2. The actions needed to execute this instruction
are:

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

A Read control signal is activated at the same time MAR is


loaded, causes bus interface circuit to send a read command
MR on bus (combine 1 & 2)

Activating control signal MDRinE while waiting for a response


from memory. Thus data received from the memory are
loaded into MDR at the end of the clock cycle in which the
MFC signal is received (combine 3 & 4)

MDRout is activated to transfer data to register R2


Mov (R1), R2,
Sequence of Steps:

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

2. MDRinE, WMFC (wait until the loading is completed)

3. MDRout,R2in
Timing Sequence:

1. R1-out (not shown),


MAR-in, Read (start to read a word from memory)
MAR ← [R1]

=== assume memory read


takes 3 cycles ===
Start a Read operation on the memory bus

2. MDR-inE ,
WaitMFC(wait until the loading is completed)

3. MDR-out, R2-in(not shown)

Wait for the MFC response from the memory

Load MDR from the memory bus


Storing a Word in memory

To write a word into memory location,


• The desired address is loaded into MAR
• Data to be written are loaded into MDR and write command is
issued
Storing a Word in memory
Mov R2, (R1)

Sequence of Steps: R/W


MFC

1. R1out,MARin

2. R2out, MDR in, Write

3. MDR outE, WMFC


Execution of a complete instruction
ADD (R3),R1

Executing the instruction requires the following actions.


1. Fetch the instruction.
2. Fetch the first operand( the contents of the memory location pointed to by
R3)
3. Perform addition
4. Load the result into R1
Execution of a complete instruction
Control sequence for execution of the
instruction Add(R3),R1 Instruction Fetch R/W
MFC

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

2. Z out, PC in, Yin, WMFC

3. MDR out, IRin

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

2. Z out, PC in, Yin, WMFC

3. MDR out, IRin

4. Offset-field-of-IRout, Add,Zin,IF N=0 then End

5. Zout,PCin,End
Multiple Bus organization of the data path

• Disadvantage of single internal bus:


Only one data item can be transferred
internally at a time.

• Solution: Multiple Internal Buses


All registers combined into a register file with
three ports
TWO out-ports and ONE in-port.
Why 3? Typical instruction format

Buses A and B allow simultaneous transfer of the


two operands from registers to the ALU.

Bus C allows transferring data into a third register


during the same clock cycle.
Multiple Bus organization of the data path

Solution: Multiple Internal Buses


How to do register transfer?
ALU can pass one of its operands to output
R.
E.g. R=A or R=B

How to further reduce the internal bus


contention?
Employ an additional “Incrementer” unit to
compute [PC]+4 (IncPC).
•ALU is not used for incrementing PC.
•ALU still has a Constant 4 input for other
instructions (e.g., post-increment: [SP]++ for
stack push).
Multiple Bus organization of the data path

Control sequence for the instruction Add R4,R5,R6 for the three-bus

organization

1 PC out, R=B, MARin, Read, IncPC

2 WMFC

3 MDRoutB, R=B, IRin

4 R4outA, R5outB,SelectA, ADD, R6in,End


Multiple Bus organization of the data path

• Buses A & B are used to transfer the source operands to the inputs of the ALU, where an
ALU operation may be performed

• The result is transferred to the destination over the bus C

• 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

• There is no need of registers Y and Z.

• 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.

You might also like