How to get variables in a procedure with assembler

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

How to get variables in a procedure with assembler

Post 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)
SPAMINATOR NR.1
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Post by Nico »

It is very interesting for me, thank you! :)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

purbasic puts all variables on the stack
Of course, only those inside procedures. That's already well known. 8)
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Better known now! :)

Thanks for the tip and insight.
@}--`--,-- A rose by any other name ..
Post Reply