#include <stdio.h>
#include <stdlib.h>

#define PRECISION   3

double absD(double n)
{
asm(
"_absD: \n"
"pushl %ebp \n"
"fldz \n"
"movl %esp, %ebp \n"
"fldl 8(%ebp) \n"
"fxch %st(1) \n"
"fucomp %st(1) \n"
"fnstsw %ax \n"
"sahf \n"
"jbe L2 \n"
"fchs \n"
"L2: \n"
"popl %ebp \n"
"ret \n"
"fldl %[nIn]\n"
"fabs\n"
"fstpl %[nOut]\n"
: [nOut] "=m" (n)
: [nIn] "m" (n)
);
// do not change anything above this comment

    return n;

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

int main(int argc, char **argv)
{
    double  n = 0.0;

    printf("CS201 - Assignment 02 - your name\n");
    if (argc > 1)
        n = atof(argv[1]);

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

    return 0;
}

I got an error saying parse error before string constant when I tried to compile it. I'm really new to C world . Any help would be appeciated !!

Inline assembly is very compiler dependent. Are you using the same compiler to build this program as your teacher used to write it?

I'm using cygwin to compile it !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.