Assignment 4, Solutions

Part of the homework for 22C:60, Fall 2009
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

  1. Background: Suppose you wanted to load the Hawk registers so that the register display of the Hawk emulator showed the following:
            PC:  ????????                R8: 00000080
            PSW: 00000000  R1: 00000001  R9: 00000100
            NZVC: 0 0 0 0  R2: 00000002  RA: 00000200
                           R3: 00000004  RB: 00000400
                           R4: 00000008  RC: 00000800
                           R5: 00000010  RD: 00001000
                           R6: 00000020  RE: 00002000
                           R7: 00000040  RF: 00004000
    

    That is, Ri has the value 2i for all i from 1 to 15. Obviously, you could begin your code to set up these values with:

            LIS     R1,1
            LIS     R2,2
            LIS     R3,4
    

    a) The above pattern does not work for all 15 general purpose registers. What is the highest numbered register where the above pattern does work? (0.3 points)

            LIS     R7,64   ; this works
            LIS     R8,128  ; this fails (the value loaded is negative)
    

    b) Suggest at least two different ways to get the intended value into the next higher numbered register after the point where pattern breaks down. (0.4 points)

            LIL     R8,128  ; this always works
            ADD     R8,R7,R7; this works for all but the first
    

    c) How many halfwords of program does the shortest solution to this problem require to fill all of the general purpose registers from 1 to 15 with the correct values. (0.3 points)

    15 halfowords, from 1 to 7 LIS instructions followed by from 8 to 14 ADD instructions.

  2. Background: Consider this bit of SMAL Hawk code:
            .       =       0
            X:      LIL     R1,X
                    LOADS   R2,R1
    

    a) When this code is assembled, what values are placed in memory? Show the result as a sequence of 16-bit halfwords, expressed in base 16.

    Note: That this is not the way the SMAL assembler shows the results; the assembler shows the results as a mix of bytes, halfwords and three-quarter words. If you use the SMAL assembler to help solve this problem, you will have to hand-transform the result to a sequence of halfwords. (0.5 points)

    Here's an actual assembly listing

                                        1          USE     "hawk.macs"
                                        2  .       =       0
                                        3  X:      LIL     R1,X
            000000: E1  000000          4          LOADS   R2,R1
            000004: F2  D1              5  END
    

    Here's how it lands in memory as halfwords

            000000: 00E1
            000002: 0000
            000003: D1F2
    

    b) When this code runs, what value does it leave in R2? (0.5 points)

    Here's how the emulator shows the result

    HAWK EMULATOR
            /------------------CPU------------------\   /----MEMORY----\
            PC:  00000006                R8: 00000000  *000000: LIL     R1,#000000
            PSW: 00000000  R1: 00000000  R9: 00000000   000004: LOADS   R2,R1
            NZVC: 0 0 0 0  R2: 000000E1  RA: 00000000 ->000006: NOP
                           R3: 00000000  RB: 00000000   000008: NOP
                           R4: 00000000  RC: 00000000   00000A: NOP
                           R5: 00000000  RD: 00000000   00000C: NOP
                           R6: 00000000  RE: 00000000   00000E: NOP
                           R7: 00000000  RF: 00000000   000010: NOP
    

    That is, R2 = 000000E1

  3. Background: Here is the contents of part of the Hawk memory as a sequence of 32-bit words:
    000000: F463C113
    000004: E501000A
    000008: 355486A0
    

    A question: This represents a sequence of Hawk instructions. Give SMAL Hawk assembly code for this sequence of instructions. (1.0 points)

    Hint: You can actually use the Hawk emulator to help you interpret this code, if you first create a SMAL program that loads it into memory for the interpreter to interpret. However, it is recommended that you learn how to do this using the manuals.

    The Hawk emulator can disassemble this to show the code

     HAWK EMULATOR
       /------------------CPU------------------\   /----MEMORY----\
       PC:  00000000                R8: 00000000 -*000000: ADDSI   R3,#1
       PSW: 00000000  R1: 00000000  R9: 00000000   000002: STUFFH  R3,RF,R4
       NZVC: 0 0 0 0  R2: 00000000  RA: 00000000   000004: BNE     #000006
                      R3: 00000000  RB: 00000000   000006: BNS     #FFFFFFD2
                      R4: 00000000  RC: 00000000   000008: ADDSL   R0,R8,#6
                      R5: 00000000  RD: 00000000   00000A: EXTB    R4,R3,R5
                      R6: 00000000  RE: 00000000   00000C: NOP
                      R7: 00000000  RF: 00000000   00000E: NOP
    

    It looks like nonsense because the original binary contained a mistake.