CS 273

Homework 4

Due Friday, February 23, 2001

No reading assignment this week. We're going to get some practice with things we've already seen.

From the Book

Not From the Book

Background

The Fibonacci series is defined recursively as follows:

A good way to calculate a Fibonacci number Fn is as follows:

  1. Maintain three variables, which we'll call Fn, Fn1, and Fn2, for ``Fibonacci of n,'' ``Fibonacci of n+1,'' and``Fibonacci of n+2,'' respectively.
  2. The initial values of Fn, Fn1, and Fn2 are 0, 1, and 1, respectively.
  3. To compute F0, you've already got the answer in Fn.
  4. To compute any other Fn, execute the following loop n times:
    1. Set Fn2 to Fn + Fn1
    2. Set Fn to Fn1
    3. Set Fn1 to Fn2
    When you've finished the loop, your result is in Fn.

Assignment (25 points)

Write an assembly program to calculate Fn, for some n. Your program should:

You may (in fact, you probably will) find it helpful to start by writing the program in some imperative high-level language of your choice, and translate that program into assembly code. But that's not an explicit part of the assignment.


Last modified: Fri Feb 16 10:55:34 MST 2001