L12 - CS 61C L12 MIPS Procedures II / Logical (1) Wawrzynek...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 61C L12 MIPS Procedures II / Logical (1) Wawrzynek Fall 2007 © UCB 9/24/2007 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS61C – Machine Structures Lecture 12 - MIPS Procedures II & Logical Ops CS 61C L12 MIPS Procedures II / Logical (2) Wawrzynek Fall 2007 © UCB Review ° Functions called with jal , return with jr $ra . ° The stack is your friend: Use it to save anything you need. Just be sure to leave it the way you found it. ° Instructions we know so far Arithmetic: add, addi, sub, addu, addiu, subu Memory: lw, sw Decision: beq, bne, slt, slti, sltu, sltiu Unconditional Branches (Jumps): j, jal, jr ° Registers we know so far • All of them! • There are CONVENTIONS when calling procedures! CS 61C L12 MIPS Procedures II / Logical (3) Wawrzynek Fall 2007 © UCB Register Conventions (1/4) ° Calle R : the calling function ° Calle E : the function being called ° When callee returns from executing, the caller needs to know which registers may have changed and which are guaranteed to be unchanged. ° Register Conventions : A set rules as to which registers will be unchanged after a procedure call ( jal ) and which may be changed . Note: This is software policy, no hardware support. CS 61C L12 MIPS Procedures II / Logical (4) Wawrzynek Fall 2007 © UCB Register Conventions (2/4)- saved ° $0 : No Change . Always 0. ° $s0- $s7 : Restore if you change . Very important, that ’ s why they ’ re called saved registers. If the callee changes these in any way, it must restore the original values before returning. ° $sp : Restore if you change . The stack pointer must point to the same place before and after the jal call, or else the caller won ’ t be able to restore values from the stack. ° HINT -- All saved registers start with S ! CS 61C L12 MIPS Procedures II / Logical (5) Wawrzynek Fall 2007 © UCB Register Conventions (3/4) - volatile ° $ra : Can Change . The jal call itself will change this register. Caller needs to save on stack if nested call. ° $v0- $v1 : Can Change . These will contain the new returned values. ° $a0- $a3 : Can change . These are volatile argument registers. Caller needs to save if they are needed after the call. ° $t0- $t9 : Can change . That ’ s why they ’ re called temporary: any procedure may change them at any time. Caller needs to save if they ’ ll need them afterwards. CS 61C L12 MIPS Procedures II / Logical (6) Wawrzynek Fall 2007 © UCB Register Conventions (4/4) ° What do these conventions mean? • If function R calls function E, then function R must save any volatile registers that it may be using onto the stack before making a jal call. • Function E must save any S (saved) registers it intends to use before garbling up their values • Remember: Caller /callee need to save only temporary/saved registers they are using , not all registers. CS 61C L12 MIPS Procedures II / Logical (7) Wawrzynek Fall 2007 © UCB Example: Fibonacci Numbers 1/8 °...
View Full Document

This note was uploaded on 04/09/2008 for the course CS 61A taught by Professor Harvey during the Spring '08 term at University of California, Berkeley.

Page1 / 17

L12 - CS 61C L12 MIPS Procedures II / Logical (1) Wawrzynek...

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

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