Qbasicnews.com

Full Version: ASM block, floating point operations
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm having a very strange problem, when I run the program below, angle stays constant at 1, when infact it should be increasing...
Why is it constant at 1 when it shouldnt... :-?

Thanks for your help! 8)

Code:
Dim cosval As Single
Dim sinval As Single
Dim angle As Single

Do
angle += 1

Print angle

Asm
    fbld angle
    fbld angle
    fsin
    fcos
    fbstp cosval
    fbstp sinval
End Asm

Loop Until Multikey(1)
fbld and fbst[p] are for 80-bit reals, whereas FB's Single is 32 bits. You should use FLD and FSTP (with size specifiers) instead:

Code:
option explicit

Dim cosval As Single
Dim sinval As Single
Dim angle As Single

Do
angle += 1

Print angle

Asm
    fld dword ptr [angle]
    fld dword ptr [angle]
    fsin
    fcos
    fstp dword ptr [cosval]
    fstp dword ptr [sinval]
End Asm

Loop Until Multikey(1)
I'll leave it up to you to test if this is actually producing the correct results... I don't have time to check the logic atm...
Yup, it works, thanks! 8)