Lecture-4-08 01 2025
Lecture-4-08 01 2025
Memory
+ NP
C IR ← Mem [PC];
4
NPC ← PC + 4;
P Instruction
IR
C Memory • 32-bit PC
• 32-bit NPC
• 32-bit IR
• 32-bit Adder
The ID Stage
rs
A ← Reg [rs];
rt A B ← Reg [rt];
Register IMM ← (IR15)16 ## IR15..0
rd
IR Bank IMM1 ← IR25..0 ## 00
B
The IMM1 calculation is not shown
I • 32-bit A
Sign
M • 32-bit B
Extend M
• 32-bit IMM
From WB
The EX Stage
Memory Reference:
ALUOut ← A + IMM;
=0? cond
From IMM
Branch:
(<<2)
ALUOut ← NPC + (IMM << 2);
Func cond ← (A op 0);
• 32-bit ALUOut
• 1-bit cond
• 32-bit 2:1 MUX
The MEM Stage
Load instruction:
To PC PC ← NPC;
LMD ← Mem [ALUOut];
Store instruction:
From NPC PC ← NPC;
MUX Mem [ALUOut] ← B;
From cond
Branch instruction:
if (cond) PC ← ALUOut;
From ALUOut else PC ← NPC;
Data
LMD
Memory Other instructions:
From B
PC ← NPC;
• 32-bit LMD
• 32-bit 2:1 MUX
The WB Stage
Register-Register ALU Instruction:
Reg [rd] ← ALUOut;
From LMD To write port
MUX
of register
From ALUOut bank Register-Immediate ALU Instruction:
Reg [rt] ← ALUOut;
Load Instruction:
Reg [rt] ← LMD;
=0 cond
NP
+
MUX
4 C
rs
MUX
A
ALUOu
Instructio rt A
L
t
PC n IR Register
rd U Data
LMD
Memory
Bank
MUX
Memor
MUX
B y
I
Sign
M
Extend M
Simplicity of the Control Unit Design
◦ Due to the regularity in instruction encoding and simplicity of the instruction set, the design of the
control unit becomes very easy.
◦ Control signals in the data path:
a) LoadPC i) LoadIMM q) LoadLMD
b) LoadNPC j) MuxALU1 r) MuxWB
c) ReadIM k) MuxALU2 s) WriteReg
d) LoadIR l) ALUfunc
e) ReadRegPort1 m) LoadALUOut
f) ReadRegPort2 n) MuxPC
g) LoadA o) ReadDM
h) LoadB p) WriteDM
Example: Control Signal for ADD R1, R2, R3
ReadRegPort1
ReadIM ALUfunc = add
ReadRegPort2
ADD R1, R2, R3 LoadIR MuxALU1 = 0
LoadA
LoadNPC MuxALU2 = 0
IF IR ← Mem [PC]; LoadB
NPC ← PC + 4; LoadALUOut
δ T δ T δ T δ T δ T δ
IF ID EX MEM WB
Instructions 1 2 3 4 5 6 7 8
i IF ID EX MEM WB
i+1 IF ID EX MEM WB
i+2 IF ID EX MEM WB
i+3 IF ID EX MEM WB
Instr-i Instr-i+2
completes completes
Instr-i+1 Instr-i+3
completes completes
Clock cycles
Instructions 1 2 3 4 5 6 7 8
i IF ID EX MEM WB
i+1 IF ID EX MEM WB
i+2 IF ID EX MEM WB
i+3 IF ID EX MEM WB
• ID & WB: In clock cycle 5, both instructions i and i+3 access register bank.
• Solution: allow both read and write access to registers in the same clock cycle.
Advantages of Pipelining
I-
Cache
CPU
D-
Cache
Observation: ID and WB conflict
◦ The register bank is accessed both in the stages ID and WB.
◦ ID requires 2 register reads, and WB requires 1 register write.
◦ We thus have the requirement of 2 reads and 1 write in every clock cycle.
◦ Two register reads can be supported by having two register read ports.
◦ Simultaneous reads and write may result in clashes (e.g., same register used).
◦ Solution adopted in MIPS32 pipeline is to perform the write during the first
half of the clock cycle, and the reads during the second half of the clock cycle.
IR ← Mem [PC];
IF Register-Register ALU Instruction:
NPC ← PC + 4;
ALUOut ← A func B;
Other instructions:
PC ← NPC;
Putting it all together
=0 cond
NP
+
MUX
4 C
rs
MUX
A
ALUOu
Instructio rt A
L
t
PC n IR Register
rd U Data
LMD
Memory
Bank
MUX
Memor
MUX
B y
I
Sign
M
Extend M
Thank You