CSE 30 -- Lecture 11 -- Nov 5


Assignment 4

Write MIPS code to compute the following function:
int fab(int n)	/* assume n >= 0 */
{
	switch (n) {
	case 0: return 0;
	case 1: return 0;
	case 2: return 1;
	default:
		return 3 * fab(n-1) + 2 * fab(n-2) + fab(n-3);
	}
}
This is equivalently defined as:
fab(0) = fab(1) = 0;
fab(2) = 1;
fab(n+3) = 3 fab(n+2) + 2 fab(n+1) + fab(n);
This program must be implemented using the naive recursive algorithm. The exact control structure that you use, however, is up to you, i.e., you can use a series of if statements or use the switch as above. Efficiency matters. As usual, you must follow the standard register usage convention. Assume that you're coding for an R2000.

You must write your own driver to test out this code. Feel free to adapt the driver from assignment 3. Your turn in should have the function and the driver as separate files: fab.mips and driver.mips. If you have multiple test drivers, name them driver1.mips, driver2.mips, etc.

Lecture

I went over the Fibonacci function as an example of how to do recursion.

I went over jump tables and the translation of the switch statement. See p129 in your text. I also went over using table lookups for speeding up functions with small domains.


[ search CSE | CSE home | bsy's home page | webster i/f | yahoo | hotbot | lycos | altavista ]
picture of bsy

bsy+www@cs.ucsd.edu, last updated Mon Nov 30 21:53:16 PST 1998.

email bsy & tutors


Don't make me hand over my privacy keys!