Beruflich Dokumente
Kultur Dokumente
The Processor:
Datapath & Control
add
add n
4
Data
Reg. #
PC
k m
Datapath
Elements that process data and addresses in the CPU
• Registers, ALUs, multiplexors, memories, …
We will build a MIPS datapath incrementally
Refining the overview design
Instruction memory:
A memory unit that stores the instructions of a program
Supplies an instruction given its address
Program counter:
A register storing the address of the instruction being executed
Adder:
A unit that increments PC to form the address of next instruction
Instruction
address
PC
Instruction Add Sum
Instruction
memory
Add
Read
PC
address Increment by
4 for next
Instruction
32-bit instruction
Instruction
register memory
k l
ALU
instr[25-21] 17 Read operation
Add 3
register 1 100
4 Read
instr[20-16] 18 data 1
PC Read Read
address
register 2 Zero
Register
Instruction
File ALU 300
Instruction
memory
instr. 8 Write result
register 200
instr[15-11] Read
data 2
Write
data
j n RegWrite
Register Value
E.g.: lw $t0, 1000($s1)
t0 200
35 17 (s1) 8 (t0) 1000 (immediate) s1 100
100011 10001 01000 0000 0011 1110 1000 Memory[1100]
6 bits 5 bits 5 bits 16 bits 50
instr[20-16]
register 1
Read 100 m MemWrite
8 Read
data 1
Instruction register 2 Zero
ALU ALU
8 Write
Registers
Read 50
instr[20-16] result Address
register 1100 data
Read
Write data 2
Data
data
k RegWrite
200
(not used)
Write
data
memory
16 32
1000 Sign MemRead
instr[15-0]
(Offset) extend l
n
Note: For load word instruction, MemWrite has to be de-asserted so that the memory will not be modified by
incoming write data.
COMP2611 CSE HKUST The Processor: Datapath & Control
Datapath for Branch (I-Format) Instr. 14
2 Shift 8 1012
Register Value left 2
t0 200
instr[25-21] ALU operation
8 Read 3
t1 200
Instruction register 1
Read 200
PC 1000 9 Read
data 1
instr[20-16] register 2
Register ALU Zero To branch
Write File control logic
register
Read 200
data 2
Write
data
RegWrite
2 16
Sign
32
instr[15-0]
extend
Key to combine
Note:
This simple implementation is based on the (unrealistic) assumption
i.e. all instructions take just one clock cycle each to complete
Implication:
No datapath resource can be used more than once per instruction
Any element needed more than once must be duplicated
Instructions and data have to be stored in separate memories
Use multiplexers where alternate data sources are used for
different instructions
COMP2611 CSE HKUST The Processor: Datapath & Control
R-Type/Load/Store Datapath 16
Add
4 k l m
R eg isters
Read ALU operatio n
register 1 3 MemW rite
PC Re ad
Read
address Read MemtoReg
register 2 data 1
ALUSrc Zero
Instruction
W rite Read AL U A LU R ea d
Address
register data 2 result data
M M
Instruction u u
W rite x Data
m emory x
data mem ory
W rite
RegW rite data
j 16 Sig n 32 Mem R ead
extend
n
COMP2611 CSE HKUST The Processor: Datapath & Control
Combined Datapath for Different Instr. Classes 17
PCSrc
M
Add u
x
4 Add A LU
result
Shift
left 2
n
COMP2611 CSE HKUST The Processor: Datapath & Control
Full Datapath: Muxing Two Possible Destination Registers 18
PCSrc
M
Add u
x
4 Add A LU
result
Shift
left 2
R eg isters
Read ALU operatio n
register 1 3 MemW rite
PC Read
Read
address Read MemtoReg
register 2 data 1 ALUSrc Zero
Instruction
M W rite Read AL U A LU R ead
Address
u register data 2 result data
x M M
Instructio n u u
W rite x Data
m emory x
data mem ory
W rite
RegW rite data
16 Sig n 32
Destination register: e xtend
Mem R ead
2. Single-cycle Control
0
M
u
x
ALU
Add 1
result
Add
Shift PCSrc
RegDst left 2
4 Branch
MemRead
Instruction [31 26] MemtoReg
Control ALUOp
MemWrite
ALUSrc
RegWrite
Instruction [5 0]
0
M
u
x
ALU
Add 1
result
Add
Shift PCSrc
RegDst left 2
4 Branch
MemRead
Instruction [31 26] MemtoReg
Control ALUOp
MemWrite
ALUSrc
RegWrite
k j
Opcode ALU Op Opcode
6 bit 2 bit 6 bit
ALU Control
Function 4 bit Function
code code
6 bit 6 bit
2 levels of decoding: only 8 inputs are 1 level only, a logic circuit with
used to generate 3 outputs in 2nd level 12 inputs is needed
ALUOp
ALU control block
ALUOp0
ALUOp1
Operation2
F3
Operation
F2 Operation1
F (5– 0)
F1
Operation0
F0
Load/ 35 or 43 rs rt address
Store
31:26 25:21 20:16 15:0
Branch 4 rs rt address
31:26 25:21 20:16 15:0
0
M
u
x
ALU
Add 1
result
Add
RegDst
Shift
left 2
PCSrc 0
4 Branch
MemRead
Instruction [31 26] MemtoReg
Control ALUOp
MemWrite
ALUSrc
1
RegWrite
0
Instruction [25 21] Read
Read register 1
PC Read
0
address
data 1
0
Instruction [20 16] Read
register 2 Zero
Instruction
0 Registers Read ALU ALU
[31– 0] 0 Read
M W rite data 2 result Address 1
Instruction u register M data
u M
memory x u
Instruction [15 11] W rite x
1 Data x
data 1 memory 0
Write
1
data
j Instruction [15 0]
16
Sign
32
extend
0
ALU
Instruction [5 0]
control
10
0
M
u
x
ALU
Add 1
result
Add
RegDst
Shift
left 2
PCSrc 0
4 Branch
MemRead
Instruction [31 26] MemtoReg
Control ALUOp
MemWrite
ALUSrc
RegWrite
1
0
Instruction [25 21] Read
Read register 1
PC Read
1
address
data 1
1
Instruction [20 16] Read
register 2 Zero
Instruction
0 Registers Read ALU ALU
[31– 0] 0 Read
M W rite data 2 result Address 1
Instruction u register M data
u M
memory x u
Instruction [15 11] W rite x
1 Data x
data 1 memory 0
Write
0 data
j Instruction [15 0]
16
Sign
extend
32
1
ALU
Instruction [5 0]
control
00
0
M
u
x Checking
ALU
Add
result
1
condition
Add
RegDst
Shift
left 2
PCSrc 1 for PCSrc
4 Branch
MemRead
Instruction [31 26] MemtoReg
Control ALUOp
MemWrite
ALUSrc
0
RegWrite
0
Instruction [25 21] Read
Read register 1
PC Read
address
data 1
0 X
Instruction [20 16] Read
register 2 Zero
Instruction
0 Registers Read ALU ALU
[31– 0] 0 Read
M W rite data 2 result Address 1
Instruction u register M data
u M
memory x u
Instruction [15 11] W rite x
1 Data x
data 1 memory 0
Write
X data
j Instruction [15 0]
16
Sign
extend
32
0
ALU
Instruction [5 0]
control
01
Outputs
R-format Iw sw beq
RegDst
ALUSrc
MemtoReg
RegWrite
MemRead
MemWrite
Branch
ALUOp1
ALUOpO
Jump 2 address
31:26 25:0
16 32
Instruction [15– 0] Sign
extend ALU
control
Instruction [5– 0]