Exam 3: Final

Solutions and Commentary

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

Grade Distributions

Final Exam

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

Exams 1 to 3

                  X
Mean   = 23.04    X
Median = 22.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_________
   10. 12. 14. 16. 18. 20. 22. 24. 26. 28. 30. 32. 34. 36. 38. 40

Machine Problems 1 to 6

                                X
                                X
Mean   = 17.80                  X
Median = 17.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_______
   2 . 4 . 6 . 8 . 10. 12. 14. 16. 18. 20. 22. 24. 26. 28. 30. 32

Homework 1 to 12

Mean   = 21.51
Median = 22.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_X_X_X_X_X_X_X_________
   6 . 8 . 10. 12. 14. 16. 18. 20. 22. 24. 26. 28. 30. 32. 34. 36

Homework, Top 10 out of 12

                                      X
Mean   = 20.43        X               X
Median = 21.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_______________
   6 . 8 . 10. 12. 14. 16. 18. 20. 22. 24. 26. 28. 30. 32. 34. 36

Total Scores and Grade Distribution

                      X
Mean   = 61.28        X             X
Median = 60.8         X   X     X X X               X
                    X X   X X   X X X   X X X     X X
 _________X_X_X___X_X_X___X_X_X_X_X_X_X_X_X_X_X___X_X_X_X_X___X_X___X_____
   28. 32. 36. 40. 44. 48. 52. 56. 60. 64. 68. 72. 76. 80. 84. 88. 92. 96
        D +   + -   - C   C +   + -   - B   B +   + -   - A   A +   +

Exam 3 Solutions and Commentary

  1. Background: Here is a code fragment lifted from the code for MP6 distributed to the class, with line numbers added for reference; you worked for three weeks on this assignment, and this code was discussed on exam 2, so it should be very familiar by now:
    01 INSTLIL:                        ;   case 1110 { -- LIL instruction
    02         ; here:   R3 = points to savearea->pc
    03         ;         R4 = pc -- user's
    04         ;         R5 = M[pc] -- fullword
    05         ;         R6 = ir = M[pc] -- halfword
    06         ;         R7 = op field of IR (bits 7 to 4)
    07         ;         R8 = dst field of IR (bits 3 to 0)
    08         BZS     INSTNOPE        ;     if (dst = 0) go fail
    09         MOVE    R7,R6
    10         SR      R7,8            ;     acc = ir:8-15 -- const part 1
    11         ADDSI   R4,2            ;     pc = pc + 2
    12         LOADS   R5,R4
    13         EXTH    R6,R5,R4        ;     ir = M[pc] -- const part 2
    14         ADDSI   R4,2            ;     pc = pc + 2
    15         SL      R6,16
    16         SR      R6,8
    17         OR      R7,R6           ;     acc = acc | sxt(ir << 8)
    18         ADDSL   R8,R3,2         ;     -- address of saved r[dst]
    19         STORES  R7,R8           ;     r[dst] = acc
    20         STORES  R4,R3           ;     -- save updated pc to finish job
    21         BR      INSTDONE        ;   }
    

    Consider how this would virtualize LIL R0,X for some 24-bit constant X (if the hawk.h macros permitted it; currently, it objects to R0).

    a) What does LIL R0,X do, as given here?

    (0.8 points) __Branch to Instnope____or___Fatal trap message__

    2/5 got this. 1/8 lost points for poor choice of language, for example, saying that this code calls INSTNOPE. 1/4 gave a somewhat ambiguous statement that "it fails" for partial credit. The remainder of the answers were difficult to classify and mostly earned no credit.

    b) Delete line 8, now what does LIL R0,X do?

    (0.8 points) __Nothing____or___The result is a no-op__________

    1/9 got this right. 1/5 earned partial credit by explaining step by step what happens without drawing the conclusion that the resulting virtual machine instruction does nothing. Many students earned no credit by stating that the result was some kind of error.

    c) Delete line 8 and swap lines 19 and 20, now what does LIL R0,X do?

    (0.8 points) __The result is a branch to X____________________

    Only 2 students got this. 1/6 earned partial credit with a step by step explanation leading to no conclusion. A large number concluded that the result was an error, earning no credit unless they mentioned overwriting the PC. A number concluded that there was no difference between the consequences of parts b and c.

    d) What happens if line 20 is accidentally omitted? (Here, assume lines 8 and 19 remain unchanged, abandoning the changes discussed in parts b and c).

    (0.8 points) __An infinite loop___or___Another trap on return_

    1/5 did well. 1/3 got partial credit for noting that the PC is not updated (obvious from the comments) without drawing any conclusions about the consequence. 1/7 got a little credit for noting that the result fails without saying how.

     

  2. Background: Here is a code fragment lifted from the code for MP5 distributed to the class, with line numbers added for reference:
    01 MACRO LIL =dst,=const
    02   IF TYP(const)=0
    03     IF (const > 32767) | (const < -32768)
    04       LIS   dst, (const >> 16)
    05       ORIS  dst, (const >>  8) & #FF
    06       ORIS  dst, (const      ) & #FF
    07     ELSEIF (const > 127) | (const < -128)
    08       LIS   dst, (const >> 8)
    09       ORIS  dst, (const    ) & #FF
    10     ELSE
    11       LIS   dst, const
    12     ENDIF
    13   ELSE
    14     LOAD dst,qCONSTPOOLq
    15     qLCSAVEq=.
    16     .=qCONSTPOOLq
    17     W const
    18     qCONSTPOOLq=.
    19     .=qLCSAVEq
    20   ENDIF
    21 ENDMAC
    

    a) Suppose someone writes LIL R3,#0FFFFFFF. Which line (or lines) in the above macro will raise an assembly error?

    (0.8 points) __4______________________________________________

    1/11 got this. 1/4 got half credit for saying lines 4-6 (in fact, the &#FF on lines 5 and 6 prevents any error from being reported. 1/8 included line 3, reducing their credit. The if definitely does not detect an error.

    b) Suppose someone writes LIL R3,#00000FFF. Which line (or lines) in the above will be assembled into memory?

    (0.8 points) __8-9____________________________________________

    1/3 did well, 1/5 earned various amounts of partial credit, typically by listing lines such as ELSEIF or ELSE that control what is assembled into memory but do not themselves put anything into memory. The most popular wrong answer, given by 1/7, was 4-6; evidentally these students have very limited ability to compare numbers given in different number bases.

    c) Suppose XT is an external symbol and someone writes LIL R3,XT. Which line (or lines) in the above will be assembled into memory?

    (0.8 points) __14,17__________________________________________

    Only 2 got this right, while 2/5 got more than half credit for listing lines 14-19, most of which are not assembled into memory but rather control what is assembled into memory and where. An additional 1/6 lost more points for saying 13-20. 1/7 listed just one of line 14 or 17, earning half credit.

    d) Where do the constants assembled relative to qCONSTPOOLq get put, relative to the body of the assembled code?

    (0.8 points) __Immediately after the end______________________

    1/4 got this. 1/8 said before the start (being mislead by the location of the macro definitions in MP5). 1/3 earned no credit by giving answers that were not "where ... relative to the assembled code" (things like RAM and cache).

  3. Background: The figure to the right combines elements of some kind of flipflop with elements of some kind of multiplexer. It is typical of the way these functions might combine in a real CPU.

    a) Which is the clock input?

    (0.8 points) __c______

    5/6 got this right. 1/12 said d earning half credit -- at least this is an input and it is not a data input.

    b) Is this flipflop triggered by a positive pulse, negative pulse, positive edge, or negative edge?

    (0.8 points) __+pulse_

    1/3 got this right. 1/5 got partial credit for saying postive edge, while 2/5 earned no credit for guessing negative edge.

    c) Which is the multiplexer control input?

    (0.8 points) __d______

    3/4 got this right. 1/12 got partical credit for c, at least it is an input and not a data input.

    d) Which data input is selected when the multiplexor control is zero?

    (0.8 points) __a______

    Almost 1/2 got this right. 1/4 got partial credit for saying b, at least it is a data input. Credit was reduced for giving answers incompatible with the answers already given for parts a to c. Remarkably 1/9 gave Q or Q as answers, despite the fact that these are clearly outputs.

  4. Background: Consider the following little poorly-commented subroutine:
    00 DOIT:   ; given:   R3 = n, an integer parameter
    01         ; uses:    R3,R4
    02         ; returns: Z,      a boolean result
    03         ADDI    R4,R3,-1
    04         BLT     DONE
    05         AND     R3,R4
    06 DONE:
    07         JUMPS   R1
    

    a) what is the value of the R3, R4 and the Z condition code after doit(0)

    (0.8 points) R3 = __0______ R4 = __-1____ Z = __O__

    Almost 2/3 got this right. Another 2/5 got partial credit for the value of R3 and similarly the value of R4. Most of these missed the value of the Z condition code.

    b) what is the value of the R3, R4 and the Z condition code after doit(8)

    (0.8 points) R3 = __0______ R4 = __7_____ Z = __1__

    Almost 1/3 got this right. An additional 1/2 earned partial credit for the value of R4 and similarly the Z condition code Z, typically missing R3. Only 1/7 got partial credit for getting R3 right.

    c) what is the value of the R3, R4 and the Z condition code after doit(12)

    (0.8 points) R3 = __8______ R4 = __11____ Z = __0__

    Again, almost 1/3 got this right -- scores generally were similar to part b, except that only one student got partial credit for a correct answer for R3.

    d) In general, this routine returns Z = 1 when the parameter n is

    (0.8 points) ___a positive power of 2_________________________

    1/5 got this right. 1/5 left it blank. 1/5 got no credit, saying that the Z=1 for negative values of n.

    If I had to base a final grade on just one question, this would be it.

  5. Background: Here is a macro that takes an integer argument and converts it to a word in memory in IEEE floating-point format. This macro has been tested and it works for a variety of integer values.
    01 MACRO FLOAT =x
    02   IF x > 0
    03     qNORMALIZEq 0,#96,x
    04   ELSEIF x < 0
    05     qNORMALIZEq 1,#96,-x
    06   ELSE
    07     W 0
    08   ENDIF
    09 ENDMAC
    10     
    11 MACRO qNORMALIZEq =sign, =exp, =mant
    12   IF mant >= #800000
    13     W (sign << 31) | (exp << 23) | (mant & #7FFFFF)
    14   ELSE
    15     qNORMALIZEq sign, exp - 1, mant << 1
    16   ENDIF
    17 ENDMAC
    

    a) Given line 12, it seems that anding with #7FFFFF on line 13 is guaranteed to discard part of the mantissa. What is the name for the discarded part?

    (0.8 points) __the hidden bit_________________________________

    1/2 got this right. There was some partial credit foro the 1/9 who understood that this and operation was also protecting the sign bit and exponent fields. Wrong answers included wild guesses such as overflow and remainder.

    b) Give (in base 16) the smallest positive value for which this macro fails to assemble the correct result. Hint: See line 12, but the answer is not #800000.

    (0.8 points) __#1000000_______________________________________

    1/8 got this right. 1/8 were off by one, earning more than half credit for #FFFFFF. The latter number is what you get from #800000 (the number in the hint) if you set all the less significant zero bits to one -- this actually gives the largest number for which this macro gives the correct floating point value.

    c) For values greater than or equal to your answer to part b) a different recursive call should replace that on line 15. Give it:

    (0.8 points) __qNORMALIZEq sign,exp+1,mant>>1_________________

    1/8 got this right. 1/2 got partial credit for the most obvious part, the sign parameter. 1/12 got partial credit for the exponent field, while even fewer got partial credit for the mantissa field.

    This problem seems to have been fair in the context of the extensive experience with macros from MP5, but many students were unprepared to apply macros to questions of floating point representation.

    d) The value #96 on lines 3 and 5 seems to have been pulled out of thin air. What value does it represent? Hint: See line 13, you don't need to understand biased numbers.

    (0.8 points) __The exponent 23________________________________

    1/9 got this right, and one more was off by one for good partial credit. 1/12 got partial credit for ambiguous statements about the largest exponent, making it unclear whether this was the largest exponent overall or just the largest in this context. No credit was given the 1/12 who merely converted to decimal, since the value is just as much a "value out of thin air" in decimal.

  6. Background: The following fragment of SMAL Hawk code transforms a value in R3, leaving the result there:
    01         NEG     R1,R3
    02         ADDSL   R3,R3,1
    03         ADDSL   R3,R1,4
    

    a) What is the transformation?

    (0.8 points) __times 47_______________________________________

    1/2 got this. There was very little partial credit except where the answer given could be clearly related to a single clear and consistent error. In many cases where students showed their work, multiple errors were plainly evident.

    b) If you change the shift count on line 2 to 2, what is the transformation?

    (0.8 points) __times 79_______________________________________

    2/5 got this. A few of those who got full credit on part a earned partial credit here for clerical errors.

  7. Background: Suppose I want to extract the middle 16 bits of the 32-bit integer in R3. This doesn't work.
    01         TRUNC   R3,24
    02         SR      R3,8
    

    a) This doesn't work. Why?

    (0.8 points) __The maximum count on TRUNC is 16_______________

    3/5 got this (not surprising, this is a rerun of material from an earlier exam). Partial credit was not offered here.

    b) We can fix this by replacing line 1 with SL R3,8. What change do we need to make to line 2 to complete the repair?

    (0.8 points) __SRU R3,16______________________________________

    Only 1/12 got this right, but 1/2 got partial credit for giving SR instead of SRU. There was modest partial credit for SRU with the wrong shift count.

    c) Alternatively, we can fix this by exchanging lines 1 and 2. what change to the count on the TRUNC would complete the repair?

    (0.8 points) __16_____________________________________________

    2/3 got this.