Search code examples
assemblyx86tasmfpux87

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?? =(


Solution

  • 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.