CPS 104 Computer Organization and Programming Lecture-22: Single Cycle Datapath, Control
CPS 104 Computer Organization and Programming Lecture-22: Single Cycle Datapath, Control
CPS104 Lec22.1
GK Spring 2004
Admin.
Homework-4 is Due. Homework-5: Posted, Due March15, in Class u Do homework-5 this week as preparation for the midterm exam. Midterm Exam March 5th. u In Class u 1 hour u Closed books u Covers all material including Data-path. u Bring SPIM manual and/or Common MIPS Instructions. Wednesday March 3, Review Session u Bring questions about ANY topic we covered in the course.
GK Spring 2004
CPS104 Lec22.2
Branch Rd RegDst Rt Rs 5 5 busA 32 0 Mux ALU Rt Jump Clk Instruction Fetch Unit
Rt Zero
Rs
Rd
busW 32 Clk
MemWr
32 32 WrEn Adr
1 32
imm16
Data In 32 Clk
16
Data Memory
ALUSrc
CPS104 Lec22.3
ExtOp
GK Spring 2004
CPS104 Lec22.4
GK Spring 2004
Fetch the instruction from Instruction memory: Instruction <- mem[PC] u This is the same for all instructions
30 PC<31:28> Target Instruction<25:0> PC Clk 30 1 4 30 26 0 30 Adder Mux 30 00 1 Mux 0 Addr<31:2> Addr<1:0> Instruction Memory 32
Adder SignExt 30
1 30
imm16 Instruction<15:0> 16
26 rs
21 rt
16 rd
11 shamt
6 funct
RegDst = ?
1 Mux 0
Rt Zero ALU
Rs
Rd
Imm16 MemtoReg = ?
MemWr = ? 0 Mux 32
32 WrEn Adr
imm16
16
Data Memory
ALUSrc = ?
CPS104 Lec22.6
ExtOp = ?
GK Spring 2004
26 rs
21 rt
16 rd
11 shamt
6 funct
RegDst = 1
1 Mux 0
Rt Zero
Rs
Rd
Imm16 MemtoReg = 0
MemWr = 0 0 Mux 32
ALU
32 WrEn Adr
imm16
16
Data Memory
ALUSrc = 0
CPS104 Lec22.7
ExtOp = x
GK Spring 2004
PC <- PC + 4 u This is the same for all instructions except: Branch and Jump
30 PC<31:28> Target Instruction<25:0> PC Clk 30 1 4 30 26 0 30 Adder Mux 30 00 1 Mux 0 Addr<31:2> Addr<1:0> Instruction Memory 32
Adder SignExt 30
1 30
Jump = ?
Instruction<31:0>
imm16 Instruction<15:0> 16
Branch = ? Zero = ?
CPS104 Lec22.8
GK Spring 2004
PC <- PC + 4 u This is the same for all instructions except: Branch and Jump
30 PC<31:28> Target Instruction<25:0> PC Clk 30 1 4 30 26 0 30 Adder Mux 30 00 1 Mux 0 Addr<31:2> Addr<1:0> Instruction Memory 32
Adder SignExt 30
1 30
Jump = 0
Instruction<31:0>
imm16 Instruction<15:0> 16
Branch = 0 Zero = x
CPS104 Lec22.9
GK Spring 2004
26 rs
21 rt
16 immediate
RegDst = ?
1 Mux 0 ALUctr = ?
Rt Zero ALU
Rs
Rd
Imm16 MemtoReg = ?
MemWr = ? 0 Mux 32
32 WrEn Adr
imm16
16
Data Memory
ALUSrc = ?
CPS104 Lec22.10
ExtOp = ?
GK Spring 2004
26 rs
21 rt
16 immediate
RegDst = 0
1 Mux 0 ALUctr = Or
Rt Zero
Rs
Rd
Imm16 MemtoReg = 0
MemWr = 0 0 Mux 32
ALU
32 WrEn Adr
imm16
16
Data Memory
ALUSrc = 1
CPS104 Lec22.11
ExtOp = 0
GK Spring 2004
26 rs
21 rt
16 immediate
RegDst = ?
1 Mux 0
Rt Zero
Rs
Rd
Imm16 MemtoReg = ?
MemWr = ? 0 Mux
ALU
32 WrEn Adr
1 32
imm16
16
Data Memory
ALUSrc = ?
CPS104 Lec22.12
ExtOp = ?
GK Spring 2004
26 rs
21 rt
16 immediate
RegDst = 0
1 Mux 0
Rt Zero
Rs
Rd
Imm16 MemtoReg = 1
MemWr = 0 0 Mux
ALU
32 WrEn Adr
1 32
imm16
16
Data Memory
ALUSrc = 1
CPS104 Lec22.13
ExtOp = 1
GK Spring 2004
26 rs
21 rt
16 immediate
RegDst =
1 Mux 0 5 Rs Rt 5 5
Rt Zero ALU
Rs
Rd
Imm16 MemtoReg =
MemWr = 0 Mux 32
32 WrEn Adr
imm16
16
Data Memory
ALUSrc =
CPS104 Lec22.14
ExtOp =
GK Spring 2004
26 rs
21 rt
16 immediate
RegDst =x
1 Mux 0 Rs Rt 5 5
Rt Zero ALU
Rs
Rd
Imm16 MemtoReg =x
MemWr =1 0 Mux 32
32 WrEn Adr
imm16
16
Data Memory
ALUSrc =1
CPS104 Lec22.15
ExtOp = 1
GK Spring 2004
26 rs
21 rt
16 immediate
RegDst = ?
1 Mux 0
RegWr = ?
Rt
Rs
Rd
Imm16 MemtoReg = ?
busW 32 Clk
32
Mux
imm16
16
CPS104 Lec22.16
ExtOp = ?
GK Spring 2004
26 rs
21 rt
16 immediate
RegDst = x
1 Mux 0
RegWr = 0
Rt Zero ALU
Rs
Rd
Imm16 MemtoReg = x
busW 32 Clk
MemWr = 0 0 Mux 32
32 WrEn Adr
imm16
16
Data Memory
ALUSrc = 0
CPS104 Lec22.17
ExtOp = x
GK Spring 2004
26 rs
21 rt
16 immediate
30 00 Mux
1 30
Instruction<31:0>
imm16 16 Instruction<15:0>
CPS104 Lec22.18
26 rs
21 rt
16 immediate
30 00 Mux
1 30
Instruction<31:0>
imm16 16 Instruction<15:0>
CPS104 Lec22.19
26 target address
RegDst = x
1 Mux 0
Rt
Rs
Rd
Imm16 MemtoReg = x
32
Mux
imm16
16
CPS104 Lec22.20
ExtOp = x
GK Spring 2004
26 target address
Adder SignExt 30
1 30
Jump = 1
Instruction<31:0>
imm16 Instruction<15:0> 16
Branch = X Zero = x
CPS104 Lec22.21
GK Spring 2004
CPS104 Lec22.22
op 6
Main Control
func 6 ALUop N
ALUctr 3 ALU
CPS104 Lec22.23
GK Spring 2004
In this exercise, ALUop has to be 2 bits wide to represent: u (1) R-type instructions u I-type instructions that require the ALU to perform:
To implement the full MIPS ISA, ALUop hat to be 3 bits to represent: u (1) R-type instructions u I-type instructions that require the ALU to perform:
(2) Or, (3) Add, (4) Subtract, and (5) And (Example: andi) R-type R-type 1 00 ori Or 0 10 lw Add 0 00 sw Add 0 00 jump Subtract xxx xxx 0 01
GK Spring 2004
beq
ALUop (Symbolic) ALUop<2:0> 31 R-type funct<5:0> 10 0000 10 0010 10 0100 10 0101 10 1010 op 26
R-type R-type 1 00 21 rs
sw Add 0 00 6
jump Subtract xxx xxx 0 01 0 funct ALU Operation Add Subtract And Or Set-on-less-than
GK Spring 2004
beq
ALU
CPS104 Lec22.25
CPS104 Lec22.26
GK Spring 2004
ALUctr<2> = !ALUop<2> & ALUop<0> + ALUop<2> & !func<2> & func<1> & !func<0>
CPS104 Lec22.27
GK Spring 2004
CPS104 Lec22.28
GK Spring 2004
ALUctr<0> = !ALUop<2> & ALUop<0> + ALUop<2> & !func<3> & func<2> & !func<1> & func<0> + ALUop<2> & func<3> & !func<2> & func<1> & !func<0>
CPS104 Lec22.29
GK Spring 2004
ALUctr<2> = !ALUop<2> & ALUop<0> + ALUop<2> & !func<2> & func<1> & !func<0>
ALUctr<0> = !ALUop<2> & ALUop<0> + ALUop<2> & !func<3> & func<2> & !func<1> & func<0> + ALUop<2> & func<3> & !func<2> & func<1> & !func<0>
CPS104 Lec22.30
GK Spring 2004
:
ALUop 3 00 0000 R-type 1 0 0 1 0 0 0 x R-type 1 0 0
func 6
ALUctr 3
op RegDst ALUSrc MemtoReg RegWrite MemWrite Branch Jump ExtOp ALUop (Symbolic) ALUop <2> ALUop <1> ALUop <0>
CPS104 Lec22.31
00 1101 10 0011 10 1011 00 0100 00 0010 ori lw sw beq jump 0 0 x x x 1 1 1 0 x 0 1 x x x 1 1 0 0 0 0 0 1 0 0 0 0 0 1 x 0 0 0 0 1 0 1 1 x x Or Add Add Subtract xxx 0 0 0 x 0 1 0 0 x 0 0 0 0 x 1 GK Spring 2004
00 0000 R-type 1
RegWrite = R-type + ori + lw = !op<5> & !op<4> & !op<3> & !op<2> & !op<1> & !op<0>(R-type) + !op<5> & !op<4> & op<3> & op<2> & !op<1> & op<0>(ori) + op<5> & !op<4> & !op<3> & !op<2> & op<1> & op<0>(lw)
op<5>
..
op<5>
..
op<5>
..
op<5>
..
op<5>
..
<0>
op<5>
..
op<0>
<0>
<0>
<0>
<0>
R-type
ori
lw
sw
beq
jump RegWrite
CPS104 Lec22.32
GK Spring 2004
..
op<5>
..
op<5>
..
op<5>
..
op<5>
..
<0>
op<5>
..
op<0>
<0>
<0>
<0>
<0>
R-type
ori
lw
sw
beq
jump
RegWrite ALUSrc RegDst MemtoReg MemWrite Branch Jump ExtOp ALUop<2> ALUop<1> ALUop<0> GK Spring 2004
CPS104 Lec22.33
:
Rt Rs Rt 5 5
Rt Zero
Rs
Rd
busW 32 Clk
MemWr
32 32 WrEn Adr
1 32
imm16 Instr<15:0> 16
Data In 32 Clk
Data Memory
ALUSrc
CPS104 Lec22.34
ExtOp
GK Spring 2004
ALUctr ExtOp ALUSrc MemtoReg RegWr busA busB Addres s busW CPS104 Lec22.35
Instruction Memoey Access Time New Value Delay through Control Logic New Value New Value New Value New Value
New Value Register File Access Time New Value New Value ALU Delay
New Value
Long cycle time: u Cycle time must be long enough for the load instruction:
PCs Clock -to-Q + Instruction Memory Access Time + Register File Access Time + ALU Delay (address calculation) + Data Memory Access Time + Register File Setup Time + Clock Skew
Cycle time is much longer than needed for all other instructions
CPS104 Lec22.36
GK Spring 2004