News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

About LOCAL string

Started by stbfish, September 16, 2009, 06:08:02 AM

Previous topic - Next topic

jj2007

For the lazy programmer - short and fast, works with all kind of LOCAL variables, including strings and structures:

QuoteMyTest proc
LOCAL MyVar1:DWORD, LocBuffer[120]:BYTE, MyVar2:DWORD
  call ClearLocals
  ret
MyTest endp

ClearLocals proc ; put "call ClearLocals" as first instruction after LOCALS - eax will be unchanged on exit
  push eax ; do not use with uses esi etc - push them manually behind the call!
  lea eax, [esp+8] ; pushed eax and ret address
  mov esp, ebp ; base page of calling procedure
  align 4 ; 74 instead of 123 cycles on Celeron M, no effect on P4
@@:
  push 0 ; 120 bytes: 196 cycles on P4
  cmp esp, eax ; rep stosd??
  ja @B
  sub esp, 8 ; 19 bytes with align 4
  pop eax
  ret
ClearLocals endp

NightWare

Quote from: stbfish on September 16, 2009, 06:08:02 AM
LOCAL szDir[124]:BYTE

how to initialize it to all 0? like this szBuffer db 124 dup(0)

when i define a LOCAL Var, what is the default value inside?

to init/re-init a string you just need to clean the first byte, here :
mov BYTE PTR szDir,0
coz there is NO REASONS to clean the entire area (at least if your string functions are well coded...).

ecube

You guys like the caps...I tend to use buffers for alot more than strings, and that's why I recommended the full clearing, is a piece of mind for me and doesn't limit. If he's sure he's just gonna mess with strings then YEAH, clearing the first byte is sufficient.