Exam 1: Midterm

Solutions and Commentaries

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

Grade Distributions

Exam 1

Mean   = 6.75             X           X X  
Median = 6.9          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_X_X_X_X_X_X_X_X_X_X___
   0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10

Homeworks 1 to 6

Mean   = 12.13                         X         X
Median = 13.3                          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_X_X_X_X_X_X_X_X_X_X_X__
   2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10 .11 .12 .13 .14 .15 .16 .17 .18

Machine Problems 1 and 2

                                            XX
                                            XX
Mean   = 8.33                               XX
Median = 9.8                                XX
                                            XX
                                        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_X_
   0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10

Total Scores

Mean   = 26.80                            X           X
Median = 28.9                         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___X_X_X_X_X_X_X_X_X_X_X___
   4 . 6 . 8 . 10. 12. 14. 16. 18. 20. 22. 24. 26. 28. 30. 32. 34. 36. 38
Midterm Grades:  F           D           C           B           A

Note regarding midterm grades: Of those who earned midterm grades of D or F, all earned less than 5 points on homework (most did only one or two assignments). Among those earning midterm grades of F, two earned no credit on machine problems, and the other two earned 5 or fewer points.

Solutions and Commentary

Note that there were two versions of the exam in order to deter cheating, solutions to both are given here where they differed.

  1. Fill in the following table; values in the blanks in each column derive from the given values in that column, all values in each row are derived from the given values using the same rules. (4 points)
    Bit Pattern x         111011   110001   001110   001101   101100   111011
    
    Unsigned decimal     ___59___ ___49___ ___14___ ___13___ ___44___ ___59___
    
    1's complement of x  _000100_ _001110_ _110001_ _110010_ _010011_ _000100_
       (binary)
    2's complement of x  _000101_ _001111_ _110010_ _110011_ _010100_ _000101_
    
    x as a 1's comp num  ___-4___ __-14___ ___14___ ___13___ __-19___ ___-4___
       (signed decimal)
    x as a 2's comp num  ___-5___ __-15___ ___14___ ___13___ __-20___ ___-5___
    
    One exam version did not include the left column above, one exam version did not include the right column above. Those columns are identical.

    20 students had perfect or near perfect scores on this problem. Among those who had problems, the 1's and 2's complement interpretations of the positive numbers 001110 and 001101 posed the greatest problem, with close to 14 students having difficulty with each. Those who earned below 3.5 points on this problem need to do intensive review of these basic concepts.

  2. Translate the following brief useless SMAL code to a sequence of bytes loaded in memory. The spaces to the right are labeled with a word and byte in word addresses; fill in the hexadecimal value that goes in that byte; leave uninitialized bytes blank. The result of assembling the first lines are given. (2 points)
        . = 0                       ||  Address    3    2    1    0
            H     #4567             ||          |----|----|----|----|
        A:  B     #23,#01           ||  000000: | 01 | 23 | 45 | 67 |
            ; solved to here        ||          |----|----|----|----|
            ALIGN 4                 ||  000004: |    |[04]|[42]|[0A]|
        B:  B     #A                ||          |----|----|----|----|
        C:  B     "B",B             ||  000008: |[00 | 0C]|[00 | 05]|
            ALIGN 2                 ||          |----|----|----|----|
        D:  H     C,#C              ||  00000C: |[02]|[04]|[05]|[08]|
            ALIGN 4                 ||          |----|----|----|----|
            B     D,C,B,A           ||  000010: |    |    |    |    |
            END                     ||          |----|----|----|----|
    
        . = 0                       ||  Address    3    2    1    0
            H     #4567             ||          |----|----|----|----|
        A:  B     #23,#01           ||  000000: | 01 | 23 | 45 | 67 |
            ; solved to here        ||          |----|----|----|----|
            ALIGN 4                 ||  000004: |    |[42]|[04]|[0A]|
        B:  B     #A                ||          |----|----|----|----|
        C:  B     B,"B"             ||  000008: |[00 | 05]|[00 | 0C]|
            ALIGN 2                 ||          |----|----|----|----|
        D:  H     #C,C              ||  00000C: |[08]|[05]|[04]|[02]|
            ALIGN 4                 ||          |----|----|----|----|
            B     A,B,C,D           ||  000010: |    |    |    |    |
            END                     ||          |----|----|----|----|
    

    Both versions of this problem are solved above. 10 students earned no credit, most giving answers where there was so much wrong that it was almost impossible to relate the values shown in memory to the assembly code from which it was purportedly derived. 4 students did perfect work, and 5 more made only the smallest of clerical errors. A total of 20 students earned more than half credit.

    Among those students who made few enough errors that diagnosis of their difficulty was possible, the most common errors involved misunderstanding of the ALIGN directive, usually by inserting many extra blank bytes in memory. Many students reversed the byte order in halfwords, and many had incorrect values for the labels.

  3. a) A small Hawk subroutine is given below to the right. Assemble this into the halfword memory locations given to the left below. The first instruction is worked for you. (1.5 points)
    
    
  4. a) A small Hawk subroutine is given below to the right. Assemble this into the halfword memory locations given to the left below. The first instruction is worked for you. (1.5 points)
        Addr:     Val        ||    .       =       #1000
        1000:  ___A2F1___    ||    ARSIZE  =       4
                             ||    FUNCT:
        1002:  ___E3F0___    ||            STORES  R1,R2
                             ||            TESTR   R3
        1004:  ___0502___    ||            BZS     FUNXT
                             ||            ADDSI   R3,-1      ;**
        1006:  ___CF13___ ** ||            ADDSI   R2,ARSIZE  ;**
                             ||            JSR     R1,FUNCT
        1008:  ___C412___ ** ||            ADDSI   R2,-ARSIZE
                             ||    FUNXT:
        100A:  ___30F1___    ||            LOADS   R1,R2
                             ||            JUMPS   R1
        100C:  ___FFF2___    ||
                             ||   
        100E:  ___CC12___    ||
                             ||   
        1010:  ___D2F1___    ||
                             ||   
        1012:  ___B1F0___    ||
    

    In the two versions of the exam, the two lines marked with stars were exchanged.

    10 earned no credit on this problem, and 5 more earned very little credit, making significant errors on every line. Nobody did perfect work, but 3 made only one significant error, and 18 earned more than half credit.

    The hardest part of this problem was the JSR instruction. Nobody noticed that this was a long instruction with a halfword displacement following the instruction word. The second hardest part of the problem was the branch displacement on the BZS instruction. Among weaker students, many made errors in binary to hexadecimal conversion.

    b) It is a subroutine. If FUNCT is called with the integer value i in R3, what value is returned? (The answer is very short.) (0.5 points)

    __zero__________________________________
    

    13 students gave this answer. 2 gave long winded answers from which it was possible to infer that the function always returns zero, earning partial credit.

  5. The following SMAL Hawk code is related to MP3, using some code (and the array A) swiped from the solution to homework 6. The array A is not given, but it is in ROM with this code and would be declared right before or after this code. The comments are correct. The program was somewhat optimized and it worked before parts of it were carefully cut out and replaced by blanks. Fill in the missing parts. (2 points)
            SUBTITLE "Heptavintimal to Binary Converter"
    ; activation record
    ;RETAD  =       0       ; return address
    SAVER8  =       4       ; saved copy of R8
    SAVER9  =       8       ; saved copy of R9
    ARSIZE  =       12
    
    HTOI:           ; expects R3 = s, a pointer to a null terminated string
                    ; returns R3 = a, the integer value of the string
                    ; may use R4-R7
          __STORES__R1,R2_________  ; -- save return address
            STORE   R8,R2,SAVER8    ; -- save R8
            STORE   R9,R2,SAVER9    ; -- save R9
            MOVE    R8,R3           ; -- from here on, R8 is s
            LIS     R3,0            ; a = 0 -- the accumulator for the value
    HTOILP:                         ; for (;;) {
            LOADS   R9,R8
            EXTB    R9,R9,R8        ;   ch = s[] -- the next char in string
            BZS     HTOIQT          ;   if (ch == '\000') break;
            TRUNC   R9,7            ;   ch = ch & 0x7F -- don't want 8-bit values
            LEA     R4,A
            ADDSL   R9,R4,2         ;   -- compute address of array element
            LOADS   R9,R9           ;   d = A[ch] -- the value of one digit
            MOVE    R4,R3           ;   -- parameter a
            LIS     R5,27           ;   -- parameter 27
          __ADDI____R2,R2,ARSIZE__  ;   ***
            LIL     R1,TIMESU
          __JSRS____R1,R1_________  ;   a = timesu( a, 27 )
          __ADDI____R2,R2,-ARSIZE_  ;   ***
          __ADD_____R3,R3,R9______  ;   a = a + d
            ADDSI   R8,1            ;   s = s + 1 -- advance to next character
            BR      HTOILP
    HTOIQT:                         ; }
            LOAD    R8,R2,SAVER8    ; -- restore R8
            LOAD    R9,R2,SAVER9    ; -- restore R9
            LOADS   R1,R2           ; -- restore return address
          __JUMPS___R1____________  ; return a
    

    There were two versions of the above that differed in the lines marked with asterisks. Only one of these lines was ommited in each version.

    7 students did perfect work here.

    The hardest lines for students were the ADDI lines used to adjust R2, pushing and popping the activation record from the stack. 15 earned no credit for these lines, and another 5 had difficulty.

    The JSRS instruction to call TIMESU was also difficult. 11 earned no credit, and another 7 had dificulty.

    3 earned no credit for the ADD instruction to accumulate the result, but 17 had trouble with it. Most used the wrong kind of add, either ADDI or ADDSI. A few used the wrong registers, evidence of difficulty reading the code.

    Subroutine entry and exit were comparable in difficulty. About 5 had serious trouble at each end of the subroutine, and 7 or 8 made errors.