It is currently Wed Nov 20, 2019 11:40 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [Inline ASM] What is the prefix for a static variable?
PostPosted: Fri Oct 25, 2019 7:23 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 568
What is the prefix for a static variable?

Code:
Procedure.i DoSomething()
  Static dummy.i
  !mov [???_dummy],123;<-
  ProcedureReturn dummy
EndProcedure


Top
 Profile  
Reply with quote  
 Post subject: Re: [Inline ASM] What is the prefix for a static variable?
PostPosted: Fri Oct 25, 2019 7:34 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3519
Location: Netherlands
At the moment it is like this
Code:
Procedure.l DoSomething()
  Static dummy.l
  !mov dword [so_DoSomething.v_dummy], 123
  ProcedureReturn dummy
EndProcedure

If you embed the procedure in a module, it will be different.

Since it includes the procedure name, I personally prefer to use a local variable as a pointer
Code:
Procedure.l DoSomething()
  Static dummy.l
  Protected *dummy = @dummy
  !mov rdx, [p.p_dummy]
  !mov dword [rdx], 123
  ProcedureReturn dummy
EndProcedure

That way it's not a problem if I want to change the name of the procedure or embed it in a module.

_________________
macOS 10.15 Catalina, PB 5.71 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: [Inline ASM] What is the prefix for a static variable?
PostPosted: Fri Oct 25, 2019 8:43 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 568
Thanks for the fast reply :)
The trick with the pointer is great 8)

I did not find any information about this in the helpfile is there
another documentation for asm?


Top
 Profile  
Reply with quote  
 Post subject: Re: [Inline ASM] What is the prefix for a static variable?
PostPosted: Fri Oct 25, 2019 9:12 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3519
Location: Netherlands
Mijikai wrote:
I did not find any information about this in the helpfile is there
another documentation for asm?

I looked at the asm code PureBasic generated. :)

_________________
macOS 10.15 Catalina, PB 5.71 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: [Inline ASM] What is the prefix for a static variable?
PostPosted: Fri Oct 25, 2019 9:25 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2046
Location: Germany
Asm 'lea' get the adress of variable...
Code:
Procedure.l DoSomething()
  Static dummy.l
  !lea rax, [so_DoSomething.v_dummy]
  !mov dword [rax], 123
  ProcedureReturn dummy
EndProcedure

Procedure.f DoSomething2()
  Protected dummy.f
  !lea rax, [p.v_dummy]
  !mov dword [rax], 0.123
  ProcedureReturn dummy
EndProcedure

Debug DoSomething()
Debug DoSomething2()

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: [Inline ASM] What is the prefix for a static variable?
PostPosted: Fri Oct 25, 2019 9:36 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3519
Location: Netherlands
mk-soft wrote:
Asm 'lea' get the adress of variable...

I know.
The pointer *dummy to the static variable is so that it's no problem to change the name of the procedure or place it inside a module.
Otherwise you have to change the asm code each time you change the procedure name.

Using EnableASM is another way to handle the problem
Code:
Procedure.l DoSomething()
  EnableASM
  Static dummy.l
  mov dummy, 123
  ProcedureReturn dummy
  DisableASM 
EndProcedure

Debug DoSomething()

But since some opcodes aren't recognized with EnableASM, I prefer to use a local variable as a pointer.

_________________
macOS 10.15 Catalina, PB 5.71 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: [Inline ASM] What is the prefix for a static variable?
PostPosted: Fri Oct 25, 2019 9:38 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 568
wilbert wrote:
Mijikai wrote:
I did not find any information about this in the helpfile is there
another documentation for asm?

I looked at the asm code PureBasic generated. :)


I always forget about that option :oops:

mk-soft wrote:
Asm 'lea' get the adress of variable...


I know...


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye