PDA

View Full Version : Floating Point Tutorial.



InvertedProphet
09-07-2008, 06:54 PM
floating point values are always held in f registers ($f0-$f31). each register is always 32 bits long and can hold only one single precision value.

Mathematical Operations For Floating Point Values

mul.s = multiply
div.s = divide
add.s = add
sub.s = subtract

lets say you wanted to multiply $f0 and $f12 and store the result in $f3, the syntax would be:

mul.s $f3, $f0, $f12

because:
mul.s = instruction of the operation
$f3 = destination register
$f0 and $f12 = registers getting instructed

Converting A Number To A Floating Point Value

you would first use a convert instruction such as cvt.?.?

first ? = whats being converted
second ? = what its being converted to

you fill the ? in with one of these:

w = integer
s = single precision floating point
d = double precision floating point

lets say we wanted to write a function that put 10 into a float point value. we would get:

li $t0, 10 < loads 10 into $t0 register
mtc1 $t0, $f2 < puts the data from the $t0 register into the $f2 register
cvt.s.w $f3, $f2 < puts the data from $f2 into $f3