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

Please help Using FPU assembly code in the \"double hullSpeed(double lgth)\" par

ID: 3668755 • Letter: P

Question

Please help Using FPU assembly code in the "double hullSpeed(double lgth)" part !

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

// do not change anything above this comment

double hullSpeed(double lgth)

{

       // here you will compute the hull speed for the specified boat length,

       // implementing the numerical computation in GNU Assembly Language

       // through use of FPU instructions (do NOT call sqrt() from math.h)

       return 0.0;

}

// do not change anything below this comment, except for printing out your name

double hullSpeedC(double lgth)

{

       // this C implementation of the hull speed computation is provided

       // so you can compare its correct results with the results of your code

       return 1.34 * sqrt(lgth);

}

int main(int argc, char **argv)

{

       double lgth;

       double hullSpd, hullSpdC;

       printf("CS201 - Assignment 02 - I. Forgot ");

       if (argc != 2) {

              printf("need 1 argument: boat length ");

              return -1;

       }

       lgth = atof(argv[1]);

       hullSpd = hullSpeed(lgth);

       hullSpdC = hullSpeedC(lgth);

       printf("hullSpeed(%.0f) = %.3f, %.3f ", lgth, hullSpd, hullSpdC);

       return 0;

}

Explanation / Answer

global _start section .data val: dq 123.45 ;declare quad word (double precision) section .bss res: resq 1 ;reserve 1 quad word for result section .text _start: fld qword [val] ;load value into st0 fsqrt ;compute square root of st0 and store in st0 fst qword [res] ;store st0 in result ;end program ;; c^2 = a^2 + b^2 - cos(C)*2*a*b ;; C is stored in ang global _start section .data a: dq 4.56 ;length of side a b: dq 7.89 ;length of side b ang: dq 1.5 ;opposite angle to side c (around 85.94 degrees) section .bss c: resq 1 ;the result length of side c section .text _start: fld qword [a] ;load a into st0 fmul st0, st0 ;st0 = a * a = a^2 fld qword [b] ;load b into st1 fmul st1, st1 ;st1 = b * b = b^2 fadd st0, st1 ;st0 = a^2 + b^2 fld qword [ang] ;load angle into st0 fcos ;st0 = cos(ang) fmul qword [a] ;st0 = cos(ang) * a fmul qword [b] ;st0 = cos(ang) * a * b fadd st0, st0 ;st0 = cos(ang) * a * b + cos(ang) * a * b = 2(cos(ang) * a * b) fsubp st1, st0 ;st1 = st1 - st0 = (a^2 + b^2) - (2 * a * b * cos(ang)) ;and pop st0 fsqrt ;take square root of st0 = c fst qword [c] ;store st0 in c and we're done! ;end program