Page 1 of 1

PB4 Win32 - using ASM and doubles problem (solved)

Posted: Mon May 15, 2006 2:52 am
by va!n
I am working on some stuff and i am trying/playing to get some ASM routines correctly working. Here is a small procedure using x86 ASM for getting the value of PI. Using double as ReturnValue would be nice instead using floats as ReturnValue. So i have declared the Procedure as double by using Procedure.d! Inside the procedure i am using the protected variable fReturnValue.f - as long as declaring this as float, i get a ReturnValue! But when i try to set the fReturnValue.d as double, i get everytime a zero result! If someone can show me my mistake i would be very happy. Or does it is still a hidden v4 bug?

Code: Select all


; ------------------------------------------------------------
; PB v4 Win32 API Test by Thorsten Will aka va!n in 05/2006
; ------------------------------------------------------------
;
; I am trying to return the value of PI! Storing the value
; to the variable fReturnValue.f (defined as float) works
; but not really correct... 
;
; Trying to define the variable fReturnValue.d (as double),
; for handling a more correct PI result does not work and
; returns only zero values (my mistake or a hidden bug?)
;
; ------------------------------------------------------------

Procedure.d MyPI() 
  Protected fReturnValue.f       ; Change this to .d (double)
  ! fldpi                         ; and test it
  ! fstp dword[p.v_fReturnValue]
  ! mov eax,[p.v_fReturnValue]
  
  Debug fReturnValue
   
  ProcedureReturn fReturnValue
EndProcedure


Debug "---- Using Floats ----"
fTest1.f = MyPi()
Debug fTest1.f

Debug "---- Using Doubles ----"
dTest2.d = MyPi()
Debug dTest2.d

Debug "" ; ==================================================

Debug "---- #PI using Float ----"
fTest3.f = #PI
Debug fTest3.f

Debug "---- #PI using Doubles ----"
dTest4.d = #PI
Debug dTest4.d

; ------------------------------------------------------------

Posted: Mon May 15, 2006 4:50 am
by va!n
problem solved! :wink: now i got the point and i did a very strange mistage DWord and QWord (just a stupid tpye mistake) :lol: Here is a working version for such are intersted in ^^

Code: Select all

; ------------------------------------------------------------
; PB v4 Win32 API Test by Thorsten Will aka va!n in 05/2006
; ------------------------------------------------------------
;
; Just a small procedure using x86 ASM to return the PI value
; as double. Just only a small inline asm test for PB4 ^^
;
; ------------------------------------------------------------

Procedure.d MyPI() 
  Protected dReturnValue.d       
  ! fldpi                         
  ! fstp qword[p.v_dReturnValue]
  ! mov eax,[p.v_dReturnValue]

  ProcedureReturn dReturnValue
EndProcedure


Debug "---- Using Floats ----"
fTest1.f = MyPi()
Debug fTest1.f

Debug "---- Using Doubles ----"
dTest2.d = MyPi()
Debug dTest2.d

Debug "" ; ==================================================

Debug "---- #PI using Float ----"
fTest3.f = #PI
Debug fTest3.f

Debug "---- #PI using Doubles ----"
dTest4.d = #PI
Debug dTest4.d


; ------------------------------------------------------------

Posted: Mon May 15, 2006 5:14 am
by va!n
Just a small question... is it possible that i can remove following line without any problems? I see no longer any reason yet for using it...

Code: Select all

 ! mov eax,[p.v_dReturnValue]
Thanks in advance

Posted: Mon May 15, 2006 6:32 am
by traumatic
Floats aren't returned through EAX anyway, so yes, remove it.
A single "ProcedureReturn" should be enough.

Posted: Mon May 15, 2006 2:20 pm
by va!n
thanks traumatic