flat assembler
Message board for the users of flat assembler.

Index > Windows > big local variable size causes fasm hung

Author
Thread Post new topic Reply to topic
nazha



Joined: 05 Mar 2009
Posts: 40
Location: Beijing, China
nazha 02 Sep 2009, 09:06
if declare a local variable with big size, fasm will always in the progress of compiling when compile this code:

proc myproc
locals
var1 dd 51200 dup (0)
endl
ret
endp

I see the esp's initial value is 0007FFC4, does it means the max size a local variable can be<0007FFC4? is there a way to extend the default stack size?

_________________
Assembly Asker
Post 02 Sep 2009, 09:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20448
Location: In your JS exploiting you and your system
revolution 02 Sep 2009, 09:18
The problem is that you have to "touch" then stack at runtime else you will get access exception. See this thread for more information.
Post 02 Sep 2009, 09:18
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 02 Sep 2009, 12:37
It fails to compile or it fails to run?
Post 02 Sep 2009, 12:37
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 02 Sep 2009, 12:40
it fails to compile, but who declares initialized data in local variables?
Post 02 Sep 2009, 12:40
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 02 Sep 2009, 12:43
I think touching will only help for running.. try changing 0 to ? to help it compile..
Post 02 Sep 2009, 12:43
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
nazha



Joined: 05 Mar 2009
Posts: 40
Location: Beijing, China
nazha 02 Sep 2009, 14:07
it fails to compile, even add following lines to proc32.inc:
repeat localbytes shr 12
mov byte[esp-%*4096],0
end repeat

yes, after change to rd 51200, it can be compiled. above three lines help to run.
tks.
Post 02 Sep 2009, 14:07
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 02 Sep 2009, 14:52
Can you do it manually, without using macros, does it still not compile? I guess not right? (I don't use the macros anyway)
Post 02 Sep 2009, 14:52
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 02 Sep 2009, 15:00
It doesn't really hang, it just enters a really long loop of virtual-load directives to generate MOV instructions that initialize the local variables for you. You really shouldn't use initialized locals that big - it generates 12800 MOV instructions (and for each one it virtualizes the whole block - really an overkill, but it's because of the limitations of "load"/"store" directives in fasm 1.x architecture). On my system it took 128 seconds to assemble and generated 500 KB executable.
Post 02 Sep 2009, 15:00
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 02 Sep 2009, 17:38
Confused

Why does it need 500,000 bytes to make 12,800 movs? Is each mov 39 bytes long?
Post 02 Sep 2009, 17:38
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael 02 Sep 2009, 17:56
Because there are 51,200 MOVs. 9.77 byte per MOV, so it's possible (there are many MOVs with DWORD displacement and immediate - 8 bytes, and we must remember that there are two bytes more per MOV - one for opcode and one for mod r/m, so, the size of most MOVs is 10 bytes).
Post 02 Sep 2009, 17:56
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 02 Sep 2009, 18:03
Yes, there are 51200 MOVs, my mistake, I thought it was "db" there, but it was "dd".
Post 02 Sep 2009, 18:03
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 02 Sep 2009, 18:12
Why not use dword movs for dd?
Post 02 Sep 2009, 18:12
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 02 Sep 2009, 18:43
Quote:

Why not use dword movs for dd?

They are dword movs already.
Post 02 Sep 2009, 18:43
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 02 Sep 2009, 18:52
Oops x_x my math was all wrong. Sorry.
Post 02 Sep 2009, 18:52
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 02 Sep 2009, 19:00
Interesting corner-case flaw, this thread should probably be in Macro or Compiler Internals forum.

The compiler would need extra logic to figure out whether it should generate the MOVs inline or use the REP loop if the number before the DUP is too large, or just use a REP prefix loop all the time.
Post 02 Sep 2009, 19:00
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 02 Sep 2009, 19:10
It's not the compiler here, it's the macros. Wink
Post 02 Sep 2009, 19:10
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.