50
1 / 52 ןןןן ןןןןן ןןןן ןןןןןןן?? ןןןן ןןןןןןµProc 60%/yr. (2X/ 1.5yr) DRAM 9%/yr. (2X/10 yrs) 1 10 100 1000 198 0 198 1 198 3 198 4 198 5 198 6 198 7 198 8 198 9 199 0 199 1 199 2 199 3 199 4 199 5 199 6 199 7 199 8 199 9 200 0 DRAM CPU 198 2 Processor-Memory Performance Gap: (grows 50% / year) Performance Time “Moore’s Law” 34-bit A LU LO register (16x2 b its) LoadH I ClearHI LoadLO M u ltiplicand R egiste r S hiftA ll LoadM p Extra 2 bits 32 32 LO [1:0] R esult[H I] R esult[LO ] 32 32 Prev LO [1] Booth Encoder E N C [0] E N C [2] "LO[ 0] " C on trol Logic Input M ultiplier 32 S u b/A d d 2 34 34 32 In pu t M u ltiplicand 32=>34 signE x 34 34x2 MUX 32=>34 signE x <<1 34 E N C [1] M ulti x2/x1 2 2 H I register (16x2 b its) 2 0 1 34 Arithmetic Single/multicycle Datapaths IFetch Dcd Exec Mem WB IFetch Dcd Exec Mem WB IFetch Dcd Exec Mem WB IFetch Dcd Exec Mem WB Pipelining Memory Systems I/O

איפה אנחנו ולאן ממשיכים ??

  • Upload
    hedva

  • View
    61

  • Download
    0

Embed Size (px)

DESCRIPTION

Arithmetic. Single/multicycle Datapaths. IFetch. Dcd. Exec. Mem. WB. µProc 60%/yr. (2X/1.5yr). 1000. CPU. IFetch. Dcd. Exec. Mem. WB. “Moore’s Law”. IFetch. Dcd. Exec. Mem. WB. 100. Processor-Memory Performance Gap: (grows 50% / year). IFetch. Dcd. Exec. Mem. WB. 10. - PowerPoint PPT Presentation

Citation preview

Page 1: איפה אנחנו ולאן ממשיכים ??

1 / 52

??איפה אנחנו ולאן ממשיכים

מבנהמחשבים

µProc60%/yr.(2X/1.5yr)

DRAM9%/yr.(2X/10 yrs)

1

10

100

1000

19

80 1

98

1 19

83 1

98

4 19

85 1

98

6 19

87 1

98

8 19

89 1

99

0 19

91 1

99

2 19

93 1

99

4 19

95 1

99

6 19

97 1

99

8 19

99 2

00

0

DRAM

CPU

19

82

Processor-MemoryPerformance Gap:(grows 50% / year)

Per

form

ance

Time

“Moore’s Law”

34-b it A LU

LO register(16x2 bits)

Load

HI

Cle

arH

I

Load

LO

M ultiplicandRegister

S h iftA ll

LoadM p

Extra

2 bits

3 232

LO [1 :0 ]

Result[H I] Result[LO]

32 32

Prev

LO[1]

Booth

Encoder E N C [0 ]

E N C [2 ]

"LO

[0]"

Con trolLog ic

InputM ultiplier

32

S ub /A dd

2

34

34

32

InputM ultiplicand

32=>34sig nEx

34

34x2 M U X

32=>34sig nEx

<<13 4

E N C [1 ]

M ulti x2 /x1

2

2HI register(16x2 bits)

2

01

3 4 Arithmetic

Single/multicycleDatapaths

IFetchDcd Exec Mem WB

IFetchDcd Exec Mem WB

IFetchDcd Exec Mem WB

IFetchDcd Exec Mem WB

Pipelining

Memory Systems

I/O

Page 2: איפה אנחנו ולאן ממשיכים ??

2 / 52

נלמד ? מה

•. בנוי מחשב כיצד

•. מחשב ביצועי לנתח כיצד

חדשים )• מעבדים על המשפיעים (cache, pipelineנושאים

הספר:Computer Organization & Design The hardware/software interface,

David A. Patterson and

John L. Hennessy.

Third Edition 2005

Page 3: איפה אנחנו ולאן ממשיכים ??

4 / 52

Page 4: איפה אנחנו ולאן ממשיכים ??

5 / 52

Levels of Representation

temp = v[k];

v[k] = v[k+1];

v[k+1] = temp;

lw$15, 0($2)lw$16, 4($2)

,sw$16 0($2)sw$15, 4($2)

0000 1001 1100 0110 1010 1111 0101 10001010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111

ALUOP[0:3] <= InstReg[9:11] & MASK

שפה עלית:קל לתכנת•לא חד ערכי לשפת מכונה•תלוי קומפיילר אופטימיזר••Portable

שפת סף (אסמבלי Assembly(

לשפת מכונה1:1•יותר קריא מש' מכונה•

High Level Language Program

Assembly Language Program

Machine Language Program

Control Signal Specification

°°

Compiler

Assembler

Machine Interpretation

Page 5: איפה אנחנו ולאן ממשיכים ??

6 / 52

MIPS Instruction SetUse the MIPS ISA document as the final word on the ISA

MIPS ISA documen

t available

on Course

Web Site.

Page 6: איפה אנחנו ולאן ממשיכים ??

7 / 52

Instruction Sets: A Thin Interface

Instruction Set Architecture

I/O systemProcessor

Digital DesignCircuit Design

Datapath & Control

Transistors

MemoryHardware

CompilerOperating

System(Mac OS X)

Application (iTunes)

Software Assembler

Syntax: ADD $8 $9 $10 Semantics: $8 = $9 + $10

In Hexadecimal: 012A4020000000 01001 01010 01000 00000 100000Binary:

6 bits 5 bits 5 bits 5 bits 5 bits 6 bitsFieldsize:

opcode rs rt rd functshamtBitfield:

“R-Format”

Page 7: איפה אנחנו ולאן ממשיכים ??

8 / 52

Instruction Set Architecture

השונות • המכונה שפות בין רב דמיון יש• - ה מעבד של המכונה שפת את נלמד בתחילת MIPSאנו שפותח

- ה - 80שנות ב ) בו (.Silicon Graphics,NEC,Sonyמשתמשים

•RISC v. CISC

–Reduced Instruction Set Computer - MIPS–8086 - Complex Instruction Set Computer

יותר המוטו “• זה “פחות

, , יותר: פשוטות עצמן הפקודות כאשר יותר קטן פקודות סט כלומר . לביצוע הדרושה והחומרה היות זאת יותר טובים ביצועים מאפשר

” הסיליקון ושטח תגדל המהירות יותר פשוטה תהיה ל הנ הפקודות. ) יצטמצם )= המחיר הדרוש

Page 8: איפה אנחנו ולאן ממשיכים ??

9 / 52

Hardware implements semantics...

Instruction

Fetch

Instruction

Decode

Operand

Fetch

Execute

Result

Store

Next

Instruction

Fetch next inst from memory:012A4020

opcode rs rt rd functshamtDecode fields to get : ADD $8 $9 $10

“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.

Syntax: ADD $8 $9 $10 Semantics: $8 = $9 + $10

Page 9: איפה אנחנו ולאן ממשיכים ??

10 / 52

Memory Instructions: LW $1,32($2)

Instruction

Fetch

Instruction

Decode

Operand

Fetch

Execute

Result

Store

Next

Instruction

Fetch the load inst from memory

“Retrieve” register value: $2

Compute memory address: 32 + $2

Load memory address contents into: $1

Prepare to fetch instr that follows the LW in the program. Depending on load semantics, new $1 is visible to that instr, or not until the following instr (”delayed loads”).

Decode fields to get : LW $1, 32($2)

opcode rs rt offset “I-Format”

Page 10: איפה אנחנו ולאן ממשיכים ??

11 / 52

Branch Instructions: BEQ $1,$2,25

Instruction

Fetch

Instruction

Decode

Operand

Fetch

Execute

Result

Store

Next

Instruction

Fetch branch inst from memory

“Retrieve” register values: $1, $2

Compute if we take branch: $1 == $2 ?

Decode fields to get: BEQ $1, $2, 25

opcode rs rt offset “I-Format”

ALWAYS prepare to fetch instr that follows the BEQ in the program (”delayed branch”). IF we take branch, the instr we fetch AFTER that instruction is PC + 4 + 100.PC == “Program

Counter”

Page 11: איפה אנחנו ולאן ממשיכים ??

12 / 52

Why ISA is important?

•Code size

– long instructions may take more time to be fetched

– Requires larges memory (important in small devices, e.g., cell phones)

•Number of instructions (IC) – Reducing IC reduce execution time (assuming same CPI and

frequency)

•Code “simplicity”– Simple HW implementation which leads to higher frequency and lower

power

– Code optimization can better be applied to “simple code”

Page 12: איפה אנחנו ולאן ממשיכים ??

13 / 52

The impact of the ISA

RISC vs CISC

Page 13: איפה אנחנו ולאן ממשיכים ??

14 / 52

CISC Processors

•CISC - Complex Instruction Set Computer

•The idea: a high level machine language

•Characteristic– Many instruction types, with many addressing modes– Some of the instructions are complex:

• Perform complex tasks• Require many cycles

– ALU operations directly on memory

• Usually uses limited number of registers– Variable length instructions

• Common instructions get short codes save code length

•Example: x86

Page 14: איפה אנחנו ולאן ממשיכים ??

15 / 52

CISC Drawbacks

•Compilers do not take advantage of the complex instructions and the complex indexing methods

•Implement complex instructions and complex addressing modes

complicate the processor

slow down the simple, common instructions contradict Amdahl’s law corollary:

Make The Common Case Fast

•Variable length instructions are real pain in the neck:– It is difficult to decode few instructions in parallel

• As long as instruction is not decoded, its length is unknown It is unknown where the instruction ends It is unknown where the next instruction starts

– An instruction may not fit into the “right behavior” of the memory hierarchy (will be discussed next lectures)

•Examples: VAX, x86)!?!(

Page 15: איפה אנחנו ולאן ממשיכים ??

16 / 52

RISC Processors

•RISC - Reduced Instruction Set Computer•The idea: simple instructions enable fast hardware

•Characteristic– A small instruction set, with only a few instructions formats– Simple instructions

• execute simple tasks• require a single cycle (with pipeline)

– A few indexing methods– ALU operations on registers only

• Memory is accessed using Load and Store instructions only.

• Many orthogonal registers • Three address machine: Add dst, src1, src2

– Fixed length instructions•Examples: MIPSTM, SparcTM, AlphaTM, PowerPCTM

Page 16: איפה אנחנו ולאן ממשיכים ??

17 / 52

RISC Processors (Cont.)

•Simple architecture Simple micro-architecture – Simple, small and fast control logic

– Simpler to design and validate

– Room for on die caches: instruction cache + data cache

• Parallelize data and instruction access– Shorten time-to-market

•Using a smart compiler – Better pipeline usage

– Better register allocation

•Existing RISC processor are not “pure” RISC – e.g., support division which takes many cycles

Page 17: איפה אנחנו ולאן ממשיכים ??

18 / 52

RISC v. CISC

I - בתוכנית פקודות מספר

T –פקודה לביצוע הזמן

RISC:

I * T

CISC:

I * T

Page 18: איפה אנחנו ולאן ממשיכים ??

19 / 52

So, what is better, RISC or CISC

•Today CISC architectures (X86) are running as fast as RISC (or even faster)

•The main reasons are:– Translates CISC instructions into RISC instructions (ucode) – CISC architecture are using “RISC like engine”

•We will discuss this kind of solutions later on in this course.

Page 19: איפה אנחנו ולאן ממשיכים ??

20 / 52

מספר תכנון Simplicity favors Regularity: 1כלל

אריתמטיות אריתמטיות פעולות פעולות

•MIPS

addi a,b,100 # a=b+100 add a,b,c # a=b+c

•8086 ADD EAX,B # EAX= EAX+B

כמו מינימליות פקודות עם פשוט מנגנון מעדיפים אנו R3 = R1 op R2 משתנים פניעל כמה עם לתכנות יותר שקל מחשב

למשל בפקודה שרוציםR5 = ( R1 op1 R2) op2 (R3 op3 R4)

. אותו ולממש לתכנן מאוד קשה אבל

Page 20: איפה אנחנו ולאן ממשיכים ??

21 / 52

’ מס תכנון Smaller is faster: 2כלל

•. רגיסטרים על רק אריתמטיות פעולות נאפשר• .) אחד ) קבוע או רגיסטר להיות יכולים האופרנדיםיש” • כ . 32סה spillingרגיסטרים word = 32 bits = 4 bytesרגיסטר •קונבנציות•

$1,$2 …

$s0,$s1 ... - C של משתנים$t1,$t2 … - זמניים משתנים

דוגמא:f=(g+h)-(k+j) # $s0=f, $s1=g, $s2=h, $s3=k, $s4=j

add $t0,$s1,$s2

add $t1,$s3,$s4

sub $s0, $t0, $t1

” י ע מסומנים הרגיסטריםאו. $31$ - 0$ ” י ע או

הקשורים שמות . יש בתכנית לתפקידיהם

תפקידי על הסכמה ” בכל ל הנ הרגיסטרים

בשפת . Cהתכניות למשל

המשפט איך מתארת הדוגצא ( f=(g+h)-(k+j פקודות” מיוצג י ע

אסמבלי. . הפרוססור של ליבו הם הרגיסטרים

. מלזיכרון מהירה אליהם הגישה- ” ל , בוזמנית -3נגשים : מ 2רגיסטרים

. כותבים ולשלישי קוראים.

110עמ’

Page 21: איפה אנחנו ולאן ממשיכים ??

22 / 52

Policy of Use Conventions

Name Register number Usage$zero 0 the constant value 0$v0-$v1 2-3 values for results and expression evaluation$a0-$a3 4-7 arguments$t0-$t7 8-15 temporaries$s0-$s7 16-23 saved$t8-$t9 24-25 more temporaries$gp 28 global pointer$sp 29 stack pointer$fp 30 frame pointer$ra 31 return address

הם נוספים השמור at = $1רגיסטרים $לאסמבלר

למערכת k0 , $ k1 = $ 26, $ 27ו- השמורים $ההפעלה

Page 22: איפה אנחנו ולאן ממשיכים ??

23 / 52

הזיכרון

•. גדול - מערך הזיכרון•. למערך - אינדקס לזיכרון כתובת•Byte addressing. בבתים - האינדקס

המכסימלי • הזיכרון גודל 230 words = 232 bytes

0123456...

8 bits of data

8 bits of data

8 bits of data

8 bits of data

8 bits of data

8 bits of data

8 bits of data

Page 23: איפה אנחנו ולאן ממשיכים ??

24 / 52

לזיכרון פניה

Load and Storeפקודות •בבתים - • היא בזיכרון הכתובת אבל מילה LWטוענים

lw $s1,100($s2) # $s1=Memory[$s2+100]

sw $s1,100($s2) # Memory[$s2+100]=$s1

•: נוספת דוגמא save - של Word מערך

muli $9,$19,4 # Temporary reg $9:=i*4

lw $8,save($9) # Temporary reg $8:=save[i]

במערך = offsetמקום למערך = base registerמצביע

למערך = baseמצביעregister

במערך = מקוםoffset

Page 24: איפה אנחנו ולאן ממשיכים ??

25 / 52

של byteקריאה

כמו )• פקודות גם lb (load byteישנםsb(store byteו- )

לקריאת • ASCIIב - byteגודל: charשימושיAmerican Standard Code For Information

Interchange

.2הוא charגודל - Unicodeב- • בתים

Page 25: איפה אנחנו ולאן ממשיכים ??

27 / 52

לזיכרון גישה

דוגמא: • A של wordsמערך

- Aכתובת $ s3ב h- ב $ s2נמצא

C code: A[2] = h + A[2];

MIPS code: lw $t0, 8($s3) # $t0=$s3[8] add $t0, $s2,$t0 # $t0=$s2+$t0 sw $t0, 8($s3) # $s3[8]=$t0

0

4

8

12

16

32 bits of dataA A[0]

A[1]

INTEL = Little endianA[2]

MIPS = Big endian

013

0 1 2 3

2

Page 26: איפה אנחנו ולאן ממשיכים ??

28 / 52

• - ב של MIPSהפקודות זהה . 32 בגודל ביט -8086ב - • מ - משתנה בגודל -1פקודות ל .17עד בתים

דוגמא: add $s1,$s2,$s3 # $s1=$17,$s2=$18, $s3=$19

הפקודה R-typeמסוג פורמט 0 31

3201719180 000000 10010 10011 10001 00000 100000

op rs rt rd shamt funct

op - opecode rs - register source

rt- register source no 2 rd - register destination

funct - function shamt - shift amount

המכונה שפת

6 5 5 5 5 6

Page 27: איפה אנחנו ולאן ממשיכים ??

29 / 52

•. . הפקודות בין דמיון השונים הפקודות סוגי מספר צמצום

• Example: lw $s1, 32($s2) # $s1 =$17, $s2=18

35 18 17 32

op rs rt 16 bit number

’ מס תכנון לעיתים : 3כלל דורש טוב תכנוןפשרות

op rs rt rd shamt funct

op rs rt 16 bit address

op 26 bit address

R

I

J

6 5 5 5 5 6

6 5 5 5 5 6

Page 28: איפה אנחנו ולאן ממשיכים ??

30 / 52

נתונים • כמו בדיוק בזיכרון נשמרת התוכנית

תוכנית ביצועמיוחד • . PC - Program Counterרגיסטר הפקודה כתובת את שומר•. מהזיכרון שלמה מילה קוראיםה - • את .PCמקדמים

Processor Memory

memory for data, programs, compilers, editors, etc.

בזיכרון התוכנית

Page 29: איפה אנחנו ולאן ממשיכים ??

31 / 52

•Jump ” תנאים - “ ללא אבסולוטית קפיצה

j label

•Branch - מותנת יחסית קפיצה bne $1,$2,label # $1!=$2 go to label

• Example:

if (i!=j) beq $s4, $s5, Lab1 h=i+j; add $s3, $s4, $s5else j Lab2 h=i-j; Lab1: sub $s3, $s4, $s5

Lab2: ...

Branch vs Jump

($s3=h $s4 =i $s5=j )

Page 30: איפה אנחנו ולאן ממשיכים ??

32 / 52

• Instructions:

bne $t4,$t5,Label Next instruction is at Label if $t4!= $t5

beq $t4,$t5,Label Next instruction is at Label if $t4 = $t5

j Label Next instruction is at Label

•Formats:

מכאןbranch - בגבולות יחסית .2^16קפיצה מילים

- ה: רוב . branchesהנחה לוקאליות קפיצות יהיו

•Beq $s1,$s2,25 # if ($s1 ==$s2) go to PC +4 +25*4

op rs rt 16 bit address

op 26 bit address

I

J

Addresses in Branches and Jumps

Page 31: איפה אנחנו ולאן ממשיכים ??

33 / 52

לקידוד דוגמא

Loop: lw $8, save($19) # $8=save[i]

bne $8, $21,Exit #Goto Exit if save[i]<> k

add $19,$19,$20 # i:=i+j

j Loop # Goto Loop

Exit:

SAVE - 1000

1000 8 19 35 80,000

2 21 8 5 80,004

32 0 19 20 19 0 80,008

20,000 2 80,012

80,016

Page 32: איפה אנחנו ולאן ממשיכים ??

34 / 52

לזכור שחשוב כלל

של MIPS מקודדים: באסמבלי

במילים codeכתובת

בבתים dataכתובת

בבתים הכתובת את מבקש הוא לזיכרון כאשר MIPS ניגש מעבד

Page 33: איפה אנחנו ולאן ממשיכים ??

35 / 52

Slt- set less then if $s1 < $s2 then $t0 = 1

slt $t0, $s1, $s2 else $t0 = 0

את • לבנות :bltניתןBlt –branch less then blt $s0,$s1, Less

slt $at,$s0,$s1 # $t0 gets 1 if $s0<$s1bne $at,$zero, Less # go to Less if $t0 != 0

• blt היא Pseudo instruction •Assembler uses $at (= $1) for pseudo instructions

Branch-if-less-than?

Page 34: איפה אנחנו ולאן ממשיכים ??

36 / 52

- ל נוספות Pseudo instructionדוגמאות

bne $8,$21,far_adrs

ל - שקול beq $8,$21,nxt j far_adrsnxt:

move $t1,$s4

add $t1,$s4,$zero

ל - שקול

Page 35: איפה אנחנו ולאן ממשיכים ??

37 / 52

’ מס תכנון מהיר : - 4כלל השכיח המקרה את בנה

קבועים • עם מתבצעות ארתמטיות פעולות הרבה.קטנים

גדולים • קבועים

$t0=101010101010101011111111111111111

addi $29, $29, 4

1010101010101010

0000000000000000 1111111111111111

1010101010101010 1111111111111111

0000000000000000 lui $t0,1010101010101010

# $t0=2^16*(101010101010101010)2

ori $t0,$t0, 1111111111111111

# $t0=$t0||1010101010101010

$to=10101010101010101111111111111…

: קטנים קבועים של והשוואה חיסור לחיבור מיוחדות פקודות הוקצו לכןaddi, slti, andi, ori, xori

- ב , 2נחשב , נדרשת אבל יותר לאט כלומר פקודות : נוספת אחת פקודה luiרק

Page 36: איפה אנחנו ולאן ממשיכים ??

38 / 52

לסיכוםMIPS operands

Name Example Comments$s0-$s7, $t0-$t9, $zero, Fast locations for data. In MIPS, data must be in registers to perform

32 registers $a0-$a3, $v0-$v1, $gp, arithmetic. MIPS register $zero always equals 0. Register $at is $fp, $sp, $ra, $at reserved for the assembler to handle large constants.

Memory[0], Accessed only by data transfer instructions. MIPS uses byte addresses, so

230

memory Memory[4], ..., sequential words differ by 4. Memory holds data structures, such as arrays,

words Memory[4294967292] and spilled registers, such as those saved on procedure calls.MIPS assembly language

Category Instruction Example Meaning Commentsadd add $s1, $s2, $s3 $s1 = $s2 + $s3 Three operands; data in registers

Arithmetic subtract sub $s1, $s2, $s3 $s1 = $s2 - $s3 Three operands; data in registers

add immediate addi $s1, $s2, 100 $s1 = $s2 + 100 Used to add constants

load w ord lw $s1, 100($s2) $s1 = Memory[$s2 + 100]Word from memory to register

store w ord sw $s1, 100($s2) Memory[$s2 + 100] = $s1 Word from register to memory

Data transfer load byte lb $s1, 100($s2) $s1 = Memory[$s2 + 100]Byte from memory to register

store byte sb $s1, 100($s2) Memory[$s2 + 100] = $s1 Byte from register to memoryload upper immediate

lui $s1, 100 $s1 = 100 * 216 Loads constant in upper 16 bits

branch on equal beq $s1, $s2, 25 if ($s1 == $s2) go to PC + 4 + 100

Equal test; PC-relative branch

Conditional

branch on not equal bne $s1, $s2, 25 if ($s1 != $s2) go to PC + 4 + 100

Not equal test; PC-relative

branch set on less than slt $s1, $s2, $s3 if ($s2 < $s3) $s1 = 1; else $s1 = 0

Compare less than; for beq, bne

set less than immediate

slti $s1, $s2, 100 if ($s2 < 100) $s1 = 1; else $s1 = 0

Compare less than constant

jump j 2500 go to 10000 Jump to target address

Uncondi- jump register jr $ra go to $ra For sw itch, procedure return

tional jump jump and link jal 2500 $ra = PC + 4; go to 10000 For procedure call

Page 37: איפה אנחנו ולאן ממשיכים ??

39 / 52

תרגיל

:MIPS, ושני תרגומים שלו לשפת האסמבלי של C לפניך קוד הכתוב ב-:1שאלה

while (save[i]!=k) doi=i+j ;

save:array [ 0..100] of word.k כ-$21 ו-j כ-$20 ו i מתפקד כ$19

:תרגום ראשון•

Loop: muli $9,$19,4 # Temporary reg $9:=i*4 lw $8,save($9) # Temporary reg $8:=save[i] beq $8,$21,Exit # Goto Exit if save[i] = k add $19,$19,$20 # i:=i+j j Loop # Goto Loop

Exit:

Page 38: איפה אנחנו ולאן ממשיכים ??

40 / 52

תרגיל המשך

:תרגום שני•

muli $9,$19,4 # Temporary reg $9:=i*4

lw $8,save($9) # Temporary reg $8:=save[i]

beq $8,$21,Exit # Goto Exit if save[i] = k

Loop: add $19,$19,$20 # i:=i+j

muli $9,$19,4 # Temporary reg $9:=i*4

lw $8,save($9) # Temporary reg $8:=save[i]

bnq $8,$21,Loop # Goto Loop if save[i]!=k

Exit:

שמתבצעות פעמים, מה מספר הפקודות 10 בהנחה שהלולאה מתבצעת שאלה:•בכל אחד מהתרגומים?

Page 39: איפה אנחנו ולאן ממשיכים ??

41 / 52

Compiler

A.asm

B.asm compiler

compilerA.obj

B.obj

linker

C.lib

(c.obj)

P.exeloader

Memory

Page 40: איפה אנחנו ולאן ממשיכים ??

42 / 52

הקומפילציה תהליך

Page 41: איפה אנחנו ולאן ממשיכים ??

43 / 52

דוגמא

B.asm

compiler

compiler

A.obj

B.obj

s: .word 3,4

j k

lw $1,s ($2)

k: add $1,$2,$3

m: .word 2

sw 7, m($3)

A.asm

3 4

j 2

lw $1,0($2)

add $1,$2,$3

2

sw $7,0($3)2

3

4

sw $7,0($3)

j 3

lw $1,4($2)

add $1,$2,$3

linker

P.exe

Page 42: איפה אנחנו ולאן ממשיכים ??

44 / 52

Unixב- Objectקובץ

• Object file header

• text segment

• data segment

• relocation information

• symbol table

• debugging information

Page 43: איפה אנחנו ולאן ממשיכים ??

45 / 52

במחשב הזיכרון MIPSמבנה

Page 44: איפה אנחנו ולאן ממשיכים ??

46 / 52

Page 45: איפה אנחנו ולאן ממשיכים ??

47 / 52

Preprocessing • Macro:

• Code:

• After preprocessing

Page 46: איפה אנחנו ולאן ממשיכים ??

48 / 52

Page 47: איפה אנחנו ולאן ממשיכים ??

49 / 52

Page 48: איפה אנחנו ולאן ממשיכים ??

50 / 52

Calling procedure:

Page 49: איפה אנחנו ולאן ממשיכים ??

51 / 52

Sub1:

Callee procedure:

Page 50: איפה אנחנו ולאן ממשיכים ??

52 / 52

Single Cycle

Shiftleft 2

PC

Instr uctionme mor y

Readaddre ss

Instr uction[31– 0]

Datame mory

Readdata

Writedata

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

I nstr uction [15 – 11]

I nstr uction [20 – 16]

I nstr uction [25 – 21]

Add

AL Uresult

Zer o

I nstruction [5– 0]

Me mto Reg

AL U Op

Me m Write

Reg Write

Me mRead

Br an ch

Ju mpReg Dst

AL U Src

I nstr uction [31 – 26]

4

Mux

I nstru ction [25– 0] Ju mp addr ess [31 – 0]

PC +4 [31 – 2 8]

Signexte nd

16 32I nstr uction [15 – 0]

1

Mux

1

0

Mux

0

1

Mux

0

1

AL Ucontr ol

Control

AddALU

result

Mux

0

1 0

AL U

Shiftleft 2

26 2 8

Address