flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > recursion in macros |
Author |
|
gandalf 01 Mar 2009, 18:31
Is it possible that I can't refer to the macro X inside of the macro X?
|
|||
01 Mar 2009, 18:31 |
|
Tomasz Grysztar 01 Mar 2009, 18:42
Yes, it's true that you cannot access macro from within itself (read about it here, for example).
However it is possible to do macro recursion with a constructor-macro technique, but to show you how to do it, I would have to know more about what you're trying to achieve. |
|||
01 Mar 2009, 18:42 |
|
Tomasz Grysztar 01 Mar 2009, 20:58
Have a look at the MACRO/IF.INC from the standard set of Windows includes to see how such recursion is realised with fasm's preprocessor.
As for regular expressions, this is very unlike to be realizable with fasm's preprocessor because of the text tokenization it uses. I would suggest using some separate alternative preprocessor to get such features. |
|||
01 Mar 2009, 20:58 |
|
Tomasz Grysztar 01 Mar 2009, 21:03
This is how to apply that aforementioned constructor-macro trick into your sources to make the recursion work:
Code: macro def_match2 { macro match2 [args] \{ \common \local done define done 0 match , args \\{ define done 1 \\} match =| tail , args \\{ define toGo tail define done 1 \\} match =0 head tail , done args \\{ token equ token head def_match2 match2 tail \\} \} } def_match2 token equ match2 eax,3|ebx|ecx mov token |
|||
01 Mar 2009, 21:03 |
|
gandalf 02 Mar 2009, 18:50
Could you explain why it works?
The modification doesn't seem significant. Is there a way to see the result of macro expansions? |
|||
02 Mar 2009, 18:50 |
|
gandalf 02 Mar 2009, 18:54
gandalf wrote: Could you explain why it works? Sorry! I missed a very important thing |
|||
02 Mar 2009, 18:54 |
|
Tomasz Grysztar 02 Mar 2009, 18:55
gandalf wrote: Could you explain why it works? The "def_match2" macro defines the "match2" macro so that it can be called then. It's called once to define "match2" globally, and then it's called from inside the "match2" macro to make it possible to call the same "match2" from there. However I forgot to purge the macro definition in the example above. To keep the things clean, the recursive entry part should look like: Code: def_match2 match2 tail purge match2 gandalf wrote: Is there a way to see the result of macro expansions? Use "-s" switch with command line fasm to generate the symbolic info file, and the process it with "prepsrc" tool (from the TOOLS directory) to get the preprocessed source. |
|||
02 Mar 2009, 18:55 |
|
vid 02 Mar 2009, 23:54
Quote: Use "-s" switch with command line fasm to generate the symbolic info file, and the process it with "prepsrc" tool (from the TOOLS directory) to get the preprocessed source. or, use the "display" directive to see result |
|||
02 Mar 2009, 23:54 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.