.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,

Slides:



Advertisements
Similar presentations
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,
Advertisements

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.
5Z032 Processor Design SPIM, a MIPS simulator Henk Corporaal
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.
The University of Adelaide, School of Computer Science
SPIM and MIPS programming
Syscall in MIPS Xinhui Hu Yuan Wang.
MIPS Function Continued
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
Ch. 8 Functions.
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.
PCSpim Introduction. Register contentProgramMemory contentMessage.
Writing an Embedded Controller. It usually consists of two parts – Initialization – A main loop Experience: – The main loop usually has to deal with many.
B1010 Advanced Math Stuff ENGR xD52 Eric VanWyk Fall 2012.
ECE 0142 Recitation #5.
Solution to Problem Recitation #1 (Week 2) ECEN350 Prof. Choi.
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
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 Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
20/06/2015CSE1303 Part B lecture notes 1 Functions, part 2 Lecture B15 Lecture notes, section B15.
Intro to Computer Architecture
Lecture 5: Procedures. Function call book-keeping in C main() { int i,j,k,m;... i = mult(j,k);... m = mult(i,i);... } /* really dumb mult function */
Slides revised 3/25/2014 by Patrick Kelley. 2 Procedures Higher Level languages have adopted a standard Referred to as C-style calling Uses the stack.
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.
Procedures 2a MIPS code examples Making Use of a Stack.
In Class Execise. .data A:.word 0,1,2,3,4,5,6,7,8,9.text.globl main main: la $a0,A li $a1,6 li $a2,5 jal onUpStream done: li $v0, 10# exit syscall onUpStream:
OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 1CS 116 Fall 2003 Not quite finished Creating.
Procedure Basics Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Procedure Support From previous study of high-level languages,
Runtime Stack Computer Organization I 1 November 2009 © McQuain, Feng & Ribbens MIPS Memory Organization In addition to memory for static.
Subroutines, parameters and the stack Bryan Duggan.
Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1.
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.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Function Calls in Assembly MIPS R3000 Language (extensive use of stack) Updated 7/11/2013.
Function Calls in MIPS To call a function: jal func
CSCI206 - Computer Organization & Programming
MIPS Assembly Language Programming
Writing an Embedded Controller
MIPS Procedures.
MIPS instructions.
Procedures (Functions)
Pseudo instructions.
CSCI206 - Computer Organization & Programming
CSCI206 - Computer Organization & Programming
What's wrong with this procedure?
SPIM Syscalls.
MIPS Procedures.
MIPS Functions.
CSCI206 - Computer Organization & Programming
Pseudo instructions.
MIPS Functions.
MIPS functions.
MIPS Procedures.
MIPS function continued
Компьютерийн зохион байгуулалт, ассемблер CS201
MIPS Functions.
Program and memory layout
MIPS function continued
Writing an Embedded Controller
MIPS Functions.
MIPS function continued
MIPS Functions.
PROF. JOHN ABRAHAM UTRGV
Presentation transcript:

.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, -1 # or addiu ? jal fact # fact(n-1) now in $v0 lw $t0, 0($fp) # pick up n mul $v0, $v0, $t0 suffix: # note: return value must be already set in $v0 lw $fp, 16($sp) lw $ra, 20($sp) addiu $sp, $sp, 32 jr $ra

main: addiu $sp, $sp, -4 # minimum prolog sw $ra, 0($sp) # print a prompt li $v0, 4 la $a0, prompt syscall # read a number li $v0, 5 syscall move $a0, $v0 # compute its factorial jal fact # print the factorial move $a0, $v0 li $v0, 1 syscall lw $ra, 0($sp) # minimum epilog addiu $sp, $sp, 4 jr $ra.data prompt:.asciiz "Enter a small number\n" outputLabel:.asciiz "The factorial is " newline:.asciiz "\n"