Page 1 of 1

How to get variables in a procedure with assembler

Posted: Tue Aug 31, 2004 5:44 pm
by Rings
Code updated For 5.20+

not a real tip, but good to know that purbasic puts all variables on the stack:

Code: Select all

EnableASM
Global L
Procedure testme(a,b,c,d)
  Debug a
  Debug b
  Debug c
  Debug d
  Debug "------------"
  MOV eax,dword[esp] ; this is variable a
  MOV L,eax
  Debug L
  MOV eax,dword[esp+4] ; this is variable b
  MOV L,eax
  Debug L
  MOV eax,dword[esp+8] ; this is variable c
  MOV L,eax
  Debug L
  MOV eax,dword[esp+12] ; this is variable d
  MOV L,eax
  Debug L
  
  Debug "------------"
  !MOV eax,dword[esp] ; this is variable a
  !MOV dword[v_L],eax
  Debug L
  !MOV eax,dword[esp+4]
  !MOV dword[v_L],eax
  Debug L
  !MOV eax,dword[esp+8] ; this is variable c
  !MOV dword[v_L],eax
  Debug L
  !MOV eax,dword[esp+12] ; this is variable d
  !MOV dword[v_L],eax
  Debug L
EndProcedure

result=testme(1,2,3,4)

Posted: Thu Sep 02, 2004 4:46 pm
by Nico
It is very interesting for me, thank you! :)

Posted: Fri Sep 03, 2004 3:19 pm
by Psychophanta
purbasic puts all variables on the stack
Of course, only those inside procedures. That's already well known. 8)

Posted: Fri Sep 03, 2004 3:21 pm
by Dare2
Better known now! :)

Thanks for the tip and insight.