Lab 7 - Calling Conventions

CS 3410 Spring 2018


Due: Upload your implementation of the Iterative and/or Recursive Fibonacci by 11:59pm on Sunday, March 18th, 2018

Optional: If you upload your memoized version, we will run it through the auto-grader, too.

(Only the highest of the iterative, recursive, or memoized scores counts for this lab grade, but all three versions will be turned in again and graded again as part of your next project, so it is in your best interests to get feedback early on.)


Overview

In this lab you will re-visit the fibonacci programs that you worked on in a previous project.

The Fibonacci sequence is defined as follows: start with 0, 1; for the code you are implementing, the zeroth Fibonacci number is defined to be 0, and the first Fibonacci number is defined to be 1. To obtain subsequent numbers in the sequence, we take the sum of the previous two numbers in the sequence. Thus, the second number in the seqeuence is 0 + 1 = 1, and the third number in the sequence is 1 + 1 = 2. The function you implement will return the nth Fibonacci number, where the value n is an input to your function.

There are several ways to compute the Fibonacci sequence. You will implement one (optionally, more) of the methods below (please do not submit MIPS code with any form of main function).

Implement one (optionally, more) of these versions of the Fibonacci function using MIPS assembly code. They must all work on your processor in Logisim, though you will have be careful when testing to select indices whose Fibonacci number can be computed in a reasonable time.

Testing and input for Fibonacci functions

Your Fibonacci functions should follow the calling convention covered in lecture. In particular, they should get their inputs from the argument registers ($a0, $a1, etc.) and return their outputs in the result register $v0. If you want to test each function, you can create a "main" program which initializes the stack (by setting $sp and $fp to something reasonable and usable) and calls the function on an input. If you add testing code to a file, make sure to turn in a version without the testing code. Since all of your functions will follow the calling convention, you'll invoke them from your main program by loading the input registers, saving caller-saved registers if necessary, and then executing a JAL instruction.

As a reminder, don't forget to save the previous value in callee-saved registers before you use them in your function!

MIPS (subset) Assembly Syntax

The assembly syntax used by Logisim (and the interpreter) is described in the P2 spec.