PB4 Win32 - using ASM and doubles problem (solved)

Everything else that doesn't fall into one of the other PB categories.
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

PB4 Win32 - using ASM and doubles problem (solved)

Post 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

; ------------------------------------------------------------
Last edited by va!n on Mon May 15, 2006 4:50 am, edited 1 time in total.
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post 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


; ------------------------------------------------------------
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post 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
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Floats aren't returned through EAX anyway, so yes, remove it.
A single "ProcedureReturn" should be enough.
Good programmers don't comment their code. It was hard to write, should be hard to read.
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

thanks traumatic
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Post Reply