division 8086/8087 1/3 =3?
题
I´m having a huge problem using fdiv
!!!! I'm trying to divide 1/3
so this is what I do
.model small
.stack 100h
.data
var1 dd 1
var2 dd 3
var3 dd 2
resultado dt 0.0
.code
mov ax,@data
mov ds,ax
finit
fild var1
fild var2
fdiv
fstp resultado
ffree
.exit
As you can see I move the result to resultado
because I can't see the result in st(0)
(I'm using tasm so I just can see variables in the debugger) the result should be 3EAAAA3A
but I'm getting 40400000
... that's 3
!!! how is it possible?? I tried exchanging variables and nothing!!! Can you help me?? =(
解决方案
If the FPU is as old as a 8087 you have to put a fwait
instruction after the fdiv
. Otherwise you may read a result from the FPU while the FPU is still executing the division and the result you write back is undefined.
This 'feature' has been removed in the 80287 FPU.
其他提示
The presented code does not exhibit the stated problem. It calculates 0.3(3) with FDIV
(it's actually FDIVP ST(1), ST
, so it divides ST(1)=1.0 by ST(0)=3.0) and then stores it as as a sequence of 10 bytes (AB AA AA AA AA AA AA AA FD 3F) into resultado
.