Assignment 5, due Feb 22
Part of
the homework for 22C:60 (CS:2630), Spring 2013
|
On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!
; --- begin aplication code --- LIL R3,HELLO LIL R1,PUTS JSRS R1,R1 ; puts(HELLO) ; --- end aplication code ---
In class, the following alternative code was given that works equally well:
; --- begin aplication code --- LIL R3,HELLO LIL R4,PUTS LIL R1,RET JUMPS R4 ; puts(HELLO) RET: ; --- end aplication code ---
A Problem: Define a macro called MYJSRS that uses the combination of LIL and JUMPS that was given in class, so that this code would work:
; --- begin aplication code --- LIL R3,HELLO LIL R4,PUTS MYJSRS R1,R4 ; puts(HELLO) ; --- end aplication code ---
Feel free to test your result, but all you need to turn in is the 4 lines of SMAL code that define the macro. Handwriting is good enough, if it is legible. (0.5 point)
You can take for granted the fact that the instruction SR R5,1 will divide the value stored R5 by 2, and this works for any register,
A Problem: Write SMAL Hawk code to output an x at approximately the center of the screen. This will require calls to two monitor routines. One to set the screen coordinates and one to output the character. This takes a total of about 7 machine instructions, excluding the 'boilerplate' code from the main program. Turn in just those 7 instructions (legible handwriting is good enough), but you are free to substitute your code into the Hello World program in order to test it. (0.7 point)
A Problem: Give the binary code for these two instrucitons. (0.8 points, 0.4 each)
Suggestion: Do it by hand first! Then check your work by assembling the code.
if (a < b) { c = a; a = b; b = c; }
A Problem: Give an equivalent fragment of SMAL Hawk code, assuming that the variable a is R3, b is R4, and c is R5. this code takes about 5 machine instructions. (0.5 points)
a) One feature has to do with the addressing mode. What are the two alternatives? (0.3 points)
b) What is the other feature? What are the two alternatives? (0.2 points)