Exam 1: Midterm

Exam 1: Solutions and Commentary

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

Grade Distributions

EX1

Mean   = 4.39
Median = 3.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 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

MP1 - MP3 (added Oct. 17)

Mean = 9.35                           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_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. 11. 12. 13. 14. 15

HW1 - HW8 (added Oct. 17)

Mean = 20.32                                                  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 X
 _________X_X_______X___X_______X_X_______X_X_X_X_X_X_X_X_X_X_X_X_X_X_
   8 . 9 . 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24

Total EX1, MP1-3, HW1-8 (added Oct. 17)

Mean = 33.52                                              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_______X_X___X_X_X___X_X_X_X_X_X_X_X___X_X_X_X_X_X_X___X__
 . 10. 12. 14. 16. 18. 20. 22. 24. 26. 28. 30. 32. 34. 36. 38. 40. 42. 44. 46
               ?      DD      ?      CC      ?      BB      ?      AA      |
Approximate midterm grades

Solutions and Commentary

This exam is open book, open-notes, closed neighbor, no phones, no internet. This exam is worth 10 points so allocate 5 minutes of your time per point.

During the exam, it was obvious that a number of students did not bring much in the way of notes. On the first day of class, students were advised to bring, at the very least, the lab manual to exams, and preferably also the textbook.

  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 8-bit binary representations of the given decimal number in the indicated number system. (2 points)
    A decimal number: -63 23 -97 17 -80
    Binary absolute value: 001111110001011101100001 0001000101010000
    Signed-magnitude: 101111110001011111100001 0001000111010000
    1's complement: 110000000001011110011110 0001000110101111
    2's complement: 110000010001011110011111 0001000110110000
    naturally biased: 010000011001011100011111 1001000100110000

    18 did prfect work here, and a comparable number did well except for careless errors.

    Half the class was very confused about naturally biased numbers. For 8 bits, the bias is 128 (28/2), and either adding or subtracting this bias just flips the top bit of the 8-bit number from the 2's complement value.

    About 1/3 of the class had problems with one's complement numbers.

    About 1/3 of the class (not necessarily the same third) had difficulty with positive numbers, and proceeded to negate the positive numbers when told to show those numbers in the one's complement or two's complement representations. This is evidence of confusion between the name of the number system and the name of the negation operator in that system.

    Finally note that one example was worked for each column of the table (shown in bold face above). This worked example was supposed to help people check their answers.

  2. Here is a big part of the tribonacci code from MP2, minus most comments:
    LOOP:                           ; _for_(;;)_{_________________
            MOVE    R3,R10            
            LIS     R4,1
            LIL     R1,PUTDECU
            JSRS    R1,R1           ; ____putdecu(_trib,_1_);_____
            ADDSI   R8,1            ;
            CMPI    R8,15
            BGE     QUIT            ; ____if_(++count_>=_15)_break;_
            LIS     R3,','
            LIL     R1,PUTCHAR
            JSRS    R1,R1           ; ____putchar(_','_);_________
            ADD     R3,R10,R11
            ADD     R3,R3,R12       ; ____temp_=_trib_+_trib1_+_trib2;
            MOVE    R10,R11         ;     trib = trib1
            MOVE    R11,R12         ;     trib1 = trib2
            MOVE    R12,R3          ;     trib2 = temp
            BR      LOOP            ;
    QUIT:                           ; _}__________________________
    

    a) Fill in the comments above with well formatted C code to explain the assembly code. (0.5 points)

    About 1/8 of the class left this problem blank.

    By far the biggest problem was "well formatted C code." Hardly anyone made any effort to indent their code to make it clear which parts were a loop body.

    Many failed to name the variables. The registers used for most of the variables were given in the comments on the three move instructions. Creative naming was only required for the variable in R8, named count above.

    b) What addressing mode is used to save and restore R8? (0.5 points) _immediate?________

    This question was an error, since R8 was not saved or restored in this code. It was onl manipulated in two lines, and in each line, only two modes were used, immediate and regiter mode.

    About 1/3 of the class said immediate for full credit. A few said register, but another 1/3 said indexed addressing, which is never used with R8 in this code!

    c) What addressing mode is used in the BR instruction? (0.5 points)   _PC_relative_______

    At least 1/3 of the class got this right. The most popular wrong answer was short-indexed addressing, but a comparable number gave answers that were not addresing modes.

    d) What is the displacement on the BGE instruction? (0.5 points)      _10________________

    Perhaps 1/10 of the class got this. More gave 9, off by 1 for partial credit. For some reason, 15 was a popular answer, but many gave no number or left the question blank.

  3. 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
    D:      B       A,B,C,D
    C       =       'b'
            ALIGN   2
    B:      ASCII   "ad"
            ALIGN   4
    A       =       . - D
            W       C
            H       A
    
    Address   3    2     1    0  
    000000 0062 0408
    000004 6461
    000008 0000 0062
    00000C 0008
    000010

    Only a few did perfect work, while 1/6 of the class left the problem blank and 1/4 earned no credit for their answers. A number gave the bytes in row zero in the wrong order, many had trouble with align, and many put explicit zeros in uninitialized bytes -- the SMAL assembler definitely does not do that.

  4. 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:
            STORES  R1,R2
            ADDSI   R2,4
            TESTR   R3
            BNE     SUBQT
            ADDSI   R3,-1
            ADDSI   R4,1
            JSR     R1,SUBR
    SUBQT:
            ADDSI   R2,-4
            LOADS   PC,R2
    
             scratch space         
    Address    Value    
    000000 A  2  F  1
    000002 C 4 1 2
    000004 E 3 F 0
    000006 0 4 0 A
    000008 C F 1 3
    00000A C 1 1 4
    00000C 3 0 F 1
    00000E F F F 0
    000010 C C 1 2
    000012 D 2 F 0
    000014

    Only 1 did perfect work, while 1/5 of the class left the problem blank. Clerical errors were common, and many had difficulty with the displacement on the BNE instruction. At least 1/6 forgot the displacement halfword on the JSR instruction. Another popular error was to add a final halfword to fill out the table.

    b) What register(s) does it expect parameters in? (0.5 points) __R3__R4_________________

    This problem was fairly easy, although a few gae nonsense answers such as R1 or R2, answers that suggest a failure to understand the standard calling sequence on the Hawk. Some just listed R3.

    c) What register(s) does it alter? (0.5 points)              __R3__R4__R1__________________

    The most popular answer omitted R1 for a small penalty. The code definitely modifies R1 when it does a recursive call. Some mentioned R2, a register that is carefully restored to its original value before return.

    d) What register(s) does it return? (0.5 points)            __R3__R4______________________

    Over 1/5 earned no credit. A significant number omitted R3 after concluding (incorrectly) that the code returns a sum in R4. A surprising number suggested that R2 is a return value, suggesting again a significant misunderstanding of the standard calling sequence on the Hawk.

    e) What does it do (in one line!)? (0.5 points) __if_(R3==0)_{_R3--;_R4++_}______________

    Over 1/3 earned no credit. The code contained an error. Many read the code and did not notice the error. Had the code been correct, the answer would have been R4 = R4 + R3; R3 = 0; Many gave the first half of this answer for a small penalty.

    One category of confused answers included discussion of loops. The code is recursive, but it contains no loop.