flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Main > Out of memory when a lot of local (stack) variables declared

Author
Thread Post new topic Reply to topic
6a05



Joined: 31 Mar 2018
Posts: 3

Out of memory when a lot of local (stack) variables declared

Hello,
I started to use fasm as last stage in my compiler toolchain. I have generated x64 code with a lot of local declarations:


Code:

format PE64 console 5.0
entry start
include 'win64a.inc'

section '.text' code readable executable

proc start
  local .tmp0:QWORD
  local .tmp1:QWORD
  local .tmp2:QWORD
  ...
  local .tmp8191:QWORD  
  ret
endp  




I found that above code generates "error: out of memory" message even if I set memory limit to 1GB or more (-m flag). Also I found that a lot of local variables make assembly process much slower.

I already found that I can skip this problem by using tmp[8192]:QWORD construction, but I think it's not desired behavior for assembler.

Is it known beheavior and does somebody investigated it before?

Thanks in advice.
Post 31 Mar 2018, 15:30
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6769
Location: Kraków, Poland

The standard "proc" with "local" are defined as quite complex macros, and if you use these macros so many times, the source text grows quickly to large sizes (the assembler only starts processing the source text after it has gone through preprocessing in its entirety).

You could try using some customized macros with smaller implementation, so that the source text would not grow so large.

Alternatively, you could try fasmg with its set of fasm-compatibility Win32/Win64 macros. Because fasmg has no separate preprocessor/assembler layers like fasm 1, its macros use less memory. Your sample assembles easily with fasmg (with only problem being that "local" has to be replaced with uppercase "LOCAL" in current implementation of these compatibility macros), even though in that case even all the instructions are implemented as macros.
Post 31 Mar 2018, 17:11
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6769
Location: Kraków, Poland

I have updated fasmg with a new experimental feature which I had in mind since quite a long ago and it allows me to finally implement "proc" for fasmg with case-insensitive "local" without causing any problems with usage of "local" directive inside instruction set macros. I may update the Windows headers to use this new feature soon, but then they are going to need the latest fasmg to work.
Post 31 Mar 2018, 19:49
View user's profile Send private message Visit poster's website Reply with quote
6a05



Joined: 31 Mar 2018
Posts: 3


Tomasz Grysztar wrote:
The standard "proc" with "local" are defined as quite complex macros, and if you use these macros so many times, the source text grows quickly to large sizes (...)



I understand. Thanks for quick reply.


Tomasz Grysztar wrote:
Alternatively, you could try fasmg



I already switched to local .tmp[8191]:QWORD like constructon and calculate var offset manually while generating code in compiler. It's sufficient to go on with my current work. Result code is little less readable for human, but it's not a big issue for now.

I'll check out fasmg when earlier stages will be more stable. Thanks.
Post 01 Apr 2018, 13:50
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6769
Location: Kraków, Poland

If this is a code generated by your own compiler, the best solution for you might be to make custom macro package, best suited to the code that your compiler is able to produce. fasm's "proc" is a large macro mainly because it implements many syntax variants for the manual use. In case of compiler output the macros may support just one simplified syntax generated by compiler and nothing else.
Post 01 Apr 2018, 14:03
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


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.