Computer Science 281
Second Exercise Set
Purpose
- To see how various control structures can be implemented.
Due: Wednesday, Feb. 11
- Exercise A: Write a subroutine called mid.s (and with
an entry point called mid) which accepts three integer arguments and returns
the one in the middle. Make no assumptions about the order of the
arguments (i.e., don't assume that the arguments are in order and return the
second argument). This program will be run with the program midmain.c
which can be found in ~matthews/cs281.
- Exercise B: Write a subroutine called fib.s (and with
an entry point called fib) which accepts an integer and calculates the
corresponding Fibonacci number using repetition (while/until/for). Do
not use recursion. Please note that fib(1) = fib(2) = 1, fib(3) = 2,
fib(4) = 3, and so on. This program will be run with the program
fibmain.c which can be found in ~matthews/cs281.
Some notes:
- One thing I will be looking for in these two programs is the careful and
disciplined implementation of control structures. For both consider
implementing the program first in C, get it to work, and then include the C
code as documentation.
- All programs should have adequate header documentation. At the very
least, a document line at the start of the program should have your name.
- All programs should have adequate internal documentation. Internal
documentation should explain register usage, and comments on each line (at
least at this stage of our experience with assembly language programming)
would be very appropriate.
- Use /* .... */ for multi-line comments, and ! for one line and partial
line comments
Any questions? Please ask!