Assignment 3, Solutions
Part of
the homework for 22C:60 (CS:2630), Fall 2011
|
. = 0 W 1234567890 H #02D2, #4996 W 2#01001001100101100000001011010010 W 8#11145401322 B #D2, 2, 8#226, 32#29
A Problem: Which of the above lines, if any, assemble the same value into a word of memory? (0.5 points)
They are all the same. Here is an assembly listing:
1 . = 0 00000000: 499602D2 2 W 1234567890 00000004: 02D2 4996 3 H #02D2, #4996 00000008: 499602D2 4 W 2#01001001100101100000001011010010 0000000C: 499602D2 5 W 8#11145401322 00000010: D2 02 96 49 6 B #D2, 2, 8#226, 32#29 7 ENDThere is a strong hint here, 3 lines produce exactly the same data, and two lines show scrambled versions of the same thing. Are they all the same? Yes! The listing shows bytes and halfwords from left to right, but when they are assembled into memory, they are assembled least significant byte or halfword first. This is confirmed by loading the object code and displaying the contents of the memory on the Hawk emulator:
/------------------CPU------------------\ /----MEMORY----\ PC: 00000000 R8: 00000000 -*000000: 499602D2 R I PSW: 00000000 R1: 00000000 R9: 00000000 000004: 499602D2 R I NZVC: 0 0 0 0 R2: 00000000 RA: 00000000 000008: 499602D2 R I R3: 00000000 RB: 00000000 00000C: 499602D2 R I R4: 00000000 RC: 00000000 000010: 499602D2 R INote: The assembler and Hawk emulator can be used to mechanically solve this kind of problem, but you are responsible for understanding what the assembler did. Questions such as this are completely fair exam questions, where you will be responsible for doing the work without relying on computerized assistance to solve the problem.
ASCII "Two",CR,LF,"lines",NUL
A Problem: Give SMAL definitions for the symbols CR, LF, and NUL that would make this string assemble correctly. This problem is closely related to exercise i) in Chapter 3 of the notes. (0.5 points)
The following definitions are based on the ASCII character table in Chapter 2 of the notes:
NUL = #00 ; = 000 0000 LF = #0A ; = 000 1010 = 10 CR = #0D ; = 000 1101 = 13
. = 0 A: W 0 B = . - 3 C = D + #FFFFFFFF D = A + 3 E: B 0
A Problem: What are the values of the 5 identifiers A, B, C, D and E. (0.5 points)
Assembling this with the -D assembler option produces this dump file, giving the definitions of the identifiers:
A =#00000000 B =#00000001 C =#00000002 D =#00000003 E =#00000004Alternatively, the source file can be modified so that the values are shown by the assembler:
1 . = 0 00000000: 00000000 2 A: W 0 3 B = . - 3 4 C = D + #FFFFFFFF 5 D = A + 3 00000004: 00 6 E: B 0 7 00000005: 00000000 8 W A 00000009: 00000001 9 W B 0000000D: 00000002 10 W C 00000011: 00000003 11 W D 00000015: 00000004 12 W E
DAYTABLE: W SUN W MON W TUE W WED W THU W FRI W SAT SUN: ASCII "Sunday",0 MON: ASCII "Monday",0 TUE: ASCII "Tuesday",0 WED: ASCII "Wednesday",0 THU: ASCII "Thursday",0 FRI: ASCII "Friday",0 SAT: ASCII "Saturday",0The identifiers SUN, MON etc. used above are entirely arbitrary. Stupid names like DOG or Q5P3 would have worked just as well, but they would be very poor style, from the point of view of making the code understandable.
The following wrong answer fragments, however, do not work at all:
DAYTABLE: W "Sunday" W "Monday" DAYTABLE: ASCII "Sunday",0 ASCII "Monday",0The first wrong answer above tries to cram more than 4 characters into a word, and that word ends up being the characters instead of being a pointer the text. The second version does not try to make an array of words, but simply puts the strings in memory with no way to find the start of each string except searching.
9B3716.
One way to solve this is to assemble the code:
1 USE "hawk.h" +00000000: 37 9B 2 ADD R7, R9, R11Then, pack the two bytes into a halfword to get 9B3716.
Note: The assembler and Hawk emulator can be used to mechanically solve this kind of problem, but you are responsible for understanding what the assembler did. This question could easily appear on an open-book exam, where you would have to solve it using the reference material in the Hawk manual.