go to previous page   go to home page   go to next page hear noise

Answer:

Floating point constants


Evaluation

Here is the part of the code that evaluates the polynomial. Remember that x is in $f0.

        # Register Use Chart
        # $f0 -- x
        # $f2 -- sum of terms
        . . . . . 
        
        # evaluate the quadratic
        l.s     $f2,a               # sum = a
        mul.s   $f2,$f2,$f0         # sum = ax
        
        l.s     $f4,bb              # get b
        add.s   $f2,$f2,$f4         # sum = ax + b
        mul.s   $f2,$f2,$f0         # sum = (ax+b)x = ax^2 + bx
        
        l.s     $f4,c               # get c
        add.s   $f2,$f2,$f4         # sum = ax^2 + bx + c
        . . . . . .

        .data
a:      .float  1.0
bb:     .float  1.0
c:      .float  1.0

The assembler objects to the symbolic address "b" (because there is a mnemonic "b", for branch) so use "bb" instead.

The polynomial is evaluated from left to right. First ax + b is calculated. Then that is multiplied by x and c is added in, giving axx + bx + c.

The value x2 is not explicitly calculated. This way of calculating a polynomial is called Horner's Method. It is useful to have in your bag of tricks.


QUESTION 17:

Why (do you suppose) are the constants a, b, and c set to 1.0?