33
הההה ההההה ההההה ההההה( 1 ) FETCH = תתת תתתתת תתתתתתתת ת"ת תתתתתת- תתתתת תPC . ( 2 ) DECODE = תתתת תת תתתתתת תתתת תת תתתתתתת.)תתת תת תתתתת( תתתתתתת( 3 ) EXECUTE - = תתתתת תALU תתת תת תתתתתת, תת תתתתת תתתתת.( 4 ) MEMORY = תתתתת תתתתתת תתתת תתתתת תתתתת: תת( תתתתת תתתתתתתStore תתתתתתתת תת תתתתת) ( Load .) ( 5 ) WRITE BACK = תתת תתתתת תתתתת תתתתת תתתתת.

שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

  • View
    233

  • Download
    4

Embed Size (px)

Citation preview

Page 1: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

שלבי ביצוע הוראת מכונה

(1 )FETCH-קרא הוראה מהזיכרון ע"פ הכתובת שמכיל ה = PC.(2 )DECODE פענח את הפקודה וקרא את האוגרים הנחוצים =

)אחד או שניים(.(3 )EXECUTE-בעזרת ה = ALU חשב את התוצאה, או כתובת

רצויה.(4 )MEMORY השתמש בתוצאה לבצע במידת הצורך: או =

(.Load( או קריאה מהזיכרון )Storeטעינה לזיכרון )(5 )WRITE BACK.בצע במידת הצורך טעינה לאוגר =

Page 2: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

במשך כל מחזור השעון קוראים בסוף השעון כותבים

cycle time

rising edge

falling edge

קווי הבקרה - מיוצרים על פי השעון, כל עליית שעון תשנה בעקבותיה את קווי הבקרה )אם נדרש(

Page 3: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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כמובן שנצטרך לדעת כיצד מוסיפים פקודות נוספות כמו למשל:

Page 4: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

עוד שלושה שבועות

Page 5: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

:fetchחלקים בסיסים של המחשב הדרושים לשלב ה-

InstructionAddress

Instruction

InstructionMemory

PC

Write

Add

Sum

כמובן שדרוש זיכרון פקודות , רגיסטר לשמירת הכתובת לחשוב הכתובת הבאהadderוכן

Page 6: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

FETCH -שלב ה

Add

PC Readaddress

Instruction

Instructionmemory

4

Page 7: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 8: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

decodeיחידת הרגיסטרים. יחידה זו דרושה לשלב ה-(write back)ולשלב ה-

Readregister 1

Registers

Readregister 2

Write register

WriteData

Readdata 1

Readdata 2

מספרי האוגרים

Data

Page 9: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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הפעולה הבסיסית שנדגים הנה פקודת

Page 10: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 11: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 12: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

קוראים משתי היציאות בוזמנית ערכים של שני רגיסטרים שוניםכותבים לאחד הרגיסטרים האחרים )בעליית השעון הבאה(

Page 13: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 14: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 15: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 16: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 17: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

Load,Store בניית פעולות

Readaddress

Datamemory

Writeaddress

Writedata

Readdata

Write

Read

Signextend

16 32

ממנו נקרא ואליו נכתובdataכאן נדרש זיכרון ל- 16bit שהוא רק imm של ה- sign extensionכמו כן יש לבצע

Page 18: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 19: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 20: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 21: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 22: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 23: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 24: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 25: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

: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

Page 26: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

שילוב כל הפקודות

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

Page 27: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

?CPUאיפה ה-

CPU

InstructionMemory

DataMemory

PC

Page 28: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

קווי בקרה

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

Page 29: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 30: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 31: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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

Page 32: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

jumpפקודת ה-

4 bits 26 bits 2 bits

00

כתובת קפיצה במילים :

כתובת קפיצה בבתים :

0110

101 … 101111011

101 … 101111011

101 … 101111011

00 101 … 1011110110110 הקפיצה הסופית :

ביטים אחרונים4תוספת :

J 101…101111011 פירוש הפקודה:

1001…111111011 הפקודה הבאה נמצאת בכתובת

Page 33: שלבי ביצוע הוראת מכונה (1) FETCH = קרא הוראה מהזיכרון ע " פ הכתובת שמכיל ה -PC. (2) DECODE = פענח את הפקודה וקרא את

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