





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Dr. Rahul Singh April 23, 2009
Lecture 7: Procedures^ Electrical and Computer Engineering University of California, Santa Barbara April 23, 2009^1
Electrical and Computer Engineering Lecture 7: Procedures (^) University of California, Santa Barbara April 23, 2009^2
Electrical and Computer Engineering University of California, Santa Barbara
Lecture 7: Procedures^ Electrical and Computer Engineering University of California, Santa Barbara April 23, 2009^12 ... 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 Instruction Support for Functions C M I P S Question: Why use jr here? Why not simply use j? Answer : sum might be called by many functions, so can’t return to a fixed place. The calling proc to sum must be able to say when done, “return here” somehow. Lecture 7: Procedures^ Electrical and Computer Engineering University of California, Santa Barbara April 23, 2009^13 Instruction Support for Functions
Electrical and Computer Engineering Lecture 7: Procedures (^) University of California, Santa Barbara April 23, 2009^15 Instruction Support for Functions
Lecture 7: Procedures^ Electrical and Computer Engineering University of California, Santa Barbara April 23, 2009^16 Nested Procedures int sumSquare(int x, int y) { return mult(x,x)+ y; }
Lecture 7: Procedures^ Electrical and Computer Engineering University of California, Santa Barbara April 23, 2009^24 Register Conventions
Lecture 7: Procedures^ Electrical and Computer Engineering University of California, Santa Barbara April 23, 2009^28