Académique Documents
Professionnel Documents
Culture Documents
CPS104 Lec20.1
GK Spring 2004
Admin.
Homework-4 is posted. Due March. 1st. In class. 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.
CPS104 Lec20.2
GK Spring 2004
Output
CPS104 Lec20.3
GK Spring 2004
CPS104 Lec20.4
GK Spring 2004
lw
u
Addr <- R[rs] + SignExt(imm16) Calculate the memory address R[rt] <- Mem[Addr] PC <- PC + 4 Load the data into the register
CPS104 Lec20.5
GK Spring 2004
32
Adder
Adder
B 32 Select A B 32 32 OP A 32
32
Sum Carry
MUX
MUX ALU
32
ALU
B
32
Result Zero
GK Spring 2004
CPS104 Lec20.6
32
Write Enable
Data In N
Data Out N
Write Enable:
negated (0): Data Out will not change asserted (1): Data Out will become the same as Data In.
Clk
CPS104 Lec20.7
GK Spring 2004
. . .
. . .
. . .
. . .
All storage elements are clocked by the same clock edge Cycle Time >= CLK-to-Q + Longest Delay Path + Setup + Clock Skew
CPS104 Lec20.8
GK Spring 2004
Register File consists of 32 registers: busA u Two 32-bit output busses: busW 32 32 32-bit busA and busB 32 Registers busB u One 32-bit input bus: busW Clk 32 Register is selected by: u RA selects the register to put on busA u RB selects the register to put on busB u RW selects the register to be written via busW when Write Enable is 1 Clock input (CLK) u The CLK input is a factor ONLY during write operation u During read operation, behaves as a combinational logic block:
RW RA RB Write Enable5 5 5
CPS104 Lec20.9
Address
Memory (idealized) Data In DataOut u One input bus: Data In 32 32 u One output bus: Data Out Clk Memory word is selected by: u Write Enable = 0: Address selects the word to put on the Data Out bus u Write Enable = 1: Address selects the memory word to be written via the Data In bus Clock input (CLK) u The CLK input is a factor ONLY during write operation u During read operation, behaves as a combinational logic block:
CPS104 Lec20.10
GK Spring 2004
The common RTL operations u Fetch the Instruction: mem[PC] u Update the program counter:
Clk
Instruction Word 32
CPS104 Lec20.11
GK Spring 2004
CPS104 Lec20.12
GK Spring 2004
CPS104 Lec20.13
GK Spring 2004
R[rd] <- R[rs] op R[rt] Example: add rd, rs, rt u Ra, Rb, and Rw comes from instructions rs, rt, and rd fields u ALUctr and RegWr: control logic after decoding the instruction fields: op and func
31 op 6 bits 26 rs 5 bits 21 rt 5 bits 16 rd 5 bits 11 shamt 5 bits ALUctr busA 32 busB 32 Result 32 ALU 6 funct 6 bits 0
CPS104 Lec20.14
GK Spring 2004
Register-Register Timing
Inst fetch
Clk PC Old Value Rs, Rt, Rd, Op, Func Clk-to-Q New Value Old Value Old Value Old Value Old Value Old Value Instruction Memory Access Time New Value Delay through Control Logic New Value New Value Register File Access Time New Value ALU Delay New Value
Write Back
Rw Ra Rb 32 32-bit Registers
GK Spring 2004
21 rs 5 bits
mem[PC]
31 0000000000000000 16 bits
CPS104 Lec20.16
16 15 immediate 16 bits
GK Spring 2004
Example: ori
immediate 16 bits
21 rs 5 bits Rt Rs 5 5
16 rt 5 bits
ALUctr
Rw Ra Rb 32 32-bit Registers
Result 32
ALU
Mux
1
imm16
16
32 ALUSrc
GK Spring 2004
CPS104 Lec20.17
26 op 6 bits
21 rs 5 bits
lw
u
Addr <- R[rs] + SignExt(imm16) Calculate the memory address R[rt] <- Mem[Addr] Load the data into the register PC <- PC + 4
31
31
CPS104 Lec20.18
GK Spring 2004
Example: lw
0
rt, rs,
rs 5 bits
rt 5 bits
immediate 16 bits
1 Mux 0
ALUctr MemtoReg
0
Rw Ra Rb 32 32-bit Registers
ALU
Mux
32
imm16
16
Data Memory
CPS104 Lec20.19
GK Spring 2004
ExtOp
21 rs 5 bits
mem[PC]
Addr <- R[rs] + SignExt(imm16) Calculate the memory address Mem[Addr] <- R[rt] PC <- PC + 4 Store the register into memory Calculate the next instructions address
CPS104 Lec20.20
GK Spring 2004
21 rs 5 bits
RegDst
1 Mux 0
Rw Ra Rb 32 32-bit Registers
Mux
32 32 WrEn Adr
imm16
16
Data Memory
CPS104 Lec20.21
ExtOp
GK Spring 2004
21 rs 5 bits
else
CPS104 Lec20.22
GK Spring 2004
beq
RegDst
PC
1 Mux 0
ALUctr
imm16 16
Rw Ra Rb 32 32-bit Registers
ALU
Zero
To Instruction Memory
Mux
imm16
16
CPS104 Lec20.23
GK Spring 2004
ExtOp
In theory, the PC is a 32-bit byte address into the instruction memory: u Sequential operation: PC<31:0> = PC<31:0> + 4 u Branch operation: PC<31:0> = PC<31:0> + 4 + SignExt[Imm16] * 4 The magic number 4 always comes up because: u The 32-bit PC is a byte address u And all our instructions are 4 bytes (32 bits) long In other words: u The 2 LSBs of the 32-bit PC are always zeros u There is no reason to have hardware to keep the 2 LSBs In practice, we can simplify the hardware by using a 30-bit PC<31:2>: u Sequential operation: PC<31:2> = PC<31:2> + 1 u Branch operation: PC<31:2> = PC<31:2> + 1 + SignExt[Imm16] u In either case: Instruction-Memory-Address = PC<31:2> concat 00
GK Spring 2004
CPS104 Lec20.24
Using a 30-bit PC: u Sequential operation: PC<31:2> = PC<31:2> + 1 u Branch operation: PC<31:2> = PC<31:2> + 1 + SignExt[Imm16] u In either case: Instruction-Memory-Address = PC<31:2> concat 00
30 30 30 1 Clk imm16 Instruction<15:0> 16 SignExt 00 0 30 Adder Mux Adder Addr<31:2> Addr<1:0> Instruction Memory 32 PC
1 30
30
CPS104 Lec20.25
1 Carry In Adder
00
1 30 30
30
SignExt
CPS104 Lec20.26
GK Spring 2004
j
u
PC<31:2> <- PC<31:28> concat target<26:0> concat <00> Calculate the next instructions address
CPS104 Lec20.27
GK Spring 2004
j
u
Adder SignExt 30
1 30
Jump
Instruction<31:0>
imm16 Instruction<15:0> 16
Branch
CPS104 Lec20.28
Zero
GK Spring 2004
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 Lec20.29
ExtOp
GK Spring 2004