Assignment 3, due Sep 12Solutions
Part of
the homework for CS:2630 (22C:60), Fall 2014
|
B #D5 B #EF B #E4 T #654321 B #33 B #54
a) Write a sequence of SMAL H (halfword) directives that loads the same data in memory. The tricky part here is the order of the bytes in a halfword. (0.5 points)
H #EFD5 H #12E4 H #6543 H #5433There is only one acceptable answer here, although variations involving putting comma separated operands on one line only mildly violate the spirit of the assignment.
b) Write a sequence of SMAL W (word) directives that loads the same data in memory. The tricky part here is the order of the halfwords in a word. (0.5 points)
W #12E4EFD5 W #54336543As above, there is only one acceptable answer here.
c) Write a sequence of SMAL Hawk machine instructions equivalent to the above. The instructions you need are all discussed in the early part of Chapter 4. (0.5 points)
LIS R5,#EF ; or LIS R5,-#11 or LIS R5,#FFFFFFEF LIL R4,#654321 ADD R3,R5,R4The code given is the most obvious, but if you assemble it, you get an assembly error because #EF is expressed as a positive integer which is outside the range -128 to +127. Nonetheless, it produces the correct object code so it is acceptable. The version in the comments avoids this error message. In fact, you could have used other number bases here, so -17 would work too.
d) If the Hawk CPU executed this sequence of machine instructions, what if any registers would be changed, and how would they change. (0.5 points)
Register 5 changes to FFFFFFEF16 as a result of the LIS.
Register 4 changes to 0065432116 as a result of the LIL.
Register 3 changes to 0065431016 as a result of the ADD.
Suggestion: You can gain some insight by assembling the SMAL code given above and then (without linking) running the Hawk processor on this code. Do not hit the r key to make the Hawk run, but rather, hit the s key to make it execute just one instruction at a time, and watch how things change as you do so.
LIS R3,'a' LIL R4,#FFFF0001 ;or LIL R4,#FF0001 ORIS R4,#08 STORES R3,R4Note that USE "hawk.h" is required to assemble this, but it is not required as part of the answer to the assignment.
Note that as with the LIS in the previous problem, there is a version that causes an assembly error but generates the correct object code despite this error. For this problem, both are acceptable.
If someone gave the hexadecimal code for ASCII 'a', that would work but it is silly and worth a small penalty. As a rule, you should let the assembler translate human readable code when it is able to do so.
Finally, when you run this code, you get this output. Note the extra at-signs! The assignment asked you to change the byte at address #FF000108, but because you had to use a STORES to do this, your code also changed the contents of the next 3 consecutive memory locations. Later, we will learn how to change just one byte, but for now, this is the best we can do.
HAWK EMULATOR /------------------CPU------------------\ /----MEMORY----\ PC: 0000000A R8: 00000000 *000000: LIS R3,#61 PSW: 00000000 R1: 00000000 R9: 00000000 000002: LIL R4,#FF0001 NZVC: 0 0 0 0 R2: 00000000 RA: 00000000 000006: ORIS R4,#08 R3: 00000061 RB: 00000000 000008: STORES R3,R4 R4: FF000108 RC: 00000000 ->00000A: NOP R5: 00000000 RD: 00000000 00000C: NOP R6: 00000000 RE: 00000000 00000E: NOP R7: 00000000 RF: 00000000 000010: NOP **HALTED** r(run) s(step) q(quit) ?(help) a@@@
Suggestion: You can gain some insight by assembling your SMAL code (using the "hawk.h" include file), and then (without linking) running the Hawk processor on this code. Do not hit the r key to make the Hawk run, but rather, hit the s key to make it execute just one instruction at a time, and watch how things change as you do so. Note that the hexadecimal address used for this problem is in the I/O part of the Hawk memory.