Download presentation
Presentation is loading. Please wait.
1
Tutorial #10 MIPS commands
234262 Tutorial #10 MIPS commands – © Yohai Devir 2007 Technion - IIT
2
MIPS overview MIPS is a simple processor:
All arithmetic operations are done with registers only. Memory access is done with only two instructions – LW\ SW. The MIPS is a 32-bit machine. The instructions are 32-bits long. Register file (RF), with 32 registers of 32 bits each (5 bit for the number) Memory address size – 32 bits. We’ll work in resolution of words – 32 bit each. – © Yohai Devir 2007 Technion - IIT
3
Registers There are registers which are denoted by R0, R1,…R31.
Register 0 is read-only and its value is 0 (R0 ≡ 0). The PC (Program Counter) is a special register. The PC points to the next instruction to be executed. In some places register K is marked as $K (i.e. R8 ≡ $8) – © Yohai Devir 2007 Technion - IIT
4
Memory (maximal) size 230 words of 32 bits each.
Each word has a 32-bit address, the two LSB bits of the address are ’00’. Memory can be accessed by LW or SW commands only. – © Yohai Devir 2007 Technion - IIT
5
Instructions 3 types of instructions, each kind with a fixed structure: Type R (Register) Type I (Immediate) Type J (Jump) – © Yohai Devir 2007 Technion - IIT
6
Tutorial #11 Multicycle MIPS
234262 Tutorial #11 Multicycle MIPS – © Yohai Devir 2007 Technion - IIT
7
MIPS - מבנה כללי MEM 234262 – © Yohai Devir 2007 Technion - IIT
5 IR[d] 5 IR[t] 5 IR[s] 4 NREG1 WDATA 5 Rs Rt 6 IR[OP+FUN] NREG2 IR[IM] WNREG ZERO REG FILE 4 SIGN EXT C1 C3 WR I T E 6 IR[OP] ALUout B P C 1 2 IR[XI] PC[31:28] C2 R E A D ADDR MEMout MEM A L U – © Yohai Devir 2007 Technion - IIT
8
הבקר 234262 – © Yohai Devir 2007 Technion - IIT C1 6 IR[OP]
R E A D WR I T E WR I T E IR[OP] IR[OP+FUN] C3 C2 ZERO B P C ZERO M 5 M 1 P C M 2 A L U MEM REG FILE I R M 6 M 3 M 4 – © Yohai Devir 2007 Technion - IIT
9
ALU C3 ZERO A L U ALUout – © Yohai Devir 2007 Technion - IIT
10
יחידת ה- MEMORY MEM 234262 – © Yohai Devir 2007 Technion - IIT
R E A D WR I T E ADDR MEMout MEM WDATA – © Yohai Devir 2007 Technion - IIT
11
יחידת ה- RF 234262 – © Yohai Devir 2007 Technion - IIT WDATA WNREG
WR I T E WDATA WNREG NREG1 NREG2 Rs Rt 31*32 WRITE NREG1 REG FILE Rs NREG2 Rt WNREG WDATA – © Yohai Devir 2007 Technion - IIT
12
234262 – © Dima Elenbogen 2010 Technion - IIT
מבנה ה- RF Rs R31 R1 Nreg1 נתב כתיבה נתב קריאה #1 נתב קריאה #2 Nreg2 WNreg WData WRITE Rt הערה: הנתבים צירופיים!
13
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
לכל הפקודות – שלב fetch IR ← Mem[PC] PC ← PC + 4 M 5 M 1 A L U P C M 2 ADDR MEMout MEM WDATA ALUout I R M 6 4 ALUout
14
Type I OP Rs Rt IM OPeration Source \ Target Registers IMmediate 6 bit
– © Yohai Devir 2007 Technion - IIT
15
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
BNE R31,R8,loop1 OP Rs Rt IM 4 31 8 ? 6 bit 5 bit 16 bit Branch on Not Equal Semantic: if R31≠R8, the next instruction to be executed is the on which is stored in the memory at label ‘loop1’ BEQ branches if EQual
16
BNE PCnew (BNEaddr +4) (BNEaddr ) + IM x 4
We want to branch to address 00… However, this a 32bit address while having only 16bit of IM. Most branches are to “nearby” addresses. We can put address relative to the PC. 2 LSB bits are ’00 (Why?) No need to specify the 2 LSBs. We’ll see this later: After bringing the intruction (before really reading it) the PC is incremented in 4 bytes. PCnew (BNEaddr +4) (BNEaddr ) + IM x 4 – © Yohai Devir 2007 Technion - IIT
17
לכל הפקודות – שלב decode
– © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT לכל הפקודות – שלב decode C1 is decoding IR[OP] Rs is being read Rt is being read BPC ← PC + SX(Imm)*4 C1 6 IR[OP] B P C ALUout M 5 6 A L U 5 IR[s] Rs NREG1 REG FILE 5 IR[t] NREG2 Rt ALUout I R IR[IM] 4 SIGN EXT
18
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
Type R OP Rs Rt Rd shamt func 6 bit 5 bit OPeration Source \ Target \ Destination Register SHift AMounT FUNCtion Rs מיועד לקריאה בלבד Rt מיועד לקריאה ולכתיבה (לכתיבה בחלק של פקודות מסוג I) Rd מיועד לכתיבה בלבד ומופיע בפקודות מסוג R בלבד
19
ADD R11,R22,R31 22 31 11 32 OP Rs Rt Rd shamt func
22 31 11 32 6 bit 5 bit Semantic: R11 R22 + R31 OP Rs Rt Rd shamt func 6 bit 5 bit OP Rs Rt Rd shamt func 000000 10110 11111 01011 00000 100000 6 bit 5 bit – © Yohai Devir 2007 Technion - IIT
20
פקודה מסוג R – add R11,R22,R31 MEM A L U 5 IR[s] NREG1 REG FILE Rs
P C M 2 ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] NREG2 I R Rt M 6 M 3 WNREG 5 IR[d] 4 M 4 WDATA ALUout – © Yohai Devir 2007 Technion - IIT
21
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
פקודה מסוג R – add R11,R22,R31 Fetch Decode 3- EX) ALUout <= Rs + Rt 4-WB) Rd ← ALUout IR[OP+FUN] C3 M 5 M 1 A L U P C M 2 ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] NREG2 I R M 3 Rt M 6 WNREG 5 IR[d] 4 M 4 WDATA ALUout
22
פקודה מסוג I – addi R11,R22,-12 8 22 11 -12 MEM OP Rs Rt IM 6 bit
5 M 1 P C M 2 A L U ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] I R M 6 M 3 WNREG 4 M 4 WDATA SIGN EXT IR[IM] ALUout – © Yohai Devir 2007 Technion - IIT
23
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
פקודה מסוג I – addi R11,R22,-12 Fetch Decode 3- EX) ALUout <= Rs + SX(Imm) 4-WB) Rt ← ALUout M 5 M 1 P C M 2 A L U ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] I R M 6 M 3 WNREG 4 M 4 WDATA SIGN EXT IR[IM] ALUout
24
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
פקודת BEQ – BEQ R11,R22,loop Fetch Decode 3- EX) if (zero) PC ← BPC C2 ZERO B P C ZERO M 5 M 1 P C M 2 A L U ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] NREG2 I R Rt M 6 4 SIGN EXT IR[IM] 4 ALUout
25
הבקר 234262 – © Yohai Devir 2007 Technion - IIT C1 6 IR[OP]
R E A D WR I T E WR I T E IR[OP] IR[OP+FUN] C3 C2 ZERO B P C ZERO M 5 M 1 P C M 2 A L U MEM REG FILE I R M 6 M 3 M 4 – © Yohai Devir 2007 Technion - IIT
26
LW R23,300(R3) OP Rs Rt IM 35 3 23 300 6 bit 5 bit 16 bit Load Word Semantic: Read the word located in the memory address of [R3] (not 303 !!!) and write it to R23 NOTE: Rs is the Base register Rt is the register to write to. – © Yohai Devir 2007 Technion - IIT
27
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
פקודה LW – LW R23, 300(R3) Fetch Decode 3- EX) ALUout <= Rs + SX(Imm) 4-MEM) MEMout <= Mem[ALUout] 5-WB) Rt ← MEMout M 5 M 1 P C M 2 A L U ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] I R Rt M 6 M 3 WNREG 4 M 4 WDATA SIGN EXT IR[IM] ALUout
28
SW R7,200(R6) OP Rs Rt IM 43 6 7 200 6 bit 5 bit 16 bit Load Word Semantic: Writes the word located in R7 to the memory address of [R6] (not 206!!!) NOTE: Rs is the Base register Rt is the read from. – © Yohai Devir 2007 Technion - IIT
29
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
פקודה SW – SW R7, 200(R6) Fetch Decode 3- EX) ALUout <= Rs + SX(Imm) 4-MEM) Mem[ALUout] ← Rt M 5 M 1 P C M 2 A L U ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] NREG2 I R Rt M 6 4 SIGN EXT IR[IM] ALUout
30
Type J OP XI OPeration eXtended Immediate Unconditional jumps
6 bit 26 bits OPeration eXtended Immediate Unconditional jumps 2 LSBs are ’00’. No need to specify them. 4 MSBs are taken from PC – © Yohai Devir 2007 Technion - IIT
31
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
J 0xCF OP XI 2 0x03D1 1111 6 bit 26 bits Assume that there is a J instruction in the following address : 0xCE125678: J 0xCF It jumps to a specific address. Semantic: PCnew PC[upper 4 MSBs] || XI || 00
32
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
פקודת J – J 0xCF C1 6 IR[OP] M 1 P C M 2 ADDR MEMout MEM WDATA I R 4 PC[31:28] Fetch Decode 3- EX) PC ← PC[31:28] || XI*4 2 IR[XI] ב-EX ה-ALU לא בשימוש, אך עדיין עליו לבצע איזשהו חישוב סרק על מנת למנוע אות סטטוס zero מזוהם. למשל, ALUout <= PC + 4
33
FETCH IR (PC)MEM PC PC+4 DECODE REG2 Rt ;REG1 Rs
BPC PC + 4 SX(IM ) OP = ’LW’ or ‘SW’ I מסוג OP R מסוג OP OP= ’BEQ’ ALUout Rs + SX(IM) ALUout f (Rs, SX(IM)) f מצוין ב- IR[OP] ALUout f (Rs, Rt) f מצוין ב- IR[FUN] ALUout Rs Rt IF(Rs=Rt) PC BPC OP= ’SW’ OP= ‘LW’ FETCH (כתיבה בזיכרון) MEM(ALUout) Rt (קריאה) MEMout MEM(ALUout) Rt ALUout Rd ALUout OP= ’J’ PC[27:0] 4 XI FETCH FETCH FETCH Rt MEMout FETCH FETCH – © Yohai Devir 2007 Technion - IIT
34
MIPS - מבנה כללי MEM 234262 – © Yohai Devir 2007 Technion - IIT C1
R E A D WR I T E WR I T E 6 IR[OP] IR[OP+FUN] C3 C2 ZERO B P C ZERO M 5 M 1 P C M 2 A L U ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] NREG2 I R M 3 Rt M 6 WNREG 4 5 IR[d] 4 M 4 PC[31:28] WDATA 2 SIGN EXT IR[XI] IR[IM] 4 ALUout – © Yohai Devir 2007 Technion - IIT
35
לא כל הבוררים מוכרחים להיות אדישים!
– © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT לא כל הבוררים מוכרחים להיות אדישים! בפועל כל ה-MUX-ים במעבד הם אדישים. אבל לא כולם מוכרחים להיות כאלה: אדום – חייב להיות אדיש סגול – תלוי במימוש של הזיכרון (האם הפלט לוגי כשלא קוראים ולא כותבים) ירוק – רשאי להיות לא אדיש M 5 M 1 M 2 M 6 M 3 M 4 אותות בקרה לבוררים האדומים חייבים להגיע ישירות מתוך FF-ים חסרי ספחות סטטיות של הבקר!
36
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
אדישות הבוררים C1 R E A D WR I T E WR I T E 6 IR[OP] IR[OP+FUN] C3 C2 ZERO B P C ZERO M 5 M 1 P C M 2 A L U ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] NREG2 I R Rt M 6 M 3 WNREG 4 5 IR[d] 4 M 4 PC[31:28] WDATA 2 SIGN EXT IR[XI] IR[IM] 4 ALUout אותות בקרה לבוררים האדומים חייבים להגיע ישירות מתוך FF-ים חסרי ספחות סטטיות של הבקר!
37
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
JAL 0xEF OP XI 3 0x03D1 1111 6 bit 26 bits Jump And Link Assume that there is a JAL instruction in the following address : 0xEE125678: JAL 0xEF Stores PC in Register 31 and then jumps to given address. Semantic: R31 PC PC PC[upper 4 MSBs] || XI || 00
38
JAL – פיתרון פשוט אם כי יקר
– © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT JAL – פיתרון פשוט אם כי יקר C1 R E A D WR I T E WR I T E 6 IR[OP] IR[OP+FUN] C3 C2 ZERO B P C ZERO M 5 M 1 P C M 2 A L U ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] NREG2 Rt I R M 6 M 3 31 WNREG 4 5 4 5 IR[d] M 4 PC[31:28] WDATA 2 32 SIGN EXT IR[XI] IR[IM] 4 ALUout
39
JAL – פיתרון פשוט אם כי יקר
– © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT JAL – פיתרון פשוט אם כי יקר Fetch Decode 3- EX) R31 ← PC PC ← PC[31:28] || XI*4 I R M 3 5 IR[d] 5 IR[t] 5 IR[s] 4 NREG1 WDATA 5 Rs Rt 6 IR[OP+FUN] NREG2 IR[IM] WNREG ZERO REG FILE 4 SIGN EXT C1 C3 WR I T E 6 IR[OP] ALUout B P C 1 2 IR[XI] PC[31:28] C2 R E A D ADDR MEMout MEM A L U 31 32
40
JAL – פיתרון זול אם כי מתוחכם
– © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT הרעיון: ננצל מסלול צירופי מ-PC ל-M4 העובר דרך ALU. כלומר, נבצע: R31 ← PC + 0 בעיה: ערך 0 היינו יכולים לקרוא מ-R0 אבל אין בקידוד הפקודה קבוע 0 ולכן לא נוכל לקרוא את R0 (אלא אם נוסיף MUX לפני Nreg1). פיתרון: נשתמש בזהות: PC + 0 ≡ PC + 4 – 4 I R M 3 5 IR[d] 5 IR[t] 5 IR[s] 4 NREG1 WDATA 5 Rs Rt 6 IR[OP+FUN] NREG2 IR[IM] WNREG ZERO REG FILE 4 SIGN EXT C1 C3 WR I T E 6 IR[OP] ALUout B P C 1 2 IR[XI] PC[31:28] C2 R E A D ADDR MEMout MEM A L U 31
41
JAL – פיתרון זול אם כי מתוחכם
– © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT Fetch // PC ← α + 4, Decode 3- EX1) PC ← PC // PC ← α + 8 4- EX2) ALUout <= PC – 4 // ALUout <= α + 4 5- WB) R31 ← ALUout // R31 ← α + 4 PC ← PC[31:28] || XI*4 // J כמו // α is the address of the current (JAL) command I R M 3 5 IR[d] 5 IR[t] 5 IR[s] 4 NREG1 WDATA 5 Rs Rt 6 IR[OP+FUN] NREG2 IR[IM] WNREG ZERO REG FILE 4 SIGN EXT C1 C3 WR I T E 6 IR[OP] ALUout B P C 1 2 IR[XI] PC[31:28] C2 R E A D ADDR MEMout MEM A L U 31
42
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
Pre-fetch C1 R E A D WR I T E WR I T E 6 IR[OP] IR[OP+FUN] C3 C2 ZERO B P C ZERO M 5 M 1 P C M 2 A L U ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs 5 IR[t] NREG2 Rt I R M 6 M 3 WNREG 4 5 IR[d] 4 M 4 PC[31:28] WDATA 2 SIGN EXT IR[XI] IR[IM] 4 ALUout
43
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
תיזכורת: שלב fetch IR ← Mem[PC] PC ← PC + 4 M 5 M 1 A L U P C M 2 ADDR MEMout MEM WDATA ALUout I R M 6 4 ALUout
44
לדוגמא: pre-fetch בסיום של add R11,R22,R31
– © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT לדוגמא: pre-fetch בסיום של add R11,R22,R31 3- EX) ALUout <= Rs + Rt 4-WB) Rd ← ALUout IR[OP+FUN] C3 M 5 A L U 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] NREG2 Rt I R M 6 M 3 WNREG 5 IR[d] M 4 WDATA
45
לדוגמא: pre-fetch בסיום של add R11,R22,R31
– © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT לדוגמא: pre-fetch בסיום של add R11,R22,R31 IR ← Mem[PC] PC ← PC + 4 3- EX) ALUout <= Rs + Rt 4-WB) Rd ← ALUout כנגד IR[OP+FUN] C3 M 5 M 1 A L U P C M 2 ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] NREG2 Rt I R M 6 M 3 WNREG 5 IR[d] 4 M 4 WDATA ALUout
46
לדוגמא: pre-fetch בסיום של add R11,R22,R31
– © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT לדוגמא: pre-fetch בסיום של add R11,R22,R31 3- EX) RWD ←Rs + Rt 4-WB) Rd ← RWD IR ← Mem[PC] PC ← PC + 4 add pre-fetch IR[OP+FUN] C3 M 5 M 1 A L U P C M 2 ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] NREG2 Rt I R M 6 M 3 WNREG 5 IR[d] 4 M 4 RWD WDATA ALUout
47
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
Prefetch שימו לב כי pre-fetching לא מתרחש תוך כדי ביצוע פקודות: קפיצה והסתעפות SW C1 R E A D WR I T E WR I T E 6 IR[OP] IR[OP+FUN] C3 C2 ZERO B P C ZERO M 5 M 1 P C M 2 A L U ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs 5 IR[t] NREG2 Rt I R M 6 M 3 WNREG 4 5 IR[d] 4 M 4 PC[31:28] WDATA RWD 2 SIGN EXT IR[XI] IR[IM] 4 ALUout
48
234262 – © Yohai Devir 2007 Dima Elenbogen 2010 Technion - IIT
FETCH IR (PC)MEM PC PC+4 DECODE REG2 Rt ;REG1 Rs BPC PC + 4 SX(IM ) OP = ’LW’ or ‘SW’ I מסוג OP R מסוג OP OP= ’BEQ’ ALUout Rs + SX(IM) RWD ← f (Rs, SX(IM)) f מצוין ב- IR[OP] RWD ← f (Rs, Rt) f מצוין ב- IR[FUN] ALUout Rs Rt IF(Rs=Rt) PC BPC OP= ’SW’ OP= ‘LW’ FETCH (כתיבה בזיכרון) MEM(ALUout) Rt (קריאה) RWD ← MEM(ALUout) Rt RWD IR ← MEM(PC) PC ← PC + 4 Rd RWD IR ← MEM(PC) PC ← PC + 4 OP= ’J’ PC[27:0] 4 XI FETCH DECODE DECODE FETCH שימו לב כי pre-fetching לא מתרחש תוך כדי ביצוע פקודות: קפיצה והסתעפות SW
49
Prefetch – מימוש תוך ניצול BPC
– © Yohai Devir 2007 Dima Elenbogen 2011 Technion - IIT C1 R E A D WR I T E WR I T E 6 IR[OP] IR[OP+FUN] C3 M 7 C2 ZERO B P C ZERO M 5 M 1 P C M 2 A L U ADDR MEMout MEM WDATA 5 IR[s] NREG1 REG FILE Rs ALUout 5 IR[t] NREG2 I R Rt M 6 M 3 WNREG 4 5 IR[d] 4 PC[31:28] WDATA SIGN EXT 2 IR[XI] IR[IM] 4 ALUout החל במחזור 3 הבקר יודע האם ניתן לשכוח את הכתובת השמורה ב-BPC. ניתן לוותר בכלל על בורר M4 מכיוון ש-Wdata מקבל את כל ערכיו מ-BPC. עלות השינויים: 0! הסבנו את BPC כך שימלא גם את תפקידו של RWD.
50
אני מאחל הצלחה בבחינות ושתעברו אותן בקלות!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.