MCS-284 Chapter 3 Homework (Fall 2001)
When turning in a homework problem, if it is one from the book, you
should indicate the exercise number. If it is not from the book, you
should indicate the number I give with an x in it, as in 3.x1
below. These will be the reference numbers I use in reporting back
your standing on the homework.
-
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
time.
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.
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.
For an extra challenge, make sure your version should produce the same result as
the given one for all integer values of n, rather than only
when n is positive.
-
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.
-
Problem 3.x1: Write (in MIPS assembly language) a procedure named
whence
, such that after calling the procedure with the
instruction
jal whence
the procedure will return (to the next instruction after the
jal whence
) with the $v0
register
containing the address in memory where that
jal whence
instruction occurs.
Instructor: Max Hailperin