0
#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 !!

2
Contributors
2
Replies
18
Views
4 Years
Discussion Span
Last Post by jay889000
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.