flat assembler
Message board for the users of flat assembler.

flat assembler > Main > set all local variable to 0?

Author
Thread Post new topic Reply to topic
celtic88



Joined: 26 Mar 2018
Posts: 6
Hi Smile,


i want set all local variable to 0 , but i don't know the size of local.
Is there another solution?

code:

proc start
local var1:DWORD,var2:DWORD,var3[1000]:DWORD, ....

LEA edi, [var1]
MOV ecx, ??????
XOR eax, eax
@@:
STOSB
LOOP @b



ret
endp
Post 28 Sep 2018, 07:36
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16133
Location: Hyperborea
You can place a dummy label at the end of the locals list and subtract the first from the last to get the size.

BTW: You might want to consider using rep stosd instead of stosb/loop.

Also be mindful of the possibility of getting an exception when your local stack size is more than 4kB in size. You can fill the stack from the top down to properly trigger the guard page allocation mechanism.
Post 28 Sep 2018, 07:42
View user's profile Send private message Visit poster's website Reply with quote
celtic88



Joined: 26 Mar 2018
Posts: 6
@revolution, Very Happy Thank you so much
Post 28 Sep 2018, 08:01
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7003
Location: Kraków, Poland
revolution wrote:
You can place a dummy label at the end of the locals list and subtract the first from the last to get the size.

BTW: You might want to consider using rep stosd instead of stosb/loop.

Also be mindful of the possibility of getting an exception when your local stack size is more than 4kB in size. You can fill the stack from the top down to properly trigger the guard page allocation mechanism.
Perhaps it's worth mentioning that something like:
Code:
        lea     edi,[topmost_variable]
        mov     ecx,NUMBER_OF_VARIABLES ; assuming all are DWORDs
        xor     eax,eax
        std
        rep     stosd
        cld    
would do what you suggest.


Also, probably the best way to do it would be to write a customized prologue macro.
Post 28 Sep 2018, 10:00
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 453
Location: Belarus
I’d ask why would you want to do that. Having variable initialized to zero almost always gives you nothing: you’ll almost certainly write some other value to it. At least it is so for most variables, especially local ones. So, having them initialized to zero just to later be reinitialized to a useful value has no practical sense.

In cases you require exactly zeros it’s not that difficult to perform the initialization manually.

One more thing: you may add another local variable later which doesn’t require zero initialization. Will you still include it into the initialization process? Why?
Post 28 Sep 2018, 18:07
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.