CS 0447 – Lab 3: Functions

Description

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:

  1. Once from the return value of a recursive function and
  2. Once from a function that computes it iteratively (use two variables to hold the previous two terms and generate the next from them).

Note that for large n, you may run out of stack space in the naïve recursive implementation.

Requirements

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.

What to Demo

During your assigned recitation on June 26 or June 28, show the TA: