flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macro in Macro

Author
Thread Post new topic Reply to topic
Sarge



Joined: 04 Nov 2005
Posts: 14
Location: Australia
Sarge 14 Feb 2006, 03:42
Hi,

I was wondering, whats the downside to using a macro in another macro eg:

Code:
Macro a
{
}

Macro b
{
a
}    

_________________
Thanks,
Sarge
Post 14 Feb 2006, 03:42
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 14 Feb 2006, 10:27
think of this code:
Code:
macro a { macro_a_body }
macro b {a}
b    

steps:

1. preprocessor finds macro "a" declaration and saves it

2. same for macro "b" declaration

3. preprocessor finds macro "b" used, so it replaces this line with body of macro "b", and continues preprocessing this body.

4. as next thing, it finds usage of macro "a" (generated by macro "b" body), so it again expands this macro (replaces "a" line with body of macro "a")

5. it continues to preprocess new lines, finds line with "macro_a_body", which is not any kind of preprocessor directive, so it lets it be. So result is one line containing "macro_a_body"

PS: It doesn't work exactly as i described, but it is enough to understand behavior in such cases.
Post 14 Feb 2006, 10:27
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 14 Feb 2006, 12:32
additional thoughts:
The problem is that with some tricky code that includes nested macros, matches etc. the assembler does more and more passes to resolve the code. When you have no nestings and everything is in correct order, there are fewer passes and the job gets done quicker.
Post 14 Feb 2006, 12:32
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 14 Feb 2006, 12:37
This is not really so straightforward related. Especially when you use matches and not if's, it's unlikely to get more passes because of it.
Post 14 Feb 2006, 12:37
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 14 Feb 2006, 14:44
these passes have nothing to do with macros.... multiple passes happen duing assembling (if, repeat), after all preprocessing (macro, match) is done.
Post 14 Feb 2006, 14:44
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Sarge



Joined: 04 Nov 2005
Posts: 14
Location: Australia
Sarge 14 Feb 2006, 15:52
Yea i understand, thanks for the info guys.

Thanks,
Sarge
Post 14 Feb 2006, 15:52
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 14 Feb 2006, 22:16
@vid:
Don't say it has *nothing to do* with macros etc.
Like Tomasz said, it is not that straigh-forward:
Code:
dd x,y

x=y+y
y=x-2 
    

This one takes 64 passes and as I understand there is little related to assembly... :/ ...only the dword
Post 14 Feb 2006, 22:16
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 14 Feb 2006, 22:25
But it is not related to preprocessor either. And in fact, in fasm's meaning of this term, this is exactly the "assembly" what happens here. Wink

Well, I still need to finish that "Understanding fasm" text to cover the preprocessor layer and then all the possible interactions between various layers...
Post 14 Feb 2006, 22:25
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 15 Feb 2006, 08:05
You do that! And then we'll come back on this topic to clear out what "macro in macro" means Very Happy

Sorry for confusion I've made :$
Post 15 Feb 2006, 08:05
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 15 Feb 2006, 09:13
i think reading my preprossesor tutorial may clear it for you _what_ is preprocessor (eg. just some textual substitutions)/
Post 15 Feb 2006, 09:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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.