CS 0447 – Lab 3: Functions
In this lab, you will write a two implementations of calculating the nth Fibonacci number:
fib(n)=fib(n-1)+fib(n-2).
fib(0)=fib(1)=1
Write a program that reads in an integer from the user and prints out the answer twice:
Note that for large n, you may run out of stack space in the naïve recursive implementation.
Functions must comply with MIPS calling conventions, such as:
• Pass the parameter via the $a0 register.
• Put the return value in the $v0 register.
• Save registers on the stack as necessary (i.e., if your function uses any $s0-$s7 registers, it should save and restore the used registers using a prologue/epilogue).
• Save $ra on the stack, if the function is a non-leaf function.
During your assigned recitation on June 26 or June 28, show the TA: