News:

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

Location counter??

Started by Ficko, June 06, 2010, 06:10:52 PM

Previous topic - Next topic

jj2007

Quote from: Ficko on June 06, 2010, 09:39:08 PM
(Zeroing local variables taking into account how many GPR was pushed)

The MasmBasic equivalent. In contrast to RtlZeroMemory, no regs are trashed here - think of fastcall...

include \masm32\include\masm32rt.inc

.code
start: call MySub
exit

MySub Proc
LOCAL Var01 :DWORD
LOCAL Var02[10h]:BYTE
call ClearLocVars
push esi
push edi
xor ebx, ebx
pop edi
pop esi
ret
MySub endp

ClearLocVars proc ; put "call ClearLocals" as first instruction after LOCALS - eax 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
@@:
 push 0
 cmp esp, eax
 ja @B
 sub esp, 8 ; 19 bytes with align 4
 pop eax
 ret
ClearLocVars endp
end start

Ficko

#16
A little correction:


ZEROSUBVARS MACRO Subroutine:REQ
mov ecx, ebp
lea eax, [esp+(($-Subroutine)-8)*4]
sub ecx, eax
invoke RtlZeroMemory,eax,ecx
ENDM


That way  "ZEROSUBVARS" can be put  immediately as the first "command" after "locals". :wink