Documente Academic
Documente Profesional
Documente Cultură
1. AND gate (c = a . b)
a
2. OR gate (c = a + b)
a
3. Inverter (c = a)
a
4. Multiplexor
(if d = = 0, c = a;
else c = b)
d
a
0
c
c=a.b
0
0
1
1
0
1
0
1
0
0
0
1
c=a+b
0
0
1
1
0
1
0
1
0
1
1
1
c=a
0
1
1
0
0
1
a
b
a
output
b
Operation
a
0
Result
b
Implementations
CarryOut
exclusive or (xor)
How could we build a 1-bit ALU for add, and, and or?
a0
b0
a1
b1
CarryIn
ALU0
Result0
CarryOut
CarryIn
Operation
CarryIn
ALU1
Result1
CarryOut
Result
a2
b
b2
CarryIn
ALU2
Result2
CarryOut
CarryOut
CarryIn
ALU31
Result31
Operation
CarryIn
a
0
1
CarryOut
Result
B inv e rt
Supporting slt
O p era tion
C arryIn
Binvert
CarryIn
Operation
1
R esult
b
1
L ess
Less input of
the 31 most
significant ALUs
is always 0
a.
C arryO u t
a0
b0
CarryIn
ALU0
Less
CarryOut
a1
b1
0
CarryIn
ALU1
Less
CarryOut
a2
b2
0
CarryIn
ALU2
Less
CarryOut
Extra set bit, to be routed to the Less input of the least significant 1-bit
ALU, is computed from the most significant Result bit and the Overflow bit
Bin ve rt
Op eration
C arryIn
a
0
Result0
Result1
Result2
CarryIn
R esu lt
b
1
Le ss
3
Set
Ov erflo w
de tection
b.
a31
b31
0
CarryIn
ALU31
Less
Result31
Set
Overflow
O ve rflow
use subtraction: rs - rt = 0 rs = rt
Supporting
Test for Equality
Bnegate
Combine CarryIn
to least significant
ALU and Binvert to
a single control line
as both are always
either 1 or 0
ALU
control
lines
Bneg- Operate
ation
Operation
a0
b0
CarryIn
ALU0
Less
CarryOut
Result0
a1
b1
0
CarryIn
ALU1
Less
CarryOut
Result1
0
0
0
1
1
00
01
10
10
11
Function
and
or
add
sub
slt
Zero
ALU operation
a2
b2
0
CarryIn
ALU2
Less
CarryOut
Result2
a
Output is 1 only if all Result bits are 0
ALU
Zero
Result
Overflow
a31
b31
0
CarryIn
ALU31
Less
Result31
CarryOut
Set
Overflow
Conclusion
Implementing MIPS
6 bits
5 bits
5 bits
5 bits
5 bits
op
rs
rt
rd
6 bits
5 bits
5 bits
16 bits
op
rs
rt
offset
6 bits
shamt funct
6 bits
26 bits
op
address
R-Format
I-Format
J-Format
Data
PC
Address
Instruction
memory
Instruction
Register #
Registers
Register #
ALU
Address
Data
memory
Register #
Data
Single Cycle
Multi-Cycle
Pipelined
Functional Elements
Combinational Elements
State
element
1
Clock cycle
Combinational logic
State
element
2
State
element
Combinational logic
State Elements
5 bits
5 bits
5 bits
W rite
re giste r
32 bits
R ead
data 1
32 bits
R ead
data 2
32 bits
Register file
W rite
da ta
W rite
Control signal
Port implementation:
Clock
Clock
Write
Read register
number 1
0
Register 0
Register 1
Register n 1
Register n
M
u
x
Read data 1
Register number
C
Register 0
n-to-1
decoder
n 1
Register 1
D
Read register
number 2
M
u
x
C
Register n 1
D
Read data 2
C
Register n
Register data
Verilog
Instruction
address
Add
PC
Instruction
Add Sum
Instruction
memory
PC
a. Instruction memory
b. Program counter
Read
address
c. Adder
Instruction
Instruction
memory
Datapath
ADD
4
PC
ADDR
Memory
RD
Instruction
5
Register
numbers
5
5
Data
Read
register 1
Read
data 1
Read
register 2
Registers
Write
register
Read
data 2
Write
data
Data
ALU control
Zero
ALU ALU
result
Instruction
Read
register 2
Registers
Write
register
Write
data
RegWrite
Read
register 1
Read
data 1
Zero
ALU ALU
result
Read
data 2
RegWrite
a. Registers
b. ALU
ALU operation
Datapath
Instruction
op
rs
rt
5
rd
shamt funct
Operation
RN1
RN2
WN
RD1
Register File
WD
RD2
RegWrite
ALU
Zero
MemWrite
Instruction
Address
Write
data
Read
data
Data
memory
Read
register 1
16
Sign
extend
32
MemWrite
Read
data 1
Read
register 2
Registers
Write
register
Read
data 2
Write
data
Zero
ALU ALU
result
16
Sign
extend
32
Read
data
Data
memory
MemRead
b. Sign-extension unit
Address
Write
data
RegWrite
MemRead
a. Data memory unit
ALU operation
Datapath
Instruction
Add Sum
Branch target
Shift
left 2
3
Read
register 1
ALU operation
Read
data 1
Read
register 2
Registers
Write
register
Read
data
2
Write
data
RegWrite
16
Sign
extend
32
Datapath
ALU Zero
To branch
control logic
rs
rt
offset/immediate
16
PC +4 from
instruction
datapath
ADD
Operation
<<2
RN1
RN2
WN
RD1
Register File
ALU
Zero
WD
RD2
RegWrite
16
E
X
T
N
D
32
Instruction
32
16
Operation
RN1
RN2
WN
RD1
Register File
ALU
Zero
WD
RD2
RegWrite
16
E
X
T
N
D
32
M
U
X
ALUSrc
MemWrite
MemtoReg
ADDR
Data
Memory
WD
MemRead
RD
M
U
X
Instruction
32
16
Operation
RN1
RN2
WN
RD1
Register File
ALU
Zero
WD
RD2
RegWrite
16
E
X
T
N
D
32
M
U
X
ALUSrc
MemWrite
MemtoReg
ADDR
Data
Memory
WD
MemRead
RD
M
U
X
Instruction
32
16
Operation
RN1
RN2
WN
RD1
Register File
ALU
Zero
WD
RD2
RegWrite
16
E
X
T
N
D
32
M
U
X
ALUSrc
MemWrite
MemtoReg
ADDR
Data
Memory
WD
MemRead
RD
M
U
X
PC
Read
address
Instruction
Instruction
memory
Registers
Read
register 1
Read
Read
data
1
register 2
Read
Write
data 2
register
3
ALUSrc
M
u
x
RegWrite
MemWrite
MemtoReg
Write
data
16
ALU operation
Sign 32
extend
Zero
ALU ALU
result
Address
Read
data
Data
memory
Write
data
MemRead
M
u
x
PCSrc
M
u
x
Add
Add ALU
result
4
Shift
left 2
PC
Registers
Read
register 1
Read
Read
data 1
register 2
Read
address
Instruction
Instruction
memory
Write
register
Write
data
RegWrite
16
ALUSrc
Read
data 2
M
u
x
ALU operation
Zero
ALU ALU
result
MemtoReg
Address
Write
data
Sign
extend
MemWrite
Data
memory
32
MemRead
Read
data
M
u
x
ADD
M
U
X
ADD
ADD
PC
<<2
Instruction
ADDR
Instruction
Memory
RD
32
RN1
RN2
16
PCSrc
Operation
WN
RD1
Register File
ALU
Zero
WD
RD2
RegWrite
16
E
X
T
N
D
32
M
U
X
ALUSrc
MemWrite
ADDR
Data
Memory
WD
MemRead
MemtoReg
RD
M
U
X
Datapath Executing lw
ADD
M
U
X
ADD
ADD
PC
<<2
Instruction
ADDR
Instruction
Memory
RD
32
RN1
RN2
16
PCSrc
Operation
WN
RD1
Register File
ALU
Zero
WD
RD2
RegWrite
16
lw rt,offset(rs)
E
X
T
N
D
32
M
U
X
ALUSrc
MemWrite
ADDR
Data
Memory
WD
MemRead
MemtoReg
RD
M
U
X
Datapath Executing sw
ADD
M
U
X
ADD
ADD
PC
<<2
Instruction
ADDR
Instruction
Memory
RD
32
RN1
RN2
16
PCSrc
Operation
WN
RD1
Register File
ALU
Zero
WD
RD2
RegWrite
16
sw rt,offset(rs)
E
X
T
N
D
32
M
U
X
ALUSrc
MemWrite
ADDR
Data
Memory
WD
MemRead
MemtoReg
RD
M
U
X
ADD
M
U
X
ADD
ADD
PC
<<2
Instruction
ADDR
Instruction
Memory
RD
32
RN1
RN2
16
PCSrc
Operation
WN
RD1
Register File
ALU
Zero
WD
RD2
RegWrite
16
beq r1,r2,offset
E
X
T
N
D
32
M
U
X
ALUSrc
MemWrite
ADDR
Data
Memory
WD
MemRead
MemtoReg
RD
M
U
X
Control
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
F3
F2
F (5 0)
Operation2
Operation1
F1
Operation0
F0
Operation
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
R-type
rs
31:26
Load/
Store
35 or 43
25:21
rs
31:26
Branch
rt
opcode
20:16
rt
25:21
rs
31:26
rd
always
read
15:11
10:6
funct
5:0
address
20:16
rt
25:21
shamt
15:0
address
20:16
read,
except
for load
15:0
write for
R-type and
load
sign-extend
and add
Add
4
Add
New multiplexor
Read
address
Instruction
[31 0]
Instruction
memory
Shift
left 2
RegWrite
Read
register 1
Read
register 2
Read
data 1
MemWrite
ALUSrc
Read
Write
data 2
register
Write
Registers
data
1
M
u
x
0
16
Sign
extend
Zero
ALU ALU
result
MemtoReg
Address
Write
data
RegDst
Instruction [15 0]
ALU
result
1
M
u
x
0
32
ALU
control
Read
data
Data
memory
1
M
u
x
0
MemRead
Instruction [5 0]
ALUOp
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
Signal Name
RegDst
RegWrite
AlLUSrc
MemRead
MemWrite
None
MemtoReg
PCSrc
Read
address
Instruction
memory
PCSrc
Read
register 1
Shift
left 2
RegDst
Branch
MemRead
MemtoReg
Control
ALUOp
MemWrite
ALUSrc
RegWrite
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
Control Signals:
R-Type Instruction
ADD
0
M
U
X
ADD
ADD
rs
I[25:21]
PC
rt
I[20:16]
rd
I[15:11]
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
Data
Memory
1
32
ALUSrc
MemWrite
ADDR
MemtoReg
1
RD
M
U
X
WD
MemRead
Control Signals:
lw Instruction
ADD
0
M
U
X
ADD
ADD
rs
I[25:21]
PC
rt
I[20:16]
rd
I[15:11]
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
Data
Memory
1
32
ALUSrc
MemWrite
ADDR
MemtoReg
1
RD
M
U
X
WD
MemRead
Control Signals:
sw Instruction
ADD
0
M
U
X
ADD
ADD
rs
rt
rd
I[25:21] I[20:16] I[15:11]
PC
Instruction
ADDR
RD
Instruction
Memory
I
32
0
5
RN1
RN2
RegDst
WN
RD1
WD
ALU
Zero
0
M
U
X
RD2
RegWrite
0
Control signals
shown in blue
010
Operation
Register File
immediate/
offset
I[15:0]
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
I[25:21]
PC
rt
I[20:16]
rd
I[15:11]
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
Data
Memory
1
32
ALUSrc
MemWrite
ADDR
MemtoReg
1
RD
M
U
X
WD
MemRead
0
M
u
x
Add
Add
Shift
left 2
RegDst
Branch
ALU
result
PCSrc cannot be
set directly from the
opcode: zero test
outcome is required
PCSrc
MemRead
MemtoReg
Control
ALUOp
MemWrite
ALUSrc
RegWrite
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
0
0
1
0
0
0
1
0
lw
0
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
Outputs
Inputs
Signal
name
Rlw
format
Op5
Op4
Op3
Op2
Op1
Op0
RegDst
ALUSrc
MemtoReg
RegWrite
MemRead
MemWrite
Branch
ALUOp1
ALUOP2
0
0
0
0
0
0
1
0
0
1
0
0
0
1
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
Implementing Jumps
Jump
address
31:26
25:0
opcode
address
31-26
25-0
Composing jump
target address
Instruction [25 0]
26
Shift
left 2
M
u
x
M
u
x
Shift
left 2
RegDst
Jump
Branch
Instruction [31 26]
MemRead
Control
MemtoReg
ALUOp
MemW rite
ALUSrc
RegWrite
Instruction [25 21]
PC
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
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
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
ALU
control
Instruction [5 0]
Read
data
Data
memory
1
M
u
x
0
Add
4
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
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
3.
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
CPI = 1
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: