Assignment 5, due Sept. 25
Part of
the homework for 22C:60, Fall 2009
|
A problem: Take the framework of an empty SMAL Hawk program and fill in code to make it plot an asterisk as close to the center of the available output area as you can. Turn in clean readable source code with appropriate comments. (1.2 points)
Note. You need not run the above code, and if it is correct and readable, you could get full credit for a handwritten submission. You may opt to use the computer to check your syntax and to see how your code works. If you do, note that you can resize the terminal window before you start the Hawk emulator, and it will work in that new size, but you should not resize the window while the emulator is running.
S START USE "hawk.macs" USE "monitor.h" EXT UNUSED START: ; begin execution here LIL R2,UNUSED ; set up the stack ; --- begin aplication code LIL R1,DSPINI JSRS R1,R1 ; initialize the display SR R3,1 ; divide X (width) by 2 SR R4,1 ; divide Y (height) by 2 LIL R1,DSPAT JSRS R1,R1 ; call dspat(X,Y) LIS R3,'*' LIL R1,DSPCH JSRS R1,R1 ; call dspch('*') ; --- end aplication code LIL R1,EXIT JSRS R1,R1 ; call monitor routine to stop! END
USE "hawk.macs" S START . = #10000 START: LEA R1,NEXT LOADS R2,R1 ADDSI R1,4 NEXT: STORES R2,R1 ADDSI R1,4
a) What value does this program load in R2 and what does this value represent? (0.4 points)
It loads C411A1F216.
This is the assembled code for the two instruction sequence STORES R2,R1 followed by ADDSI R1,4 that is loaded from the memory location with the label NEXT.
b) Where does the STORES instruction store this value? (0.4 points)
In the location immediately followint the ADDSI at the end of the program.
c) What does this program do? (0.4 points)
Hint: You can actually use the Hawk emulator to help you with this, but you will do better in the long run if you try to figure out the code using only manuals and then use the emulator to check your understanding.
Each time it executes a STORES instruction, it adds another pair of instructions to the end of the program, STORES R2,R1 followed by ADDSI R1,4. The purpose of the ADDSI is to move the address used by the next STORES forward one word, so the program keeps growing.
MOVECC R2,R1 ; copy and test the value BGE ITSPOS ; if value was negative SUB R2,R0,R2; negate R2 ITSPOS: ; now R2 = |R1|