flat assembler
Message board for the users of flat assembler.

Index > Main > Local variables initial values

Author
Thread Post new topic Reply to topic
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 29 Oct 2012, 14:02
So when we write this code

Code:
local strHey[5]:BYTE
    


Does the system allocate 5 null bytes on the stack so that the following would be ok without explicitly mov-ing a 0 at the 4th index of the string "hey!" to terminate it?

Code:
mov dword[strHey], "hey!" ; 4 bytes
;------------------------------ I want to skip mov byte[strHey+4],0
invoke MessageBoxA,0,addr strHey,0,0
...
    


I want to skip the extra step of having to manually put a null byte but at the same time I'm not sure if there'll be garbage or not.
Post 29 Oct 2012, 14:02
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1618
Location: Toronto, Canada
AsmGuru62 29 Oct 2012, 14:41
There will be whatever is left on stack from previous code.
Post 29 Oct 2012, 14:41
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 29 Oct 2012, 23:50
That makes sense. Thanks. I checked in OllyDbg and in my case since the proc was the first to execute, there was a huge cave of null's on the stack after ntdll and kernel used it.

Thanks for the answer though.
Post 29 Oct 2012, 23:50
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1618
Location: Toronto, Canada
AsmGuru62 30 Oct 2012, 02:32
My code generator will have an option for this:
Code:
locals @8 =0      ; Align EBP to 8 byte boundary and set all local bytes to zero
{
    HANDLE  hFile
       INT32   value = -1
  PWCHAR  path = stkalloc (WCHAR, MAX_PATH)
   PVOID   pData
}
    
Post 30 Oct 2012, 02:32
View user's profile Send private message Send e-mail 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.