Assignment 4, due Sep 19
Part of
the homework for CS:2630 (22C:60), Fall 2014
|
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!
TITLE "mp1.a by Douglas W. Jones, Sept. 12, 2014" ; -- yet another solution to MP1 using a clever macro ; 3 MACRO RECORD =x,=y,text ; 4 IF LEN(text) > 0 ; 5 (an error was here, now fixed) W x, y, TEXT ; 6 LCSAVE = . ; 7 . = TEXT ; 8 ASCII text,0 ; 9 TEXT = . ; 10 . = LCSAVE ; 11 ELSE ; 12 W 0, 0, 0 ; 13 ENDIF ; 14 ENDMAC ; 15 ; 16 INT ARRAY ; 17 ARRAY: RECORD 1,1,"Hello" ; 18 RECORD 1,2,"World" ; 19 RECORD 1,3,"-----" ; 20 RECORD ; 21 TEXT = . ; 22 END ; 23
a) Does this code load anything in memory that differs from the data loaded by the version given in the assignment for MP1? If so, what? (0.3 points)
b) In the original code from the assignment for MP1, the programmer had to explicitly include a null terminator on every string. Here, the programmer just typed RECORD 1,1,"Hello" with no following ,0. What part of this code puts the null terminator on the string? (You can refer to parts of the code by the line numbers provided in the comments.) (0.3 points)
c) How does this code keep the text strings separated from the array of records? In the original code, all the records were given first and then the text strings were all given later. Here, they seem to be mingled. (0.4 points)
TITLE "mp1test.a by Douglas Jones, broken on Sept. 12, 2014" USE "hawk.h" ARSIZE = 4 INT MAIN S MAIN MAIN: STORES R1,R2 ADDI R2,R2,ARSIZE ; ------- start application code EXT ARRAY LIL R8,ARRAY ; R8 points to an array entry LOOP: ; do { LOADS R3,R8 ; load R3 with the X coordinate ADDI R9,R8,4 ; make R9 point to the Y coordinate *** LOADS R4,R9 ; load R4 with the Y coordinate LIL R1,PUTAT JSRS R1,R1 ; putat( X, Y ); ---- ------- ; make R9 point to the text pointer LOADS R3,R9 ; load R3 with the text pointer CMPI R3,0 BEQ DONE ; if (text == NULL) break LIL R1,PUTS JSRS R1,R1 ; puts( text ); ADDI R8,R8,12 ; make R8 point to the next array entry BR LOOP ; } until break DONE: ; ------- end application code ADDI R2,R2,-ARSIZE LOADS R1,R2 JUMPS R1 END
a) An instruction is missing, it has been replaced with ---- -------. What is it (give the opcode and operands in SMAL Hawk format). (0.5 points)
b) The instruction on the line marked with *** uses an ADDI to add 4 to the pointer in R8. Why not use an ADDSI instead? (0.5 points)
c) List all of the instructions in the above code that have 32-bit (long) formats. You don't need to list multiple occurances of each, so if the instruction GREPL is used twice, just say GREPL, don't mention the operands. (0.5 points)
d) If this program used the opcode BZS instead of BEQ, would the result be any different? Why? (0.5 points)