News:

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

Finding out the total size of local variables

Started by Cobra, November 10, 2006, 12:14:47 PM

Previous topic - Next topic

Cobra

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

sinsi

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

Light travels faster than sound, that's why some people seem bright until you hear them.

Ratch

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

ToutEnMasm

The exact size in bytes
         mov ecx,ebp
         lea edx,lastlocal
                                                sub ecx,edx
Where last local is the name of the last .