I wrote a function named absD that i want to return the absolute value of its argument.. I am using GCC inline assembly with cygwin..
I dont see why its not working. i m loading into memory. then into st(0) where i am using fabs - absolute value. Do i have to allocate memory?
I am trying to learn assembly with C here so please be nice. Please give me good help. Thank you
heres the code and then the error:
#include <stdio.h>
#include <stdlib.h>
#define PRECISION 3
double absD (double n)
{
asm(
"fldl %[nIn]\n"
"fabs\n"
"fstpl %[nOut]\n"
: [nOut] "=m" (n)
: [nIn] "m" (n)
);
return n;
}
int main (int argc, char **argv)
{
double n = 0.0;
printf("Absolute value\n");
if (argc > 1)
n = atof(argv[1]);
printf("abs(%.*f) = %.*f\n", PRECISION, n, PRECISION, absD(n));
return 0;
}
here is the output:
~ $ gc a3
gcc -Wall -g a3.c -o a3
~ $ ./a3
Absolute value
abs(0.000) = 0.000
~ $
Not outputing its absolute value... Thank you..