MIPS - PowerPoint PPT Presentation

1 / 47
About This Presentation
Title:

MIPS

Description:

MIPS – PowerPoint PPT presentation

Number of Views:159
Avg rating:3.0/5.0
Slides: 48
Provided by: csta3
Category:
Tags: mips | register

less

Transcript and Presenter's Notes

Title: MIPS


1
MIPS ????? ????? ?? ????
???????? ???????? ?????? ??? ???? ?????? R-type
?- I-type ??? ????? ??????? add, sub, or, xor,
and, slt, lw, sw, beq, j ????? ?????? ???? ????
??????? ?????? ?????? ??? ???? bne, addi, jal,
jr
2
??? ????? ??????
3
???? ????? ????? ?????
  • (1) FETCH ??? ????? ???????? ?"? ?????? ?????
    ?-PC.
  • (2) DECODE ???? ?? ?????? ???? ?? ???????
    ??????? (??? ?? ?????).
  • (3) EXECUTE ????? ?-ALU ??? ?? ??????, ?? ?????
    ?????.
  • (4) MEMORY ????? ?????? ???? ????? ????? ??
    ????? ??????? (Store) ?? ????? ???????? (Load).
  • (5) WRITE BACK ??? ????? ????? ????? ?????.

4
???? ?? ????? ????? ?????? ???? ????? ??????
???? ????? - ??????? ?? ?? ?????, ?? ????? ????
???? ???????? ?? ???? ????? (?? ????)
5
Single cycle data paths
Processor uses synchronous logic design (a
clock).
6
Edge-Triggered D Flip Flops
Value of D is sampled on positive clock edge.
Q outputs sampled value for rest of cycle.
D
Q
7
Single cycle data paths Definition
All instructions execute in a single cycle of the
clock (positive edge to positive edge)
Advantage a great way to learn CPUs.
Drawbacks unrealistic hardware assumptions, slow
clock period
8
Recall MIPS R-format instructions
Syntax ADD 8 9 10
Semantics 8 9 10
Fetch next inst from memory012A4020
Retrieve register values 9 10
Add 9 to 10
Place this sum in 8
Prepare to fetch instruction that follows the ADD
in the program.
9
Separate Read-Only Instruction Memory
Reads are combinational Put a stable address on
input, a short time later data appears on output.
????? (?????) ???? ??????? ???????? (Instruction
Memory Data Memory)
????? ??????? ?????? ?? ??????? ????
10
??? 1 Straight-line Instruction Fetch
Fetching straight-line MIPS instructions requires
a machine that generates this timing diagram
Why do we increment every clock cycle?
Why 4 and not 1?
11
New Component Register (for PC)
PC
32
32
Din
Dout
Clk
In later examples, we will add an enable input
clock edge updates state only if enable is high
12
New Component A 32-bit adder (ALU)
13
Design Straight-line Instruction Fetch
State machine design in the service of an ISA
Instr Mem
32
PC
32
32
32
Addr
Data
D
Q

32
32
0x4
4 in hexadecimal
Clk
14
Goal 1 An R-format single-cycle CPU
Syntax ADD 8 9 10
Semantics 8 9 10
Fetch next inst from memory012A4020
Retrieve register values 9 10
Add 9 to 10
Place this sum in 8
Prepare to fetch instruction that follows the ADD
in the program.
15
Register files
Why is R0 special?
En
Q
R1
D
En
Q
R2
D
...
En
R31
Q
D
32
16
Register File Schematic Symbol
Why do we need WE (Write Enable)?
If we had a register file w/o WE, how could we
work around it?
17
Goal 1 An R-format single-cycle CPU
Syntax ADD 8 9 10
Semantics 8 9 10
Fetch next inst from memory012A4020
Retrieve register values 9 10
Add 9 to 10
Place this sum in 8
Prepare to fetch instruction that follows the ADD
in the program.
18
Computing engine of the R-format CPU
Decode fields to get ADD 8 9 10
Logic
What do we do with WE?
19
Putting it all together ...
To rs1, rs2, ws, op decode logic ...
Logic
Is it safe to use same clock for PC and RegFile?
20
Reminder How data flows after posedge
PC
D
Q
21
Next posedge Update state and repeat
PC
D
Q
22
A CPU capable of R-type instructions only
??? ?? ???? ?????
4
Adder
6
3126
Instruction Memory
PC
6
50funct
23
????? ?????????. ????? ?? ????? ????
?-decode(????? ?-write back)
Read
register
1
Read
data
1
Read
2
????? ???????
register
Registers
Write
Read

register
data
2
Write
Data
Data
24
Arithmetic Logic operation
ALU operation
Read
ALU operation
register
1
Read
data
1
Zero
Read
register
2
Instruction
Registers
ALU
Write
ALU

register
Read
result
data
2
ALU
Write
Data
?????? ??????? ?????? ??? ????? R-type
25
A CPU capable of R-type instructions only
??? ?? ???? ?????
4
Adder
6
3126
Reg File
Instruction Memory
PC
ALU
6
50funct
26
A CPU capable of R-type instructions only
??? ?? ???? ?????
4
Adder
6
3126
Reg File
Instruction Memory
PC
ALU
6
50funct
27
The internal structure of the Register File
Rd reg 1 ( Rs)
32
5
32
32
32
32
Read data 1
write data
32
32
32
Rd reg 2 ( Rt)
5
32
32
32
Read data 2
32
32
Wr reg ( Rd)
5
E
RegWrite
?????? ???? ??????? ??????? ????? ?? ??? ????????
????? ?????? ???? ????????? ?????? (?????? ?????
????)
28
A CPU capable of R-type instructions only
4
Adder
6
3126
RegWrite
Reg File
Instruction Memory
PC
ALU
29
A CPU capable of R-type instructions only
Instruction Memory
Reg File
PC
ALU
30
A CPU capable of R-type instructions only
4
Instruction Memory
Reg File
ALU
PC
31
A CPU capable of R-type instructions only
4
Adder
6
3126
RegWrite
6
50funct
ALU control
Reg File
Instruction Memory
PC
ALU
32
??? ?? 2 I-format ALU instructions
Syntax ORI 8 9 64
Semantics 8 9 64
Zero-extend 0x8000 ? 0x00008000
Sign-extend 0x8000 ? 0xFFFF8000
Some MIPS instructions zero-extend immediate
field, other instructions sign-extend.
33
Computing engine of the I-format CPU
Decode fields to get ORI 8 9 64
32
32
In a Verilog implementation, what should we do
with rs2?
34
Merging data paths ...
two read ports
R-format
How many ?
I-format
Where ?
35
The merged data path ...
ALUctr
36
Load,Store ????? ??????
Write
Read
address
Read
data
Write
address
Data
Write
memory
data
Read
??? ???? ?????? ?- data ???? ???? ????? ????? ???
?? ?? ???? sign extension ?? ?- imm ???? ?? 16bit
37
Loads, Stores, and Data Memory ...
Syntax LW 1, 32(2)
Syntax SW 3, 12(4)
Action 1 M2 32
Action M4 12 3
Zero-extend or sign-extend immediate field?
Writes are clocked If WE is high, memory Addr
captures Din on positive edge of clock.
Note Not a realistic main memory (DRAM) model ...
38
???? ?- CPU?
Instruction Memory
CPU
PC
Data Memory
39
A CPU capable of lw instructions only
4
Adder
6
3126
add
RegWrite1
Reg File
Data Memory
Instruction Memory
PC
ALU
Address
D. Out
5
16
150
Sext 16-gt32
40
A CPU capable of lw instructions only
4
Adder
6
3126
add
RegWrite1
Reg File
Data Memory
Instruction Memory
PC
ALU
Address
D. Out
5
16
150
Sext 16-gt32
41
A CPU capable of lw sw instructions only
4
MeWrite1
Adder
6
3126
add
RegWrite0
Reg File
Data Memory
Instruction Memory
PC
ALU
Address
5
D.In
16
150
Sext 16-gt32
42
A CPU capable of R-type lw instructions
(principle)
4
Adder
6
3126
add
RegWrite
6
50funct
ALU control
Reg File
Data Memory
Instruction Memory
PC
ALU
Address
5
16
150
Sext 16-gt32
43
A CPU capable of R-type lw instructions
4
Adder
6
3126
add
RegWrite
6
50funct
ALU control
Reg File
Data Memory
Instruction Memory
PC
ALU
Address
D. Out
5
Rd
16
150
Sext 16-gt32
44
A CPU capable of R-type lw/sw instructions
4
MemWrite
Adder
6
3126
add
RegWrite
6
50funct
ALU control
Reg File
Data Memory
Instruction Memory
PC
ALU
Address
D. Out
5
Rd
D.In
16
150
Sext 16-gt32
45
Conditional Branches in MIPS ...
Syntax BEQ 1, 2, 12
Action If (1 ! 2), PC PC 4
Action If (1 2), PC PC 4 48
Why is this encoding a good idea?
Zero-extend or sign-extend immediate field?
46
Branch ??????? ?????? ??????
PC4 ???? ?- Fetch
Adder
In addresses, we always shift left by two bits
Sum
Shift
Branch
Read
left
2
Target
register
1
Read
Read
data
1
register
2
Registers
Write
Instruction
Zero
register

?????
ALU
Read
Write
data
2
??????
Data
?????
??????
16
32
Sigh
??????
Extend
??
???????
47
Design Instruction Fetch with Branch
Syntax BEQ 1, 2, 12
Action If (1 ! 2), PC PC 4
Action If (1 2), PC PC 4 48
Instr Mem
PC
32
32
Addr
Data
D
Q
32
Clk
48
????? ?? ???????
M
u
x
Add
4
ADD
Write
PC
Read
Zero
data
1
Instruction
Read
ALU
data
2
Data
memory
Read
16
32
49
What is single cycle control?
ALUctr
Equal
Ext
RegDest
ALUsrc
ExtOp
RegWr
50
???? ????
P
C
S
r
c
M
u
Add
A
d
d
x
ALU result
4
Shift left 2
R
e
g
i
s
t
e
r
s
A
L
U

o
p
e
r
a
t
i
o
n
R
e
a
d
3
M
e
m
W
r
i
t
e
R
e
a
d
r
e
g
i
s
t
e
r

1
A
L
U
S
r
c
P
C
R
e
a
d
a
d
d
r
e
s
s
R
e
a
d
d
a
t
a

1
M
e
m
t
o
R
e
g
r
e
g
i
s
t
e
r

2
Z
e
r
o
I
n
s
t
r
u
c
t
i
o
n
A
L
U
A
L
U
W
r
i
t
e
R
e
a
d
R
e
a
d
A
d
d
r
e
s
s
r
e
g
i
s
t
e
r
r
e
s
u
l
t
d
a
t
a

2
M
d
a
t
a
I
n
s
t
r
u
c
t
i
o
n
M
u
W
r
i
t
e
u
m
e
m
o
r
y
x
D
a
t
a
x
d
a
t
a
m
e
m
o
r
y
W
r
i
t
e
R
e
g
W
r
i
t
e
d
a
t
a
1
6
3
2
S
i
g
n
M
e
m
R
e
a
d
e
x
t
e
n
d
51
Control
A
d
d
S
h
i
f
t
l
e
f
t

2
R
B
r
a
n
c
h
M
e
m
R
e
a
d
M
e
m
t
o
R
e
g
A
L
U
O
p
M
e
m
W
r
i
t
e
R
e
g
W
r
i
t
e
I
n
s
t
r
u
c
t
i
o
n


2
5

2
1

R
e
a
d
P
C
a
d
d
r
e
s
s
I
n
s
t
r
u
c
t
i
o
n


2
0

1
6

Z
e
r
o
r
e
g
i
s
t
e
r

2
I
n
s
t
r
u
c
t
i
o
n
A
L
U
A
L
U

3
1

0

R
e
a
d
r
e
s
u
l
t
1
A
d
d
r
e
s
s
d
a
t
a
I
n
s
t
r
u
c
t
i
o
n
M
M
u
m
e
m
o
r
y
u
I
n
s
t
r
u
c
t
i
o
n


1
5

1
1

x
D
a
t
a
x
1
m
e
m
o
r
y
W
r
i
t
e
d
a
t
a
S
i
g
n
e
x
t
e
n
d
A
L
U
c
o
n
t
r
o
l
I
n
s
t
r
u
c
t
i
o
n


5

0

52
Control
53
ALU control
ALU control output000 AND001 OR010 add110 s
ubtract111 set-on-less-than (sign of rs-rt
-gt rd)
00 lw, sw01 beq, 10 arithmetic
ALUop
54
????? ?- jump
????? ?????? J 101101111011
?????? ???? ????? ?????? 1111110111001
4 bits 26 bits 2 bits
????? ????? ??????
101 101111011
????? ????? ?????
00
101 101111011
0110
101 101111011
????? 4 ????? ???????
00
101 101111011
0110
?????? ??????
55
Jump
S
h
i
f
t
l
e
f
t

2
2
6
2
8
0
M
u
x
1
0
s
u
l
t
A
d
d
S
h
i
f
t
R
e
g
D
s
t
l
e
f
t

2
J
u
m
p
B
r
a
n
c
h
M
e
m
R
e
a
d
I
M
e
m
t
o
R
e
g
A
L
U
O
p
M
e
m
W
r
i
t
e
A
L
U
S
r
c
R
e
g
W
r
i
t
e
I
n
s
t
r
u
c
t
i
o
n


2
5

2
1

R
e
a
d
R
e
a
d
r
e
g
i
s
t
e
r

1
P
C
R
e
a
d
a
d
d
r
e
s
s
d
a
t
a

1
I
n
s
t
r
u
c
t
i
o
n


2
0

1
6

R
e
a
d
Z
e
r
o
r
e
g
i
s
t
e
r

2
I
n
s
t
r
u
c
t
i
o
n
R
e
g
i
s
t
e
r
s
A
L
U
R
e
a
d
A
L
U

3
1

0

R
e
a
d
W
r
i
t
e
d
a
t
a

2
r
e
s
u
l
t
A
d
d
r
e
s
s
d
a
t
a
I
n
s
t
r
u
c
t
i
o
n
r
e
g
i
s
t
e
r
m
e
m
o
r
y
I
n
s
t
r
u
c
t
i
o
n


1
5

1
1

W
r
i
t
e
D
a
t
a
d
a
t
a
m
e
m
o
r
y
W
r
i
t
e
d
a
t
a
I
n
s
t
r
u
c
t
i
o
n


5

0
Write a Comment
User Comments (0)
About PowerShow.com