RISC Processor Design: Multi-Cycle Cycle Implementation: Mips
RISC Processor Design: Multi-Cycle Cycle Implementation: Mips
SE-273@SERC
16-20
11-15
Combined
Datapaths
0-15
Sign
ext.
Shift
left 2
0 mux 1
1 mux 0
ALU
zero
MemtoReg
MemWrite
MemRead
Data
mem.
ALU
Cont.
0-5
Mar 07, 2008
SE-273@SERC
0 mux 1
Instr.
mem.
ALU
PC
1 mux 0
21-25
1 mux 0
26-31
Branch
Reg. File
opcode
Jump
Shift
left 2
CONTROL
RegDst
Add
0-25
ALU (R-type)
Load word (I-type)
Store word (I-type)
Branch on equal (I-type)
Jump (J-type)
SE-273@SERC
6ns
8ns
7ns
5ns
2ns
2ns
4
SE-273@SERC
a31
.
.
.
a2
a1
a0
b31
.
.
.
b2
b1
b0
1-b full
adder
1-b full
adder
1-b full
adder
1-b full
adder
0
Mar 07, 2008
c32
s31
.
.
.
s2
s1
s0
a31
.
.
.
a2
a1
a0
b31
.
.
.
b2
b1
b0
Mar 07, 2008
FF
Initialize
to 0
SE-273@SERC
s31
.
.
.
s2
s1
s0
Shift
Shift
Shift
A Multicycle Implementation
ALUOut Reg.
ALU
A Reg.
B Reg.
Register file
Data
Addr.
Memory
PC
Multi-cycle Datapath
SE-273@SERC
SE-273@SERC
Multicycle Datapath
MUX
in1
control
in2
MemRead
MemWrite
Mar 07, 2008
IRWrite
RegDst
MemtoReg
0-15
0-5
SE-273@SERC
Sign
extend
ALUOut Reg.
ALU
ALUSrcB
28-31
ALUSrcA
A Reg.
11-15
16-20
Shift
left 2
RegWrite
B Reg.
out
21-25
Register file
Data
0-25
IorD
Memory
Addr.
PC
26-31 to
Control
FSM
PCWrite
etc.
PCSource
Shift
left 2
ALU
control
10
ALUOp
R-type
(4 cycles)
Mem. Ref.
(4 or 5 cycles)
Branch type
(3 cycles)
J-type
(3 cycles)
Instruction fetch
IR Memory[PC]; PC PC+4
Instr. decode/
Reg. fetch
A Reg(IR[21-25]); B Reg(IR[16-20])
ALUOut PC + (sign extend IR[0-15]) << 2
Execution,
addr. Comp.,
branch & jump
completion
Mem. Access
or R-type
completion
ALUOut
A op B
Reg(IR[1115])
ALUOut
Memory read
completion
Mar 07, 2008
ALUOut
A+sign extend
(IR[0-15])
If (A= =B)
then
PCALUOut
PCPC[2831]
||
(IR[0-25]<<2)
MDRM[ALUout]
or M[ALUOut]B
Reg(IR[16-20])
MDR
SE-273@SERC
11
IorD
=
0
MemRead =
1
IRWrite
=
1
Increment PC, PC + 4 PC
select PC
read memory
write IR
=
=
=
=
=
0
01
00
00
1
SE-273@SERC
z
z
25-21
20-16
15-11
10-6
5-0
opcode |
SE-273@SERC
13
ALUSrcA
=
1
A reg into ALU
ALUsrcB
=
00
B reg into ALU
ALUOp
=
10
instr. Bits 0-5 control ALU
I type, lw or sw: compute memory address in
ALUOut A reg + sign extend IR[0-15]
ALUSrcA
ALUSrcB
ALUOp
=
=
=
1
10
00
SE-273@SERC
ALUSrcA
=
1
A reg into ALU
ALUsrcB
=
00
B reg into ALU
ALUOp
=
01
ALU subtracts
If zero = 1, PCSource = 01
ALUOut to PC
If zero = 1, PCwriteCond =1
write PC
Instruction complete, go to IF
PCSource
=
10
PCWrite
=
1
Instruction complete,
go to IF
SE-273@SERC
write PC
15
IorD
=
1 select ALUOut into mem adr.
MemRead
=
1 read memory to MDR
I type, sw: write M[ALUOut] from B reg
IorD
=
1
select ALUOut into mem adr.
MemWrite =
1
write memory
Mar 07, 2008
16
SE-273@SERC
Instruction complete,
go to IF
RegDst
=
0
instr. Bits 16-20 are write reg
MemtoReg =
1
MDR to reg file write input
RegWrite =
1
read memory to MDR
Instruction complete, go to IF
SE-273@SERC
17
Value = 0
Value =1
RegDst
RegWrite
No action
ALUSrcA
MemRead
No action
Mem.Data OutputM[Addr.]
MemWrite
No action
MemtoReg
IorD
Mem. Addr. PC
IRWrite
No action
IR Mem.Data Output
PCWrite
No action
PC is written
PCWriteCond
No action
PC is written if zero(ALU)=1
zero(ALU)
PCWriteCond
PCWrite
Mar 07, 2008
SE-273@SERC
PCWrite etc.
18
ALUSrcB
PCSource
Value
Action
00
01
10
00
01
10
11
Second input of ALU 0-15 bits of IR sign ext. and left shift
2 bits
00
01
10
SE-273@SERC
19
Clock
cycle 1
Instruction fetch
State 1
Clock
cycle 2
Clock
cycles
3-5
Memory
access
instr.
FSM-R
FSM-B
R-type
instr.
Branch
instr.
SE-273@SERC
FSM-J
Jump
instr.
20
MUX
in1
control
in2
MemRead = 1
MemWrite
Mar 07, 2008
IRWrite
=1
RegDst
MemtoReg
Shift
left 2
0-15
0-5
SE-273@SERC
Sign
extend
ALUOut Reg.
ALU
ALUSrcB=01
28-31
ALUSrcA=0
A Reg.
RegWrite
B Reg.
out
16-20
21-25
Register file
Data
0-25
IorD=0
Memory
Addr.
PC
26-31 to
Control
FSM
PCWrite
etc.=1
PCSource=00
Add
Shift
left 2
ALU
control
21
ALUOp
=00
State 1
Instruction decode/
Register fetch/
Branch addr.
Outputs?
SE-273@SERC
22
MUX
in1
control
in2
MemRead
MemWrite
Mar 07, 2008
IRWrite
RegDst
MemtoReg
Shift
left 2
0-15
0-5
SE-273@SERC
Sign
extend
ALUOut Reg.
ALU
ALUSrcB=11
28-31
ALUSrcA=0
A Reg.
RegWrite
B Reg.
out
16-20
21-25
Register file
Data
0-25
IorD
Memory
Addr.
PC
26-31 to
Control
FSM
PCWrite
etc.
PCSource
Add
Shift
left 2
ALU
control
23
ALUOp
= 00
State0
Instruction
fetch
MemRead =1
(IF)
ALUSrcA = 0
IorD = 0
IRWrite = 1
ALUSrcB = 01
ALUOp = 00
PCWrite = 1
PCSource = 00
FSM-M
State 1
Instruction decode (ID) /
Register fetch /
Branch addr.
ALUSrcA = 0
ALUSrcB = 11
ALUOp = 00
e=
d
=
o
c
Op , sw ode
lw
c ype
p
O R- t
FSM-R
Opcode
= BEQ
FSM-B
SE-273@SERC
Opcode = J-type
FSM-J
24
MUX
in1
control
in2
MemRead=1
MemWrite
Mar 07, 2008
IRWrite
RegDst=0
MemtoReg=1
0-15
0-5
SE-273@SERC
Sign
extend
CC3
ALU
ALUSrcB=10
ALUSrcA=1
A Reg.
28-31
ALUOut Reg.
CC5
B Reg.
out
16-20
Shift
left 2
RegWrite=1
21-25
Register file
Data
0-25
IorD=1
Memory
Addr.
PC
26-31 to
Control
FSM
PCWrite
etc.
CC4
Add
Shift
left 2
ALU
control
25
ALUOp
= 00
MUX
in1
control
IRWrite
CC4
in2
MemRead
MemWrite=1
Mar 07, 2008
RegDst=0
MemtoReg
Shift
left 2
0-15
0-5
SE-273@SERC
Sign
extend
ALUOut Reg.
CC3
ALU
ALUSrcB=10
28-31
ALUSrcA=1
A Reg.
RegWrite
B Reg.
out
16-20
21-25
Register file
Data
0-25
IorD=1
Memory
Addr.
PC
26-31 to
Control
FSM
PCWrite
etc.
PCSource
Add
Shift
left 2
ALU
control
26
ALUOp
= 00
Opcode
Read
Memory data
Compute mem
addrress
ALUSrcA =1
ALUSrcB = 10 Opcode
ALUOp = 00
= lw
= sw
MemRead = 1
IorD = 1
Write
register
Write
memory
MemWrite = 1
IorD = 1
RegWrite = 1
MemtoReg = 1
RegDst = 0
Mar 07, 2008
SE-273@SERC
To state 0
(Instr. Fetch)
27
MUX
in1
control
in2
MemRead
MemWrite
Mar 07, 2008
IRWrite
RegDst=0
CC4
MemtoReg=0
0-15
0-5
SE-273@SERC
Sign
extend
ALUOut Reg.
ALU
ALUSrcB=00
A Reg.
CC3
28-31
ALUSrcA=1
11-15
Shift
left 2
RegWrite
B Reg.
out
16-20
21-25
Register file
Data
0-25
IorD
Memory
Addr.
PC
26-31 to
Control
FSM
PCWrite
etc.
PCSource
funct. code
Shift
left 2
ALU
control
28
ALUOp
= 10
Write
register
RegWrite = 1
MemtoReg = 0
RegDst = 1
Mar 07, 2008
SE-273@SERC
To state 0
(Instr. Fetch)
29
MUX
in1
control
in2
MemRead
MemWrite
Mar 07, 2008
IRWrite
RegDst
MemtoReg
0-15
0-5
SE-273@SERC
Sign
extend
ALUOut Reg.
zero
ALU
ALUSrcB=00
CC3
28-31
ALUSrcA=1
11-15
A Reg.
16-20
PCSource
01
Shift
left 2
RegWrite
B Reg.
out
0-25
Register file
Data
21-25
IorD
Memory
Addr.
PC
26-31 to
Control
FSM
PCWrite
etc.=1
If(zero)
subtract
Shift
left 2
ALU
control
30
ALUOp
= 01
Write PC on zero
zero=1
PCWriteCond=1
PCWrite etc.=1
PCWrite
SE-273@SERC
31
FSM-B (Branch)
From state 1 Opcode = beq
Write PC on
branch condition
ALUSrcA =1
ALUSrcB = 00
ALUOp = 01
PCWriteCond=1
PCSource=01
Branch condition:
If A B=0
zero = 1
To state 0
(Instr. Fetch)
Mar 07, 2008
SE-273@SERC
32
control
MUX
in1
in2
MemRead
MemWrite
Mar 07, 2008
IRWrite
RegDst
MemtoReg
0-15
Shift
left 2
Sign
extend
0-5
SE-273@SERC
ALUOut
Reg.
zero
ALU
ALUSrcB
A Reg.
28-31
ALUSrcA
11-15
PCSource
10
RegWrite
Register file
16-20
21-25
B Reg.
out
Dat
a
0-25
IorD
Memory
Addr.
26-31 to
Control
FSM
PC PCWrite
etc.
CC3
Shift
left 2
ALU
control
ALUOp
33
Write PC
zero
PCWriteCond
PCWrite etc.=1
PCWrite=1
SE-273@SERC
34
FSM-J (Jump)
From state 1 Opcode = jump
Write
jump addr. In PC
PCWrite=1
PCSource=10
To state 0
(Instr. Fetch)
Mar 07, 2008
SE-273@SERC
35
Control FSM
State 0
Start
1
Instr.
fetch/
adv. PC
rs
o
lw
2
Read
memory
data
Compute
memory
addr.
lw
Instr.
decode/reg.
fetch/branch
addr.
5
Write
register
ALU
operation
sw
4
J
Write
jump addr.
to PC
Write PC
on branch
condition
7
Write
memory
data
Write
register
SE-273@SERC
36
Combinational
logic
Present
state
Reset
Clock
16 control
outputs
Next
state
FF
FF
FF
FF
Mar 07, 2008
SE-273@SERC
37
z
z
Present state
0000
....
Control signals
0001000110000100
....
Next state
0001
....
SE-273@SERC
38
funct.
[0,5]
PCWriteCond
PCWrite
IRWrite
IorD
MemtoReg
RegWrite
ALUSrcB
2-bits
PCSource
2-bits
RegDst
ALUSrcA
Overflow
Opcode
6-bits
zero
Reset
Clock
Datapath
(PC, register file, registers, ALU)
Mem. Addr.
Mem. write data
Mem. data out
Mar 07, 2008
SE-273@SERC
ALU
control
39
ALUOp
3-bits
ALUOp
2-bits
Controller
(Control FSM)
MemRead
Exceptions or Interrupts
z
z
z
SE-273@SERC
40
Implementing Exceptions
MUX
out
control
in2
EPC
Overflow to
Control FSM
0
1
EPCWrite=1
ALU
ALUSrcB=01
PC
26-31 to
Control
FSM
ALUSrcA=0
PCWrite
etc.=1
8000 0180(hex)
CauseWrite=1
in1
PCSource
11
Cause
32-bit
register
SE-273@SERC
Subtract
ALU
control
41
ALUOp
=01
SE-273@SERC
2ns
1ns
2ns
1ns
42
Single-Cycle Datapath
z
z
z
z
z
z
z
R-type
Load word (I-type)
Store word (I-type)
Branch on equal (I-type)
Jump (J-type)
Clock cycle time
=
Each instruction takes one cycle
Mar 07, 2008
SE-273@SERC
6ns
8ns
7ns
5ns
2ns
8ns
43
Multicycle Datapath
z
lw
sw
R-type
beq
j
5
4
4
3
3
SE-273@SERC
(10ns)
(8ns)
(8ns)
(6ns)
(6ns)
44
CPI of a Computer
k (instructions of type k)
CPIk
Note:
CPI
where
SE-273@SERC
45
Example
z
loads
stores
branches
jumps
Arithmetic
CPI
CPI
Mar 07, 2008
25%
10%
11%
2%
52%
46
1.00 8ns
4.12 2ns
0.97
SE-273@SERC
47
Microprogram: An alternative
implementation of controller.
SE-273@SERC
48
Thank You
Mar 07, 2008
SE-273@SERC
49