So I am writing some C with Assembly in AT&T. I've got small problem right now, because when I call first function that is f_float with float parameter, parameter is loaded from stack and returned value is proper. But with the second call f_double with double parameter, the value isn't loading from stack. I'm on linux Mint 17.1, gcc version 4.9.2(Ubuntu4.9.2-0ubuntu1~14.04). Any advices?
main.cpp
#include <stdio.h>
float f_float(float);
double f_double(double);
int main()
{
float a, f_result;
double b, d_result;
printf("\nInsert float number: ");
scanf("%f", &a);
printf("\nInsert double number: ");
scanf("%lf", &b);
f_result = f_float(a);
d_result = f_double(b);
printf("\nResult of float with f function: %f", f_result);
printf("\nResult of double with f function: %lf", d_result);
return 0;
}
functions.s
s_precision = 0x007f
d_precision = 0x027f
#(x^2)/(sqrt(x^2 +1) +1)
.globl f_float
.type f_float, @function
f_float:
pushl %ebp
movl %esp, %ebp
subl $2, %esp
finit
movl $s_precision, -2(%ebp)
fldcw -2(%ebp)
flds 8(%ebp)
fmul %st(0)
fld1
fadd %st(1), %st(0)
fsqrt
fld1
fsubr %st(1), %st(0)
movl %ebp, %esp
pop %ebp
ret
.globl f_double
.type f_double, @function
f_double:
pushl %ebp
movl %esp, %ebp
subl $2, %esp
finit
movl $d_precision, -2(%ebp)
fldcw -2(%ebp)
fldl 8(%ebp)
fmul %st(0)
fld1
fadd %st(1), %st(0)
fsqrt
fld1
fsubr %st(1), %st(0)
movl %ebp, %esp
pop %ebp
ret
Changing
movl $*_precision
tomovw $*_precision
resolved problem. That was mistake of course, but thought that it will overwrite the data left on stack later on. Anyway, problem soved. Thanks to everyone for help. – Robs