Assignment 9, Solutions

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

  1. Background: Suppose you wanted to write a floating point package for a down-market version of the Hawk that had no floating point hardware. You'd have to do it in software, and your first challenge would be to design the interface to your package. You opt to use two data representations: Single precision, with a one-word exponent field and a one-word mantissa field, and double precision, with a one-word exponent field and a two-word mantissa field. Having read Chapter 10 of the notes, you decide that you will implement this as a polymorphic class.

    The parent class, float, has two subclasses, single-float and double-float. All floating point numbers have methods FADD, FSUB. (Yes, real useful floating point numbers will have more methods, but this is a toy example). From a high-level language perspective, the statement a=b+c would be objectified as in your system as a.fadd(b,c).

    a) Write an appropriate SMAL Hawk header file, float.h, that defines the interface to the parent class. This will contain some comments and a few definitions. (0.5 points)

    ; float.h
    ; a polymorphic class for representing floating point numbers
    ; each floating object begins with pointers to the methods that
    ; operate on that object, so that users need not know what kind
    ; of object it is after it is initialized.
    
    ; The following definitions give the displacement from the start
    ; of the floating object of each of the method pointers:
    FADD    =       0       ; the floating add routine
                            ;  expects R3 = this object, it will hold a + b
                            ;          R4 = the float object a 
                            ;          R5 = the float object b
    
    FSUB    =       4       ; the floating subtract routine
                            ;  expects R3 = this object, it will hold a - b
                            ;          R4 = the float object a 
                            ;          R5 = the float object b
    

    b) Given that the variables a, b and c are local variables of the current subroutine that point to floating point objects, give code that is equivalent to a.fadd(b,c). Note that you do not know which floating point representation is involved, so you cannot directly call the floating point operation.

            LEA     R3,R2,A         ; -- put parameter a in place
            LEA     R4,R2,B         ; --               b
            LEA     R5,R2,C         ; --               c
            ADDI    R2,R2,ARSIZE
            LOAD    R1,R3,FADD      ; -- get pointer to method
            JSRS    R1,R1           ; a.fadd(b,c)
            ADDI    R2,R2,-ARSIZE
    

  2. Background: Usually, we are interested in great big floating point numbers. IEEE format, for example, works with a minimum of 32 bits -- a sign, 8 bits of exponent, and 24 bits of mantissa (including a hidden bit). Here, we are interested in working at the opposite extreme. Consider a system with 3-bit floating point numbers. One bit for the sign, one bit for the exponent, and one bit for the mantissa, with no hidden bit. Assume the point is to the left of the most significant mantissa bit, and assume the exponent has is a biased number with the natural bias bias.

    a) Enumerate the signed fixed point decimal equivalents of all of these (0.3 points)

    First, work out the meaning of each field:

    1xx = negative
    0xx = positive
    x1x = × 20
    x0x = × 2-1
    xx1 = 0.5
    xx1 = 0.0

    From this, we can work out the 8 values

    111 = -0.5 × 20 = -0.5
    110 = -0.0 × 20 = 0.0
    101 = -0.5 × 2-1 = -0.25
    100 = -0.0 × 2-1 = 0.0
    011 = 0.5 × 20 = 0.5
    010 = 0.0 × 20 = 0.0
    001 = 0.5 × 2-1 = 0.25
    000 = 0.0 × 2-1 = 0.0

    From this, we can conclude that this is not a very useful system!

    b) What is the minimum number of bits you need in the exponent field in order to support an IEEE-style number with support for normalized floating point numbers, non-normalized numbers and NANs (IEEE-style not-a-numbers). (0.2 points)

    There are 3 possibilities we are trying to distinguish: Not a number, normalized. and not normalized. It takes at least 2 bits to distinguish between 3 alternatives, so the answer must be 2.

    c) Enumerate signed fixed-point decimal equivalents of all of the numbers you get in this scheme. There will be more entries in your table than in the answer for part a, but the table should not be too big to imagine writing down. (0.5 points)

    First, work out the meaning of each field, just as in part a:

    1xxx = negative
    0xxx = positive
    x11x = not a number
    x10x = × 20 normalized
    x01x = × 2-1 normalized
    x00x = × 2-1 not normalized
    xxx1 = 1.5 when normalized
    xxx0 = 1.0 when normalized
    xxx1 = 0.5 when not normalized
    xxx0 = 0.0 when not normalized

    From this, we can work out the 16 values

    1111 = -not a number
    1110 = -not a number
    1101 = -1.5 × 20 = -3
    1100 = -1.0 × 20 = -2
    1011 = -1.5 × 2-1 = -0.75
    1010 = -1.0 × 2-1 = -0.5
    1001 = -0.5 × 2-1 = -0.25
    1000 = -0.0 × 2-1 = -0.0
    0111 = not a number
    0110 = not a number
    0101 = 1.5 × 20 = 3
    0100 = 1.0 × 20 = 2
    0011 = 1.5 × 2-1 = 0.75
    0010 = 1.0 × 2-1 = 0.5
    0001 = 0.5 × 2-1 = 0.25
    0000 = 0.0 × 2-1 = 0.0

  3. Background: The type D latch given in Chapter 12 of the notes (about 2/5 of the way through the chapter) uses 4 nand gates and one inverter. It is interesting that, if you replace all of these nand gates with nor gates, keeping all other details of the circuit the same, the result is useful.

    a) Draw the schematic diagram that incorporates this change. Neatness counts. Label the inputs and outputs "oldD", "oldC", "oldQ", etc. in order to emphasize that the labels might not reflect the new purpose of those connections. (0.3 points)

    schematic diagram of the modified type D latch

    b) Draw the timing diagram. As inputs, use the exact same sequence as shown in the timing diagram in the notes (but re-label so "C" is "oldC", etc). You are not required to give the intermediate values at the points labeled R and S in the figure, but they are certainly useful in working out the correct answer. (0.5 points)

    timing diagram for the altered type-D latch

    c) Give appropriate labels for the points originally labeled old. That is, what should "oldC" be called, what should "oldD" be called, etc. These labels should reflect the function. If a Data input line exists, call it D. If it behaves as a flipflop, call the outputs Q and Qbar, and if one of those outputs can be set to the data input, call that one Q. If positive pulses on the clock input cause a data transfer, clock should be called C. If negative pulses cause data transfer, clock should be called Cbar. (0.2 points)

    Old   New   Reason
    oldQ Q Still follows D when C permits
    oldQQ Still the opposite of Q
    oldD D Still sets Q when C permits
    oldC C Like the old C, but active low