Professional Documents
Culture Documents
PC 0 0
M Instruction Read
[25– 21] register 1 M
u Address u
x Read x
Instruction Read A Zero
1 Memory data 1
[20– 16] register 2 1
0 ALU ALU ALUOut
MemData Registers
Instruction M Write Read result
[15– 0] register data 2 B
Instruction u 0
Write x
Instruction [15– 11]
Write 4 1 M
data 1 u
register data 2 x
Instruction 0 3
[15– 0] M
u
x
Memory 1
data 16 32 ALU
Sign Shift
register control
extend left 2
Instruction [5– 0]
… with control lines and the ALU control block added – not all control lines are shown
Multicycle Datapath with Control II
New gates New multiplexor
For the jump address
PCWriteCond PCSource
PCWrite ALUOp
IorD Outputs
ALUSrcB
MemRead
ALUSrcA
MemWrite Control
MemtoReg RegWrite
Op RegDst
IRWrite [5– 0]
0
M
Jump 1 u
Instruction [25– 0] 26 28 address [31-0] x
Shift
left 2 2
Instruction
[31-26]
PC 0 PC [31-28]
0
M Instruction Read
[25– 21] register 1 M
u Address u
x Read x
Instruction Read A Zero
1 Memory
[20– 16] register 2 data 1 1
0 ALU ALU ALUOut
MemData Registers
Instruction M Write result
Read B
[15– 0] Instruction u register data 2 0
Write Instruction [15– 11] x 1 M
Write 4
data register 1 u
data 2 x
Instruction 0 3
[15– 0] M
u
x
Memory 1
data 16 32 ALU
Sign Shift
register control
extend left 2
Instruction [5– 0]
1
IRWrite
I Instruction I jmpaddr 28 32
1 R 5 I[25:0] <<2 CONCAT
PCWr* rs rt rd
2
0 0 32 5 5
0
MUX
1 RegDst
0 M
IorD 1U
PC
5 X ALUSrcA 010
Operation 0
X
0IRWrite
I Instruction I jmpaddr 28 32
0 R 5 I[25:0] <<2 CONCAT
PCWr* rs rt rd
X 0 1 RegDst 0 2
IorD 0 32 5 5 MUX
5 X ALUSrcA 010 1U
M
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U
1X
ADDR M Registers U PCSource
D 1M A 1X Zero
Memory
RD R U WD
RD1
ALU X
0X ALU
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
X 2X
3
RegWrite
0 0 E
X ALUSrcB
immediate 16 32
T <<2 3
N
D
Multicycle Datapath with Control II
New gates New multiplexor
For the jump address
PCWriteCond PCSource
PCWrite ALUOp
IorD Outputs
ALUSrcB
MemRead
ALUSrcA
MemWrite Control
MemtoReg RegWrite
Op RegDst
IRWrite [5– 0]
0
M
Jump 1 u
Instruction [25– 0] 26 28 address [31-0] x
Shift
left 2 2
Instruction
[31-26]
PC 0 PC [31-28]
0
M Instruction Read
[25– 21] register 1 M
u Address u
x Read x
Instruction Read A Zero
1 Memory
[20– 16] register 2 data 1 1
0 ALU ALU ALUOut
MemData Registers
Instruction M Write result
Read B
[15– 0] Instruction u register data 2 0
Write Instruction [15– 11] x 1 M
Write 4
data register 1 u
data 2 x
Instruction 0 3
[15– 0] M
u
x
Memory 1
data 16 32 ALU
Sign Shift
register control
extend left 2
Instruction [5– 0]
0
IRWrite
I Instruction I jmpaddr 28 32
0
PCWr*
R
rs rt
5
rd
I[25:0] <<2 CONCAT
2
X 32 5 5
0
MUX
1 RegDst
1 M
IorD 0 5 X ALUSrcA 010 1U
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U
1X
ADDR M Registers U PCSource
D 1M RD1 A 1X Zero
Memory
RD R U
0X
WD ALU
ALU
X
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
2X
X RegWrite 3
0 0 E
X ALUSrcB
immediate 16 32
T <<2 2
N
D
Multicycle Control Step (3):
ALU Instruction (R-Type)
ALUOut = A op B;
0
IRWrite
I Instruction I jmpaddr 28 32
0 R 5 I[25:0] <<2 CONCAT
PCWr* rs rt rd
X 32
0 1 RegDst
1 2
IorD 0 5 5 MUX
5 X ALUSrcA ??? 1U
M
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U
1X
ADDR M Registers U PCSource
D 1M RD1 A 1X Zero
Memory
RD R U
0X
WD ALU X
ALU
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
2X
X RegWrite 3
0 0 E
X ALUSrcB
immediate 16 32
T
N
<<2 0
D
Multicycle Control Step (3):
Branch Instructions
if (A == B) PC = ALUOut;
0
IRWrite
1 if I Instruction I jmpaddr 28 32
Zero=1 R 5 I[25:0] <<2 CONCAT
PCWr* rs rt rd
X 32
0 1 RegDst
1 2
IorD 0 5 5 MUX
5 X ALUSrcA 011 1U
M
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U
1X
ADDR M Registers U PCSource
D 1M RD1 A 1X Zero
Memory
RD R U
0X
WD ALU 1
ALU
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
2X
X RegWrite 3
0 0 E
X ALUSrcB
immediate 16 32
T
N
<<2 0
D
Multicycle Execution Step (3):
Jump Instruction
PC = PC[21-28] concat (IR[25-0] << 2);
0
IRWrite
I Instruction I jmpaddr 28 32
1
PCWr*
R
rs rt
5
rd
I[25:0] <<2 CONCAT
X 32 5 5
0
MUX
1 RegDst
X
2
M
IorD 0 5 X ALUSrcA XXX 1U
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U
1X
ADDR M Registers U PCSource
D 1M RD1 A 1X Zero
Memory
RD R U
0X
WD ALU
ALU
2
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
2X
X RegWrite 3
0 0 E
X ALUSrcB
immediate 16 32
T <<2 X
N
D
Multicycle Control Step (4):
Memory Access - Read (lw)
MDR = Memory[ALUOut];
IRWrite 0
I Instruction I jmpaddr 28 32
0 R 5 I[25:0] <<2 CONCAT
PCWr* rs rt rd
1 32
0 1 RegDst
X
2
IorD 0 5 5 MUX
5 X ALUSrcA XXX 1U
M
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U
1X
ADDR M Registers U PCSource
D 1M RD1 A 1X Zero
Memory
RD R U
0X
WD ALU X
ALU
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
2X
X RegWrite 3
1 0 E
X ALUSrcB
immediate 16 32
T
N
<<2 X
D
Multicycle Execution Steps (4)
Memory Access - Write (sw)
Memory[ALUOut] = B;
IRWrite 0
I Instruction I jmpaddr 28 32
0
PCWr*
R
rs rt
5
rd
I[25:0] <<2 CONCAT
1 32 5 5
0 1 RegDst
X
2
M
IorD 1 MUX
5 X ALUSrcA XXX 1U
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U
1X
ADDR M Registers U PCSource
D 1M RD1 A 1X Zero
Memory U WD ALU X
RD R 0X ALU
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
2X
X RegWrite 3
0 0 E
X ALUSrcB
immediate 16 32
T <<2 X
N
D
Multicycle Control Step (4):
ALU Instruction (R-Type)
(Reg[Rd] = ALUOut)
0
IRWrite
I Instruction I jmpaddr 28 32
0 R 5 I[25:0] <<2 CONCAT
PCWr* rs rt rd
2
X 32 5 5
0
MUX
1 RegDst
X M
IorD
0 5 1 ALUSrcA
XXX
1U
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U ADDR M U PCSource
1X 0M Registers 1X Zero
Memory D RD1 A
RD R U
1X
WD ALU
ALU
X
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
2X
1 RegWrite 3
0 1 E
ALUSrcB
immediate 16 X 32
T <<2
N X
D
Multicycle Execution Steps (5)
Memory Read Completion (lw)
Reg[IR[20-16]] = MDR;
IRWrite 0
I Instruction I jmpaddr 28 32
0 R 5 I[25:0] <<2 CONCAT
PCWr* rs rt rd
X 32
0 1 RegDst
X 2
IorD 0 5 5 MUX
5 0 ALUSrcA XXX 1U
M
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U ADDR M U PCSource
1X 0M Registers 1X Zero
D RD1 A
Memory
RD R U
1X
WD ALU X
ALU
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
2X
0 RegWrite 3
0
immediate 16
1 E
X 32
ALUSrcB
T
N
<<2 X
D
Implementing Control
Value of control signals is dependent upon:
what instruction is being executed
which step is being performed
Next
state
Next-state
Current state
function
Clock
Inputs
Output
Outputs
function
Memory access
R-type instructions Branch instruction Jump instruction
instructions
(Figure 5.39) (Figure 5.40) (Figure 5.41)
(Figure 5.38)
(Op = 'JMP')
Memory reference FSM R-type FSM Branch FSM Jump FSM
(Figure 5.38) (Figure 5.39) (Figure 5.40) (Figure 5.41)
ALUSrcA = 1
ALUSrcB = 10
ALUOp = 00
(Op = 'LW')
Memory Memory
access access
3 5
MemRead
MemWrite
IorD = 1
IorD = 1
Write-back step
4
RegWrite To state 0
MemtoReg = 1 (Figure 5.37)
RegDst = 0
Execution
6
ALUSrcA = 1
ALUSrcB = 00
ALUOp = 10
R-type completion
7
RegDst = 1
RegWrite
MemtoReg = 0
To state 0
(Figure 5.37)
FSM control to implement R-type instructions has 2 states
FSM Control: Branch Instruction
From state 1
(Op = 'BEQ')
Branch completion
8
ALUSrcA = 1
ALUSrcB = 00
ALUOp = 01
PCWriteCond
PCSource = 01
To state 0
(Figure 5.37)
Jump completion
9
PCWrite
PCSource = 10
To state 0
(Figure 5.37)
(Op = 'J')
Memory address Branch
computation Jump
Execution completion completion
2 6 8 9
ALUSrcA = 1
ALUSrcA = 1 ALUSrcA =1 ALUSrcB = 00
EX ALUSrcB = 10
ALUOp = 00
ALUSrcB = 00 ALUOp = 01
PCWrite
PCSource = 10
ALUOp= 10 PCWriteCond
PCSource = 01
(Op = 'LW')
Memory Memory
access access R-type completion
3 5 7
Write-back step
4
RegDst =0
WB RegWrite
MemtoReg=1
The complete FSM control for the multicycle MIPS datapath:
refer Multicycle Datapath with Control II
FSM Control:
PCW rite
PCW riteCond
IorD
M emRead
ation
M emtoReg
PCS ource
ALUOp
Outputs
ALUSrcB
ALUSrcA
RegW rite
RegDst
NS3
NS2
NS1
Inputs NS0
Op4
Op5
Op2
Op0
Op3
Op1
S3
S0
S2
S1
Instruction register State register
opcode field
High-level view of FSM implementation: inputs to the combinational logic block are
the current state number and instruction opcode bits; outputs are the next state
number and control signals to be asserted for the current state
Logic Equation for Control Unit
Example of Combinational Circuit
NS0 = NextState1 + NextState3 + NextState5 + NextState7 + NextState9
Truth Table for Next-State
Truth Table for 16 Control Signals
O p5
FSM
O p4
O p3
O p2
Control: O p1
O p0
PLA
S3
S2
S1
Implem- S0
PC W rite
entation
PC W riteCond
IorD
M em Read
M em W rite
IR W rite
M em toR eg
PC Source1
PC Source0
ALU O p1
ALU O p0
ALU SrcB 1
ALU SrcB 0
ALU SrcA
RegW rite
RegDst
NS 3
NS 2
NS 1
NS 0
Upper half is the AND plane that computes all the products. The products are carried
to the lower OR plane by the vertical lines. The sum terms for each output is given by
the corresponding horizontal line
E.g., IorD = S0.S1.S2.S3 + S0.S1.S2.S3
FSM Control: ROM
Implementation
ROM (Read Only Memory)
values of memory locations are fixed ahead of time
A ROM can be used to implement a truth table
if the address is m-bits, we can address 2m entries in the ROM
outputs are the bits of the entry the address points to
address output
0 0 0 0 0 1 1
m n
0 0 1 1 1 0 0
0 1 0 1 1 0 0
ROM m = 3 0 1 1 1 0 0 0
n = 4 1 0 0 0 0 0 0
1 0 1 0 0 0 1
1 1 0 0 1 1 0
1 1 1 0 1 1 1
The size of an m-input n-output ROM is 2m x n bits – such a ROM can
be thought of as an array of size 2m with each entry in the array being
n bits
FSM Control: ROM vs. PLA
First improve the ROM: break the table into two parts
4 state bits give the 16 output signals – 24 x 16 bits of ROM
all 10 input bits give the 4 next state bits – 210 x 4 bits of ROM
Total – 4.3K bits of ROM
PLA is much smaller
can share product terms
only need entries that produce an active output
can take into account don't cares
PLA size = (#inputs #product-terms) + (#outputs
#product-terms)
FSM control PLA = (10x17)+(20x17) = 460 PLA cells
PLA cells usually about the size of a ROM cell (slightly bigger)
Microprogramming
Microprogramming is a method of specifying FSM control that
resembles a programming language – textual rather graphic
this is appropriate when the FSM becomes very large, e.g., if the
instruction set is large and/or the number of cycles per instruction
is large
in such situations graphical representation becomes difficult as
there may be thousands of states and even more arcs joining them
a microprogram is specification : implementation is by ROM or PLA
A microprogram is a sequence of microinstructions
each microinstruction has eight fields (label + 7 functional)
Label: used to control microcode sequencing
ALU control: specify operation to be done by ALU
SRC1: specify source for first ALU operand
SRC2: specify source for second ALU operand
Register control: specify read/write for register file
Memory: specify read/write for memory
PCWrite control: specify the writing of the PC
Sequencing: specify choice of next microinstruction
Microprogramming
The Sequencing field value determines the execution order
of the microprogram
value Seq : control passes to the sequentially next
microinstruction
value Fetch : branch to the first microinstruction to begin the
next MIPS instruction, i.e., the first microinstruction in the
microprogram
value Dispatch i : branch to a microinstruction based on
control input and a dispatch table entry (called dispatching):
Dispatching is implemented by means of creating a table, called
dispatch table, whose entries are microinstruction labels and
which is indexed by the control input. There may be multiple
dispatch tables – the value Dispatch i in the sequencing field
indicates that the i th dispatch table is to be used
Control Microprogram
The microprogram corresponding to the FSM control shown
graphically earlier:
ALU Register PCWrite
Label control SRC1 SRC2 control Memory control Sequencing
Fetch Add PC 4 Read PC ALU Seq
Add PC Extshft Read Dispatch 1
Mem1 Add A Extend Dispatch 2
LW2 Read ALU Seq
Write MDR Fetch
SW2 Write ALU Fetch
Rformat1 Func code A B Seq
Write ALU Fetch
BEQ1 Subt A B ALUOut-cond Fetch
JUMP1 Jump address Fetch
Microprogram containing 10 microinstructions
Dispatch ROM 1
Dispatch ROM 2
Op Opcode name Value
000000 R-format Rformat1 Op Opcode name Value