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.
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.
bsy+www@cs.ucsd.edu, last updated