flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Efficient use of symbolic constants

Author
Thread Post new topic Reply to topic
DimonSoft



Joined: 03 Mar 2010
Posts: 835
Location: Belarus
DimonSoft
I have a symbolic constant, its value is affected by several different macros. Generally they use the constant to store temporary list. Thus its value changes this way:

Code:
Item1
Item1 Item2
Item1 Item2 Item3
<Empty>
Item4
Item4 Item5
<Empty>
etc…    


The use of the symbolic constant expands to sth like this (pseudocode):

Code:
MyConst equ
MyConst equ Item1
MyConst equ MyConst Item2
MyConst equ MyConst Item3
MyConst equ
MyConst equ Item4
MyConst equ MyConst Item5
MyConst equ
etc…    


Since you can use restore, I guess, some kind of stack is maintained by FASM, which can grow quite large. In my case I don't need the previous values of the constant and I'd better decrease the amount of memory used by the preprocessor since the lists can become pretty large.

What is the preferred way of symbolic constant usage for such cases?
Post 12 Dec 2013, 21:14
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
DimonSoft,

That depends. If you simply need to redefine symbolic constant, you may use somethine like this:
Code:
struc reequ [val] {
common
  restore .
  . equ val
}    
When val can refer to symbol being redefined, match should be used to expand it beforehand:
Code:
struc reEqu [val] {
common
  match _val, val \{ . reequ _val \}
  match , val \{ . reequ \}
}    
These macros work well for building intra-macros symbolics; to maintain lists you may find several implementations around here.

Another way is to use symbolics' stack directly: put a sentinel value in advance, then simply use equ to push values; pop them with restore.
Post 13 Dec 2013, 03:17
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
DimonSoft
Quote:
In my case I don't need the previous values of the constant and I'd better decrease the amount of memory used by the preprocessor

I completely understand your need to clean up, and I also try to clean up after myself, but it empirically turns out, that you cannot decrease the memory consumption by restoring the values of symbolic constants. I'm not aware of whether fasm frees any stack memory, but even if it does the very usage of any additional directive in the source increases the memory consumption, just because fasm does a straightforward textual expansion of macros.

Thus to sum up reequ provided by baldr is a nice macro and I use it extensively, but every time you invoke an additional restore you make fasm consume more memory than you could free from the symbolic constant stack.

_________________
Faith is a superposition of knowledge and fallacy
Post 13 Dec 2013, 09:44
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
baldr
Quote:
When val can refer to symbol being redefined, match should be used to expand it beforehand

This one is a bit unfortunate because of the constant expanding behaviour of match. In order to have a no-strings-attached-additional-variable, you could either use irp {common } or replace your reequ with an analogous redefine instead. I prefer to use the following way:
Code:
struc reequ [val]
{
        common
                tmp equ val
                        restore .
                        . equ tmp
                restore tmp
}    

It does not look that nice and cannot be rewritten into a single line, but it also consumes a bit less memory.

_________________
Faith is a superposition of knowledge and fallacy
Post 13 Dec 2013, 09:55
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.