CS 110 Intro to Computer Systems
Fibonacci Project - Version .98
15 Points
Due 2 November, 9pm
Introduction
Write two
assembly language
programs, each with different
subprograms that both compute the Fibonacci function.
F(n) = 0 if n = 0
F(n) = 1 if n = 1
F(n) = F(n-1)+ F(n-2) otherwise
undefined if n < 0
The first program/subprogram is to be
recursive,
following the above definition
exactly.
The second is to be
iterative, avoiding recursion entirely by
using a loop.
For each subprogram, determine the size of the stack frame
and identify the purpose of each word in the frame.
Note: depending on your implementation, this may be nothing
more than room for the registers, etc. You can determine this
information by comparing the sp and fp and
using bt of gdb.
Use script to capture the execution.
This is an exploratory exercise. You will have to go through many
cycles of
gdb
as you learn how subprograms actually execute.
Do not pass parameters in the Global registers.
Due Dates:
What to Turn-In:
-
Submit your code in the usual fashion.
-
An intro program comment that describes your
overall implementation.
-
A print out of the stack/registers at the call and return of
each subprogram (use F(3) or F(4)) with descriptions of
each stack entry if any -
Note the overlap of register sets.
Indicate them by using a value in a shared register
that is incremented in each recursive call.
Also, highlight the return addresses, stack address
and frame address, add comments to show what they are
and their relationship to each other.
You can use a highlighter or just annotate with pen/pencil.
-
We will set up times for demonstration
and grading
of your programs - probably only those that I do not understand..
Where to Turn-In:
To the plastic bin outside Professor Erlinger's office.
References:
Notes:
subprograms is an attempt to be generic about what is
being requested.
Another way to look at the exercise
is to view it as a stack trace
for
recursion vs. iteration.
Creating 2 programs with a subprogram in each
makes it easier to grade.
FAQ:
-
For the iterative Fibonacci program/subprogram, if we're supposed to work
everything into a loop, then why would we using a stack at all?
The project asks you to write a subprogram, so there's just one stack
frame for its invocation. In the iterative case, that's all you'd have.
-
How many Fibonacci numbers should we compute?
Again, you're asked for a subprogram which is passed a parameter
specifying which Fibonacci number to return. It should work for all
values.
You'll write an encapsulating
routine to test and demonstrate your subprograms;
it's enough to compute F(3) or F(4).
-
Do you want us to store variables in the subprograms in local registers, ie
%l0 or should we load them and store them from memory.
Use registers whenever you can; it's easier.
-
What are the exact commands you would like us to print for the gdb and turn
in? (If you say print the stack using bt, when do you put it in?) Also,
when can you just say call subprogram(3) in gdb?
You don't call the subprogram from gdb, you write a
program that
makes the call and then watch it using gdb.
I mean a wrapper main program that has the initial values
and makes the calls.
Part of the project is to
stop gdb at the right time(s) and explore the stack.
-
What to use for input?
Use constants to input the various values
This is an exploratory exercise. You will have to go through many
cycles of gdb as you learn how subprograms actually execute.
-
How do I print things from the stack?
The easiest way to print the stack is to use the "examine" command.
"x/8lx $sp" will print 8 longwords starting at the address currently
pointed to by the stack pointer.
We reserve the right to change the problem statement
when someone demonstrates the ambiguity of said
problem statement.
1. have them read in fib from command line.
2. have them pass parameters in the stack....
3. Change points to 15
Last modified Oct 31, 01 by mike@cs.hmc.edu