Homework Assignment 2
MCS-178: Introduction to Computer Science II
Max Hailperin, Fall 2001; Due: October 5th
Remember: You are encouraged to turn in individual
problems as soon as possible, rather than turning in the whole
assignment on the due date. Please mark each problem with the exercise
number from the book.
Exercises 11.21-11.23 below call for procedures that modify a given
vector. Each of these procedures takes a vector as an argument (as
well as, in some cases, other arguments). The procedure should modify
this vector, not create a new one. It doesn't matter what value the
- Do exercise 11.1 on page 344. You can print and use either of the
following two versions of figure 11.5: a PostScript version or a PDF version.
There is no need to allocate register names.
You may want to test out your code in SLIME.
- Do exercise 11.17 on page 372.
- For part (a) two opcodes can
be eliminated; show how to rewrite each instruction using one of the
eliminated opcodes in terms
of a non-eliminated opcode.
- For part (b) all but one opcode can be eliminated. To argue an
individual opcode can be eliminated,
give specific code fragments showing how an instruction using it can be rewritten in terms
of any uneliminated opcodes. For example, assuming we have an
otherwise unused register
tmp at our disposal, we can start by
sne s, a, b
can be replaced by the sequence of instructions:
seq s, a, b
li tmp, 1
sub s, tmp, s
or with the sequence of instructions:
sub, s, a, b
li tmp, done-label
jeqz s, tmp
li s, 1
Remember, that the instruction you are replacing
could appear anywhere in a larger program, so (for example) your
proposed replacement should not
halt. (See how few auxiliary
tmp you can get away with.)
To make DrScheme display vectors in the standard Scheme way, you can evaluate
the following expression in DrScheme:
This will, for example, make a vector of length four containing four
zeros print out as
#(0 0 0 0)
- Do exercise 11.21 on page 373
- Do exercise 11.22 on page 373
- Do exercise 11.23 on page 373-374.