www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/16/17:57:03

Message-ID: <355E0B45.19556968@hotmail.com>
Date: Sat, 16 May 1998 23:55:17 +0200
From: Archee/CoNTRACT <soltesz AT hotmail DOT com>
Reply-To: soltesz AT hotmail DOT com
Organization: School
MIME-Version: 1.0
To: Atte Koivula <yorka AT dlc DOT fi>
CC: djgpp AT delorie DOT com
Subject: Re: FPU instructions in NASM
References: <355ca863 DOT 1204556 AT news DOT dlc DOT fi>

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019