| Assignment 10, Solutions
    
     Part of 
      
      the homework for 22C:60 (CS:2630), Spring 2013
      
     
      | 
A Problem: Write a Hawk subroutine that accepts the following parameters:
Do this without calling PUTAT or PUTCHAR or other Hawk output routines. You are free to call multiplication or division routines in the hawk monitor, if you need them. Your goal is to go straight to the Hawk's I/O hardware, bypassing the Hawk monitor for I/O. (2 points)
Note: This is not a machine problem, but you are welcome to test your work. We will only grade your code, we will not try to run it. We will be mercyless in grading unreadable or illegible code.
; activation record for PLOT
;RETAD  =       0
R8SV    =       4
R9SV    =       8
R10SV   =       12
ARSIZE  =       16
PLOT:   ; expects R3 = char
        ;         R4 = x
        ;         R5 = y
        ; uses    R6 = temp for addressing
        STORES  R1,R2
        STORE   R8,R2,R8SV
        STORE   R9,R2,R9SV
        STORE   R10,R2,R10SV
        MOVE    R8,R3           ; -- set ch aside
        MOVE    R9,R4           ; -- set x aside
        LIW     R10,#FF000000   ; -- set up pointer to display interface
        LOAD    R4,R10,#0004    ; -- parameter columns in R4
                                ; -- parameter y is already in R5
        ADDI    R2,R2,ARSIZE
        LIL     R1,TIMES
        JSRS    R1,R1           ; R3 = y*columns
        ADDI    R2,R2,-ARSIZE
        ADD     R3,R3,R9        ; R3 = x + y*columns
        LEA     R4,R10,#0100    ; -- get display base address
        ADD     R3,R3,R4        ; R3 = base + x + y*columns
        LOADS   R4,R3
        STUFFB  R4,R8,R3
        STORES  R4,R3           ; M[R3] = ch
        LOAD    R10,R2,R10SV
        LOAD    R9,R2,R9SV
        LOAD    R8,R2,R8SV
        LOADS   R1,R2
        JUMPS   R1              ; return
try {
   if (b == 0) throw;
   a = b;
} catch {
   a = -a;
}
A Problem: Write equivalent SMAL Hawk code. (1 point)
Assume all the variables mentioned are local variables (any other reasonable assumption is OK, since this is a question about control structures).
; try { LOADCC R3,B BZS HANDLER ; if (b == 0) throw LOAD R3,B ; -- this line is optional STORE R3,A ; a = b BR ENDTRY HANDLER: ; } catch { LOAD R3,A NEG R3,R3 STORE R3,A ; a = -a ENDTRY: ; }Note that all the complex mechanisms from the notes and from the lecture are irrelevant to this problem because the try clause calls no subroutines and the handler is local to the same subroutine as the try clause.