This program is due Thursday April 5.
In this homework you are going to write a MIPS assembly language program
to compute $e^x$. Do this by writing a function exp(x)
that computes $e^x$. Here, $x$ can be a floating-point number and should be
passed as a parameter (which means it should be passed in
$f12
).
There is a nice formula for computing $e^x$ which is:
\[ e^x = \sum_{k=0}^{\infty} \frac{x^k}{k!} = \frac{x^0}{0!} + \frac{x^1}{1!} + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots + \frac{x^k}{k!} + \cdots \]
The best way to write this program is to break it up into three functions,
one to compute powers (the numerators), one to compute factorials (the denominators) and one to compute
the series. The function to compute the series will call
pow
and fact
.
pow(x,k)
Modify the pow
function from your previous MIPS assignment so that
it computes pow(x,k)
where $x$ is a floating-point number and
$k$ is an integer. Floating-point results are returned in $f0
(not $v0
).
If you want to start from my version of the power function in MIPS here is mine.
fact(n)
Write a function fact(n)
that takes an integer $n$ and computes the
factorial of that number (denoted $n!$). Question: What is the largest $n$ that
you can compute the factorial of that will fit in 32 bits?).
exp(x)
Write a function exp(x)
to compute $e^x$ using the series
expansion above. Do this for the first $n$ terms of the series where
$n$ is the largest value that you can safely compute a factorial for that will fit in
a 32-bit two's-complement integer register.
Use the functions pow
and fact
that you wrote previously.
The answer converges rather quickly because the denominators
get huge quickly.
main
Your main program should read a floating-point number $x$ from the user and output
$e^x$ using the fucntion exp
you just wrote.
username_hw4.s
where
username
is your user name. Make sure the subject heading in the email says
CS220 HW 4
#-------------------------------------------------------- # Name: your name # Date: 3/6/2012 # Assignment: HW 4 # # program description #--------------------------------------------------------