You will work on this lab individually. However, feel free to ask your neighbor for help when you are getting started.
SLIME has a text area for entering your program and a ``load'' button that loads the program into the instruction memory and pops up additional windows for interacting with the simulated SLIM. To include your program in your lab report, and save it for later use, you can use the Copy and Paste features to copy it from the web browser to Applix (or some other editor, like emacs). Conversely, if you would rather edit your program in Applix (or some other editor), you can then just Copy it and Paste it into the SLIME program text area in the web browser.
The SLIME web page also contains links to several example programs from the book. You can Copy and Paste any of these programs into SLIME's program text area in order to try it out.
As with most activities involving the mouse, this is easier shown than described. Once in lab, your lab instructor (or a neighbor) will help to get you past these hurdles.
(define power (lambda (b e) (power-product 1 b e))) (define power-product (lambda (a b e) ; returns a times b to the e power (if (= e 0) a (power-product (* a b) b (- e 1)))))
Your program should read in only the base and exponent from the user,
and should itself provide the starting value of 1 for
Note that a large result such as (power 3 32) may result in
an overflow, that is, a value that differs from the correct one by
some multiple of 232. Feel free to ignore the overflows
(also in the remaining problems).
(define power (lambda (base exponent) (if (= exponent 0) 1 (* base (power base (- exponent 1))))))
You are asked to compare the efficiency of the three different
assembly language versions of
power in exercises 11.4,
11.5, and 11.10. First, looking at each program, predict
how many instructions will get executed by each program as a function
of the exponent. Then, try experimentally verifying your predictions.
You'll find that for 11.5, it's quite challenging to find a formula
for the number of instructions when the exponent is not a power
That's OK; give a formula that
only works for powers of 2, and test your program with several such
exponents (e.g., 2, 4, 8, 16, and 32). All experimental results should be
presented in a single table or one or more graphs.
In your report, for each of the three exponentiation programs, be sure to (a) give a precise formula for the number of steps as a function of the exponent, (b) state your logic for why the formula should be the one you gave (i.e., by looking at your program), and (c) explain how your data matches or fails to match your formula (and, in the latter case, why?).
In presenting numerical data in a table, your presentation is important. Be sure that if you are comparing results of two experiments, that you place the results in the same table so the reader can easily compare the numbers.
Additional programming: The following is another recursive exponentiation procedure, more efficient than the one given above for exercise 11.10.
(define power (lambda (b e) (cond ((= e 0) 1) ((even? e) (square (power b (/ e 2)))) (else (* b (power b (- e 1)))))))Translate this into SLIM assembly language. As with exercise 11.5, you can make analysis of this program easier by limiting yourself to exponents that are powers of two.
Additional analysis: In the postlab section, we suggested making measurements with exponents of 2, 4, 8, 16, and 32, all of which are powers of two. If you use exponents that aren't powers of two, then the analysis of the program from exercise 11.5 becomes more interesting. Suppose you write a number n in binary; for example 13 would be written as 1101 because it is 1*23 + 1*22 + 0*21 + 1*20, i.e., 8+4+1. Let a(n) be the number of zeros in this binary numeral (without any extra leading zeros tacked on at the left end), so that for example a(13)=1, and let b(n) be the number of ones in the binary numeral, so for example b(13)=3. Can you make a predication regarding how the number of instructions executed by the program from exercise 11.5 can be computed as a function of a(n) and b(n), where n is the exponent? Try experimentally verifying your prediction. The same issues also apply to the additional exponentiation program from the preceding optional activity. If you wrote that program, you can analyze it the same way and check your prediction for it as well.