Assignment 10, due Nov 7

Solutions

Part of the homework for CS:2630 (22C:60), Fall 2014
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

  1. Background: The macros from sparrowhawk.h that are given in mp5.h have the following problem: In some contexts, CMPI under hawk.h will produce different value in the condition codes from CMPI under sparrowhawk.h. Ultimately, this is because the Sparrowhawk macro for CMPI r,c produces the following instruction sequence:
            LIS     R1,(-c) >> 8
            ORIS    R1,(-c) & #FF
            PLUS    R1,r
    	TESTR   R1
    

    a) Which condition codes are set differently by TESTR and CMPI? (0.2 points).

    CMPI r,c is really LEACC R0,r,-c, and TESTR r is really MOVECC R0,r, so we compare how LEACC and MOVECC set the condition codes. They are identical for N and Z, but MOVECC sets V and C to zero while LEACC sets V and C from the ALU.

    b) Which of the following conditional branch instructions might behave differently after a CMPI for programs assembled with sparrowhawk.h instead of hawk.h?
    BGTU BGT BGE BCR BVR BZR BNR
    (0.4 points; -0.1 point per error).

    Here, we look at which of these test the V and C condition codes, since these are the ones that differ between the two contexts.

    BGTU depends on C, among others.
    BGT depends on V, among others.
    BGE depends on V, among others.
    BCR (which is BLTU) tests C (and nothing else).
    BVR tests V (and nothing else).

    Note, there was a typo in the manual that could have caused students to miss BCR. Therefore, no penalty is assigned to that error.

    c) What sequence of instructions should CMPI have assembled to on the Sparrowhawk in order to avoid this incompatability? (0.4 points).

            LIS     R1,(-c) >> 8
            ORIS    R1,(-c) & #FF
            ADD     R1,R1,r
    

  2. Background: Suppose the Hawk monitor supported a windowing model on the display. Instead of calling putchar(ch) to put a character into video RAM, instead you would work with windown w -- where w could be the entire video RAM, or it could be a sub-window of the display area. This would require a much more sophisticated monitor, but that is not the question here. Rather, let's just assume that the monitor.h includes the following:
    ; class window
    ; all window objects begin with a pointer to the class descriptor
    ;DESCR  =       0
                    ; windows contain many private fields
    WINSIZE =       28
    
    ; all window implementations include a descriptor as follows,
    ; each descriptor entry points to one method, called as follows
    ; uses R3 - pointer to window w.
    ;      R4 - first parameter if any, additional parameters go in R5 etc.
    WINCLEAR=	0	; w.winclear() clears window w
    WINAT	=	0	; w.winat(x,y) sets location for the next put
    WINCHAR =	0	; w.winchar(c) puts character c in the window
    

    A problem: Given the local variables W, the address of a window object, and CH, the character to output (both currently stored in the current activation record), write SMAL Hawk code to call W.winchar(CH) (0.5 points)

            LOAD    R3,R2,W         ; -- get object handle
            LOAD    R4,R2,CH        ; -- get character to print
            ADDI    R2,R2,ARSIZE
            LOADS   R1,R3           ; -- get pointer to object descriptor
            LOAD    R1,R1,WINCHAR   ; -- get address of winchar method
            JSRS    R1,R1           ; call W.winchar(CH)
            ADDI    R2,R2,-ARSIZE
    

  3. Background: Assume that the variables A, B, C, X and Y are all single-precision 32-bit floating point variables defined in the current activation record, and assume that the Hawk floating point coprocessor is already turned on and selected.

    A problem: Write Hawk code to compute Y=AX2+BX+C. (0.7 points)

            LOAD    R3,R2,A
            COSET   R3,FPA0         ; -- a0 = A
            LOAD    R3,R2,X
            COSET   R3,FPA0+FPMUL   ; -- a0 = AX
            LOAD    R4,R2,B
            COSET   R4,FPA0+FPADD   ; -- a0 = AX + B
            COSET   R3,FPA0+FPMUL   ; -- a0 = (AX + B)X
            LOAD    R3,R2,C
            COSET   R3,FPA0+FPADD   ; -- a0 = (AX + B)X + C
            COGET   R3,FPA0
            STORE   R3,R2,Y         ; y = AXX + BX + C
    

  4. Problems: Give the 32-bit IEEE floating point representation for each of the following, expressing your answers as 32-bit hex values: (0.2 points each)

    a) 0.510

    First, 0.510 = 0.12 = 1.0 × 2-1
    in IEEE format (binary): 0 01111110 00000000000000000000000
    expressed in hex: 3F000000

    b) 510

    First, 510 = 1012 = 1.012 × 22
    in IEEE format (binary): 0 10000001 01000000000000000000000
    expressed in hex: 40A00000

    c) 5010

    First, 5010 = 1100102 = 1.10012 × 25
    in IEEE format (binary): 0 10000100 10010000000000000000000
    expressed in hex: 42480000

    d) 50010

    First, 50010 = 1111101002 = 1.1111012 × 28
    in IEEE format (binary): 0 10000111 11110100000000000000000
    expressed in hex: 43FA0000