I'm new to assembly programming and, as a part of a bigger program I have need to pass floating point values to another C-function. I have a call from my test program to my assembly function, that only pushes the parameters on the right stack, and calls a second C function.
My C test function:
extern void ext_func(char *result, double d); // C function
extern double tester(char *str, float d);
double a = tester(str, 3.14)
printf("%s\n", str); // Resulting in '0.000000'
// doing some fancy stuff with the float value and puts in result
ext_func(str, 3.14); // gives str = "3.140000"
x86, gcc -m32:
.globl tester
tester:
pushl %ebp # Standard
movl %esp, %ebp #
flds 12(%ebp) # Push second parameter on stack
pushl 8(%ebp)
call ext_func
addl $4, %esp
leave
ret
I think theres a problem with me only pushing 32 bit when ext_funct
expecting double. But I tried to the fldl, fld1, fildl, fldl 12 and 16(%ebp), and some of the other for "fun".
- My first question is, are ext_func missing some data on the float stack(ST), and is therefore not able to make the float value?(I understand you dont have the callee function, but doesnt matter what the function does?)
- Second, does the compiler allways go to to the f-stack to get float values if it expects them, or is it possible to read them from the memorystack?
- Third, is there seomething else I'm missing here? If I
printf("%f", a); //3.140000
printf("%f", str); //3.140000
but the other way a
gives big negativ number(100 digits or so) ended by 000000.