CS 35101 Computer Architecture Spring 2006 Week 4 Paul Durand (www.cs.kent.edu/~durand) Course url: www.cs.kent.edu/~durand/cs35101.htm.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
©UCB CS 161 Lecture 4 Prof. L.N. Bhuyan
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
CSE331 W04.1Irwin&Li 2006 PSU CSE 331 Computer Organization and Design Fall 2006 Week 4 Section 1: Mary Jane Irwin (
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
331 Week 3. 1Spring 2005 Review: MIPS Organization Processor Memory 32 bits 2 30 words read/write addr read data write data word address (binary) 0…0000.
14:332:331 Computer Architecture and Assembly Language Spring 06 Week 4: Addressing Mode, Assembler, Linker [Adapted from Dave Patterson’s UCB CS152 slides.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
331 W02.1Spring 05 Announcements  HW1 is due on this Friday  Appendix A (on CD) is very helpful to HW1.
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
RISC Concepts, MIPS ISA and the Mini–MIPS project
331 Week 3. 1Fall 2003 Head’s Up  This week’s material l MIPS control flow operations (for, while, if-the-else, …) -Reading assignment - PH 3.5  Reminders.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
331 Practice Exam.1Fall 2003 Naming Conventions for Registers 0$zero constant 0 (Hdware) 1$atreserved for assembler 2$v0expression evaluation & 3$v1function.
The MIPS 32 Our objective is to get an appreciation with: working with a “typical” computer machine language. programming in assembly language. debuging.
Lecture 4 section 2.4-?? As opposed to CISC – Complicated Instruction Set Architecture (ala the x86)
CMPT 334 Computer Organization
CSE331 W03.1Irwin&Li Fall 2006 PSU CSE 331 Computer Organization and Design Fall 2006 Week 3 Section 1: Mary Jane Irwin (
CS224 Fall 2011 Chapter 2b Computer Organization CS224 Fall 2011 Chapter 2 b With thanks to M.J. Irwin, D. Patterson, and J. Hennessy for some lecture.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
CS35101 Computer Architecture Spring 2006 Week 5 Paul Durand ( Course url:
Computer Architecture Instruction Set Architecture Lynn Choi Korea University.
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 7: MIPS Instructions III
Computer Organization CS224 Fall 2012 Lessons 9 and 10.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
1  1998 Morgan Kaufmann Publishers Machine Instructions: Language of the Machine Lowest level of programming, control directly the hardware Assembly instructions.
CSIE30300 Computer Architecture Unit 02: MIPS ISA Review Hsin-Chou Chi [Adapted from material by and
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
CSE 340 Computer Architecture Spring 2014 MIPS ISA Review.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Lecture 4: MIPS Instruction Set
Computer Architecture CSE 3322 Lecture 4 crystal.uta.edu/~jpatters/cse3322 Assignments due 9/15: 3.7, 3.9, 3.11.
Digital Systems Design L02 MIPS ISA Review.1 Digital Systems Design Lecture 02: MIPS ISA Review Adapted from Mary Jane Irwin ( )
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
Assembly Language Chapter 3.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
EI209 Chapter 2.1Haojin Zhu, SJTU, 2015 EI 209 Computer Organization Fall 2015 Chapter 2: Instructions: Language of the Computer Haojin Zhu (
CDA 3101 Spring 2016 Introduction to Computer Organization
COMPUTER ORGANIZATION LECTURE 3: ISA YASSER MOHAMMAD.
CPE 232 MIPS ISA1 CPE 232 Computer Organization MIPS ISA Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin ( which.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
CSE 340 Computer Architecture Summer 2016 MIPS ISA Review.
Prof. Hsien-Hsin Sean Lee
Computer Architecture Instruction Set Architecture
Computer Architecture Instruction Set Architecture
Instructions: Language of the Computer
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Haojin Zhu ( ) Course Website:
Instructions - Type and Format
MIPS Instructions.
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
The University of Adelaide, School of Computer Science
Chapter 2 Instructions: Language of the Computer part 2
The University of Adelaide, School of Computer Science
COMS 361 Computer Organization
Systems Architecture I
CSE 331 Computer Organization and Design Fall 2007 Week 4
Computer Architecture
Presentation transcript:

CS Computer Architecture Spring 2006 Week 4 Paul Durand ( Course url:

Review: Signed Binary Representation 2’sc binarydecimal = 1011 then add a complement all the bits -( ) = -2 3 =

Review: MIPS Organization Processor Memory 32 bits 2 30 words read/write addr read data write data word address (binary) 0…0000 0…0100 0…1000 0…1100 1…1100 Register File src1 addr src2 addr dst addr write data 32 bits src1 data src2 data 32 registers ($zero - $ra) ALU byte address (big Endian)  Arithmetic instructions – to/from the register file  Load/store word and byte instructions – from/to memory Fetch DecodeExec

Review: MIPS Instructions, so far CategoryInstrOp CodeExampleMeaning Arithmetic (R format) add0 and 32add $s1, $s2, $s3$s1 = $s2 + $s3 subtract0 and 34sub $s1, $s2, $s3$s1 = $s2 - $s3 Data transfer (I format) load word35lw $s1, 100($s2)$s1 = Memory($s2+100) store word43sw $s1, 100($s2)Memory($s2+100) = $s1 load byte32lb $s1, 101($s2)$s1 = Memory($s2+101) store byte40sb $s1, 101($s2)Memory($s2+101) = $s1

Head’s Up  This week’s material l MIPS Boolean operations;control flow operations; procedures -Reading assignment - PH 2.5, 2.6  Reminders l HW # 1 Due Friday, Feb 10 l Turn in via with any assembler source code files included as attachments.  Next week’s material l MIPS procedures cont’d. and addressing modes -Reading assignment - PH 2.7, 2.9, A.5 and A.6

 Decision making instructions l alter the control flow l i.e., change the "next" instruction to be executed  MIPS conditional branch instructions: bne $s0, $s1, Label#go to Label if $s0  $s1 beq $s0, $s1, Label#go to Label if $s0=$s1  Example: if (i==j) h = i + j; bne $s0, $s1, Lab1 add $s3, $s0, $s1 Lab1:... Instructions for Making Decisions

 Instructions: bne $s0, $s1, Label#go to Label if $s0  $s1 beq $s0, $s1, Label#go to Label if $s0=$s1  Machine Formats:  How is the branch destination address specified? Assembling Branches op rs rt 16 bit number I format ???? ????

Specifying Branch Destinations  Could use a register (like lw and sw) and add to it the 16-bit offset l which register? -Instruction Address Register (PC = program counter) -its use is automatically implied by instruction -PC gets updated (PC+4) during the fetch cycle so that it holds the address of the next instruction l limits the branch distance to to instructions from the (instruction after the) branch instruction, but -most branches are local anyway (principle of locality) bne $s0,$s1,Lab1 add $s3,$s0,$s1... Lab1:  Could specify the memory address - but that would require a 32 bit field PC 

Disassembling Branch Destinations  The contents of the updated PC (PC+4) is added to the low order 16 bits of the branch instruction which is converted into a 32 bit value by l concatenated two low-order zeros to create an 18 bit number l sign-extending those 18 bits  The result is written into the PC if the branch condition is true prior to the next Fetch cycle PC Add 32 offset sign-extend from the low order 16 bits of the branch instruction branch dst address ? Add 4 32

 Assembly code bne $s0, $s1, Lab1 add $s3, $s0, $s1 Lab1:...  Machine Format of bne : Assembling Branches Example op rs rt 16 bit offset I format  Remember After the bne instruction is fetched, the PC is updated to address the add instruction (PC = PC + 4). Two low-order zeros are concatenated to the offset number and that value sign-extended is added to the (updated) PC

 Assembly code bne $s0, $s1, Lab1 add $s3, $s0, $s1 Lab1:...  Machine Format of bne : Assembling Branches Example op rs rt 16 bit offset I format  Remember After the bne instruction is fetched, the PC is updated to address the add instruction (PC = PC + 4). Two low-order zeros are concatenated to the offset number and that value sign-extended is added to the (updated) PC

MIPS Organization Processor Memory 32 bits 2 30 words read/write addr read data write data word address (binary) 0…0000 0…0100 0…1000 0…1100 1…1100 Register File src1 addr src2 addr dst addr write data 32 bits src1 data src2 data 32 registers ($zero - $ra) PC ALU byte address (big Endian) Fetch PC = PC+4 DecodeExec Add 32 4 Add 32 br offset

 MIPS also has an unconditional branch instruction or jump instruction: j label#go to label  Example: if (i!=j) h=i+j; else h=i-j; beq$s0, $s1, Lab1 add$s3, $s0, $s1 jLab2 Lab1:sub$s3, $s0, $s1 Lab2:... Another Instruction for Changing Flow

 Instruction: j label#go to label  Machine Format:  How is the jump destination address specified? l As an absolute address formed by -concatenating the upper 4 bits of the current PC (now PC+4) to the 26-bit address and -concatenating 00 as the 2 low-order bits Assembling Jumps op 26-bit address J format 2 ????

Disassembling Jump Destinations  The low order 26 bits of the jump instruction is converted into a 32 bit jump instruction destination address by l concatenated two low-order zeros to create an 28 bit (word) address and l concatenating the upper 4 bits of the current PC (now PC+4)  to create a 32 bit instruction address that is place into the PC prior to the next Fetch cycle PC from the low order 26 bits of the jump instruction

 Assemble the MIPS machine code (in decimal is fine) for the following code sequence. Assume that the address of the beq instruction is 0x (hex address) beq$s0, $s1, Lab1 add$s3, $s0, $s1 jLab2 Lab1:sub$s3, $s0, $s1 Lab2:... Assembling Branches and Jumps

 Assemble the MIPS machine code (in decimal is fine) for the following code sequence. Assume that the address of the beq instruction is 0x (hex address) beq$s0, $s1, Lab1 add$s3, $s0, $s1 jLab2 Lab1:sub$s3, $s0, $s1 Lab2:... Assembling Branches and Jumps 0x x x x c x jmp dst = (0x0) 0x (00 2 ) = 0x

Compiling While Loops  Compile the assembly code for the C while loop where i is in $s0, j is in $s1, and k is in $s2 while (i!=k) i=i+j;

Compiling While Loops  Compile the assembly code for the C while loop where i is in $s0, j is in $s1, and k is in $s2 while (i!=k) i=i+j; Loop:beq$s0, $s2, Exit add$s0, $s0, $s1 jLoop Exit:...

 We have beq, bne, but what about branch-if-less-than?  New instruction: slt $t0, $s0, $s1 # if $s0 < $s1 #then # $t0 = 1 #else # $t0 = 0  Machine format: 2 More Instructions for Making Decisions op rs rt rd funct = 0x2a

Other Branch Instructions  Can use slt, beq, bne, and the fixed value of 0 in register $zero to create all relative conditions less than blt $s1, $s2, Label less than or equal to ble $s1, $s2, Label greater than bgt $s1, $s2, Label great than or equal to bge $s1, $s2, Label  As pseudo instructions (get to practice with some of them in HW#2) - recognized (and expanded) by the assembler  The assembler needs a reserved register ( $at ) l there are policy of use conventions for registers

Other Branch Instructions  Can use slt, beq, bne, and the fixed value of 0 in register $zero to create all relative conditions less than blt $s1, $s2, Label less than or equal to ble $s1, $s2, Label greater than bgt $s1, $s2, Label great than or equal to bge $s1, $s2, Label  As pseudo instructions (get to practice with some of them in HW#2) - recognized (and expanded) by the assembler  The assembler needs a reserved register ( $at ) l there are policy of use conventions for registers slt $t0, $s1, $s2#$t0 set to 1 if bne $t0, $zero, Label# $s1 < $s2

 Most higher level languages have case or switch statements allowing the code to select one of many alternatives depending on a single value.  Instruction: jr $t1#go to address in $t1  Machine format: 2 Another Instruction for Changing Flow op rs funct = 0x08

Compiling a Case (Switch) Statement switch (k) { case 0: h=i+j; break; /*k=0*/ case 1: h=i+h; break; /*k=1*/ case 2: h=i-j; break; /*k=2*/  Assuming three sequential words in memory starting at the address in $t4 have the addresses of the labels L0, L1, and L2 and k is in $s2 add$t1, $s2, $s2#$t1 = 2*k add$t1, $t1, $t1#$t1 = 4*k add$t1, $t1, $t4#$t1 = addr of JT[k] lw$t0, 0($t1)#$t0 = JT[k] jr$t0#jump based on $t0 L0:add$s3, $s0, $s1#k=0 so h=i+j jExit L1:add$s3, $s0, $s3#k=1 so h=i+h jExit L2:sub$s3, $s0, $s1#k=2 so h=i-j Exit:... $t4  L0 L1 L2 Memory

Review: MIPS Instructions, so far CategoryInstrOp CodeExampleMeaning Arithmetic (R format) add0 and 32add $s1, $s2, $s3$s1 = $s2 + $s3 subtract0 and 34sub $s1, $s2, $s3$s1 = $s2 - $s3 Data transfer (I format) load word35lw $s1, 100($s2)$s1 = Memory($s2+100) store word43sw $s1, 100($s2)Memory($s2+100) = $s1 load byte32lb $s1, 101($s2)$s1 = Memory($s2+101) store byte40sb $s1, 101($s2)Memory($s2+101) = $s1 Cond. Branch br on equal4beq $s1, $s2, Lif ($s1==$s2) go to L br on not equal5bne $s1, $s2, Lif ($s1 !=$s2) go to L set on less than0 and 42slt $s1, $s2, $s3if ($s2<$s3) $s1=1 else $s1=0 Uncond. Jump jump2j 2500go to jump register0 and 8jr $t1go to $t1

Review: MIPS R3000 ISA  Instruction Categories l Load/Store l Computational l Jump and Branch l Floating Point -coprocessor l Memory Management l Special  3 Instruction Formats: all 32 bits wide R0 - R31 PC HI LO OPrs rt rdshamtfunct OPrs rt 16 bit number OP 26 bit jump target Registers R format I format 6 bits5 bits 6 bits J format

Programming Styles  Procedures (subroutines) allow the programmer to structure programs making them l easier to understand and debug and l allowing code to be reused  Procedures allow the programmer to concentrate on one portion of the code at a time l parameters act as barriers between the procedure and the rest of the program and data, allowing the procedure to be passed values (arguments) and to return values (results)

Six Steps in Execution of a Procedure  Main routine (caller) places parameters in a place where the procedure (callee) can access them l $a0 - $a3: four argument registers  Caller transfers control to the callee  Callee acquires the storage resources needed  Callee performs the desired task  Callee places the result value in a place where the caller can access it l $v0 - $v1: two value registers for result values  Callee returns control to the caller l $ra: one return address register to return to the point of origin

 MIPS procedure call instruction: jalProcedureAddress#jump and link  Saves PC+4 in register $ra to link to the following instruction to set up the procedure return  Machine format:  Then can do procedure return with just jr$ra#return Instruction for Calling a Procedure op 26 bit address J format 3 ????

Spilling Registers  What if the callee needs to use more registers than allocated to argument and return values? l it uses a stack – a last-in-first-out queue low addr high addr $sp  One of the general registers, $sp, is used to address the stack (which “grows” from high address to low address) l add data onto the stack – push $sp = $sp – 4 data on stack at new $sp l remove data from the stack – pop data from stack at $sp $sp = $sp + 4 top of stack

 MIPS instruction for adding immediate values: addi$sp, $sp, 4#$sp = $sp + 4 addi$sp, $sp, -4#$sp = $sp - 4  Another version of add in which one operand is a constant where the constant is kept inside the instruction itself  MIPS pseudoinstruction for multiplying: mul$v0, $a0, $v0#$v0 = $a0 * $v0  We will look at the machine representations for these instructions in the next lecture A Quick Aside

Nested Procedures  Leaf procedures do not call other procedures. What happens to return addresses with nested procedures? int rt_1 (int i) { if (i == 0) return 0; else return rt_2(i-1); } caller:jalrt_1 next:... rt_1:bne$a0, $zero, to_2 add$v0, $zero, $zero jr$ra to_2:addi$a0, $a0, -1 jalrt_2 jr$ra rt_2:...

Nested Procedures Outcome caller:jalrt_1 next:... rt_1:bne$a0, $zero, to_2 add$v0, $zero, $zero jr$ra to_2:addi$a0, $a0, -1 jalrt_2 jr$ra rt_2:...  On the call to rt_1, the return address ( next in the caller routine) gets stored in $ra. What happens to the value in $ra (when i != 0 ) when rt_1 makes a call to rt_2 ?

Saving the Return Address  Nested procedures ( i passed in $a0, return value in $v0 ) rt_1:bne$a0, $zero, to_2 add$v0, $zero, $zero jr$ra to_2:addi$sp, $sp, -8 sw$ra, 4($sp) sw$a0, 0($sp) addi$a0, $a0, -1 jalrt_2 bk_2:lw$a0, 0($sp) lw$ra, 4($sp) addi$sp, $sp, 8 jr$ra  Save the return address (and arguments) on the stack low addr high addr  $sp $ra old TOS

Saving the Return Address, Part 1  Nested procedures ( i passed in $a0, return value in $v0 ) rt_1:bne$a0, $zero, to_2 add$v0, $zero, $zero jr$ra to_2:addi$sp, $sp, -8 sw$ra, 4($sp) sw$a0, 0($sp) addi$a0, $a0, -1 jalrt_2 bk_2:lw$a0, 0($sp) lw$ra, 4($sp) addi$sp, $sp, 8 jr$ra  Save the return address (and arguments) on the stack caller rt addr high addr  $sp low addr old $a0 $racaller rt addrbk_2 old TOS

Saving the Return Address, Part 2  Nested procedures ( i passed in $a0, return value in $v0 ) rt_1:bne$a0, $zero, to_2 add$v0, $zero, $zero jr$ra to_2:addi$sp, $sp, -8 sw$ra, 4($sp) sw$a0, 0($sp) addi$a0, $a0, -1 jalrt_2 bk_2:lw$a0, 0($sp) lw$ra, 4($sp) addi$sp, $sp, 8 jr$ra  Save the return address (and arguments) on the stack caller rt addr high addr  $sp low addr old $a0 $rabk_2caller rt addr old TOS

Compiling a Recursive Procedure  Calculating factorial: int fact (int n) { if (n < 1) return 1; else return (n * fact (n-1)); }  Recursive procedure (one that calls itself!) fact (0) = 1 fact (1) = 1 * 1 = 1 fact (2) = 2 * 1 * 1 = 2 fact (3) = 3 * 2 * 1 * 1 = 6 fact (4) = 4 * 3 * 2 * 1 * 1 =  Assume n is passed in $a0 ; result returned in $v0

Compiling a Recursive Procedure fact:addi$sp, $sp, -8#adjust stack pointer sw$ra, 4($sp)#save return address sw$a0, 0($sp)#save argument n slt$t0, $a0, 1#test for n < 1 beq$t0, $zero, L1#if n >=1, go to L1 addi$v0, $zero, 1#else return 1 in $v0 addi$sp, $sp, 8#adjust stack pointer jr$ra#return to caller L1:addi$a0, $a0, -1#n >=1, so decrement n jalfact#call fact with (n-1) #this is where fact returns bk_f:lw$a0, 0($sp)#restore argument n lw$ra, 4($sp)#restore return address addi$sp, $sp, 8#adjust stack pointer mul$v0, $a0, $v0#$v0 = n * fact(n-1) jr$ra#return to caller

A Look at the Stack for $a0 = 2  $sp $ra $a0 $v0 old TOS

A Look at the Stack for $a0 = 2, Part 1  $sp $ra $a0 $v0  $sp caller rt addr $a0 = 2 21 bk_f old TOS  Stack state after execution of first encounter with the jal instruction (second call to fact routine with $a0 now holding 1) l saved return address to caller routine (i.e., location in the main routine where first call to fact is made) on the stack saved original value of $a0 on the stack

A Look at the Stack for $a0 = 2, Part 2 $ra $a0 $v0  $sp caller rt addr $a0 = 2 10 bk_f old TOS  $sp $a0 = 1 bk_f  Stack state after execution of second encounter with the jal instruction (third call to fact routine with $a0 now holding 0) saved return address of instruction in caller routine (instruction after jal ) on the stack saved previous value of $a0 on the stack

A Look at the Stack for $a0 = 2, Part 3 $ra $a0 $v0  $sp bk_f $a0 = 1 0 old TOS  $sp $a0 = 0 bk_f $a0 = 2 caller rt addr 1  $sp  Stack state after execution of first encounter with the first jr instruction ( $v0 initialized to 1) l stack pointer updated to point to third call to fact

A Look at the Stack for $a0 = 2, Part 4 $ra $a0 $v0  $sp bk_f $a0 = 1 0 old TOS $a0 = 0 bk_f $a0 = 2 caller rt addr 1  $sp 1 bk_f 1 * 1  Stack state after execution of first encounter with the second jr instruction (return from fact routine after updating $v0 to 1 * 1) return address to caller routine ( bk_f in fact routine) restored to $ra from the stack previous value of $a0 restored from the stack l stack pointer updated to point to second call to fact

A Look at the Stack for $a0 = 2, Part 5 $ra $a0 $v0  $sp bk_f $a0 = 1 1 old TOS $a0 = 0 bk_f $a0 = 2 caller rt addr 1 * 1  $sp 2 bk_f 1 * 1 * 2  Stack state after execution of second encounter with the second jr instruction (return from fact routine after updating $v0 to 1 * 1 * 2) return address to caller routine (main routine) restored to $ra from the stack original value of $a0 restored from the stack l stack pointer updated to point to first call to fact caller rt addr

MIPS Register Convention NameRegister Number UsageShould preserve on call? $zero0the constant 0n.a. $v0 - $v12-3returned valuesno $a0 - $a34-7argumentsyes $t0 - $t78-15temporariesno $s0 - $s716-23saved valuesyes $t8 - $t924-25temporariesno $gp28global pointeryes $sp29stack pointeryes $fp30frame pointeryes $ra31return addressyes

Review: MIPS Instructions, so far CategoryInstrOp CodeExampleMeaning Arithmetic (R format) add0 and 32add $s1, $s2, $s3$s1 = $s2 + $s3 subtract0 and 34sub $s1, $s2, $s3$s1 = $s2 - $s3 Data transfer (I format) load word35lw $s1, 100($s2)$s1 = Memory($s2+100) store word43sw $s1, 100($s2)Memory($s2+100) = $s1 load byte32lb $s1, 101($s2)$s1 = Memory($s2+101) store byte40sb $s1, 101($s2)Memory($s2+101) = $s1 Cond. Branch br on equal4beq $s1, $s2, Lif ($s1==$s2) go to L br on not equal5bne $s1, $s2, Lif ($s1 !=$s2) go to L set on less than0 and 42slt $s1, $s2, $s3if ($s2<$s3) $s1=1 else $s1=0 Uncond. Jump jump2j 2500go to jump register0 and 8jr $t1go to $t1 jump and link3jal 2500go to 10000; $ra=PC+4