Exam 1: Midterm

Solutions and Commentary

Part of the homework for CS:2630, Summer 2018
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Grade Distributions

Exam I

Mean = 4.34    X
               X   X
             X X X X X X X
  _________X_X_X_X_X_X_X_X_X_X_____X___X___X___
    0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10

Machine Problems 1 — 2

Mean = 5.05          X
                 X   X
     X         X X   X           X   X
  ___X_____X___X_X_X_X_X_X_X_X_X_X___X_X___X___
    0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10

Homework 1 — 7

                           X
Mean = 11.30               X
                           X
             X             X X X   X
             X         X   X X X   X
  _______X___X_____X___X___X_X_X___X___X_____X_
    0 . 2 . 4 . 6 . 8 . 10. 12. 14. 16. 18. 20

Total scores

               X
Mean = 20.09   X
               X         X
               X         X
               X   X   X X X
               X   X   X X X X   X
  _____X_____X_X___X___X_X_X_X_X_X_________X___
    0 . 4 . 8 . 12. 16. 20. 24. 28. 32. 36. 40

Solutions and Commentary

  1. A Problem: Fill in the following table; values in the blanks in each column derive from the given value in that column. All values in each row are derived from the given values using the same rules. (2 points)
    Bit pattern x 010101100101101110011 10010110100001
    unsigned x in decimal 43 ___22_____115___ ___75______33___
    1's complement of x _10101001101001_0001100 _0110100_1011110
    2's complement of x _1010101_11010100001101 _0110101_1011111
    x as a 1's comp. number, in decimal ___43______22_____-12___ -52 ___33___
    x as a 2's comp. number, in decimal ___43______22_____-13___ __-53___ 33
    x as an ASCII character + __SYN_______s___ ____K_______!___
    Only 3 did perfect work here, but nobody earned under 0.9 points. 3 more made only scattered clerical errors. By far the hardest, for most students, were the interpretations of the bit patterns in the one's and two's complement number systems. 12 or more students (over half the class) seems to have felt compelled to negate all of the positive values, and many also inverted the negative values. 6 were unable interpret the bit patterns as ASCII.

  2. A problem: Here is brief useless bit of SMAL code. Show what this code puts into memory in the spaces to the right; use hexadecimal, one byte per block. (2 points)
    
    .       =       0
    A       =       'b'
    B:      B       A,B,C,D
    C       =       . - B
            ALIGN   4
    D:      ASCII   "dc"
            ALIGN   4
            W       B
            H       D
    
    Address   3    2     1    0  
    000000 0404 0062
    000004 6364
    000008 0000 0000
    00000C 0004
    000010

    1 did perfect work here, 5 made no attempt to answer the question, and 6 gave answers that were utterly unconnected to the assembly language source code. The remaining answers had detectable relationships to the source code and earned partial credit.

    Very few seem to have carefully worked out the values of all of the identifiers before attempting to assemble the code. Doing so, you'd get a table like this:

        A = 'b' = #62
        B = 0
        C = 4
        D = 4
    

    The ALIGN directive causes trouble for many students. Also, many made clerical errors such as mistaking the identifier B for the ASCII value 'B'. In general, student solutions to this problem disclosed the simple fact that on the order of half the class do not understand what it is that the assembler is doing, at the fundamental level of organizing the contents of memory.

  3. a) Here is a small Hawk subroutine. By hand, assemble this code into a sequence of halfwords as stored in memory, each expressed in hexadecimal. (2 points)
    SUBR:
            LIS     R5,0
            TESTR   R3
            BZS     SUBQT
    SUBLP:
            ADD     R5,R5,R4
            ADDSI   R3,-1
            BZR     SUBLP
    SUBQT:
            JUMPS   R1
    
             scratch space         
    Address    Value    
    000000 00E5
    000002 E3F0
    000004 0302
    000006 5435
    000008 CF13
    00000A FD0A
    00000C B1F0
    00000E

    Nobody did perfectly. 4 left it blank, 9 filled in lots of values that had no obvious connection to the problem. There were a smattering of clerical errors, not surprising on problems like this, but most of those earing partial credit had difficulty with branch displacements, and most were penalized for giving the bytes in reverse order.

    b) What registers does it expect parameters in, what registers does it alter, and what does it return in what registers? Use a style appropriate for subroutine header comments. (2 points)

    __Multiply subroutine__________________________________________________
    
    __Expects R3, R4, two unsigned integers to multiply____________________
    
    __Returns R5, the product (a nonstandard place for the return values)__
    
    __Uses R3 (R4 remains unchanged)_______________________________________
    
    4 clearly understood what the code did and explained it well enough. 1 left it all blank. Among those earning partial credit, 12 failed to document or did not understand how the return value relates to the parameters, 9 did not ducument the use of R4 as a parameter, 6 stated that R1 was the return value (it is the return address, a completely different concept), 5 failed to note that R5 is the return value, and 2 failed to note the use of R3 as a parameter. In addition, 6 gave long winded descriptions of the algorithm in terms of repeated additions to R5 while decrementing R3 without any evidence that this was a multiply algorithm.

  4. Here is the inner loop from the main program for a solution to MP2:
      MAINXLP:                        ;   loop { -- per item in the row
              MOVE    R3,R8           ;     -- parameter x
              MOVE    R4,R9           ;     -- parameter y
              ADDI    R2,R2,ARSIZE
              JSR     R1,MULT         ;     prod = mult( x, y )
              ADDI    R2,R2,-ARSIZE  
                                      ;     -- parameter 1 already in R3
              LIS     R4,4            ;     -- parameter 2 field width
              ADDI    R2,R2,ARSIZE  
              LIL     R1,PUTDEC
              JSRS    R1,R1           ;     putdec( prod, 4 )
              ADDI    R2,R2,-ARSIZE
              ADDSI   R8,1            ;     x = x + 1
              CMPI    R8,10
              BLE     MAINXLP         ;   } while (x <= 10)
    

    a) Some instructions above can be deleted with no damage to the program. Cross them out. (0.5 points)

    12 did well. 2 earned no credit, 2 gave no answer. The remainder earned partial credit. Of these, three delted the pair of ADDI instructions surrounding the call to PUTDEC, two deleted the pair surrounding the call to MULT, and two deleted the LIS for the second parameter to PUTDEC. In addition, several deleted both lines crossed out in the above code but also crossed out one or both of the other ADDI instructions.

    b) What addressing mode is used on the JSR instruction? (0.5 points)

    ___PC relative_________________________________________________________
    

    10 did well, 4 earned no credit with answers that suggested that they were unfamiliar with the term addressing mode, and 1 left this blank. Among the remainder, several earned partial credit for calling this indexed addressing, and one each earned partial credit for omitting the word relative, for calling it displacement addressing, or other abuses of terminology.

    c) Why can't that addressing mode be used to call PUTDEC? (0.5 points)

    ___PUTDEC is not defined in the same source file_______________________
    

    4 did well, 12 gave answers that earned no credit, and 2 left this blank. Some earned partial credit with answers that were vague ("it's defined in another place" -- what kind of place?) or mentioned the monitor (that is "another place" but is the limitation specific to the monitor?).

    d) For what likely values of ARSIZE could we use ADDSI instead of ADDI (0.5 points)

    ___4 and 8_____________________________________________________________
    

    2 gave this answer, 4 earned no credit, and 2 left this blank. The most popular way to earn no credit was to assert that ADDSI allowed any 8-bit value. In fact, it only supports 4-bit constants. Correctly documenting the range as -8 to +8 excluding zero earned only partial credit because R2 is the activation record pointer and must remain word-aligned, and also because ARSIZE is the size of the activation record and must therefore be non-negative.