Page 1 of 1
[Inline ASM] What is the prefix for a static variable?
Posted: Fri Oct 25, 2019 7:23 am
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
Re: [Inline ASM] What is the prefix for a static variable?
Posted: Fri Oct 25, 2019 7:34 am
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.
Re: [Inline ASM] What is the prefix for a static variable?
Posted: Fri Oct 25, 2019 8:43 am
by Mijikai
Thanks for the fast reply
The trick with the pointer is great
I did not find any information about this in the helpfile is there
another documentation for asm?
Re: [Inline ASM] What is the prefix for a static variable?
Posted: Fri Oct 25, 2019 9:12 am
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.
Re: [Inline ASM] What is the prefix for a static variable?
Posted: Fri Oct 25, 2019 9:25 am
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()
Re: [Inline ASM] What is the prefix for a static variable?
Posted: Fri Oct 25, 2019 9:36 am
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.
Re: [Inline ASM] What is the prefix for a static variable?
Posted: Fri Oct 25, 2019 9:38 am
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
mk-soft wrote:Asm 'lea' get the adress of variable...
I know...