[Back to the 251 Home Page]

November 18, 2009
Comp Sci 251 Program 6: Floating Point Data (100 pts)

To submit electronically (suppose you are howeg89)   cp  pgm6.a  /DROPBOXES/251/howeg89/

Due date: Software electronically submitted before 3:00 pm Thursday December 10
Listings must be submitted at the beginning of class on the due date.
You may work alone or in pairs on this assignment (your choice).

Using the MIPS Register Conventions, write a MIPS assembly language program to compute and print the square root of an input value.

Program Behavior
Your program must have the following behavior (the underlined 2 is an example input value):

Program 6: Wing Huen

Enter a positive double precision integer? 2

Approximations			Difference from last approximation
2
1.5				0.5
1.41666666666666652		0.0833333333333334814
1.41421568627450966		0.00245098039215685404
1.41421356237468987		2.12389981979477227e-06

sqrt(2) = 1.41421356237468987

Behavior: empty lines as indicated; space after the question mark; and a newline after the answer is printed.

Algorithm
You must use the algorithm known as Newton's Method (an iterative method), which is defined by the following C++ function.

double root( double d )
{
  cout << d << endl;

  d1 = d ;
  do{
      d0 = d1 ;
      d1 = ( d0 + d/d0 ) / 2.0 ;
      error = abs(d1-d0);
      cout << d1 << "\t\t" << error << endl;
  }while( error >= eps );

  return d1;
}

Requirements
Use the read_double syscall to input a value and the print_double syscall to print values; write a function named root as shown above; do not use ``local variables''; call root from main (see root.cc).

Information
A complete C++ program that finds the square root of a number using Newton's Method can be found in directory ``/shared/huen/251/ch10_float_pt/''; the file name is ``root.cc''. You can create the executable by typing the command ``g++ -o root root.cc''; you can run the executable by typing ``root''.



Wing Huen 2009-11-19