Click to See Complete Forum and Search --> : FPU + external C file - how to return double


Stebel
April 20th, 2005, 01:30 PM
Hi

I'm working on a piece of assembly procedure that would enable me to return a double value (generated in asm module) to C code.

Up to now never produced such a code, so would be grateful if you could assist me a bit. I know that I should leave the value in st(0)

currently wrote a piece of C :

#include <stdio.h>

extern double test(void) ;

void main ( void )
{
double p ;
p = test () ;
printf ( "The num is %f \n", p ) ;
}

When I write and leave purre integer there's no problem. But how to leave 64bit value in ST ?

I start with

finit
fld... and here comes the problem

thanks for any assistance
Stebel.

rxbagain
April 27th, 2005, 05:39 AM
You can use FILD to return double from INTEGER or FLD to return from DOUBLE/SINGLE.

Examples: I just used C++ __asm to test it.

To return double from float/double

double dbltodbl()
{
float retval = 20;
__asm fld [retval]; /* return retval; */
}To return double from float/doubledouble inttodbl()
{
int retval = 2;
__asm fild [retval]; /* return retval; */
}
Hope it will help you.