The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
March 23, 2023, 08:44:03 AM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  General Forums
| |-+  The Campus
| | |-+  About LOCAL string
« previous next »
Pages: 1 [2] Print
Author Topic: About LOCAL string  (Read 10950 times)
Gender: Male
Posts: 6011

Re: About LOCAL string
« Reply #15 on: September 16, 2009, 08:49:25 PM »

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

MyTest proc
LOCAL MyVar1:DWORD, LocBuffer[120]:BYTE, MyVar2:DWORD
  call ClearLocals
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
ClearLocals endp

Gender: Male
Posts: 416

when dream comes true

Re: About LOCAL string
« Reply #16 on: September 16, 2009, 09:34:28 PM »

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

Re: About LOCAL string
« Reply #17 on: September 16, 2009, 10:25:49 PM »

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.
Pages: 1 [2] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!