Exam 2: Midterm

Solutions and Commentary

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

Grade Distributions

Exam 2

Mean   = 4.33        X
Median = 4.1     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 Exam 1 plus Exam 2

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

Total Machine Problems 1 to 3

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

Total Homeworks 1 to 11

Mean   = 21.84                                 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____
    2 . 4 . 6 . 8 . 10. 12. 14. 16. 18. 20. 22. 24. 26. 28. 30. 32.

Overall Total Score

Mean   = 44.09                    X
Median = 46.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_________
   12. 16. 20. 24. 28. 32. 36. 40. 44. 48. 52. 56. 60. 64. 66
        F   + -   D   + -   C   + -   B   + -   A   + 

Solutions and Commentary

  1. Background: Consider the flipflop circuit given on the right. The circuit is based on the type-D negative pulse triggered latch from Homework 11, with some extra inputs, a and b.

    a) How should the extra inputs be set so that the flipflop behaves as it did in Homework 11?
     
    a = ___1__ and b = ___1__ (1 point)

    That a and b should both be one is fairly obvious, since they are added inputs to nand gates, and if you and or nand together several terms, and then add an extra term, the behavior will stay the same when the extra term is 1.

    1/3 gave this answer, 2/5 earned partial credit. The most common errors involved the b input.

    b) If a changes from the value you gave in part a), what happens the output?
     
    Q = ___1__ (0.5 points)

    Since a is an input to the nand gate with Q as its output, an input of zero forces Q to one.

    1/3 got this right.

    c) If b changes from the value you gave in part a), what happens the output?
     
    Q = ___0__ (0.5 points)

    When b goes to zero, the outputs of all 3 nand gates in the left column go to one. Assuming that a is also one, all four inputs to the right nand gate will be one, forcing Q to zero.

    1/5 got this right.

    d) Based on the above, what are appropriate names for the new inputs?
     
    a = ___S__ and b = ___R__ (1 point)

    When a is zero, it forces the output to one, so it is S, a negative logic set input. When b is zero, it forces the output to zero, so it is R, a negative logic reset input.

    1/5 got this right. 1/5 got partial credit for reversing or inverting R and S.

  2. A Problem: Here is a code fragment. What does it do? Full credit will only be offered to those who explain it in terms of material from the assignment for MP5. (2 points)
                                         Duplicate bits 2-3 of R3 in bits 0-1
            MOVE    R4,R3              ________________________________________
            SR      R4,2                 While leaving bits 2-6 unchanged and
            TRUNC   R4,2               ________________________________________
            LIS     R5,#7C               zeroing the remainder.
            AND     R3,R5              ________________________________________
            OR      R3,R4                This sets the current state of a Life
                                       ________________________________________
                                         cell from the next state, using the
                                       ________________________________________
                                         ASCII representation suggested.
    

    The first answer given here merely requires understanding the impact of the 6 instructions on the data in R3. This was worth 1.5 points. The last 0.5 point required recognizing how this related to the machine problem.

    1 gave a perfect answer and 1 more gave a good explanation that did not connect to the machine problem. Almost 1/2 earned no credit. Of those who tried to relate the code to the game of Life, most earned no credit for answers that appeared to be guesses and had nothing to do with the actual relationship. 1/4 of the answers earned partial credit by trying to expain how the code does whatever it does. Most of these answers were incomplete, but their major flaw was that they did not rise to the level of explaining what the code does, but rather, confined themselves to how it does it.

  3. Background: Bizarre market forces have led to the return of the 6-bit byte, and new digital signal processing applications have emerged that require the use of floating point representations in 6 bits. Consider the following representation:
    s = mantissa sign
    e = 3-bit exponent
    m = 3-bit mantissa
    |_|_|_|_|_|_|
    |s|  e  | m |
    
    Exponent values: 1 1 1 = not a number
    1 1 0 = +2
    1 0 0 = 0
    0 0 1 = -3
    0 0 0 = -3 (not normalized)
    0.1
    0.01
    0.001
    0.0001
    0.00001
    = 0.5
    = 0.25
    = 0.125
    = 0.0625
    = 0.03125
    Mantissa values: 1 0 = 1.10 when normalized
    1 0 = 0.10 when not normalized

    a) what is 101010 in decimal? __-0.375______________
        (0.2 points)

    Breaking the number into fields, we get 1 010 10. The leading 1 is the sign, which is negative. The exponent 010 means -2, and the mantissa (with the hidden bit added in) is 1.10 binary or 1.5 decimal. This gives -1×2-2×1.5 which is -1×1/4×1.5 which is -3/8 or -0.375

    Quickly working out the binary to decimal fraction conversion table, as suggested to the above right, is a handy way to avoid needing a calculator to do this kind of problem.

    1/3 gave the correct answer, and 1/5 gave 0.275 for partial credit (this was counted as an off-by-one error).

    b) what is 010101 in decimal? ___2.5________________
        (0.2 points)

    Breaking the number into fields, we get 0 101 01. The leading 0 is the sign, which is positive. The exponent 101 means +1, and the mantissa (with the hidden bit added in) is 1.01 binary or 1.25 decimal. This gives 1×2+1×1.25 which is 2×1.25 which is 2.5

    Over 1/3 gave the correct answer, and as many gave the bizarre value 2.2, for no credit. Many of these showed enough work to diagnose the problem: They were assuming a decimal mantissa -- an extremely odd assumption.

    c) What is the smallest nonzero
        positive value, in decimal?  ___0.03125____________
        (0.3 points)

    To solve this, we first compose the binary representation, 0 000 01, with a positive sign, the smallest exponent, and the smallest mantissa. This is 1×2-3×0.25 (note that the mantissa is not normalized), or 1/8×1/4 which is 1/32 or 2-5. The quick and dirty binary to decimal table above shows that this is 0.03125

    1/9 did well. 1/3 gave 0.625 for partial credit. This was counted as an of by one error.

    d) What is the largest
        positive value, in decimal?  ___7.0________________
        (0.3 points)

    To solve this, we first compose the binary representation, 0 110 11, with a positive sign, the largest numeric exponent, and the largest mantissa. This is 1×22×1.75 (here, the mantissa is normalized), or 4×1.75 which is 4×(7/4) or 7.

    Over 1/3 got this right, and a few earned partial credit by giving the correct binary representation and then failing to convert to decimal.

  4. A Question: Given a value in R3, write efficient SMAL Hawk code to multiply R3 by 72. You are free to use R1 as a temporary register, if you need one. (1.0 points)
            ADDSL   R3,R3,3         ; x 9
    ________________________________________________
            SL      R3,3            ; x 8
    ________________________________________________
    
    ________________________________________________
    
    ________________________________________________
    
    ________________________________________________
    
    ________________________________________________
    

    Factoring, 72 is 8 × 9. In binary, 72 is 1001000. Both of these lead quickly to the above code.

    2 gave essentially this solution. 1/3 gave solutions that required 3 instructions for a 0.1 point demerit. All of the three instruction solutions involved moving R3 to a second register and then doing the two instructions in the fast solution. 1/4 gave correct solutions involving 4 or more instructions for a 0.2 point demerit. A few students earned very little credit, making numerous errors in shift counts, apparently using random registers, and adding odd instructions.

  5. A Question: Complete the following Hawk subroutine. It was correct until someone deleted instructions from the code. The comments remain and are correct (2 points)
            SUBTITLE "blank -- initialize video RAM to blank"
    VIDEO   =       #FF000000       ; base of video interface region
    LINES   =       #0000	        ; lines field
    COLUMNS =       #0004	        ; columns field
    VDATA   =       #0100	        ; start of video data field
    
    ; activation record for blank
    ;RETAD  =       0
    ARSIZE  =       4
    
    BLANK:  ; no parameters or return values
            ; uses R3-7
            STORES  R1,R2
            LIW     R3,VIDEO        ; -- setup to address memory
            LEA     R4,R3,VDATA     ; p = &(video.vdata) -- pointer to data
            LOAD    R5,R3,LINES     ; y = video.lines
    BLINE:                          ; do {
                                                               (a)
            _LOAD___R6,R3,COLUMNS_  ;   x = video.columns
    BCOL:                           ;   do {
            ADDSI   R6,-1           ;     x = x - 1
            LIS     R7,' '
                                                               (b)
            _LOADS__R1,R4_________
            STUFFB  R1,R7,R4
                                                               (c)
            _STORES_R1,R4_________  ;     (&p) = ' ' -- video.data[y,x] = ' '
                                                               (d)
            _ADDSI__R4,1__________  ;     p = p + 1
            ADDSI   R6,-1           ;     x = x - 1 ****** CORRECTION ******
            BLE     BCOL            ;   } while (x > 0)
            ADDSI   R5,-1           ;   y = y - 1
            BLE     BLINE           ; } while (y > 0)
            LOADS   R1,R2
            JUMPS   R1              ; return
    

    First note, there was an error in the code presented. The crossed out line above belonged where it has been moved, flagged as a correction. This error was not explicitly noticed by anyone, but it may have mislead a few students into odd answers that were granted full credit because of the error.

    2/3 of the class gave correct answers to the line marked (a).

    Only 1/5 of the class gave correct answers to the line marked (b).

    Only 1/9 of the class gave correct answers to the line marked (c). Two more got partial credit for incorrect argument order. This is strong evidence that few if any students recall anything about byte addressing on the Hawk machine.

    2/3 of the class got the correct answer to the line marked (d). This was the only line where the error in the exam could lead to problems.