Computer Science 281

Sixth Exercise Set

Purpose

Due:  Friday, April 5

Probable worth: 10 pts. each

Problem 1: Consider the following code for calculating Fibonacci numbers:

/*
	Fibonacci subroutine, iterative version
*/
   
	int fib(int a) {
   
	int previous, current, next;
	int i;
   
	if (a < 3) return 1;
	previous = 1; current = 1;
	for (i = 3; i <= a; ++i)
		{
		next = previous + current;
		previous = current;
		current = next;
		}
	return next;
}
   

Compile this into assembly language code, but do not use registers efficiently. In fact,

Call this program newfib.s. It should work with fibmain.c

 

Problem 2:Consider the program arraymain.c and array.s discussed in class (this should be Friday, March 28).

The completed program should still be called array.s, and it should work with arraymain.c