{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# lecture5 - CSCI-365 Computer Organization Lecture 5 Note...

This preview shows pages 1–7. Sign up to view the full content.

CSCI-365 Computer Organization Lecture Note : Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson & Hennessy, ©2005 Some slides and/or pictures in the following are adapted from: slides ©2008 UCB 5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Inequalities in MIPS How do we use this? Compile by hand: if (g < h) goto Less; #g:\$s0 , h:\$s1 Answer: compiled MIPS code… slt \$t0,\$s0,\$s1 # \$t0 = 1 if g<h bne \$t0,\$0,Less # goto Less # if \$t0!=0 # (if (g<h)) Less: Can we implement in one or more instructions using just slt and the branches? (done in class) What about > ? (done in class) What about ? (done in class)
Registers play a major role in keeping track of information for function calls Register conventions: Return address \$ra Arguments \$a0, \$a1, \$a2, \$a3 Return value \$v0, \$v1 Local variables \$s0, \$s1, … , \$s7 The stack is also used; more later Function Call Bookkeeping

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
... sum(a,b);... /* a,b:\$s0,\$s1 */ } int sum(int x, int y) { return x+y; } address 1000 add \$a0,\$s0,\$zero # x = a 1004 add \$a1,\$s1,\$zero # y = b 1008 addi \$ra,\$zero,1016 # \$ra=1016 1012 j sum # jump to sum 1016 ... 2000 sum: add \$v0,\$a0,\$a1 2004 jr \$ra # new instruction Function Call Bookkeeping
Function Call Bookkeeping ... sum(a,b);... /* a,b:\$s0,\$s1 */ } int sum(int x, int y) { return x+y; } Question: Why use jr here? Why not simply use j ? Answer: sum might be called by many places, so we can’t return to a fixed place. The calling proc to sum must be able to say “return here” somehow 2000 sum: add \$v0,\$a0,\$a1 2004 jr \$ra # new instruction

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Function Call Bookkeeping Single instruction to jump and save return address: jump and link ( jal ) Before : 1008 addi \$ra,\$zero,1016 #\$ra=1016 1012 j sum #goto sum After : 1008 jal sum # \$ra=1012,goto sum Why have a jal ? Make the common case fast: function calls are very common. Also, you don’t have to know where the code is loaded into memory with jal
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern