Exam 3: Final

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

Score Distributions

Final Exam

Median = 10.1   X
                X                 X
 ___________X___X_X_X___X___X_X___X_____X_____
   0 . 2 . 4 . 6 . 8 . 10. 12. 14. 16. 18. 20

All 3 exams

Mean   = 23.8     X
                  X                                 X
______________X_X_X_________X_______X_____X___X_____X_X______________
 8 . 10. 12. 14. 16. 18. 20. 22. 24. 26. 28. 30. 32. 34. 36. 38. 40.

5 Machine Problems

Mean   = 22.6                                      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. 

10 Homeworks (the lowest of 11 scores was discarded)

Mean   = 23.5                            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

Overall

Mean   = 70.0
                                   X
 __X_____________X_X___X_____X_____X___X_X_X___X_X________________
  40. 44. 48. 52. 56. 60. 64. 68. 72. 76. 80. 84. 88. 92. 96. 100
  |  -  D  +  |  -  C  +  |  -  B  +  |  -  A  +  |

Exam Solutions

  1. Consider the following fragment of SMAL Hawk code. Put the appropriate ALIGN directives in this code. (2 points)
                    JUMPS   R1       ; return subroutine A
                    _ALIGN_ _4_____
            PSTR:   W       STR
                    _______ _______
            STR:    ASCII   "A longish string",0
                    _______ _______
                    COMMON  BVAR,4   ; used only by subroutine B
                    _ALIGN_ _4_____
            PBVAR:  W       BVAR
                    _______ _______
            ARSIZE  =       4        ; size of subroutine B AR
                    _______ _______
            B:      STORES  R1,R2    ; entry point of subroutine B
    

    Note that the second ALIGN directive could optionally be put before the COMMON, and note that a third ALIGN directive is within reason before the final line, but this should align to the halfword, not the word.

    Only one did perfectly here. 4 filled in 6 ALIGN directives, an additional 3 added unnecessary alignment before the ASCII directive and an additional 2 added unnecessary alignment before the definition of ARSIZE. 5 forgot to align after the first line (an instruction) before the word at PSTR.

  2. A circuit Consider the logic circuit shown here at a high level, that takes an integer a as an input and produces an integer m as output. The function depends on the control input b0. If this is zero, m = a. If b0 is one, m = a - 1.

    a) If a = 0000 and b0 = 1, what will the output be? (1 point)
    m  = __1111__  b4 = _1__

    5 did well here, 4 had difficulty with m, and 2 had difficulty with b4.


     ai    bi    mi   bi+1
    0 0 0 0
    0 1 1 1
    1 0 1 0
    1 1 0 0
    b) Fill in the truth table to the left for this for any one of the four cells that make up the circuit. (2 points)

    5 did well here. Among those who had difficulty, the most common errors involved wrong outputs on rows 10 and 11 of the truth table.

    c) Draw the logic circuit, using standard symbols for logic gates (and, or, not, xor, etc) in the space below. (2 points)

    A circuit

    4 did well here, with 2 giving the circuit shown on the left and 2 giving variations on the circuit to the right. Three earned partial credit for circuits that gave at least one correct output that in some way matched the contents filled into the truth table for part b).

  3. Consider representing a stream of data from a microphone using 8 bits per sample. You could just represent each data point as an 8-bit two's complement value representing voltages from -1 to (almost) +1. This will be a fixed point binary number.

    a) Show, on the following diagram, where the point goes: (1/2 point)

        __ __ __ __ __ __ __ __
       |__|__|__|__|__|__|__|__|
          o
    

    8 got this, while on the other extreme, 2 had odd answers with the point way out in the middle of the byte.

    b) What is the smallest positive nonzero value in this system? Give your answer as a fraction in the form 1/n. (1/2 point)

        _____ 1/128 ___________
    

    8 got this, a few gave answers that were incompatable with the answer given for part a), and one gave an answer that was very strange.

  4. Consider this alternative to the number system from the previous problem: Each sample is represented as a floating point value with a 4 bit mantissa and a 4-bit exponent. We want the same range of values, -1 to +1, but we are satisfied if we can come close to but not quite reach the extremes) Numbers in this format will be represented as follows:
        __ __ __ __ __ __ __ __
       |__|__|__|__|__|__|__|__|  (s is the sign of the mantissa)
       |s | exponent  |fractional magnitude of the mantissa
    

    The value 01111111 is the closest possible approximation of +1 in this system.

    a) What is the exact value of 01111111 in this system? (1 point)

        ____ 7/8 or 0.875 ____
    

    The reasoning behind this is as follows: The least significant 3 bits are 111, and the format declares these to be the fractional magnitude of the mantissa, so they must represent 0.111 or 7/8. We know that this is the closest possible approximation of +1 in this system, so the exponent 1111 must mean zero so that this is 7/8×20.

    4 got this, while 5 earned partial credit for 0.9375 or 15/16ths. Presumably, those students forgot that the most significant bit of the mantissa was the sign, so there were only 3 fractional bits.

    b) What are the maximum and minimum exponent values (in decimal)? (1 point)
        1111 = _____ 0 ______________
    
        0000 = _____ -15 ____________
    

    The reasoning behind concluding that 1111 is the largest possible exponent value follows from 01111111 being the closest possible approximation of +1 in this system. Since we are uninterested in representing any numbers above 1, other exponent values must be negative, so 4 bits gives the range from 0 to -15. If we use either a biased system (with a bias of 15) or a one's complement system for the exponent, the representation of -15 comes out as 0000.

    2 gave this answer, 5 earned partial credit for flipping the sign of one or the other answer (-0 to +15) or off-by-one errors (1 to -14) or off-by-one errors in the exponent (-7).

    c) Therefore, what is the smallest positive nonzero non-normalized number in this system? Give your answer as a fraction in the form 1/n. (1 point)

        ___ 1/262144 _________
    
    This is 0.0012 × 2-15. Note that 0.001 is not normalized! The smallest normalized fraction is 0.100.

    6 got this right, in light of their answers to part b). Some had very odd answers such as 2-3 or 2-48.

  5. Given that R3 contains a floating point number in the format described in the previous problem, give SMAL Hawk code to place the mantissa (accounting for both sign and magnitude) in R4 as a 32-bit two's complement fixed point fraction. (It can be done in under 8 instructions.) (4 points)
                MOVE    R4,R3   ; copy number in this form ...sxxxxmmm
                TRUNC   R4,3    ; clip off to so it is ...000000000mmm
                SL      R4,14
                SL      R4,14   ; shift over so it is 0.mmm00000000...
                BITTST  R3,7    ; test sign of original mantissa
                BCR     NOTNEG
                NEG     R4,R4   ; negate if required
        NOTNEG:
    

    Nobody gave perfect answers. 1 forgot to convert from signed magnitude to two's complement, 2 forgot to shift the result 28 places left. 2 more gave relevant code fragments that did not accomplish much for partial credit. The remainder gave irrelevant code that did nothing except waste time for both the student and grader.

  6. Consider the following variables, each of the same type, two words in length:

    a) Give an appropriate SMAL definition for VA, including any auxiliary material you might need in order to address the variable. (1 point)

               COMMON VA,8
        PVA:   W      VA
    

    5 did well here, while 3 earned partial credit for missing the block size or using the wrong block size (64 bit variables require 8 bytes each).

    b) Give appropriate SMAL definitions for the entire activation record of the current routiine, VB, assuming that it is the only local variable. (1 point)

        ;RA    =      0
        VB     =      4
        ARSIZE =      12;
    

    5 did well here, while 5 earned partial credit for giving the wrong activation record size in the context of the fields they'd included in the activation record.

    c) Give appropriate SMAL Hawk code to be included as part of the body of the current routine, using your definitions above, to load a pointer to VA in R3 and a pointer to VB in R4. (1 point)
               LOAD   R3,PVA
               LEA    R4,R2,VB
    

    3 gave essentially this. 5 had trouble with the LEA, using LOAD instead. 6 loaded the pointer to VA correctly but had trouble dealing with VB.

    d) Assuming that a pointer to VA has been loaded in R3 and a pointer to VB has been loaded in R4, write code to copy the 64-bit value of VA to VB. (1 point)

               LOADS  R5,R3
               STORES R5,R4
               LOAD   R5,R3,4
               STORE  R5,R4,4
    

    3 gave good answers, and one of these gave correct answers to all 4 parts of the question. Partial credit here was rare, since most of the wrong answers appeared to have no connection to the question.

  7. Suppose that bit 0 of memory location FF10010016 is the ready bit of the device control register for a robotic arm. Write a fragment of SMAL Hawk code that polls this bit repeatedly, waiting for it to be set. (1 point)
               LIW    R3,#FF100100
        POLL:
               LOADS  R4,R3
               BITTST R4,0
               BCR    POLL
    

    3 gave good answers. 3 lost credit for problems with the LOADS instruction, 1 lost credit for problems with BITTST, and 3 lost for using BZR to test the result of the BITTST instruction. Of those who earned no credit, most gave answers that had extremely tenuous connections to the problem.