PureBasic Forum
http://forums.purebasic.com/english/

[Inline ASM] What is the prefix for a static variable?
http://forums.purebasic.com/english/viewtopic.php?f=35&t=73876
Page 1 of 1

Author:  Mijikai [ Fri Oct 25, 2019 7:23 am ]
Post subject:  [Inline ASM] What is the prefix for a static variable?

What is the prefix for a static variable?

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

Author:  wilbert [ Fri Oct 25, 2019 7:34 am ]
Post subject:  Re: [Inline ASM] What is the prefix for a static variable?

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.

Author:  Mijikai [ Fri Oct 25, 2019 8:43 am ]
Post subject:  Re: [Inline ASM] What is the prefix for a static variable?

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?

Author:  wilbert [ Fri Oct 25, 2019 9:12 am ]
Post subject:  Re: [Inline ASM] What is the prefix for a static variable?

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. :)

Author:  mk-soft [ Fri Oct 25, 2019 9:25 am ]
Post subject:  Re: [Inline ASM] What is the prefix for a static variable?

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()

Author:  wilbert [ Fri Oct 25, 2019 9:36 am ]
Post subject:  Re: [Inline ASM] What is the prefix for a static variable?

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.

Author:  Mijikai [ Fri Oct 25, 2019 9:38 am ]
Post subject:  Re: [Inline ASM] What is the prefix for a static variable?

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

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/