Assignment 7

Due 3 November

The goal of this assignment is to give you more programming experience with the MIPS instruction set and to expose you to issues of floating point precision.

Consider the series EN(x) = 1 + x + x2 + x3 + ... + xN. For values of -1 < x < 1 this series will produce the same value as Ec(x) = (1-xN+1)/(1-x) with exact arithmetic.

  1. Write a function float pow(float x, int N) that computes xN by repeated multiplication using single-precision floating-point arithmetic.

  2. Write a function Ec that takes a single precision floating point number x and an integer N as arguments and evaluates (1-xN+1)/(1-x) and returns the result. Call your pow function to evaluate xN in this calculation.

  3. Write a function Efwd that takes the same arguments and evaluates the series forward. That is, in the natural order starting with 1.

  4. Write a function Erev that takes the same arguments and evaluates the series backward. That is, starting from the last term xN and working back toward 1.

  5. Write a main function that calls each of your functions for x=0.99 and N = 100. Print the result of each function and the difference Efwd – Ec and Erev – Ec.

  6. Turn in your program and the numbers you printed in step 5 along with a short paragraph explaining the differences among the results.

The register usage conventions for the floating point registers are:

$f0 - $f2               floating point subprogram return value
$f4 - $f10              temporaries - not preserved across calls
$f12 - $f14             the first 2 floating point parameters - not preserved across calls
$f16 - $f18             temporaries - not preserved across calls
$f20 - $f30             saved values - preserved across calls

last edited 2005-11-08 13:26:07 by GaryBishop