MCS-284 Homework 2 (Fall 1999)
Due: September 23, 1999
Do exercise 3.1 from page 197. Also, write an alternate
version of the program that only uses one branch or jump instruction
each time through the loop, rather than both a branch and a jump each
This implies that I still want there to be a loop. As such, please
don't use your math knowledge of what the loop is calculating to write
a clever version of the procedure that avoids looping at all. Your
alternate version should still be as math-dumb as the one in the book
(looping doing a bunch of adding, instead of just directly calculating
the answer), but should be smarter about the assembly language details
of exactly how it loops.
For full credit, your version should produce the same result as
the given one for all integer values of n, rather than only
when n is positive. You may use additional branch or jump
instructions, if you like, that are executed only once regardless of
how many times the loop is taken.
Do exercise 3.14 from page 200. All instructions involve at
least one memory access, namely a read of the instruction itself.
Data transfer instructions involve a second memory access, for the
data. This data access may be either a read or a write.
Write (in MIPS assembly language) a procedure named
whence, such that after calling the procedure with the
the procedure will return (to the next instruction after the
jal whence) with the
containing the address in memory where that
jal whence instruction occurs.
Instructor: Max Hailperin