CS 220 - MIPS Homework 4

This program is due Thursday April 5.

MIPS floating-point and computing $e^x$

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.

Part 1 - 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.

Part 2 - 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?).

Part 3 - 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.

Part 4 - 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.

What to turn in

    1. Your program must obey the MIPS calling conventions.
    2. Turn in a printout of your program at the start of class on Thursday April 5.
    3. Email me a copy of your program as an attachment and make sure that the name of the file is username_hw4.s where username is your user name. Make sure the subject heading in the email says CS220 HW 4
    4. Your program should be neat and tidy. Make sure that there are no bad line breaks, lines that wrap around, etc. Make sure that indentation is consistent and that tab characters don't make the printout look messy.
    5. There should be a nice block comment at the top that has you name, the date, the homework assignment number (this is HW3). For example
            #--------------------------------------------------------
            # Name: your name
            # Date: 3/6/2012
            # Assignment: HW 4
            #
            #     program description
            #--------------------------------------------------------