Machine Problem 2, due Sep 26

Part of the homework for 22C:60 (CS:2630), Fall 2010
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Machine problems must be turned in on line before midnight on the due date. Exceptions will only be made advance arrangement except in cases that insurance companies call "acts of God" - things outside your control.

The Problem

The Collatz Conjecture suggests that, whatever positive integer value i you start with, the following loop will always terminate with i equal to one.

        while (i != 1) {
                if (i & 1) { /* if i is odd */
                        i = (3 * i) + 1;
                } else { /* if i is even */
                        i = i / 2;
                }
		putdecu( i, 4 );
        }

Translate this to SMAL Hawk code. Your program must be a SMAL Hawk main program, with a title giving the file name (mp2.a) and your name. The code must be well formatted and well commented. Well formatted code has appropriate use of white space (tabs and blank lines) and appropriate comments (neither too few nor too many).

For the version you turn in, use an initial value of 25. You might want to experiment with other values, and for debugging, you might want to use smaller values.

Notes

putchar() and putdecu() are Hawk monitor routines.

To test to see if the value in register r is even or odd, you can use the BITTST r,0 instruction to test the least significant bit, followed by BBS (branch if bit set) or BBR (branch if bit reset).

You can multiply a value by three by repeated addition, but there is also the instruction ADDSL r,r,1 that multiplies the register r by three (you don't need to figure out why this works, at least not yet).

To divide a variable in register r by two, you can use the instruction SRU r,1

You can assemble and test your solution using

	smal mp2.a
	link mp2.o
	hawk link.o

Grading Criteria

From a maximum possible of 5 points, the following penalties will be assessed:

  1. Assembly errors, -1 for any
  2. Linker errors, -1 for any
  3. Runtime errors, -1 for any
  4. Correct output of the series of values, -1
  5. Improper title on source file, -1
  6. Poorly organized control structures, -1
  7. Poor use of white space in source code, -1
  8. Poor choice of identifiers in source code, -1

Submission Mechanism

All machine problems in this course should be submitted using the submit command on the divisional Linux system. Specifically, your solution to this assignment should be in a file called mp2.a and you should see this dialogue when you submit your work:

[yourname@serv16 hw]$ submit
... several lines of long-winded instructions ...
 File/directory name:  mp2.a
 File/directory name:
course: c_060
... several lines of long-winded instructions ...
Choice: mp2

In the above, what you should type is shown in bold face.