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

#include <stdio.h> #include <stdlib.h> #define PRECISION 3 double absD (double n

ID: 3557728 • Letter: #

Question

#include <stdio.h>

#include <stdlib.h>

#define PRECISION 3

double absD (double n)

{ // ------------------------------------------------------------------ // Aside from the print statement in main() below, the only place // you can change code is between this comment block and the one at // the bottom of this function. // ------------------------------------------------------------------

return n;

// ------------------------------------------------------------------ // Here's the bottom of the function, again, aside from the print // statement below in main() do not change anything below. // ------------------------------------------------------------------ }

int main (int argc, char **argv)

{

double n = 0.0;

printf("CS201 - Assignment 04 - your name ");

if (argc > 1)

n = atof(argv[1]);

printf("abs(%.*f) = %.*f ", PRECISION, n, PRECISION, absD(n));

return 0;

}

Can someone help me explain what are the code really doing ? How each line of the codes really work ?

Thanks

Explanation / Answer

fld (%eax) means "load a float from the value at address %eax". Obviously, the contents of %eax are a double, and not a pointer to a float, which is why you segfault.