Exam 2: Midterm

Solutions and Comments

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

Grade Distributions

Exam II

                          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

Sum of Exams I and II

Mean   = 12.49                    X
Median = 12.9       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

Homeworks 1 to 11

Mean   = 21.07
Median = 22.3                                   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. 22. 24. 26. 28. 30. 32

Machine Problems 1 to 5

Mean   = 17.54                        X
Median = 17.2                         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. 22. 24. 

Total

Mean   = 49.17
Median = 51.9                                 X
                                              X       X X             X
 _________X___________X_______________X_______X_X_X_X_X_X_X_X_X_______X___X_X__
   0 . 4 . 8 . 12. 16. 20. 24. 28. 32. 36. 40. 44. 48. 52. 56. 60. 64. 68. 72.
Rough Grades           F           D           C           B           A      

Exam II Solution

  1. Consider the high level language expression a[i] = o.pop() in the context of the following definitions:
            COMMON  A,400  ; int a[100] -- array of 100 words
    PA:     W       A
    
    ; public information about fields of objects in class C
    POP     =       8      ; pointer to the parameterless pop() method
    ;                        it returns the popped value in R3
    
    ; activation record structure
    I       =       4      ; integer variable
    PO      =       8      ; pointer to the object O of class C
    ARSIZE  =       12
    

    a) Write code to call o.pop(), leaving the result in R3 (1 point)

           _LOAD__ _R3,R2,PO______  ; get pointer to o into a register
           _LOAD__ _R1,R3,POP_____  ; get pointer to pop method
           _ADDI__ _R2,R2,ARSIZE__  ; push the activation record
           _JSRS__ _R1,R1_________  ; call the pop method
           _ADDI__ _R2,R2,-ARSIZE_  ; pop the activation record
    

    Few did perfectly, the biggest problems were with register usage in the first two lines, frequently destroying R3 (an essential parameter to the method).

    b) Write commented code to finish the assignment a[i] = o.pop() (1 point)
           _LOAD__ _R4,PA_________  ; _Get pointer to A[]___
           _LOAD__ _R5,R2,I_______  ; _Get local variable i__
           _SR____ _R5,2__________  ; _Make i a byte offset__
           _ADD___ _R4,R4,R5______  ; _Make pointer to A[i]__
           _STORES _R3,R4_________  ; _A[i] = result from R3_
    

    Only 1 did well here, and 3 left this blank. The common error was to attempt something with an array of bytes (A was explicitly described as an array of words).

      A circuit

  2. The logic circuit shown here is some kind of flipflop:

     

    A B C         D
    0 0 remember
    0 1 1         0
    1 0 0         1
    1 1 0         0
    a) Fill in the truth table to the right to describe the behavior of this circuit.

    Where the inputs uniquely determine the outputs, enter values of 0 or 1. When the inputs allow the device to remember, write remember. (1 point)

    b) Given your answer to part a), which of the flipflops that we discussed does this flipflop most closely mimic? (1/2 point)

     _R_S______________________________
    

    c) Show that you understand your answer to part b by marking, on the above figure, which inputs correspond to C, D, R, S (or whatever is appropriate) and which outputs correspond to Q or Q (whichever is appropriate). (1/2 point)

    2 filled in the truth table correctly, 3 identified it as an RS flipflop, 4 identified it as some kind of R S flipflop, and the remainder gave odd answers. 4 labeled the inputs and outputs correctly.

  3. Consider a 12-bit binary floating-point number using a sign, a 3-bit biased exponent, and an 8-bit normalized fractional mantissa, in the following format:
       |___|___|___|___|___|___|___|___|___|___|___|___|
       | s | exponent  |           mantissa            |
    
    a) Give the decimal interpretation of the following values, expressed in hexadecimal: (1/2 point)
    hex                binary                algebraic           decimal
                                                         _3__
    F80 _1 _1 _1 _1 _1 _0 _0 _0 _0 _0 _0 _0  __-1/2__ x 2      = _-4.0_____
                                                         _3__
    7F0 _0 _1 _1 _1 _1 _1 _1 _1 _0 _0 _0 _0  __15/16_ x 2      = __7.5_____
                                                         _1__
    580 _0 _1 _0 _1 _1 _0 _0 _0 _0 _0 _0 _0  ___1/2__ x 2      = __1.0_____
    

    2 did well here, the most common error was to take the exponent as an unsigned integer, so that 111 was taken as 7 and not +3 (in the biased system). Some students invented strange and ornate variants on this system where they assumed hidden bits and other features of the IEEE system. 6 earned no credit at all.

    b) Give the binary representations, in this system, for the following: (1/2 point)

    The smallest positive normalized number:      _0 _0 _0 _0 _1 _0 _0 _0 _0 _0 _0 _0

    The smallest positive nonnormalized number: _0 _0 _0 _0 _0 _0 _0 _0 _0 _0 _0 _1

    1 did well here. Strangely, many students tried to give the decimal values. Only 7 earned no credit at all.

  4. In MP5, the header file box.h contained a line saying something like EXT BOXRENDER, along with the macro MAKEBOX.

    a) Under what circumstances would a program (perhaps in main.a) explicitly mention BOXRENDER (1 point)

    _When a call to b.render() is made for an object b that is_________
    _known to be a box.________________________________________________
    

    4 did well here, 8 earned no credit, and the remainder had vague answers of one kind or another.

    b) a) Why, in a good solution to MP5, would it be unlikely to find explicit mention of BOXRENDER in main.a even though, when the main program is executed, it actually calls that subroutine many times? (1 point)

    _The main program does not know the classes of the objects_________
    _so it must call methods indirectl through the objects themselves._
    

    4 did well here too. More students got partial credit here than in the first part.

  5. Consider a more fully developed version of MP5, where objects have more than just one method. In this case, you might include the following text in boxortext.h
     3   ; fields common to box and text objects
     4   METHODS =       0       ; pointer to method table of object's class
     5   NEXT    =       4       ; pointer to next object in list
     6
     7   ; structure of method table for box or text classes
     8   ; each entry in the method table of a class is a pointer to a method
     9   RENDER  =       0       ; render the object
    10   DEBUG   =       0       ; debug the object
    

    a) Under the old scheme, box.h included the text EXT BOXRENDER. What new symbols must be defined by EXT directives in the new header file for box.h? (1/2 point)

    _BOXMETHODS,_BOXDEBUG______________________________________________
    

    3 did well here, 9 mentioned just BOXDEBUG, several gave strange answers.

    b) In the old MAKEBOX macro, there was a line W BOXRENDER; which of the new external symbols from part a will be used in the macro MAKEBOX? (1/2 point)

    _BOXMETHODS________________________________________________________
    

    5 did well here, many thought that there was some reason to include pointers to BOXRENDER or BOXDEBUG, indicating a misunderstanding of either the data structure or the role of the macro in the header file.

    c) Given that R3 contains a pointer to an object of some concrete subclass of BOXORTEXT, possibly a BOX, write code to call the RENDER method of that object. Ignore the problem of passing parameters to the method other than the pointer to the object itself. (2 points)

    __LOAD___R1,R3,METHODS____; get method table pointer of object_____
    __ADDI___R2,R2,ARSIZE_____; push activation record_________________
    __JSR____R1,R1,RENDER_____; call render method of object___________
    __ADDI___R2,R2,-ARSIZE____; pop activation record__________________
    
    __LOAD___R1,R3,METHODS____; get method table pointer of object_____
    __LOAD___R1,R1,RENDER_____; get pointer to render method___________
    __ADDI___R2,R2,ARSIZE_____; push activation record_________________
    __JSRS___R1,R1____________; call the method________________________
    __ADDI___R2,R2,-ARSIZE____; pop activation record__________________
    

    3 did well here, most giving the second, longer solution. 8 more did well except that they forgot to push and pop the activation records. Those who had additional problems generally had difficulty with the data structures.