Exam 2: Midterm

Solutions and Commentary

Part of the homework for 22C:60, Fall 2004
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Grade Distributions

Exam II

MEAN   = 4.99           X
MEDIAN = 4.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_____
     0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10
            D       C       B       A

Sum of Exams I and II

                                          X
MEAN   = 13.34                            X     X
MEDIAN = 13.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_X_X_X_X_X_X___X_X_X___X_X_X_X_X___X____
     4 . 5 . 6 . 7 . 8 . 9 . 10. 11. 12. 13. 14. 15. 16. 17. 18

Machine Problems 1-4

                                      X   X    
MEAN   = 14.43              X         X   X    
MEDIAN = 15.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__
     0 . 2 . 4 . 6 . 8 . 10. 12. 14. 16. 18. 20

Homework Assignments 1-11

                            X
MEAN   = 23.21              X
MEDIAN = 23.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___
     10. 12. 14. 16. 18. 20. 22. 24. 26. 28. 30. 32

Overall

                         X           X
MEAN   = 50.75           X   X   X X X
MEDIAN = 51.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_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
             F        D        C        B        A

Exam Questions and Solutions

  1. Here is a bit of stupid Hawk code:
    	LIW     R1,#01234567
    	LIW     R2,#12345678
    	LIW     R3,#23456789
    	LIW     R4,#3456789A
    	LIW     R5,#456789AB
    	LIW     R6,#56789ABC
    	STUFFB  R1,R2,R3
    	EXTB    R4,R5,R6
    
    What registers are changed by the last two lines, and what are their new values? (2 points)
    	Register   New Value
    
    	__R1__     ___01237867______________
    
    	__R4__     ___000000AB______________
    

    10 did perfectly here, while only one earned no credit at all.

    About half the class substituted some value into the wrong byte of R1. About 1/3 of the class substituted the wrong byte of R2 into R1. About 1/4 of the class used some register other than R1.

    About 1/3 of the class did not sign extend or zero out the high bits of R4 (either sign extension or zero were taken as correct for this exam). About 1/3 of the class did not extract the correct byte from R5.

    About 1/5 of the class used 4-bits (one hex digit) as a byte.

  2. Consider this Hawk program fragment:
    	; R3 (x), R4 (y) and R8 (z) are 2's complement fixed point numbers
    	;    All have 24-bit integer parts 8-bit fractional parts
    		LOAD    R1,PMUL
    		JSRS    R1,R1           ; R3 = x * y
    
    		_SR_____R3,8______
    
    		_ADD____R3,R3,R8__      ; R3 = x * y + z
    

    a) Fill in the code it takes to put x * y + z in R3. There are two possibly answers; for full credit, give the answer that minimizes the likelihood of overflow in the result. (1 point)

    1/4 of the class got full credit for part one of this question, and a few more had answers that were good, except that they had the alternative answer that retained a 16-bit fraction and had a higher chance of overflow during the final addition as a result. 1/8 of the class earned no creditx.

    1/3 of the class had serious problems with the shift instruction, omitting it or using the wrong shift count.

    b) How many bits are in the fractional part of R3 after your code? (1 point) _8_______

    1/3 of the class got this right, in the context of their answer to part A, while 1/4 of the class had it entirely wrong. Partial credit was rare.

  3. Consider the following logic circuit:

    mux-based circuit with feedback

    mux-based circuit with feedback
    a) The above circuit can be built from a 2-input multiplexor and a few additional connections. Show the needed connections and label the inputs and outputs appropriately in the figure to the right so that the correspondence to the above circuit is clear. (1 point)

    1/4 gave this answer, while about 1/4 earned no credit. Another 1/4 connected the feedback path from c back to the zero input of the MUX instead of the one input, and 1/4 labeled the one input as a. 1/6 left out the feedback path entirely, and 1/8 gave the control input some label other than b.

    b) The above circuit is a kind of flipflop. What are the conventional letters used to label the inputs and outputs? (1 point)

        a is __D_________

        b is __C_________

        c is __Q_________

    Only 1 did this exactly. Only 1/8 earned no credit. Most understood the Q output, and a fair number used the names C and D for the inputs, but most of these exchanged these two.

     

  4. Consider the following two files, fileX.a and fileY.a; when these two files are assembled, linked and loaded, some of the lines with the comment "???" will cause assembly or linkage errors, and some will work. In your answers, refer to each of these lines by the register that is being loaded:
            ; fileX.a                       ; fileY.a
                    INT     A                       USE     "hawk.macs"
            A       =       5                       EXT     A
                    END                     PA:     W       A
                                                    S       .
                                                    LIW     R3,A    ;  ???
                                                    LIL     R4,A    ;  ???
                                                    LIS     R5,A    ;  ???
                                                    LOAD    R6,PA   ;  ???
                                                    END
    

    a) Which of the above is always safe to use? _LOAD_R6_
    (0.5 points)

    b) Which of the above might work, if the assembler is just a bit clever? _LIS_R5__
    (0.5 points)

    c) Which of the above unlikely to work, ever? _LIW_R3__
    (0.5 points)

    d) Which of the above might work, with big changes to the assembler. _LIL_R4__
    (0.5 points)

    1/8 did well here, and only one earned no credit. 2/3 got part a) correct, and only a few offered other answers.

    Part b) was harder (in fact, LIS R5,A can be made to assemble with only a small change to the hawk.macs file). Only 3 got this, while 1/4 got partial credit for suggesting that LIL R4 would be easy. The most popular answer, LIW was given by half the class. Here is the macro that will work just fine:

        MACRO LIS r,c
          B c
          B #D0 | (r-R0)
        ENDMAC

    Part c) was also hard, with 3 giving the right answer. 1/8 got partial credit for LIL R4, since this would indeed be difficult to make work. The most popular answer was the easy to fix LIS.

    Part d) was easier, 1/3 gave the right answer, and another 1/8 got partial credit for LIS R5. The most popular answer, given by about 1/4, was LIW.

  5. Here is a bit of code extracted from Chapter 11 of the notes, for getting data from the keyboard, modified and with blanks added to allow the addition of code to test for input error and return the ASCII character SUB (1A hex) in that case.
    PKBD:   W       #FF100000       ; address of keyboard interface
    KBDDATA =       0               ; offset of keyboard data register
    KBDSTAT =       4               ; offset of keyboard status register
    
    KSTATRD =       0       ; ready
    KSTATER =       6       ; error
    KSTATIE =       7       ; interrupt enable
    
    KBDGET:                 ; link through R1 
                            ; returns R3 = keyboard
                            ; uses    R4,R5
            LOAD    R5,PKBD         ; R5 = pointer to keyboard interface
    KPDPOLL:                        ; do {
            LOAD    R4,R5,KBDSTAT	;   R4 = kbdstat
            BITTST  R4,KSTATRD
            BCR     KBDPOLL         ; } while ((kbdstat & kstatrd) == 0);
    	; ???
            LOAD    R3,R5,KBDDATA
    
    	_BITTST_R4,KSTATER_______
    
    	_BCS____KBDERR___________
            JUMPS   R1              ;   return kbddata;
    KBDERR:				; else
    	LIS	R3,#1A
            JUMPS   R1              ;   return ASCII SUB character;
    

    a) Add the necessary code in the space provided above. (1 point)

    1/4 did well here, 1/8 earned no credit. About 1/3 used the wrong registers and a similar number used the wrong conditional branch. (Copying the pattern used to test the KSTATRD bit was too obvious?)

    b) Why would it be wrong to test for error and jump to KBDERR from the point marked with "???" above? Hint: the figure below, borrowed from Chapter 11, may help. (1 point)

    ___The KSTATER bit is only reset by reading KBDDATA, so if the test________
    
    ___were moved to the marked point, the KSTATER bit would never be reset,___
    
    ___and no reads, ever again, would get the data.___________________________
    

    4 did well here, 2 had answers that were almost good, and 1/5 more had answers that were worth at least some partial credit.

    The Hawk keyboard status register