IonicWind Software

IWBasic => The Roundtable => Topic started by: Ionic Wind Support Team on November 27, 2006, 08:29:26 PM

Title: Clearing local variables.
Post by: Ionic Wind Support Team on November 27, 2006, 08:29:26 PM
Original post by Fletchie on the Pyxia forums.  Works in Emergence:
---------------------------------------------------------------------------------------------

The following function CL() - automatically clears/resets all local variables/strings/types in a subroutine to zero.

Call just after the 'defs' for the variables.

Can be useful if you have a lot of vars - and you need to make sure they're zero.

Don't use outside of a subroutine !!


type test
   def a:int
   def b:uint64
   def c:double
   def d:string
   def e:int
endtype
declare CL()
TestClear(1,2)
do:until inkey$<>""
end
'---------------------------------------------------
sub TestClear(a:int,b:int)
def var1:int
def var2:double
def var3:char
def t:test
   'Comment out CL() to see the difference...
   CL()
   print var1
   print var2
   print var3+0
   print t.a
   print t.b
   print t.c
   print len(t.d)
   print t.e
   return
endsub
'---------------------------------------------------
CL:
_asm
mov eax,esp            ; transfer esp to eax
add eax,16            ; add 16, skips the pushed EIP, esi,edi,ebx
xor edx,edx            ; Sets edx to zero
loopcl:
cmp eax,ebp            ; if eax equals ebp - we're done
je fincl
mov dword [eax],edx   ; clear 4 bytes
add eax,4
jmp loopcl            ; go-again
fincl:
ret
_endasm