hi all,

from some time i would like to use local variables, but many time i discover that it is overwritten by some step of the process, so i lose the data inside:(

For example, i can't understand why i define the variable as below, but when i'm going to close the dialog box, i find that the variable is completely deleted by random values...

p_IDD_HWCONF proc uses ebx esi edi, hHwC:DWORD, wmsg:DWORD, wparam:DWORD, lparam:dword

LOCAL ActualDS[56]:dword

je @HW_Init
cmp wmsg,WM_COMMAND
je @HW_Command

mov eax,FALSE


Maybe there is a limit of space i can define as LOCAL ?

Posted on 2002-11-21 17:12:54 by Bit7

You use LOCAL values when you only need them for the life of a procedure. If you need persistent values, you write them in either the .DATA or .DATA? sections as they are GLOBAL in scope.

All that is happening is that a LOCAL is allocated on the stack when the procedure starts and is no longer valid when the procedure ends. Its like using a memory allocation function like GlobalAlloc() but simpler and faster.


Posted on 2002-11-21 17:56:29 by hutch--
Try instead

mov eax, wmsg
je @HW_Init
cmp eax,WM_COMMAND
je @HW_Command

should be able to save you some bytes.. and no data would be destroyed
Posted on 2002-11-21 21:59:18 by roticv
thx but,

nothing to do !
Also if i copt wmsg in eax data ar overwritten.
I have to define my variable as .data even if i dont need a global space for it.

Posted on 2002-11-22 09:30:49 by Bit7
The reason is that the function you define is not in constant operation.

Windows is like this:

You create a window, associate a function with it, and a structure for holding messages.

When a message appears in the queue for a window, the OS calls the function which does what you define it to do based on the given message, then quits.
Because it quits, the locals are trashed.

Basically when you perform a ret, any LOCAL variable you've defined is gone next time you come back.

Posted on 2002-11-22 11:03:15 by Mirno
THX mirno,

now is clear. So i can use a variable as LOCAL only befor the ret .

Posted on 2002-11-22 13:18:36 by Bit7
When you access a local variable, the assembler rewrites for example 'wmsg' as where ??? is the offset from the stack frame to the local variable. After you have returned and windows call the function again, ebp maybe has changed and/or some other function have been using the same space as their local variable storage. You should learn a little about what LOCAL really does and how the stack works in x86 assembler.
Posted on 2002-11-25 02:14:41 by gliptic