[30] Write a procedure, P, in MIPS assembly
language to compute the value of Legendre polynomials defined
recursively as
P(x, 0) = 1,
P(x, 1) = x,
P(x, n) = x (2 - 1/n) P(x, n-1) - (1 - 1/n) P(x, n-2). n>1.
The function P(x,n) takes two arguments. The first argument is
a real number. We use double precision for x. The second
argument is an integer. The return value should be double.
Use the double precision floating point
instructions add.d, sub.d, mul.d, div.d,
li.d (load immediate double), l.d
(load double), s.d (store double), and mov.d (move double).
To convert an integer value in a CPU register, say, $6, to a floating
point number of the same value, in FPU register $f8, (e.g., converting
integer 3 to floating 3.0), you need the following instruction
sequence
mtc1 $6, $f10 # move the bit pattern to FPU reg $f10
cvt.d.w $f8, $f10 # convert integer to double, result in $f8
Follow closely the MIPS argument passing/stack usage
convention. In particular, the argument x should be passed in
$f12, and the second argument n should be passed in $6,
and the return value should be in $f0.
Test your assembly program with an interactive main program.
Compute and report the following values P(0.0, 2), P(0.5, 3), and
P(0.25, 5). How do you know that your answers are correct?