Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Floating-Point Arithmetic Implement functions that perform calculati

ID: 3581293 • Letter: P

Question

Programming Floating-Point Arithmetic

Implement functions that perform calculation according to the tasks given below. All input and output variables must be of floating-point type (C/C++ float or double). Find correct formulas by yourself and define the required parameters and types in order to compute the result.

Note: Calculations, conditions and jumps may be implemented with Inline Assembler! Keep in mind that if you are using assembler module, then to return the floating-point result from the function by convention it must be placed in the FPU data register ST(0).

Apply The x87 FPU instructions for the solutions. Use the template below please and the app should be run without error.

Task for grade level 6: Calculate the area of parallelogram then the length of sides and angle between them is given.

Task for grade level 8: Calculate the surface area of cone when base radius and height is given.

Please use template below for the solutions;

#include "stdafx.h"

#include

#include

// For each grade level variant implement own function, e.g.:

double solution_for_grade_X(double a, double b, double c)

{

    double r;

    __asm

    {

        // Your Inline Assembler instructions for grade level X go here

        // :::

       fst QWORD PTR [r]    ; r = st(0)

    }

    return r; // Please note that in assembler module the result must be placed in st(0)!

}

int main()

{

    // Change the parameters according to your grade level function, e.g.:

    double r = solution_for_grade_X(1.5, 2.3, 5.6);

    // Print the result vector to the console:

    _tprintf(_T("%d "), r);

    // :::

    return 0;

}

Explanation / Answer

//AREA OF parallelogram

#include "stdafx.h"

#include

#include

// For each grade level variant implement own function, e.g.:

double solution_for_grade_X(double a, double b, double c)

{

    double r;

    __asm

    {
FLD a ;
FMUL b;
FSIN C ; C indicates angle
FMULP ST(0)

fst QWORD PTR [r]    ; r = st(0)

    }

    return r; // Please note that in assembler module the result must be placed in st(0)!

}

int main()

{

    // Change the parameters according to your grade level function, e.g.:

    double r = solution_for_grade_X(1.5, 2.3, 5.6);

    // Print the result vector to the console:

    _tprintf(_T("%d "), r);

    // :::

    return 0;

}

// SURFACE AREA OF CONE

#include "stdafx.h"

#include

#include

// For each grade level variant implement own function, e.g.:

double solution_for_grade_X(double a, double b)

{

    double r;

    __asm

    {
FLD H;
FMUL H;
FLD Ra;
FMUL Ra ;
FADD ST(1) ;

FSQRT;

FADD Ra;

FLD PHI;

FMUL Ra;
FMULP ST(0)

fst QWORD PTR [r]    ; r = st(0)

    }

    return r; // Please note that in assembler module the result must be placed in st(0)!

}

int main()

{

    // Change the parameters according to your grade level function, e.g.:

    double r = solution_for_grade_X(1.5, 2.3);

    // Print the result vector to the console:

    _tprintf(_T("%d "), r);

    // :::

    return 0;

}