Mail Archives: djgpp/1998/05/16/17:57:03
Atte Koivula wrote:
>
> Hi,
Hello
>
> I have a problem with FPU instructions in NASM. I'm trying to write a
> program that takes a float value as input and then gives the square
> root of that value as output (either by returning the result or by
> moving it in a variable that has been given as an argument for the
> function).
When you are writting a FUNCTION, which should return a float, you have
to
put the return value into st(0)
Your code:
global _mysqrt
_mysqrt:
push ebp ; standart proc header
mob ebp,esp
fld [ebp+8]
fsqrt
leave ; exit
ret
in C:
extern float mysqrt(float);
then YOu can use that as a function.
>
> If I understood the idea correctly (by experimenting), I should store
> the number into the FPU stack (possibly with fld or something), then
> do a 'fsqrt' and then store the output to a variable (fst or something
> like that), but I do not know the proper syntax as pieces of example
> source code on the subject are scarce to say the least.
If you wanna use void, intead of float to return, you can store the
return value in a variable.
in ASM:
EXTERN _ret
GLOBAL _mysqrt
_mysqrt:
push ebp
mov ebp,esp
fld [ebp+8]
fsqrt
fstp [_ret]
leave
ret
>
> I realize that this message should be in an asm newsgroup, but since
> many of you use NASM I thought I'd post it here.
yes, and GNU asm, I think most of `em.
>
> -aK
Good luck
- Raw text -