flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > LOCAL directive and generated names

Author
Thread Post new topic Reply to topic
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 10 Jul 2017, 08:40
Is there any way (in classic FASM) to use local directive inside macros to define macro-generated names?

For example, is it possible to write a macro which, when used like this…
Code:
defineLocals a(b, c), d(e, f, g)    

… would generate code equivalent to…
Code:
local a_b, a_c, d_e, d_f, d_g    

?

I know how to parse such parameters and tell the difference between names and “subnames”. The problem is with using something like
Code:
local some # thing    


Thanks.
Post 10 Jul 2017, 08:40
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 10 Jul 2017, 09:16
Normally LOCAL is processed with higher priority than operators like #, so to get it working you need nested macros. Either you can define external wrapper that would parse parameters and generate this line:
Code:
__defineLocals a_b, a_c, d_e, d_f, d_g    
and then use LOCAL directive inside the internal "__defineLocals" macro.

The other option is to use nested single-use macro with escaping, like:
Code:
macro defineLocals parameters&
{
    ; ...
    rept 1
    \{
        \local prefix#suffix
        ; ...
    \}
}    
Post 10 Jul 2017, 09:16
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 11 Jul 2017, 20:42
Tomasz Grysztar wrote:
Normally LOCAL is processed with higher priority than operators like #, so to get it working you need nested macros. Either you can define external wrapper that would parse parameters and generate this line:
Code:
__defineLocals a_b, a_c, d_e, d_f, d_g    
and then use LOCAL directive inside the internal "__defineLocals" macro.

The other option is to use nested single-use macro with escaping, like:
Code:
macro defineLocals parameters&
{
    ; ...
    rept 1
    \{
        \local prefix#suffix
        ; ...
    \}
}    

Got it, thanks. A few more questions if you don’t mind.

1. Am I right that the scope of local-definitions is the closest macro/struc/rept containing the local directive?
2. So, I need to save the generated unique name to a “more global” symbolic constant to use it later, right?
3. Is there any easy way (that I can’t see) to extend the defineLocals macro so that it could be used like:
Code:
defineLocals a_b, a_c, a_d  ; Defines all of them and creates a_b?XX and a_c?XX macros

macro a_d?XX params
{
  ...
}    
where a_d?XX could be written by something as simple as a_d?
Post 11 Jul 2017, 20:42
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 17 Jul 2017, 12:15
Solved the problem. Turned out to be quite easy even though my solution implied that the answers to the first two questions were “yes”.
Post 17 Jul 2017, 12:15
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.