flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > problem with circularily referencing macros |
Author |
|
vid 27 Oct 2007, 19:55
"tmp" works as supposed to. tmp uses "_push" macro, "_push" macro uses "push" macro, and it uses "_push". but since we already are in "_push" macro, FASM tries to assemble it as instruction
|
|||
27 Oct 2007, 19:55 |
|
bitRAKE 28 Oct 2007, 00:25
FASM stops when it first notices the circular reference and if that isn't an appropriate end it errors. That is the only useful way to handle circular references, imho. The other way is to always error.
push _push push <--- ah, circular - try to stop tmp _push push _push <-- ah, circular - try to stop |
|||
28 Oct 2007, 00:25 |
|
vid 28 Oct 2007, 01:05
Quote: FASM stops when it first notices the circular reference no it doesn't. there is no circular reference in FASM, there is just macro overloading. Code: macro push x{ display '1' push x } macro push x{ display '2' push x } push 10 |
|||
28 Oct 2007, 01:05 |
|
bitRAKE 28 Oct 2007, 03:41
vid, How does FASM know when to stop?
|
|||
28 Oct 2007, 03:41 |
|
LocoDelAssembly 28 Oct 2007, 04:02
Works like a stack. Everytime you define a macro with the same name the last will be in the top of the stack. When you call the macro, the body gets expanded and before preprocessing it this imaginary stack pops out one definition. When the preprocessor doesn't finds any macro with the name because of either the macro does not exists at that point or the stack is empty, the preprocessor just passes the line to the assembler stage and this one will fail if the line is not an assembler instruction.
I forgot to mention, the imaginary stack is restored once the whole expansion process of your macro invocation is finished. |
|||
28 Oct 2007, 04:02 |
|
bitRAKE 28 Oct 2007, 04:34
That seems a clear definition of the overloading process, but we are talking about macros with different names. How can the same process apply to different named macros?
|
|||
28 Oct 2007, 04:34 |
|
vid 28 Oct 2007, 12:37
same way as it applies to same-named macros. Play with this code:
Code: macro a { display 'a1' } macro b { display 'b1' a } macro a { display 'a2' b } macro b { display 'b2' a } b |
|||
28 Oct 2007, 12:37 |
|
bitRAKE 28 Oct 2007, 16:33
Why doesn't this work? Why should the B stack restore to include the new definition of B within the second A?
Code: macro a {display 'a1'} macro b {display 'b1' a} macro a {display 'a2' b} macro b {display 'b2' b a} b Code: macro a {display 'a1'} macro b {display 'b1' a} macro a {display 'a2' a b} macro b {display 'b2' a} b |
|||
28 Oct 2007, 16:33 |
|
vid 28 Oct 2007, 16:45
Code: macro a {display 'a1'} ;1 macro b {display 'b1' ;2 a} macro a {display 'a2' ;3 b} macro b {display 'b2' ;4 b a} b okay, so we have "b". that uses topmost macro "b", that is number 4. Number 4 uses nested "b" again, that is macro number 2. It uses topmost macro "a", that is number 3. This calls "b" again, but there isn't any macro "b" (we are already in both 4 and 2, so these doesn't count) |
|||
28 Oct 2007, 16:45 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.