Machine Problem 2, due Jul. 1
The Hawk has no multiply instruction, but the Hawk monitor does have a multiply function, TIMES. Later, we'll discuss efficient multiply algorithms, but for now, ignore the multiply routine built into the monitor and consider the following recursive definition of unsigned multiplication:
0 × j = 0
1 × j = j
i × j = j/2 × i + (j – j/2) × i
The first two cases are basis cases for the computation. The final recursive case involves splitting one of the multiplicands, j in half. Since j could be odd, the two halves are not necessarily equal. One half is j/2, while the other half is j – j/2.
The instruction SRU R3,1 divides an unsigned integer, in R3, by 2, and the instruction SL R3,2 multiplies by 4. If you want to try to do a little optimization, MOVESL can be used to multiply by a power of two while moving a value from one register to another.
All code you add must be at least as readable and at about as well commented as the code distributed above and in the notes.
An absolute rule: We do not do detective work to connect printed paper copies of assignments with the person who did the work. We assemble and print all assignments as part of the grading process. If your name is not included in the title line, you will not receive any credit.
A general remark: In addition to the recursion and if-then-else constructs you are likely to incorporate into your recursive subroutine, your program will have two nested for loops in the main program, and the main program will call several monitor routines within these loops as well as making calls to your subroutine. Note that the main program is itself merely a subroutine called by the Hawk monitor, and you should write it and comment it knowing this.
Finally, note that the first midterm is July 2. Several questions on this exam will assume that you have solved this machine problem.
Programming assignments will be submitted on-line using the on-line Online Coursework Submission tool provided by the Liberal Arts Linux server cluster. The user interface for this is awful, but but it works. Your source file must be named mp2.a (the name is case-sensitive). This is the name you will type in response to the File/directory name prompt. When the submission tool prompts for Course type CS2630. Select the assignment directory mp2. Remember, this is a Linux system, file names are case sensitive.
You must submit your work using the submit command from the a CLAS Linux machine. If you make repeated submissions, only the last one will count. Submissions must be in place before midnight on the indicated day.