שלבי ביצוע הוראת מכונה
(1 )FETCH-קרא הוראה מהזיכרון ע"פ הכתובת שמכיל ה = PC.(2 )DECODE פענח את הפקודה וקרא את האוגרים הנחוצים =
)אחד או שניים(.(3 )EXECUTE-בעזרת ה = ALU חשב את התוצאה, או כתובת
רצויה.(4 )MEMORY השתמש בתוצאה לבצע במידת הצורך: או =
(.Load( או קריאה מהזיכרון )Storeטעינה לזיכרון )(5 )WRITE BACK.בצע במידת הצורך טעינה לאוגר =
במשך כל מחזור השעון קוראים בסוף השעון כותבים
cycle time
rising edge
falling edge
קווי הבקרה - מיוצרים על פי השעון, כל עליית שעון תשנה בעקבותיה את קווי הבקרה )אם נדרש(
MIPS תיאור מפושט של מעבד
ALUPCInstruction
Instructionmemory
#register
Registers
Data
#register
#register
address
Datamemory
Data
I-type ו- R-typeהחיבורים המתוארים תומכים בכל שלבי פקודות add, sub, or, xor, and, slt, lw, sw, beq, jאנו נתמוך בפקודות:
bne, addi, jal, jrכמובן שנצטרך לדעת כיצד מוסיפים פקודות נוספות כמו למשל:
PCInstruction
memory
4
Registers
Mux
Mux
Mux
ALU
EX
M
WB
M
WB
WB
ID/EX
0
EX/MEM
MEM/WB
Datamemory
Mux
Hazarddetection
unit
Forwardingunit
IF.Flush
IF/ID
Signextend
Control
Mux
=
Shiftleft 2
Mux
עוד שלושה שבועות
:fetchחלקים בסיסים של המחשב הדרושים לשלב ה-
InstructionAddress
Instruction
InstructionMemory
PC
Write
Add
Sum
כמובן שדרוש זיכרון פקודות , רגיסטר לשמירת הכתובת לחשוב הכתובת הבאהadderוכן
FETCH -שלב ה
Add
PC Readaddress
Instruction
Instructionmemory
4
A CPU capable of R-type instructions only
5[25:21]=Rs
5[20:16]=Rt
5[15:11]=Rd
InstructionMemoryPC
Adder4
ck
6[31:26]
6[5:0]=funct
decodeיחידת הרגיסטרים. יחידה זו דרושה לשלב ה-(write back)ולשלב ה-
Readregister 1
Registers
Readregister 2
Write register
WriteData
Readdata 1
Readdata 2
מספרי האוגרים
Data
Arithmetic Logic operation
Readregister 1
Registers
Readregister 2
Write register
WriteData
Read
data 1
Readdata 2
ALU
Zero
ALU operation
ALUresult
Instruction
ALU
ALU
result
ALU operation
R-typeהפעולה הבסיסית שנדגים הנה פקודת
A CPU capable of R-type instructions only
5[25:21]=Rs
5[20:16]=Rt
5[15:11]=Rd
Reg File
InstructionMemoryPC ALU
Adder4
ck
ck
6[31:26]
6[5:0]=funct
A CPU capable of R-type instructions only
5[25:21]=Rs
5[20:16]=Rt
5[15:11]=Rd
Reg File
InstructionMemoryPC ALU
Adder4
ck
ck
6[31:26]
6[5:0]=funct
The internal structure of the Register File
32
32
3232
32
32
32
32
32
32
32
Read data 2
write data
Read data 1
5
5
5
Rd reg 2 )= Rt(
Rd reg 1 )= Rs(
RegWrite
Wr reg )= Rd( 32
32
E
קוראים משתי היציאות בוזמנית ערכים של שני רגיסטרים שוניםכותבים לאחד הרגיסטרים האחרים )בעליית השעון הבאה(
A CPU capable of R-type instructions only
5[25:21]=Rs
5[20:16]=Rt
5[15:11]=Rd
Reg File
InstructionMemoryPC ALU
Adder4
ck
ck
6[31:26]
RegWrite
A CPU capable of R-type instructions only
5[25:21]=Rs
5[20:16]=Rt
5[15:11]=Rd
Reg File
InstructionMemory
PC ALU
ck
ck
A CPU capable of R-type instructions only
5[25:21]=Rs
5[20:16]=Rt
5[15:11]=Rd
Reg FileInstructionMemory
PCALU
ck
ck
4
A CPU capable of R-type instructions only
5[25:21]=Rs
5[20:16]=Rt
5[15:11]=Rd
Reg File
InstructionMemoryPC ALU
Adder4
ck
ck
6[31:26]
RegWrite
6[5:0]=funct ALUcontrol
Load,Store בניית פעולות
Readaddress
Datamemory
Writeaddress
Writedata
Readdata
Write
Read
Signextend
16 32
ממנו נקרא ואליו נכתובdataכאן נדרש זיכרון ל- 16bit שהוא רק imm של ה- sign extensionכמו כן יש לבצע
A CPU capable of lw instructions only
5[25:21]=Rs
5[20:16]=Rt
Reg File
InstructionMemoryPC ALU
Adder4
ck
ck
6[31:26]
RegWrite=1
16[15:0]
5
add
Sext16->32
DataMemory
AddressD. Out
A CPU capable of lw instructions only
5[25:21]=Rs
5[20:16]=Rt
Reg File
InstructionMemoryPC ALU
Adder4
ck
ck
6[31:26]
RegWrite=1
16[15:0]
5
add
Sext16->32
DataMemory
AddressD. Out
A CPU capable of lw instructions only
5[25:21]=Rs
5[20:16]=Rt
Reg File
InstructionMemoryPC ALU
Adder4
ck
ck
6[31:26]
RegWrite=1
16[15:0]
5
add
Sext16->32
DataMemory
AddressD. Out
A CPU capable of lw & sw instructions only
5[25:21]=Rs
5[20:16]=Rt
Reg File
InstructionMemoryPC ALU
Adder4
ck
ck
6[31:26]
RegWrite=0
16[15:0]
5
add
Sext16->32
DataMemory
D.In
Address
MeWrite=1
A CPU capable of R-type & lw instructions )principle(
5[25:21]=Rs
5[20:16]=Rt
Reg File
InstructionMemoryPC ALU
Adder4
ck
ck
6[31:26]
RegWrite
16[15:0]
5
add
Sext16->32
DataMemory
5[25:21]=Rs
6[5:0]=funct ALUcontrol
5[15:11]=Rd
Address
A CPU capable of R-type & lw instructions
5[25:21]=Rs
5[20:16]=Rt
Reg File
InstructionMemoryPC ALU
Adder4
ck
ck
6[31:26]
RegWrite
16[15:0]
5
add
Sext16->32
DataMemory
5[25:21]=Rs
6[5:0]=funct ALUcontrol
Rd
AddressD. Out
A CPU capable of R-type & lw/sw instructions
5[25:21]=Rs
5[20:16]=Rt
Reg File
InstructionMemoryPC ALU
Adder4
ck
ck
6[31:26]
RegWrite
16[15:0]
5
add
Sext16->32
DataMemory
5[25:21]=Rs
6[5:0]=funct ALUcontrol
Rd
Address
D.In
D. Out
MemWrite
:Branch אלמנטים דרושים להוספת
ALU
Zero
Readregister 1
Registers
Readregister 2
Write register
WriteData
Readdata 1
Readdata 2
Instruction
AdderSum
Shiftleft 2
SighExtend
BranchTarget
מועברליחידתהבקרהכתוצאההלוגית
שלההשוואה
16 32
PC+4 -משלב הFetchIn addresses, we always shift left by two bits
שילוב כל הפקודות
Readregister 1
Registers
Readregister 2
Write register
WriteData
Readdata 1
Readdata 2
Zero
ALU
ALUresult
Data
Signextend 32
Readaddress
memory
Writeaddress
Writedata
Readdata
Write
Read
16
Add4
PC
Mux
Readaddress
Instruction
Instructionmemory
ADD
ALUresult
Shiftleft 2
Mux
Mux
?CPUאיפה ה-
CPU
InstructionMemory
DataMemory
PC
קווי בקרה
PC
Instructionmemory
Readaddress
Instruction
16 32
AddMux
Registers
Writeregister
Writedata
Readdata 1
Readdata 2
Readregister 1Readregister 2
4
Mux
ALU operation3
RegWrite
MemRead
MemWrite
PCSrc
ALUSrc
MemtoReg
ALUresult
ZeroALU
Datamemory
Address
Writedata
Readdata M
ux
Signextend
AddALU
resultShiftleft 2
Control
PC
Instructionmemory
Readaddress
Instruction]31– 0[
Instruction ]20– 16[
Instruction ]25– 21[
Add
Instruction ]5– 0[
MemtoReg
ALUOp
MemWrite
RegWrite
MemRead
BranchRegDst
ALUSrc
Instruction ]31– 26[
4
16 32Instruction ]15– 0[
0
0Mux
0
1
Control
Add ALUresult
Mux
0
1
RegistersWriteregister
Writedata
Readdata 1
Readdata 2
Readregister 1
Readregister 2
Signextend
Shiftleft 2
Mux
1
ALUresult
Zero
Datamemory
Writedata
Readdata
Mux
1
Instruction ]15– 11[
ALUcontrol
ALUAddress
Instruction RegDst ALUSrcMemto-
RegReg
WriteMem Read
Mem Write Branch ALUOp1 ALUp0
R-format 1 0 0 1 0 0 0 1 0lw 0 1 1 1 1 0 0 0 0sw X 1 X 0 0 1 0 0 0beq X 0 X 0 0 0 1 0 1
R-format Iw sw beq
Op0
Op1
Op2
Op3
Op4
Op5
Inputs
Outputs
RegDst
ALUSrc
MemtoReg
RegWrite
MemRead
MemWrite
Branch
ALUOp1
ALUOpO
Control
ALU control
ALUOp Funct field OperationALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0
0 0 X X X X X X 0100 1 X X X X X X 1101 0 X X 0 0 0 0 0101 0 X X 0 0 1 0 1101 0 X X 0 1 0 0 0001 0 X X 0 1 0 1 0011 0 X X 1 0 1 0 111
ALU control output000 AND001 OR010 add110 subtract111 set-on-less-than
(sign of rs-rt -> rd)
00 = lw, sw01 = beq, 10 = arithmetic
ALUop
Operation2
Operation1
Operation0
Operation
ALUOp1
F3
F2
F1
F0
F (5– 0)
ALUOp0
ALUOp
ALU control block
jumpפקודת ה-
4 bits 26 bits 2 bits
00
כתובת קפיצה במילים :
כתובת קפיצה בבתים :
0110
101 … 101111011
101 … 101111011
101 … 101111011
00 101 … 1011110110110 הקפיצה הסופית :
ביטים אחרונים4תוספת :
J 101…101111011 פירוש הפקודה:
1001…111111011 הפקודה הבאה נמצאת בכתובת
Jump
Shiftleft 2
PC
Instructionmemory
Readaddress
Instruction]31– 0[
Datamemory
Readdata
Writedata
RegistersWriteregister
Writedata
Readdata 1
Readdata 2
Readregister 1
Readregister 2
Instruction ]15– 11[
Instruction ]20– 16[
Instruction ]25– 21[
Add
ALUresult
Zero
Instruction ]5– 0[
MemtoReg
ALUOp
MemWrite
RegWrite
MemRead
Branch
JumpRegDst
ALUSrc
I nstruction ]31– 26[
4
Mux
Instruction ]25– 0[ Jump address ]31– 0[
PC+4 ]31– 28[
Signextend
16 32Instruction ]15– 0[
1
Mux
1
0
Mux
0
1
Mux
0
1
ALUcontrol
Contr ol
Add ALUresult
Mux
0
1 0
ALU
Shiftleft 2
26 28
Address