HW10: Floating Point Calculations due Mon 18 Nov 23:59

Purpose

This assignment gives practice writing x86_64 assembly code that:

Allowed and Disallowed Resources

In completing this assignment you MAY use/access the following resources:

You may NOT use/access:

Failure to abide by these guidelines will result in a zero for the assignment and the incident will be reported to the university provost as a violation of the university academic integrity policy. A second incident of academic dishonesty (whether from this course or another computer science course) will result in an F in the course.

Problem Description

In this assignment you will implement the calculation of a series that is used to produce estimates of $\pi$. The series, known as the “Horner form”, is expressed like this:
$\displaystyle \frac{\pi}{2} = 1 + \frac{1}{3}\left(1 + \frac{2}{5}\left(1+\frac{3}{7}\left(1+\frac{4}{9}\left(1+\ldots\right)\right)\right)\right)
$

The approximation of $\pi$ gets closer and closer to the actual value as you continue the pattern. For our purposes we'll parameterize the series with an integer value $n = 0, 1, 2, \ldots$.

When $n=0$ we get $\frac{\pi}{2}= 1$ (which with a bit of algebra yields $\pi = 2$).

When $n=1$ we get $\frac{\pi}{2}= 1+\frac{1}{3}= 1.\bar{3}$ (yielding $\pi = 2.\bar{6}$).

When $n=2$ we get $\frac{\pi}{2}= 1+\frac{1}{3}(1+\frac{2}{5})$ (yielding $\pi = 2.9\bar{3}$).

Your x86 program will implement a function called estimate_pi that will accept an integer value of $n$ as a parameter and will return a double-precision estimate of $\pi$. Your function will use register-based calling conventions.

Then, in a loop, you will call your function with increasing values of $n$ to produce output similar to this:

Estimation for pi: 2.000000
Estimation for pi: 2.666667
Estimation for pi: 2.933333
Estimation for pi: 3.047619
Estimation for pi: 3.098413
Estimation for pi: 3.121501
Estimation for pi: 3.132157
  .   .    .    .    .
  .   .    .    .    .
  .   .    .    .    .

Your program will end when your estimate gets within 0.0000001 of 3.14159265358979323846. NOTE: The I/O macros only show about 6 decimal places so you won't be able to see the exact results. To determine whether you are within a fraction of the goal you will need to do this calculation: error= abs(estimate - goal). There are several ways to calculate the absolute value in x86 assembly. We'll do it by calling the C-language fabs function provided by the math library as practiced in the lab exercises.

ADVICE: Code your solution in a high level language (including a separate function for estimate_pi). Once it is working properly then start encoding it in assembly. Write and test the function first. Once it is working then complete the main program.

Grading and Submission

Your work should be done in the hw10 directory of your homework repository. Your program will be graded according to the following criteria:
Correctness/Completeness 16 pts
Documentation 2 pts
x86 Conventions 2 pts
Total 20 pts

See Homework #6 for instructions on proper documentation and on x86 assembly language conventions.

Assembly Language

Segmentation Fault Counter

1779736961