I need to find out the total size of the local variables without manually counting them. Why does the sample code below not reference the correct size? Am I missing something here?
SomeProcedure PROC
locals_label LABEL BYTE
LOCAL var1:DWORD
LOCAL var2:DWORD
LOCAL var3:BYTE
LOCAL var4[3]:BYTE
LOCAL var5:QWORD
LOCAL var6[1000]:DWORD
locals_size = $ - locals_label
mov ecx, locals_size ; does not contain the correct size.
ret
SomeProcedure ENDP
Locals are allocated on the stack, so using the program pointer ($) won't work. Try this
SomeProcedure PROC
LOCAL a:DWORD,b[1000]:BYTE
mov eax,ebp ;EBP has the start of the locals
sub eax,esp ;ESP has the end
;now EAX has the length of all the locals (in this case, 1004)
SomeProcedure ENDP
Cobra,
You can define the local variables as a STRUC, then it is easy to count them no matter how you mix the data sizes. See #7 response of the link below. Ratch
http://www.masm32.com/board/index.php?topic=3783.0
The exact size in bytes
mov ecx,ebp
lea edx,lastlocal
sub ecx,edx
Where last local is the name of the last .