You are on page 1of 10

Stages of a Datapath

Problem: a single, atomic block which


executes
executes an instruction
instruction (performs all
necessary operations beginning with fetching
the instruction) would be too bulky and
inefficient.

Solution: break up the process of executing


an instruction into stages, and then connect
the stages to create the whole datapath.
Smaller stages are easier to design
design.
Easy to optimize (change) one stage without
touching the others.

Stages of a Datapath (2)

There is a wide variety of MIPS instructions:


so what
h t generall steps
t
d
do th
they h
have iin
common?

Stages
St
1.
2
2.
3.
4.
5.

Instruction Fetch
Instruction Decode
ALU
Memory Access
Register Write

Stages of a Datapath (3)

Stage 1: Instruction Fetch.


No matter what the instruction is, the 32-bit

instruction word must first be fetched from


memoryy ((the cache-memoryy hierarchy).
y)
Also, this is where we increment PC
(that is, PC = PC + 4, to point to the next
i t ti
instruction;
b
byte
t addressing
dd
i so + 4)
4).

Stages of a Datapath (4)

Stage 2: Instruction Decode


Upon fetching the instruction, we next gather data

from the fields (decode all necessary instruction


data).
)
First, read the opcode to determine instruction
type and field lengths.
Second, read in data from all necessary registers.
For add, read two registers.
For addi,
addi read one register
register.
For jal, no read necessary.

Stages of a Datapath (5)

Stage 3: ALU (Arithmetic-Logic Unit)


The real work of most instructions is done here:
arithmetic (+, -, *, /), shifting, logic (&, |),
comparisons
p
((slt).
)

What about loads and stores?


lw $t0, 40($t1)
The address we are accessing in memory =
the value in $t1 plus the value 40.

We do this addition at this stage


stage.

Stages of a Datapath (6)

Stage 4: Memory Access


Actually only the load and store instructions do

anything during this stage; for the other


instructions,, theyy remain idle during
g this stage.
g
Since these instructions have a unique step, we
need this extra stage to account for them.
As a result of the cache system, this stage is
expected to be just as fast (on average) as the
others.

Stages of a Datapath (7)

Stage 5: Register Write


Most instructions write the result of some
computation into a register.
Examples: arithmetic
arithmetic, logical
logical, shifts
shifts, loads
loads, slt

What about stores, branches, jumps?


Theyy do not write anything
y
g into a register
g
at

the end.
These remain idle during this fifth stage.

+4

1 Instruction
1.
Fetch

ALU

Da
ata
mem
mory

rd
rs
rt

rregisters

PC

insttruction
me
emory

Datapath: Generic Steps

imm

2 Decode/
2.
Register
Read

3 Execute 4.
3.
4 Memory 5.
5 Reg
Reg.
Write

Datapath Walkthroughs: add

add $r3,$r1,$r2 # r3 = r1+r2


Stage 1: Fetch this instruction, increment PC.
Stage 2: Decode to find that it is an add
instruction then read registers $r1 and $r2.
instruction,
$r2

Stage 3: Add the two values retrieved in stage 2.


Stage
g 4: Idle ((nothing
g to write to memory).
y)
Stage 5: Write result of stage 3 into register $r3.

+4
4

2
imm

reg[1]
[1]
reg[1]+reg[2]
reg[2]

ALU

Da
ata
mem
mory

re
egisters

add r3, r1, r2

PC

instrruction
memory

Datapath Walkthroughs: add (2)

You might also like