All MIPS instructions are 32 bits long. The three instruction formats:
31 26 op 6 bits 31 op 6 bits 31 op 6 bits 26 target address 26 bits 26 rs 5 bits rs 5 bits 21 rt 5 bits 21 rt 5 bits 16 immediate 16 bits 0 16 rd 5 bits 11 shamt 5 bits 6 funct 6 bits 0 0
The different fields are: op: operation of the instruction rs, rt, rd: the source and destination registers specifier shamt: shift amount funct: selects the variant of the operation in the op field address / immediate: address offset or immediate value target address: target address of the jump instruction
ECE4680 Control.1
2003-3-17
ECE4680 Control.2
2003-3-17
OR Imm: ori rt, rs, imm16 LOAD and STORE lw rt, rs, imm16 sw rt, rs, imm16 BRANCH: beq rs, rt, imm16 JUMP: j target
31
Rs Zero
Rt
Rd
busW 32 Clk
MemWr
Data In 32 Clk
1 32 ALUSrc
imm16
16
ExtOp
ECE4680 Control.3 ECE4680 Control.4 2003-3-17
add
rd, rs, rt Fetch the instruction from memory The actual operation Calculate the next instructions address
mem[PC]
Output
Todays Topic: Designing the Control for the Single Cycle Datapath A note: 2nd step and 3rd step can be done in parallel.
ECE4680 Control.5
2003-3-17
ECE4680 Control.6
2003-3-17
mem[PC]
1 Mux 0
Rs Zero
Rt
Rd
Imm16 MemtoReg = 0
30 1
0 30 Adder Mux
1 30
MemWr = 0 0 Mux 32
Adder SignExt 30
32 WrEn Adr
1 32
Data In 32 Clk
16
Data Memory
ALUSrc = 0 ExtOp = x
2003-3-17 ECE4680 Control.8 2003-3-17
30 00 30 1 Mux 0
Rd RegDst = 0
Rt Rs 5 5
1 Mux 0 ALUctr = Or
Rs Zero ALU
Rt
Rd
Imm16 MemtoReg = 0
30 1
0 30 Adder Mux
1 30
Jump = 0
Instruction<31:0>
MemWr = 0 0 Mux 32
Adder SignExt 30
32 WrEn Adr
1 32
Data In 32 Clk
16
Data Memory
ALUSrc = 1 ExtOp = 0
2003-3-17 ECE4680 Control.10 2003-3-17
1 Mux 0
1 Mux 0
Rs Zero
Rt
Rd
Imm16 MemtoReg = 1
RegWr = 0 5 busW
Rs Zero
Rt
Rd
Imm16 MemtoReg = x
32 WrEn Adr
MemWr = 1 0 Mux 32
32 WrEn Adr
1 32 imm16 16
1 32
imm16
Data In 32 Clk
16
Data Memory
1 32
Data In 32 Clk
Data Memory
ALUSrc = 1 ExtOp = 1
ECE4680 Control.11 2003-3-17 ECE4680 Control.12
ALUSrc = 1 ExtOp = 1
2003-3-17
1 Mux 0
RegWr = 0
Rs Zero
Rt
Rd
Imm16 MemtoReg = x
busW 32 Clk
MemWr = 0 0 Mux 32
ALU
32 WrEn Adr
1 30
Jump = 0
Instruction<31:0>
SignExt
imm16
16
Data Memory
ALUSrc = 0 ExtOp = x
ECE4680 Control.13 2003-3-17 ECE4680 Control.14
Jump = 1 Clk Rt
1 Mux 0
Rs
Rt
Rd
Imm16 MemtoReg = x
32
1 30
Jump = 1
Instruction<31:0>
Mux
SignExt
imm16
16
Data Memory
30
Branch = 0
ECE4680 Control.16
Zero = x
2003-3-17
We Dont Care :-) func 10 0000 10 0010 op 00 0000 00 0000 00 1101 10 0011 10 1011 00 0100 00 0010 add 1 0 0 1 0 0 0 x Add sub 1 0 0 1 0 0 0 x Subtract 21 rs rs rt rt target address ori 0 1 0 1 0 0 0 0 Or 16 rd lw 0 1 1 1 0 0 0 1 Add 11 shamt immediate sw x 1 x 0 1 0 0 1 Add 6 funct beq x 0 x 0 0 1 0 x Subtract jump x x x 0 0 0 1 x xxx
op 6
Main Control
6 ALUop N
ALUctr 3 ALU
2003-3-17
In this exercise, ALUop has to be 2 bits wide to represent: (1) R-type instructions I-type instructions that require the ALU to perform: (2) Or, (3) Add, and (4) Subtract
ALUop (Symbolic)
Why not consider J-type?
R-type R-type 1 00 21 rs
lw Add 0 00 11
sw Add 0 00 6 shamt
beq Subtract 0 01
ALUop<2:0> 31 R-type op 26
To implement the full MIPS ISA, ALUop hat to be 3 bits to represent: (1) R-type instructions 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
2003-3-17
funct
Recall ALU Homework (also P. 286 text): funct<5:0> 10 0000 10 0010 10 0100 10 0101 10 1010
ECE4680 Control.20
ALUctr
ALU
beq
and or set-on-less-than
ALUctr<0> = !ALUop<2> & ALUop<0> + ALUop<2> & !func<2> & func<1> & !func<0>
ECE4680 Control.21
2003-3-17
ECE4680 Control.22
2003-3-17
ALUctr<2> = !ALUop<2> & ALUop<1> ALUctr<1> = !ALUop<2> & ALUop<1> + ALUop<2> & !func<3> & func<2> & !func<1> ALUop<2> & func<3> & !func<2> & func<1> & !func<1> + ALUop<2> & !func<3> & func<2> & !func<1> & func<0> + ALUop<2> & func<3> & !func<2> & func<1> & !func<0>
ECE4680 Control.23
2003-3-17
ECE4680 Control.24
2003-3-17
:
ALUop 3 00 0000 R-type 1 0 0 1 0 0 0 x R-type 1 0 0 ori 0 1 0 1 0 0 0 0 Or 0 1 0 lw 0 1 1 1 0 0 0 1 Add 0 0 0
ALUctr 3
op
00 1101 10 0011 10 1011 00 0100 00 0010 sw x 1 x 0 1 0 0 1 Add 0 0 0 beq x 0 x 0 0 1 0 x Subtract 0 0 1 jump x x x 0 0 0 1 x xxx x x x
2003-3-17
ALUctr<0> = !ALUop<2> & ALUop<0> + ALUop<2> & !func<2> & func<1> & !func<0> ALUctr<1> = !ALUop<2> & ALUop<1> + ALUop<2> & !func<3> & func<2> & !func<1> + ALUop<2> & func<3> & !func<2> & func<1> & !func<1> ALUctr<2> = !ALUop<2> & ALUop<1> + ALUop<2> & !func<3> & func<2> & !func<1> & func<0> + ALUop<2> & func<3> & !func<2> & func<1> & !func<0>
RegDst ALUSrc MemtoReg RegWrite MemWrite Branch Jump ExtOp ALUop (Symbolic) ALUop <2> ALUop <1> ALUop <0>
ECE4680 Control.25
2003-3-17
ECE4680 Control.26
..
op<5>
..
op<5>
..
op<5>
..
op<5>
..
<0>
op<5>
..
op<0>
<0>
<0>
<0>
<0>
RegWrite = R-type + ori + lw = !op<5> & !op<4> & !op<3> & !op<2> & !op<1> & !op<0> + !op<5> & !op<4> & op<3> & op<2> & !op<1> & op<0> + op<5> & !op<4> & !op<3> & !op<2> & op<1> & op<0>
op<5>
R-type
ori
lw
sw
beq
jump
..
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
ECE4680 Control.27
2003-3-17
ECE4680 Control.28
2003-3-17
:
Rt Rs 5 5 Rt
Rd RegDst
Rt Zero
Rs
Rd
busW 32 Clk
MemWr
32 32 WrEn Adr
The effect of branch and jump in a real MIPS Processor is delayed: - Instruction Address: 0x00 j 1000 - Instruction Address: 0x04 add $1, $2, $3 Instruction Address: 0x1000 sub $1, $2, $3 Branch and jump in our single cycle processor is NOT delayed - Instruction Address: 0x00 j 1000 - Instruction Address: 0x1000 sub $1, $2, $3
1 32 ALUSrc
imm16 Instr<15:0>
Data In 32 Clk
16
Data Memory
ExtOp
ECE4680 Control.29 2003-3-17 ECE4680 Control.30 2003-3-17
Rs, Rt, Rd, Op, Func ALUctr ExtOp ALUSrc MemtoReg RegWr busA busB Address
Instruction Memory Access Time New Value Delay through Control Logic New Value New Value New Value New Value New Value
Register File Setup Time + Clock Skew Cycle time is much longer than needed for all other instructions
Register File Access Time New Value New Value ALU Delay New Value New
2003-3-17
Old Value
ECE4680 Control.32
2003-3-17
ECE4680 Control.33
2003-3-17