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

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

View Full Document Right Arrow Icon
CSCI-365 Computer Organization Lecture Note : Some slides and/or pictures in the following are adapted from: Some slides and/or pictures in the following are adapted from: slides ©2008 UCB 5
Background image of page 1

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

View Full DocumentRight Arrow Icon
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)
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
... 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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
Function Call Bookkeeping Single instruction to jump and save return address: jump and link ( jal ) Before : 1008 addi $ra,$zero,1016 #$ra=1016 1012
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/26/2009 for the course MATH AND C CSCI365 taught by Professor Laurencetianruoyang during the Spring '09 term at St. Francis Xavier, Antigonish.

Page1 / 22

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

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online