Assignment 3, Solutions
Part of
the homework for 22C:60 (CS:2630), Fall 2011
|
USE "hawk.h" . = 0 LIS R1,1 ADDI R2,R1,1 LIL R3,3 MOVE R4,R2 ADDSI R4,2 ADD R5,R3,R2
a) If execution begins at location zero and all 6 of the above instructions are executed, what values do these instructions leave in registers? (0.5 points).
Here is the Hawk emulator display of the result of executing this code:
HAWK EMULATOR /------------------CPU------------------\ /----MEMORY----\ PC: 00000010 R8: 00000000 000004: BNS #000006 PSW: 00000000 R1: 00000001 R9: 00000000 000006: LIL R3,#000003 NZVC: 0 0 0 0 R2: 00000002 RA: 00000000 00000A: MOVE R4,R2 R3: 00000003 RB: 00000000 00000C: ADDSI R4,#2 R4: 00000004 RC: 00000000 00000E: ADD R5,R3,R2 R5: 00000005 RD: 00000000 ->000010: NOP R6: 00000000 RE: 00000000 000012: NOP R7: 00000000 RF: 00000000 000014: NOPb) Show the contents of the memory locations that hold the above code. That is, show what the assembler (plus the loader) put into RAM when the above code is assembled. (1.0 points)
Hitting the t key (toggle memory display) in the Hawk emulator shows the contents of memory in hexadecimal:
HAWK EMULATOR /------------------CPU------------------\ /----MEMORY----\ PC: 00000000 R8: 00000000 -*000000: 61F201D1 Q ra PSW: 00000000 R1: 00000000 R9: 00000000 000004: 03E30001 c NZVC: 0 0 0 0 R2: 00000000 RA: 00000000 000008: F2F40000 tr R3: 00000000 RB: 00000000 00000C: 3235C214 B52 R4: 00000000 RC: 00000000 000010: 00000000 R5: 00000000 RD: 00000000 000014: 00000000 R6: 00000000 RE: 00000000 000018: 00000000 R7: 00000000 RF: 00000000 00001C: 00000000Note: Both of the above problems are typical exam questions from the first midterm. You must learn how to do this by hand, but you can check your answers using the assembler and the Hawk emulator.
- An Exercise From The Text: Do exeercise l) from Chapter 4, at the end of the section on Memory Reference Instructions.
Translate a = (b - 64) + c to Hawk assembly code, assuming that the variables a, b and c are stored in memory at words 1000016 through 1000816 in that order.
A = #10000 ; memory addresses for variables B = #10004 ; (could just use literals) C = #10008 LIL R3,B LOADS R3,R3 ; R3 = b ADDI R3,-64 ; R3 = b - 64 LIL R4,C LOADS R4,R4 ; R4 = c ADD R3,R3,R4; R3 = (b - 64) + c LIL R4,A STORES R3,R4 ; a = (b - 64) + c
- Background: Suppose you wanted to come up with a general rule for load immediate. You could express this as a macro called LI that would automatically select the best load instruction. The following macro does this in SMAL, given appropriate values for x, y, z and w.
MACRO LI =dst, =const IF (const > x) & (const < y) LIS dst,const ELSEIF (const > z) & (const < w) LIL dst,const ELSE LIW dst,const ENDIF ENDMACA Question: Give the appropriate values for x, y, z and w. (0.5 points)
x = -129 y = 128 z = -32769 w = 32768
- A Problem: When you run the Hello World program from Chapter 5, what are the values of the registers immediately prior to the execution of the JSRS instruction that calls puts()? (0.5 points)
This problem was designed to force students to run the hawk emulator.
HAWK EMULATOR /------------------CPU------------------\ /----MEMORY----\ PC: 0000100E R8: 00000000 *001000: STORES R1,R2 PSW: 00000100 R1: 000001FA R9: 00000000 001002: LEACC R2,R2,#0004 NZVC: 0 0 0 0 R2: 00010040 RA: 00000000 001006: LIL R3,#001018 R3: 00001018 RB: 00000000 00100A: LIL R1,#0001FA R4: 00000009 RC: 00000000 ->00100E: JSRS R1,R1 R5: 00000000 RD: 00000000 001010: LEACC R2,R2,#FFFC R6: 00000000 RE: 00000000 001014: LOADS R1,R2 R7: 00000000 RF: 00000000 001016: JSRS R0,R1