Assignment 10, due Jul 17

Solutions

Part of the homework for CS:2630, Summer 2018
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (Tuesday or Thursday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!

  1. Background: The seventh century Indian mathematician Bhskara I came up with the following formula for the sine of an angle (given here in radians):

    sin x16 x ( π – x )

    5 π 2 – 4 x ( π – x )

    In the following, you can assume that the floating point unit is already turned on and that it is running in single-precision mode. Assume that the following floating point constants needed to evaluate the above are available and assembled into memory near your code:

    	ALIGN	4
    F4:	W	4.00 in IEEE floating point format
    F16:	W	16.00 in IEEE floating point format
    FPI:	W	PI in IEEE floating point format
    F5PI2:	W	5.00 * PI * PI in IEEE floating point format
    

    A problem: Write a SMAL Hawk subroutine using the HAWK floating point unit that implements Bhaskara I's approximation of the sine function. This should take the parameter x in R3 and return the approximate sine of x in R3. Your code can use both floating point accumulators and it should conform to the standard Hawk calling sequence and the standard assumptions about subroutine register usage. (1.5 points)

    SIN:    ; given: R3 = x
            ; returns: R3 = sin(x) approximated by Bhskara I's formula
    	LOAD	R4,FPI
    	COSET	R4,FPA0
    	COSET	R3,FPA0+FPSUB   ; -- pi - x
    	COSET	R3,FPA0+FPMUL   ; -- x(pi - x)
    	COGET	R3,FPA0		; t = x(pi - x) -- get a copy; need it twice
    
    	LOAD	R4,F16
    	COSET	R4,FPA0+FPMUL   ; a0 = 16x(pi - x)
    
    	COSET	R3,FPA1
    	LOAD	R4,F4
    	COSET	R4,FPA1+FPMUL	; -- 4x(pi - x)
    	COGET	R3,FPA1		; t = 4x(pi - x)
    
    	LOAD	R4,F5PI2
    	COSET	R4,FPA1
    	COSET	R3,FPA1+FPSUB	; -- 5pi**2 - 4x(pi - x)
    	COGET	R3,FPA1		; t = 5pi**2 - 4x(pi - x)
    
    	COSET	R3,FPA0+FPDIV	; -- 16x(pi - x) / (5pi**2 - 4x(pi - x))
    	COGET	R3,FPA0		; -- put result in place
            JUMPS   R1		
    

    The above code is written for clarity. You could probably make the code run faster by moving the LOAD instructions forward to a point before the immediately preceeding COGET so that the coprocessor can work while the CPU is doing the load.

  2. Consider the following 32-bit binary numbers, given in hex. Split each number into its 3 components (sign, exponent and mantissa) and give decimal equivalents for each component, and then give the decimal equivalent for the result, to at least 3 significant figures.

    a) 40800000 (0.3 points)

    sign = +
    exp = 10000001 = 2
    mantissa = (1).00000000000000000000000 (parens surround the hidden bit)
    value = 1.0 × 22 = 4

    b) 40A00000 (0.3 points)

    sign = +
    exp = 10000001 = 2
    mantissa = (1).01000000000000000000000
    value = 1.25 × 22 = 5

    c) 41800000 (0.3 points)

    sign = +
    exp = 100 00011 = 4
    mantissa = (1).00000000000000000000000
    value = 1.0 × 24 = 16

    d) 40490FDB (0.3 points)

    sign = +
    exp = 10000000 = 1
    mantissa = (1).10010010000111111011011
    value = 1.57 × 21 = 3.14 = ~π

    e) 42456460 (0.3 points)

    sign = +
    exp = 10000100 = 5
    mantissa = (1).10001010110010001100000
    value = 1.54 × 25 = 49.28 = ~5π2

    Note that there are on-line IEEE calculators that can help you check your results, but note also that on the next midterm, you will be given a greatly simplified floating point format and asked to solve a related problem without use of any tools more powerful than pencil and paper.