Assignment 10 Solutions

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

Homework

  1. Background: In the 1960's, some computer vendors came out with computers with a 24-bit word. Here is a typical floating point format for such a machine:
    |23|22_21_20_19_18_17_16|15_14_13_12_11_10__9__8__7__6__5__4__3__2__1__0|
    |__|____________________|_______________________________________________|
      s       exponent                          mantissa
    
    s
    The sign of the mantissa.
    exponent
    a 7-bit natural biased binary exponent.
    mantissa
    a 16-bit magnitude for the mantissa (which, as a whole, can be treated as a 17-bit signed-magnitude number, with the exponent between the sign and magnitude). The range of possible values represented by the mantissa m is 0<m<1.0. The range of values represented by normalized mantissas is 0.5<m<1.0.

    a) Give the representation for 1.0 in this number system. (0.5 points)

    0 1000001 1000000000000000 = + 0.5 × 21

    The most widespread mistake here was to forget about biased numbers. When these were discussed at the start of the semester, there was a promise that they would come back to haunt us. 1000001 in the natural biased 7-bit binary number system is the representation for 1.

    b) Give the representatin and equivalent decimal value of the smallest normalized number in this number system. (0.5 points)

    0 0000000 1000000000000000 = + 0.5 × 2-128 = 2-129 = 1.4694 × 10-39

    Note that the exponent 0000000 in the natural biased number system means -128, and note that mantissa has a precision of 16 bits or about 5 decimal digits, so it is inappropriate to give more than 5 significant figures in the decimal equivalent.

    c) Give the representatin and equivalent decimal value of the smallest non-normalized non-zero number in this number system. (0.5 points)

    0 0000000 0000000000000001 = + 2-16 × 2-128 = 2-144 = 4.4842 × 10-44

    d) Given a floating point number in the format from problem 1 in the least-significant 24 bits of R3, write a sequence of instructions (not a subroutine, just a sequence of instructions) that computes the 2's complement integer exponent in R4 and the 2's complement binary fraction in R3. The point for this fraction should be just to the right of the sign bit. Use R4 and R5 if you need to use extra registers. (0.5 points)

            MOVE    R4,R3           ; copy exponent (and sign bit)
            TRUNC   R3,16           ; extract mantissa
            SL      R3,15           ; align mantissa as signed fraction
            BITTST  R4,23           ; test saved sign bit
            BBR     NOTNEG
            NEG     R3,R3           ; if saved sign was negative, negate
    NOTNEG:
            SR      R4,16           ; align exponent as an integer
            TRUNC   R4,7            ; clean sign off of exponent
            ADDI    R4,R4,-128      ; subtract bias from exponent
    

  2. Background A Centronics printer interface (the standard printer designed to plug into the old IBM PC parallel port) has the following wires. Wire numbers correspond to pin numbers on the 25 pin printer plug:

    1) Strobe
    Output, normally 1, set to 0 indicates data to print.
    2-9) Data
    Output, a character to print when Strobe=0, data must not change except when Strobe=1 and Ack=0.
    10) Ack
    Input, normally 0, set to 1 to indicate that the device has noticed the strobe, set back to zero to indicate that the device has successfully taken a copy of the data.
    11) Busy
    Input, normally 1, set to 0 to indicate that the device is busy and cannot accept output.
    12) Paper-Out
    Input, normally 0, set to 1 when there is no paper.
    13) Select
    Input, 0 when the printer is off, set to 1 when the printer is on.
    14) Linefeed
    Output, 1 normally, a 1 to 0 transition causes a paper advance.
    15) Error
    Input, 0 normally, 1 indicates something wrong with the printer.
    16) Reset
    Output, 0 normally, set to 1 to reset the printer.
    17) Select printer
    Output, 0 forces the printer to ignore everything, 1 enables the printer.

    Assume the following I/O registers on the HAWK parallel port, which is designed to be far more general than the old Centronics standard:

    FF100020
    Printer port data. Bit i of the data register is connected to pin i of the printer port socket. Each bit may be configured as an input or an output bit. Write operations to the data register change the output only if wires are configured as output. Read operations from the data register report the current values on all wires.

    FF100024
    Printer port control. Bit i of the control register determines whether bit i of the data register is an input bit or an output bit. Zero indicates input, one indicates output.

    a) When the Hawk system is powered up, the printer port control register is set to all zero, by the hardware. When the printer driver runs its initialization code, what values should it place in the printer port data and control registers assuming that you are trying to maintain compatibility with the old Centronics standard? (0.5 points)

    M[FF10002416] = 0000 0000 0000 0011 0100 0011 1111 11102
    M[FF10002016] = xxxx xxxx xxxx xx10 x1xx xxyy yyyy yy1x2

    In the above, the control register is specified first. Only the bits specifically documented as output bits are configured for output using one bits in this register. The data register is specified second. Here, the initial value of bits marked x do not matter because these bits are inputs and outside the control of the initialization routine. Bits marked y do not matter because the printer ignores these outputs when strobe is 1. Note that a printer driver could force a printer reset when the driver starts up, but that is not shown here.

    It is unclear why so many students didn't try this problem, because it requires little more than clerical work.

    b) Write a subroutine to output one character to a Centronics compatible printer. It will need to wait for the printer (several inputs from the printer must have specific values before an output cycle begins), then put the data into specific bits of the data register, and then manipulate one or more additional output bits while observing the printer's response. (0.5 points)

    ; parallel port addresses
    PP      =       #FF100020
    ; DATA  =       #0      ; displacement to data register
    PPCTRL  =       #4      ; displacement to control register
    
    ; parallel port bit numbers
    PPSTROB =       1       ; output, normally 1
    PPDATAB =       2       ; output, first of 8 bits
    PPACK   =       10      ; input, normally 0
    PPBUSY  =       11      ; input, normally 1
    PPPOUT  =       12      ; input, normally 0
    PPSEL   =       13      ; input, normally 1
    PPLF    =       14      ; output, normally 1
    PPERROR =       15      ; input, normally 0
    PPRESET =       16      ; output, normally 0
    PPPSEL  =       17      ; output, normally 1
    
    ; the print character routine
    PPPUTCH:        ; expects R3 holds character to output
                    ; uses R4 as pointer to parallel port
                    ; uses R5 as temp register
            LIW     R4,PP
    PPPOLL1:                        ; while ( -- wait for printer ready
            LOADS   R5,R4
            BITTST  R5,PPACK
            BBS     PPPOLL1         ;        (ppdata.ack == 1)
            BITTST  R5,PPBUSY
            BBR     PPPOLL1         ; ||     (ppdata.busy == 0)
            BITTST  R5,PPPOUT
            BBS     PPPOLL1         ; ||     (ppdata.pout == 1)
            BITTST  R5,PPSEL
            BBR     PPPOLL1         ; ||     (ppdata.sel == 0)
            BITTST  R5,PPERROR
            BBS     PPPOLL1         ; ||     (ppdata.error == 1) ) do nothing
    
            LIL     R5,(0<<PPSTROB)+(1<<PPLF)+(0<<PPRESET)+(1<<PPSEL)
            TRUNC   R3,8
            SL      R3,PPDATAB      ; -- construct output value with strobe
            OR      R5,R3
            STORES  R5,R4           ; ppdata = constructed value
    
    PPPOLL2:                        ; while ( -- wait for printer acknowledge
            LOADS   R5,R4
            BITTST  R5,PPACK
            BBR     PPPOLL1         ;        (ppdata.ack == 0) ) do nothing
    
            LIL     R5,(1<<PPSTROB)+(1<<PPLF)+(0<<PPRESET)+(1<<PPSEL)
            OR      R5,R3           ; (optionally keep data bits unchanged)
            STORES  R5,R4           ; ppdata = reset strobe bit
    
            JUMPS   R1              ; return
    

    The optional code included above to keep the data buts unchanged is optional because the value of the data bits when the strobe bit is one does not matter. The value in doing so is way outside the subject of this course -- it reduces radio frequency interference by reducing the number of unnecessary changes to the output bits.