; hi evryone!!
; get percent help!!

fild dword ptr
fild dword ptr
fild dword ptr
fist dword ptr

; some loop then, var1 == 80000000h
; why??!!

;sorry, i cant write english
Posted on 2002-10-28 08:24:54 by playh
I'm not so good at FPU coding, but it looks like you forgot to pop the values off the stack.


fild dword ptr
fild dword ptr
fild dword ptr
fistp dword ptr ; Notice the "fistp" instead of "fist"
fistp dword ptr

If anyone knows of a way to pop a value off the FPU stack without storing it, please post :)
Posted on 2002-10-28 09:08:55 by Qweerdy
got it!!
Posted on 2002-10-28 09:22:07 by playh
As I said, I'm not that good at FPU coding. I just read that fdiv and fmul without operands each pop one value off the stack, so at the end there's only one value on the stack.

In short: try removing the last line (the fistp ), it should work.
Posted on 2002-10-28 09:30:36 by Qweerdy
Why use the slooooow floating point instructions to perform integer mathematics?

; Computes a as A percentage of B
mov eax, A
mov ecx, B

lea edx, [eax*2 + eax]
lea eax, [edx*8 + eax]
shl eax, 2

xor edx, edx
idiv ecx

Note: should work for any value of A up to 42,949,672

Posted on 2002-10-28 10:01:27 by Mirno