CS 110: Elements of Computing. Instructor: Jim Aspnes


Homework Three Solutions

Due Friday, October 4th, 2002, at 5:00pm.

Original assignment.

Your task

  1. Do problem 6 from page 100 of Brookshear.
  2. Do problem 9 from page 100 of Brookshear.
  3. Using the Random Access Language described in Chapter 17 of Dewdney, write a program that writes 0 into memory locations 0 through 1,000,000 and then halts (by executing the HLT instruction). You may use any higher memory locations you like to store extra data needed by your program. If you need to assume that these other locations contain specific values when your program starts, explain what locations start with what values; however, you should not make any assumptions about the contents of locations 0 through 1,000,000, which may be arbitrary. You should write any numbers that appear in your program in the usual decimal notation (you don't need to bother with hexadecimal or binary for this problem). You are encouraged to explain how your program works.

    Hint: it may be easiest to start at the top.

Submitting your solution

Write up an email message containing your full name and the answer to these problems in plain text format (this means no HTML or Microsoft word documents), and send it to aspnes+110-02-3@cs.yale.edu. (Note: this is not the same email address as for previous homework.)

Solution:

  1. Below, ``contents'' means the contents of the memory cell at location 3B.
  2. Here is a short program that does the job. It assumes that location 1,000,001 is initialized to 1; location 1,000,002 is initialized to 1,000,000; and location 1,000,003 is initialized to 0. Lines 0 and 1 copy 0 to the location pointed to by 1,000,002; lines 2-4 decrement location 1,000,002; lines 5-6 test if the loop should continue. Since the loop terminates before writing 0 to location 0, line 7 cleans up by writing 0 to location 0 (since the accumulator just happens to be 0 at this point).
    0: LDA 1,000,003
    1: STI 1,000,002
    2: LDA 1,000,002
    3: SUB 1,000,001
    4: STA 1,000,002
    5: JMZ 7
    6: JMP 0
    7: STA 0
    8: HLT
    

Clarifications

Last problem

For the last problem, you must submit every line of your program. Absurdly long programs (e.g. ones that contain a million STA instructions) are strongly discouraged.


Fri 20 Dec 2002 16:31:36 EST hw3.solutions.tyx Copyright © 2002 by Jim Aspnes