No reading assignment this week. We're going to get some practice with things we've already seen.
The Fibonacci series is defined recursively as follows:
A good way to calculate a Fibonacci number Fn is as follows:
Fn, Fn1, and Fn2,
for ``Fibonacci of n,'' ``Fibonacci of n+1,''
and``Fibonacci of n+2,'' respectively.
Fn, Fn1,
and Fn2 are 0, 1, and 1, respectively.
n times:
Fn2 to Fn +
Fn1
Fn to Fn1Fn1 to Fn2Fn.
Write an assembly program to calculate Fn, for some n. Your program should:
rmb to declare variables fn,
fn1, and fn2 in memory locations
00, 01, and 02,
respectively.
fcb to place n in location
$f800.
equ to define symbols for the start of
RAM, the start of EEPROM, and the RESET interrupt vector
location.
and here's a bad example:ldaa fn1 * copy fn1... staa fn * ...into fn
ldaa fn1 * load fn1 into accumulator a staa fn * store accumulator into fn
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.