Control: Control Unit Takes Input From
Control: Control Unit Takes Input From
Control: Control Unit Takes Input From
ALU Control
Plan to control ALU: main control sends a 2-bit ALUOp control field
to the ALU control. Based on ALUOp and funct field of instruction the
ALU control generates the 3-bit ALU control field
ALU control
field
000
001
010
110
111
Function
and
or
add
sub
slt
2
ALUOp
Main
Control
3
ALU
Control
ALU
control
input
6
Instruction
funct field
To
ALU
00
00
01
10
10
10
10
10
xxxxxx
xxxxxx
xxxxxx
100000
100010
100100
100101
101010
add
add
subtract
add
subtract
and
or
set on less
ALUOp
Funct field
Operation
ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0
0
0
X X X X X X
010
0
1
X X X X X X
110
1
X
X X 0 0 0 0
010
1
X
X X 0 0 1 0
110
1
X
X X 0 1 0 0
000
1
X
X X 0 1 0 1
001
1
X
X X 1 0 1 0
111
Truth table for ALU control bits
010
010
110
010
110
000
001
111
opcode
31-26
Load/store
or branch
opcode
31-26
rs
25-21
rt
20-16
rs
rt
25-21
20-16
rd
shamt
funct
15-11
10-6
5-0
address
15-0
PC+4
Add
4
Add
New multiplexor
Read
address
Instruction
[31 0]
Instruction
memory
rd or rt
Read
register 2
rt or SE(offset)
Read
data 1
MemWrite
rs
ALUSrc
Read
Write
data 2
register
Write
Registers
data
rt
Zero
ALU ALU
result
1
M
u
x
0
16
Sign
extend
32
Instruction [5 0] 6 bits of
funct. field
MemtoReg
Address
Write
data
RegDst
Instruction [15 0]
PC+4 or BT
Shift
left 2
RegWrite
Read
register 1
ALU
result
1
M
u
x
0
3 bit
control signal
ALU
control
2 bits of ALUOp
ALUOp
Read
data
Data
memory
1
M
u
x
0
MemRead
use o/p
from ALU
or DM
Adding control to the MIPS Datapath III (and a new multiplexor to select field to
specify destination register): what are the functions of the 9 control signals?
Control Signals
Default Behaviour in a way
Signal Name
RegDst
RegWrite
AlLUSrc
MemRead
MemWrite
None
MemtoReg
PCSrc
Control
Read
address
Instruction
memory
Shift
left 2
RegDst
Branch
MemRead
MemtoReg
ALUOp
MemWrite
ALUSrc
RegWrite
PCSrc
Read
register 1
0
M
u
x
1
Read
data 1
Read
register 2
Registers Read
Write
data 2
register
0
M
u
x
1
Write
data
Zero
ALU ALU
result
Address
Write
data
Instruction [15 0]
16
Sign
extend
Read
data
Data
memory
32
ALU
control
Instruction [5 0]
MIPS datapath with the control unit: input to control is the 6-bit instruction
opcode field, output is seven 1-bit signals and the 2-bit ALUOp signal
1
M
u
x
0
PCSrc cannot be
set directly from the
opcode: zero test
outcome is required
M
u
x
Add
Add
Shift
left 2
RegDst
Branch
ALU
result
PCSrc
MemRead
Instruction [31 26]
MemtoReg
Control
ALUOp
MemWrite
ALUSrc
RegWrite
Instruction [25 21]
PC
Read
address
Instruction
memory
Read
register 1
Datapath with
Control II (cont.)
Instruction [15 0]
0
M
u
x
1
Read
data 1
Read
register 2
Registers Read
Write
data 2
register
0
M
u
x
1
Write
data
Zero
ALU ALU
result
Address
Write
data
16
Sign
extend
Read
data
Data
memory
1
M
u
x
0
32
ALU
control
Instruction [5 0]
Determining control signals for the MIPS datapath based on instruction opcode
Memto- Reg Mem Mem
Instruction RegDst ALUSrc
Reg
Write Read Write Branch ALUOp1 ALUp0
R-format
1 =rd
0
0
1
0
0
0
1
0
lw
0 =rt
1
1
1
1
0
0
0
0
sw
X
1
X
0
0
1
0
0
0
beq
X
0
X
0
0
0
1
0
1
Whenever we need to enable writing to Reg.
Control Signals:
R-Type Instruction
ADD
0
M
U
X
ADD
ADD
rs
rt
rd
I[25:21] I[20:16] I[15:11]
PC
Instruction
ADDR
RD
I
32
Instruction
Memory
RN1
RN2
RegDst
Register File
immediate/
offset
I[15:0]
Value depends on
funct
ALU
Zero
0
M
U
X
RD2
RegWrite
1
Control signals
shown in blue
???
Operation
WN
RD1
WD
PCSrc
MUX
16
<<2
16
E
X
T
N
D
1
32
ALUSrc
MemWrite
ADDR
Data
Memory
MemtoReg
1
RD
M
U
X
WD
MemRead
Control Signals:
lw Instruction
ADD
0
M
U
X
ADD
ADD
rs
rt
rd
I[25:21] I[20:16] I[15:11]
PC
Instruction
ADDR
RD
I
32
Instruction
Memory
RN1
RN2
RegDst
010
Operation
WN
RD1
Register File
WD
immediate/
offset
I[15:0]
ALU
Zero
0
M
U
X
RD2
RegWrite
1
Control signals
shown in blue
PCSrc
MUX
16
<<2
16
E
X
T
N
D
1
32
ALUSrc
MemWrite
ADDR
Data
Memory
MemtoReg
1
RD
M
U
X
WD
MemRead
Control Signals:
sw Instruction
ADD
0
M
U
X
ADD
ADD
rs
I[25:21]
PC
rt
I[20:16]
rd
I[15:11]
Instruction
ADDR
RD
Instruction
Memory
I
32
RN1
RN2
010
RegDst Operation
WN
RD1
Register File
WD
immediate/
offset
I[15:0]
ALU
Zero
0
M
U
X
RD2
RegWrite
0
Control signals
shown in blue
PCSrc
MUX
16
<<2
16
E
X
T
N
D
1
32
ALUSrc
MemWrite
ADDR
Data
Memory
MemtoReg
1
RD
M
U
X
WD
MemRead
Control Signals:
beq Instruction
ADD
0
M
U
X
ADD
ADD
rs
rt
rd
I[25:21] I[20:16] I[15:11]
PC
Instruction
ADDR
RD
I
32
Instruction
Memory
RN1
RN2
RegDst
110
Operation
WN
RD1
Register File
WD
immediate/
offset
I[15:0]
ALU
Zero
0
M
U
X
RD2
RegWrite
0
Control signals
shown in blue
PCSrc
1 if Zero=1
1
MUX
16
<<2
16
E
X
T
N
D
1
32
ALUSrc
MemWrite
ADDR
Data
Memory
MemtoReg
1
RD
M
U
X
WD
MemRead
opcode
address
31-26
25-0
Composing jump
target address
Instruction [25 0]
26
Shift
left 2
New MUX added since JUMP Target may replace PC, hence
PC value can now go THREE WAYS.
M
u
x
M
u
x
Shift
left 2
RegDst
Jump
Branch
Instruction [31 26]
MemRead
Control
MemtoReg
ALUOp
MemW rite
ALUSrc
RegWrite
Read
address
Instruction
memory
Read
register 1
0
M
u
x
1
Read
data 1
Read
register 2
Registers Read
Write
data 2
register
Zero
0
M
u
x
1
Write
data
ALU
ALU
result
Address
Write
data
Instruction [15 0]
16
Sign
extend
Read
data
Data
memory
1
M
u
x
0
32
ALU
control
Instruction [5 0]
MIPS datapath extended to jumps: control unit generates new Jump control bit
Datapath Executing j
Control
PC
Read
address
Instruction
memory
Shift
left 2
RegDst
Branch
MemRead
MemtoReg
ALUOp
MemWrite
ALUSrc
RegWrite
Read
register 1
ALU
result
0
M
u
x
1
Read
data 1
Read
register 2
Registers Read
Write
data 2
register
0
M
u
x
1
Write
data
Zero
ALU ALU
result
Address
Write
data
Instruction [15 0]
16
Sign
extend
32
ALU
control
Instruction [5 0]
Read
data
Data
memory
1
M
u
x
0
Add
4
Instruction [31 26]
Control
Read
address
Instruction
memory
Zero
ALU ALU
result
Address
Shift
left 2
RegDst
Branch
MemRead
MemtoReg
ALUOp
MemWrite
ALUSrc
RegWrite
Read
register 1
ALU
Add result
0
M
u
x
1
Read
data 1
Read
register 2
Registers Read
Write
data 2
register
0
M
u
x
1
Write
data
Write
data
Instruction [15 0]
16
Sign
extend
32
ALU
control
Instruction [5 0]
Read
data
Data
memory
1
M
u
x
0
Add
4
Instruction [31 26]
Control
Read
address
Instruction
memory
Zero
ALU ALU
result
Address
Shift
left 2
RegDst
Branch
MemRead
MemtoReg
ALUOp
MemWrite
ALUSrc
RegWrite
Read
register 1
ALU
Add result
0
M
u
x
1
Read
data 1
Read
register 2
Registers Read
Write
data 2
register
0
M
u
x
1
Write
data
Write
data
Instruction [15 0]
16
Sign
extend
32
ALU
control
Instruction [5 0]
Read
data
Data
memory
1
M
u
x
0
Add
4
Instruction [31 26]
Control
Read
address
Instruction
memory
Zero
ALU ALU
result
Address
Shift
left 2
RegDst
Branch
MemRead
MemtoReg
ALUOp
MemWrite
ALUSrc
RegWrite
Read
register 1
Instruction
[31 0]
ALU
Add result
0
M
u
x
1
Read
data 1
Read
register 2
Registers Read
Write
data 2
register
0
M
u
x
1
Write
data
Write
data
Instruction [15 0]
16
Sign
extend
32
Instruction [5 0]
ALU
control
Read
data
Data
memory
1
M
u
x
0
3.
4.
5.
Load Instruction
lw $t1, offset($t2)
0
M
u
x
Add
4
Instruction [31 26]
Read
address
Instruction
memory
Zero
ALU ALU
result
Address
Read
register 1
Shift
left 2
RegDst
Branch
MemRead
MemtoReg
Control
ALUOp
MemWrite
ALUSrc
RegWrite
ALU
Add result
0
M
u
x
1
Read
data 1
Read
register 2
Registers Read
Write
data 2
register
0
M
u
x
1
Write
data
Write
data
Instruction [15 0]
16
Instruction [5 0]
Sign
extend
32
ALU
control
Read
data
Data
memory
1
M
u
x
0
4.
Branch Instruction
beq $t1, $t2, offset
0
M
u
x
Add
4
Instruction [31 26]
PC
Instruction
[31 0]
Instruction
memory
Read
register 1
0
M
u
x
1
Zero
ALU ALU
result
Address
Shift
left 2
RegDst
Branch
MemRead
MemtoReg
Control
ALUOp
MemWrite
ALUSrc
RegWrite
ALU
Add result
Read
data 1
Read
register 2
Registers Read
Write
data 2
register
0
M
u
x
1
Write
data
Write
data
Instruction [15 0]
16
Instruction [5 0]
Sign
extend
32
ALU
control
Read
data
Data
memory
1
M
u
x
0
F3
F2
F (5 0)
Operation2
Operation1
F1
Operation0
F0
Operation
Outputs
Inputs
Signal
name
Rlw
format
Op5
0
6-bit
Op4 inst opcode 0
Op3 which is 0
Op2 i/p to main 0
Op1 control 0
Op0
0
RegDst
1
ALUSrc
0
MemtoReg
0
RegWrite
1
MemRead
0
MemWrite
0
Branch
0
ALUOp1
1
ALUOP2
0
1
0
0
0
1
1
0
1
1
1
1
0
0
0
0
sw
beq
Op3
Op2
Op1
1
0
1
0
1
1
x
1
x
0
0
1
0
0
0
0
0
0
1
0
0
x
0
x
0
0
0
1
0
1
Op0
Outputs
R-format
Iw
sw
beq
RegDst
ALUSrc
MemtoReg
RegWrite
MemRead
MemWrite
Branch
ALUOp1
ALUOp2
CPI = 1
cycle time determined by length of the longest instruction path
(load)
but several instructions could run in a shorter clock cycle: waste of time
memory: 2 ns., ALU and adders: 2 ns., FPU add: 8 ns., FPU multiply: 16 ns.,
register file access (read or write): 1 ns.
multiplexors, control unit, PC accesses, sign extension, wires: no delay
all loads take same time and comprise 31%
all stores take same time and comprise 21%
R-format instructions comprise 27%
branches comprise 5%
jumps comprise 2%
FP adds and subtracts take the same time and totally comprise 7%
FP multiplys and divides take the same time and totally comprise 7%
Compare the performance of (a) a single-cycle implementation using a fixedperiod clock with (b) one using a variable-period clock where each instruction
executes in one clock cycle that is only as long as it needs to be (not really
practical but pretend its possible!)
Solution
Instruction
class
Load word
Store word
R-format
Branch
Jump
FP mul/div
FP add/sub
2
2
2
2
2
2
2
1
1
1
1
1
1
2
2
2
2
Data
mem.
2
2
0
Register FPU
write
add/
sub
FPU
mul/
div
1
1
1
1
16
8
Total
time
ns.
8
7
6
5
2
20
12
Another solution: