CS 110, Architecture and Operating Systems
Due April 5th, 2002, at 9 PM
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
F(n) = undefined if n < 0
The first program/subprogram is to be
following the above definition
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
bt command of gdb.
script to capture the execution.
This is an exploratory exercise. You will have to go through many
as you learn how subprograms actually execute.
Do not pass parameters in the global registers.
What to submit:
- Submit your code in the usual fashion using
- Include introductory program comments that describe your
What to turn in:
On paper, turn in:
Where to turn in:
To the plastic bin outside Professor Kuenning's office.
- The word "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 for us to grade.
- What should the output look like?
See the sample (not annotated).
This shows only the recursive run.
- 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 that 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, i.e. %l0, or should we load them and store them from
Use registers whenever you can; it's easier.
- What are the exact commands you would like us to print and
turn in for the gdb run? (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 wrapper
program that makes the call, and then you watch the execution
of the wrapper using gdb. It is OK to hardwire the initial
values into the wrapper (
main) program. Part of
the project is to stop gdb at the right time(s) and explore
- What should we 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"
x/8lx $sp" will print 8 longwords
starting at the address currently pointed to by the stack
We reserve the right to change the problem statement when someone
demonstrates the ambiguity of said problem statement.
Last modified March 23, 2002 by email@example.com