Solution to Problem 2.19.4 Recitation #1 (Week 2) ECEN350 Prof. Choi.

Slides:



Advertisements
Similar presentations
The University of Adelaide, School of Computer Science
Advertisements

Lecture 20: 11/12/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
CDA 3100 Recitation Week 8. Question 1.data A:.word 21,3,2,9,100,22,6,15,33,90.text.globl main main: la $a0, A li $a1, 17 li $a2, 10 jal funct li $v0,
Slides revised 3/25/2014 by Patrick Kelley. 2 Procedures Unlike other branching structures (loops, etc.) a Procedure has to return to where it was called.
CDA 3100 Recitation Week 15. What does the function f1 do:.data A:.word 10,21,45,8,100,15,29,12,3,19 B:.word 2,5,33,5,20,1,53,52,5,5 C:.word 6,8,5,4,5,22,53,12,33,89.text.globl.
Recursion in MIPS Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Leaf and Non-Leaf Procedures A leaf procedure is one that.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Solution 2nd Exam.
MIPS Calling Convention Chapter 2.7 Appendix A.6.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
Assembly Code Example Selection Sort.
The University of Adelaide, School of Computer Science
MIPS Function Continued
Csci136 Computer Architecture II Lab#4. - Stack and Nested Procedures
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
Fibonacci with Loop int fib1(int i) { int f1 = 1; int f2 = 1; int f3;
Recitation Material of Engineering an Assembler June 11, 2013.
.text fact: addiu $sp, $sp, -32 sw $ra, 20($sp) sw $fp, 16($sp) addiu $fp, $sp, 28 sw $a0, 0($fp) bgtz $a0, L2 li $v0, 1 b suffix L2: addi $a0, $a0,
Procedure call frame: Hold values passed to a procedure as arguments
Lecture 8: MIPS Instruction Set
B1010 Advanced Math Stuff ENGR xD52 Eric VanWyk Fall 2012.
MIPS, C, and You. Ropes struct ropeNode { char * string; // 0x0 offset struct ropeNode * next; // 0x4 offset } typedef struct ropeNode* rope; rope weave(char.
MIPS Assembly Language
MIPS Coding. Exercise – the bubble sort 5/8/2015week04-3.ppt2.
Register Conventions (1/4) °CalleR: the calling function °CalleE: the function being called °When callee returns from executing, the caller needs to know.
Intro to Computer Architecture
CSCE 212 Quiz 2 – 2/2/11 1.What is the purpose of the jal instruction? 2.What are the two conditional branching (if, goto; not the slt instruction) instructions.
1 CS 430 Computer Architecture Clap if you like pizza! Pointless Poll.
Code Optimization Witawas Srisa-an CSCE 496: Embedded Systems Design and Implementation.
Memory/Storage Architecture Lab Computer Architecture MIPS Instruction Set Architecture ( Supporting Procedures )
The Stack Pointer and the Frame Pointer (Lecture #19) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
MIPS function continued. Recursive functions So far, we have seen how to write – A simple function – A simple function that have to use the stack to save.
MIPS Calling Convention. Procedure Calls Procedure must work the same from any call Procedure uses regs that main was using We need a convention to –pass.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Recitation Material of Quiz 1 June 11, Problem 1.
MIPS Subroutines Subroutine Call – jal subname Saves RA in $31 and jumps to subroutine entry label subname Subroutine Return – jr $31 Loads PC with return.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Single Cycle CPU - Control
Computer Architecture & Operations I
Function Calls in MIPS To call a function: jal func
MIPS Assembly Language Programming
Functions and the Stack
Function Calls in MIPS To call a function: jal func
Procedures 101: There and Back Again
CSCI206 - Computer Organization & Programming
MIPS Procedures.
MIPS instructions.
Procedures (Functions)
CSCI206 - Computer Organization & Programming
What's wrong with this procedure?
CSCI206 - Computer Organization & Programming
MIPS Procedures.
Addressing in Jumps jump j Label go to Label op address 2 address
Solutions Chapter 2.
CSCI206 - Computer Organization & Programming
MIPS Functions.
MIPS Functions.
MIPS functions.
MIPS Procedures.
MIPS function continued
MIPS Functions.
MIPS function continued
Pointless Poll Clap if you like pizza!.
MIPS Functions.
MIPS function continued
MIPS Functions.
MIPS R3000 Subroutine Calls and Stack
Presentation transcript:

Solution to Problem Recitation #1 (Week 2) ECEN350 Prof. Choi

a)f(a,b,c)=func(func(a,b),c) f: addi $sp,$sp,–8 sw $ra,4($sp) sw $s0,0($sp) move $s0,$a2 jal func #v0=func($a0,$a1)=func(a,b) move $a0,$v0# $a0= func(a,b) move $a1,$s0# $a1=c jal func# v0=func($a0,$a1)=func($v0,c)=func(func(a,b),c) lw $ra,4($sp) lw $s0,0($sp) addi $sp,$sp,8 jr $ra

b) f(a,b,c)=func(a,b)+func(b,c) f: addi $sp,$sp,–12 sw $ra,8($sp) sw $s1,4($sp) sw $s0,0($sp) move $s0,$a1 move $s1,$a2 jal func# $v0=func($a0,$a1)=func(a,b) move $a0,$s0# $a0=b move $a1,$s1#$a1=c move $s0,$v0# $s0=$v0=func(a,b) jal func;#$v0=func($a0,$a1)=func(b,c) add $v0,$v0,$s0#$v0=func(a,b)+func(b,c) lw $ra,8($sp) lw $s1,4($sp) lw $s0,0($sp) addi $sp,$sp,12 jr ra