delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/05/12:50:16

From: csgcty AT singnet DOT com DOT sg
Date: Wed, 6 Aug 1997 00:49:42 +0800 (SST)
Message-Id: <199708051649.AAA02574@wisteria.singnet.com.sg>
Mime-Version: 1.0
To: djgpp AT delorie DOT com
Subject: FPU question

Hello !

I was trying out the FPU instructions (just FLD, FMUL and FST/FSTP). It
appeared that everything worked fine when I used FST but when I used FSTP,
the result went wrong, in the sense that the result is meaningless, although
sometimes it appears to have the same value as the first argument. The code
(corrected) appears below.

Also, it appears that I can't use FMUL without operands in NASM. 

I would greatly appreciate any assistance.
Thanks in advance.

Chan Tze Yi
csgcty AT singnet DOT com DOT sg

PS : Please reply by email because I no longer subscribe to the mailing list.

***start of asm file***
[BITS 32]

[GLOBAL _fp]

[SECTION .text]

;extern float fp(float a,float b)
fp_a equ 8
fp_b equ 12

_fp:
    push ebp
    mov ebp,esp

    fld dword [ebp+fp_a]
    fmul dword [ebp+fp_b]
    fstp dword [result] <------ this is the line

    mov eax,[result]

    mov esp,ebp
    pop ebp
    ret

[SECTION .data]

result dd 0.0


***start of cpp file***
#include <stdio.h>

extern "C" float fp(float a,float b);

void main()
{   float a=1,b;
	while(a!=0)
    {	scanf("%f %f",&a,&b);
	 	printf("%f\n",fp(a,b));
   	}
}
        

- Raw text -


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