main () { int t = 50; while (t > 1) { if (t & 1) { t = (t * 3) + 1; } else { t = t / 2; } printf("%d ",t); } printf("STOP"); }You will find a solution to this problem in the solutions given in the fall 1996 offering of this course. Do not use that solution! Instead, use a solution that makes effective use of the output routines provided by the Hawk monitor. These routines make the above code far simpler to write than a full fledged machine problem would have been! Don't forget, calls to the Hawk system routines use R1 through R7, while they guarantee no damage to the contents of R8 and up.
(Aside: The above program fragment does terminate for every positive integer initial value of t that anyone has ever tried, but nobody has ever proven that it terminates for all positive integers.)
ADDS R1,R1,1 ADDSI R1,1Modify the code form problem 1 to detect overflow and output 'ERR!' instead of the 'STOP' the code outputs normally. Note that we declared t as being type int in the above code, so overflows involve results of 231 or more.
You may turn in one program listing incorporating problem 2 into your solution for problem 1.
struct rec { long int x; char y,z; } z[4];Part B: In terms of the above declarations and your answer to part A, translate the following nonsensical code fragment to SMAL Hawk assembly language:
for (i=0; i < 3; i++) { z[i].x = z[i+1].y + z[i+1].z; }
MACRO LOADHS =dst,=x LOADS dst,x EXTH dst,dst,x ENDMACThe problem you must solve (other than worrying about macro usage) is that the R[x] is not constrained to point to a properly aligned halfword, but may point to any byte in memory, and you must make your code fetch that byte and its successor into r[dst], sign extending the result. Full credit will depend on whether or not your code properly sets the N and Z condition codes to report on the value loaded in r[dst].
You will probably need a scratch register; the convention of using R15 for this purpose is encouraged. This problem can be solved in under 10 instrucitons. Typically, the only time you would expect to encounter non-aligned halfwords or words in a Hawk computer is when reading data that was tightly packed, for example, for storage on disk or transmission over the network.
LIL R5,#00012345 looptop: LOADHS R6,R5 BZS loopexit ADDSI R5,2 BR looptop loopexit:Present your result as a string of consecutive halfwords, in hexadecimal. You may check your result using the assembler, but you must be able to produce the values by hand -- a problem very like this problem will appear on the exam!