LD08: Floating Point Calculations due Thu 14 Nov 13:20

Purpose

In this lab you will learn/practice:

Preparation for Lab Day

Do these steps to get ready for lab day:

Lab Day

  1. At the beginning of the period show the modifications you made to the pre-lab program and share your conclusions.

  2. A common method in numerical algorithms it is to estimate a solution to a problem by iteratively generating closer and closer approximations to the solution. These algorithms typically have a cutoff value such that when the error gets below this value the algorithm ends with an acceptably close solution. Consider the following Java-like code (assuming all variables are double values):
    error= Math.abs(estimate - goal);
    if (error <= cutoff)
       System.out.println("Answer is: "+estimate);
    else
    	System.out.println("Try again!");
    

    NOTE: We calculate the absolute value of the difference of the estimate and the goal because the difference could be negative.

  3. There does not appear to be a great way to calculate absolute value in assembly using unpacked XMMx registers. So, we'll calculate it using by calling C's math library. The name of the function we'll call is fabs. It takes a double variable as a parameter and returns a double. Floating point parameters are passed in xmm0, xmm1, ... with the return value being placed in xmm0.

    Use what you know about calling C-language functions in assembly code to calculate x= fabs(-2.4); by calling the C fabs function.

    NOTE: To properly assemble and link the code you'll need to add the -lm switch to indicate you want to include C's math library:

    nasm -f elf64 myprog.asm
    gcc myprog.o -lm
    

  4. Continue modifying your program so you implement the Java-like algorithm presented above.

  5. Show the instructor your completed and working code.

  6. If you finish early, work on your homework assignment until the end of the lab period.

Assembly Language

Segmentation Fault Counter

1779740159