[Inline ASM] What is the prefix for a static variable?

Bare metal programming in PureBasic, for experienced users
User avatar
Mijikai
Addict
Addict
Posts: 906
Joined: Sun Sep 11, 2016 2:17 pm

[Inline ASM] What is the prefix for a static variable?

Post by Mijikai »

What is the prefix for a static variable?

Code: Select all

Procedure.i DoSomething()
  Static dummy.i
  !mov [???_dummy],123;<-
  ProcedureReturn dummy
EndProcedure
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3734
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [Inline ASM] What is the prefix for a static variable?

Post by wilbert »

At the moment it is like this

Code: Select all

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: Select all

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, Windows 10
User avatar
Mijikai
Addict
Addict
Posts: 906
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Inline ASM] What is the prefix for a static variable?

Post by Mijikai »

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?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3734
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [Inline ASM] What is the prefix for a static variable?

Post by wilbert »

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, Windows 10
User avatar
mk-soft
Addict
Addict
Posts: 3071
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Inline ASM] What is the prefix for a static variable?

Post by mk-soft »

Asm 'lea' get the adress of variable...

Code: Select all

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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3734
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [Inline ASM] What is the prefix for a static variable?

Post by wilbert »

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: Select all

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, Windows 10
User avatar
Mijikai
Addict
Addict
Posts: 906
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Inline ASM] What is the prefix for a static variable?

Post by Mijikai »

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...
Post Reply