Download FP numbers

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts

Large numbers wikipedia , lookup

Bra–ket notation wikipedia , lookup

Approximations of π wikipedia , lookup

Positional notation wikipedia , lookup

Addition wikipedia , lookup

Elementary arithmetic wikipedia , lookup

Location arithmetic wikipedia , lookup

Arithmetic wikipedia , lookup

Transcript
Compiling a FP Program into MIPS
• Let's convert a temperature in Fahrenheit to Celsius:
float f2c (float fahr)
{
return((5.0/9.0) * (fahr -32.0));
}
• In MIPS assembly (the first 2 instructions load from
memory into FP registers, fahr is in $f12):
f2c:
lwc1 $f16,const5($gp) # $f16=5.0 (5.0 in memory)
lwc1 $f18,const9($gp) # $f18=9.0 (9.0 in memory)
div.s $f16,$f16,$f18
# $f16=5.0/9.0
Many compilers would divide 5.0/9.0 at compile time and store the
result in memory, saving a divide and load
lwc1 $f18,const32($gp)# $f18=32.0
sub.s $f18,$f12,$f18
# $f18=fahr-32.0
mul.s $f0,$f16,$f18
# $f0=(5.0/9.0)*(fahr-32.0)
jr
$ra
23# return