Exam 2: Midterm

Solutions and Commentary

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

Grade Distributions

Exam 2

                               X
                   X           X
Mean   = 5.08      X X         X
Median = 5.0       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

Exam 1 and 2

                                         X
Mean   = 13.09                           X   X
Median = 13.5          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________
    5 . 6 . 7 . 8 . 9 . 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20

Machine Problems 1 to 4

                                       X
Mean   = 13.79                         X     X
Median = 14.5                          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__
    5 . 6 . 7 . 8 . 9 . 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20

Homework Assignments 1 to 11

                                 X
                                 X X
Mean   = 22.88                   X X     X
Median = 23.2      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 . 10. 12. 14. 16. 18. 20. 22. 24. 26. 28. 30. 32. 34

Total Scores

                                 X
Mean   = 49.75                   X     X
Median = 49.4              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______________
    20. 24. 28. 32. 36. 40. 44. 48. 52. 56. 60. 64. 68. 72. 76. 80
Scale?      D           C           B           A     

Solutions and Commentary

    mystery circuit
  1. Background: Consider this mystery circuit. It is some kind latch or flipflop. Note that is is made of parts you have studied in the notes and homework.

    a) Complete the timing diagram, assuming that the gate delay of the gates is equal to the horizontal spacing of the guide marks. in the diagram are each one gate delay in dur (0.3 points each)

    mystery circuit

    3/5 got c right, and another 3/10 got it right except for the delay of one tick. A few more had inconsistent delays or such ugly drafting that it was impossible to make out whether they understood the concept of a time delay. Only 1/25 gave nonsense answers or left the problem blank.

    3/5 got d right, and another 1/10 got it right except for the time delay. A few had inconsistent delays, while 1/10 gave nonsense answers or left it blank.

    1/5 got e right, while all but one of the remainder gave nonsense or blank answers.

    1/6 got f right, while all but a few of the remainder gave nonsense

    b) Which input is the C input?   __b_________________
    (0.3 points)

    2/3 got this right. Note that this was effectively a 2-way multiple choice question except for those who were totally baffled by logic diagram notation.

    c) Which input is the D input?   __a_________________
    (0.3 points)

    2/3 got this right. Note that this is significantly larger than the number who worked out the timing diagram. There are simple ways to look at the logic diagram and come up with good guesses based on symmetry arguments, and many students did this effectively.

    d) What level or edge on the C input allows the output to change?   __low_______________
    (0.3 points)

    Only 1/12 got this right. By far, the most common answers involved the incorrect guess that this was some kind of edge triggered flipflop, despite the fact that there is no evidence of a master or slave stage and the presence of only a single feedback loop.

  2. Background: Consider this code:
            NEG     R1,R3
            ADDSL   R3,R1,4
    

    A quick question: What does it do? ____R3_gets_R3_times_15____________________
    (0.4 points)

    2/3 got this right A few earned partial credit for giving long-winded algebraic expressions such as (R3<<4)-R3 without evaluating them in order to draw any conclusion about what the code actually accomplished. A few more earned a little credit by concluding that the code multiplied by 16, ignoring the subtraction, or by 17, ignoring the negtion. Outright wrong answers included multiplication by -17, 9, -15 and (very strangely) 11.

  3. Background: Consider this rather pathetic floating point format:
    |_|_|_|_|_|   s    -- the sign of the mantissa
    |_|___|___|   exp  -- the exponent, biased so 01 represents 0
    |s|exp|man|             and 00 means an unnormalized mantissa
                            and 11 means not a number
                  mant -- the mantissa, with a hidden bit left of
                            the point, normalized to 1 except when
                            exp = 00.
    

    For each of the following, give the answers in both binary and decimal:

    a) What is largest positive number in this number system?   _0_1_0_1_1_ ____3.5___
    (0.5 points)

    1/2 got this right. Incorrect binary to decimal conversion was the most common error, frequently involving off-by-a-factor-of-two errors. Several students gave an extra digit, without documenting whether it was an added mantissa digit or a guess at the hidden bit.

    b) What is the smallest nonzero positive number in it?         _0_0_0_0_1_ ___0.25___
    (0.5 points)

    2/5 got this right. As above, off-by-a-factor-of-two errors were very common. Among those adding an extra bit, there was great inconsistency.

    c) What is the normalized negative value closest to zero?     _1_0_1_0_0_ ___-1.0___
    (0.5 points)

    3/10 got this right. Aside from the kinds of errors mentioned above, many did not act on the requirement for a normalized number in the problem statement.

  4. A problem: Given that R3 points to a byte in the Hawk memory, write reasonably good code to: fetch the old value of the referenced byte into R4 and change the referenced byte to '*'. You may need one or two scratch registers; use R5 and up. (3 points)

            _LOADS  _R5,R3______
    
            _EXTB_  _R4,R5,R3___
    
            _LIS__  _R6,'*'_____
    
            _STUFFB _R5,R6,R3___
    
            _STORES _R5,R3______
    
            ______  ____________
    
            ______  ____________
    
            ______  ____________
    

    1/10 did perfect work here, and another 1/10 gave solutions that were almost as good, usually just one instruction longer, by duplicating the LOADS instruction. Many students solved the problem by assuming word addressing, despite the fact that the problem statement explicitly stated that a byte was being manipulated. A surprisingly common programming error involved exchanging the operands on the STORES instruction; it is hard to imagine that the students who made this error had any experience with programming on the Hawk. Others failed to take the final step and put the result back in main memory. 2/5 of the class gave answers that were total nonsense or contained so many errors that they were indistinguishable from nonsense.

  5. Background: If SYM is defined by EXT, which of the following lines of SMAL Hawk code will give an assembly error (linker errors are not an issue here) and which will not? (0.3 points each)

    a)     LIS     R3,SYM        ____ok____

    3/5 got this right. Macro expansion reduces this to B SYM

    b)     ADDI    R3,SYM        ____ok____

    2/5 got this right. Macro expansion reduces this to W SYM

    c)     CMPI    R3,SYM        ___error__

    1/2 got this right. Macro expansion reduces this to H -SYM

    d)     BR      SYM           ___error__

    1/2 got this right. Macro expansion reduces this to B .+1-SYM

    e)     LOAD    R3,R2,SYM     ____ok____

    4/5 got this right. Macro expansion reduces this to H SYM

    f) SYM:ADD     R3,R4,R5       ___error__

    7/10 got this right. This is a multiple label definition.

    g)     LIL     R3,SYM+1      ____ok____

    3/5 got this right. Macro expansion reduces this to T SYM+1

    h)     LIW     SYM           ___error__

    1/2 got this right. Macro expansion reduces this to T SYM>>8 followed by B SYM&#FF

    i)      JUMP    SYM           ___error__

    3/5 got this right. Macro expansion reduces this to W .+2-SYM

    j)      LIL     R3,SYM<<1     ___error__

    2/5 got this right. Macro expansion reduces this to T SYM<<1

    Except for part e) and f), most students appear to have been completely unprepared for this quesiton and resorted to random guessing.