Exam 2: Midterm

Solutions and Comments

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

Score Distributions

                                  X
                        X     X   X
__________________X_X_X_X_____X_X_X_X_______
 0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10
Rough Scores:       C      B      A

Exam Solutions

  1. Consider using unsigned fixed-point 16-bit numbers with a 12-bit fractional part to represent the coordinates of the cutting head of a lathe or other computerized machine tool. Coordinates are measured in inches. (4 points)

    a) To the nearest 10th of an inch, what is 1111.111111111111 in this number system? This number gives the maximum dimension that can be represented.

                  _ 16 _____________________
    

    Most got this, but a few rounded incorrectly, giving 15.8.

    b) What is the precision to which this system can control the machine tool? That is, what is the smallest nonzero number it can represent?

                  _ 1/4096 or 0.000244...___
    

    Most got this, but a few gave strange answers.

    c) What is an appropriate representation of three and one third (decimal) in system? Give your answer in binary. (Hint, it is a repeating fraction, and you should round it fit in the required representation.)

                  _ 0000.010101010101 ______
    

    Many got this (not as many as parts a and b) In most cases, a bit of simple checking would have sufficed to help those with strange errors catch their erors (for example, noting that 1/3 is between 1/4 and 1/2).

    d) What is an appropriate representation one one thousandth in this number system? Give your answer in binary.

                  _ 0000.000000000100 ______
    

    Only 2 got this right. All but two of the errors were off by many factors of two. Most of the errors appear to have been careless (giving 1/100 instead of 1/1000), but other answers were very hard to understand (for example, those greater than 1/16).

  2. Consider the following code. Some register is loaded on each line of this code (excepting the last). Explain the purpose of each instruction, being very careful to be as concise as possible and to avoid misusing terminology. Note that OBJECT is a global polymorphic object. (2 points)
            LOAD    R3,POBJECT      ; _ R3 now points to the object __________
    
            LOADS   R1,R3           ; _ R1 now points to the object's method table
    
            LOAD    R1,R1,METHOD    ; _ R1 now points to a method from the table
    
            JSRS    R1,R1           ; _ Call that method _____________________
    

    Half the class did reasonably well here. The hardest line was the second line. The most common errors involved confusing the thing with the pointer to that thing.

  3. Consider the following three files:
            ; module.h                              TITLE   "module.a"
                    EXT     A                       INT     A
            VA:     W       A               A:      JUMPS   R1
    
                                    TITLE   "main.a"
                                    USE     "hawk.macs"
                                    USE     "module.h"
                                    S       .
    				LOAD    R1,VA
                                    JSRS    R1,R1
                                    LIS	R1,0
                                    JSRS	R1,R1
    

    The user assembles the two .a files and then links them, main.o first, and then module.o second. The linker arranges things in memory starting at location #1000. Show, in hex, contents of memory, giving the value of each successive halfword loaded. More than enough space is given here! (2 points)

            Location  Value                       Location   Value
    
            1000      __ 100E ____ (W A)          100A       __ D100 ___ (LIS)
    
            1002      __ 0000 ____                100C       __ F1B1 ___ (JSRS)
    
            1004      __ F150 ____ (LOAD)         100E       __ F0B1 ___ (JUMPS)
    
            1006      __ FFF8 ____                1010       ___________
    
            1008      __ F1B1 ____ (JSRS)         1012       ___________
    

    Note: There was an error in the code given, but nobody noticed. The file module.a should have had USE "hawk.macs" after the TITLE directive.

    Nobody got this completely correct, allthough several students came within one or two clerical errors of perfection. The most common errors involved not knowing what to do with the code from module.h (it gets substituted verbatim into the code of main.a in place of the USE directive that cites it), or not doing anything with module.a (the problem statement says its object file goes last).

    Many students either omitted the 16-bit displacement on the LOAD instruction or gave it the wrong value.

  4. Consider the following description of a logic circuit, given in symbolic form:

    c = a and d
    d = b or c

    A circuit a) Draw a logic diagram equivalent to the above in the space to the right: (1/2 point)

    Most of the class did well here, only a very few had trouble, and in those cases, there was no partial credit.

    b) It's a flipflop. How should the inputs be set so it remembers a value? (1/2 point)

    To make it remember, set a = 1 and b = 0.

    2 did well here, many managed to confuse what might have been a good answer and earned only partial credit. 4 earned no credit.

    c) If it's a flipflop, you must be able to set it and reset it. How? (1/2 point)

    To set it, briefly put a pulse of 1 on the b input

    To reset it, briefly put a pulze of 0 on the a input

    3 did well here, many managed to confuse what might have been a good answer and earned only partial credit. 3 earned no credit.

    d) If it's a flipflop, it must have some output or outputs equivalent to Q or Qbar. What are the outputs and to what are they equivalent. (1/2 point)

    The c and d outputs are both equivalent to Q

    5 did well here, two earned no credit, and the remainder made odd errors. The most common was to assert that one of the outputs corresponded to Qbar (difficult in a circut that contains no inverters).