flat assembler
Message board for the users of flat assembler.
Index
> Main > [fasmg] Split struc macro with postpone in an if / end if |
| Author |
|
|
Tomasz Grysztar 09 Jul 2026, 09:35
If you end up with mismatched nesting of control directives when your macros are put inside a conditional section, you may need to take special steps to ensure that what is unrolled unconditionally has them all paired properly.
To better understand what is happening, let's start with what the manual has to say about control directives, as POSTPONE is one of them: fasmg manual wrote: They are the instructions that control the flow of assembly. Each of them defines its own block of subordinate instructions, closed with corresponding "end" command, and if these blocks are nested within each other, it always must be a proper nesting - the inner block must always be closed before the outer one. All control directives are therefore unconditional instructions - they are recognized even when they are inside an otherwise skipped block. When passing through a skipped block this way, the assembler also unrolls are the macros that are unconditional. If you have a regular, "conditional" macro though, the assembler passes over it, and this way you can hide a control directive. Therefore to ensure that the assembler sees proper pairs of openings and closings of control blocks, your macros should either hide both ends or expose them both. Let's prepare a simple test case: Code: macro defer?
postpone
end macro
macro end?.defer?
end postpone
end macro
if 0
defer
content
end defer
end if Code: macro defer?
postpone
end macro
macro end?.defer?!
end postpone
end macro
if 0
defer
content
end defer
end if Of course in practice ensuring that both ends are equally hidden or exposed may be tricky. See for example one of my old variants of IRPS macro. There my main IRPS_AS_IRPV macro is conditional, but END.IRPS needs to be unconditional (to ensure that the assembler sees the END.IRPV even when there is nothing to interate over and the block is skipped). To make sure that the assembler sees the opening IRPV in all cases, I added a dummy IRPV and a macro override. When the block is skipped, the assembler does not process the macro definition and notices the dummy IRPV. When the block is not skipped, the macro gets defined, dummy IRPV is sees as this macro and not a control directive, but then the actual IRPS_AS_IRPV implementation generates the proper IRPV. As you can see, once you starting messing around with control blocks like that, you need to carefully consider all the scenarios. The use of CALM may help a lot, as it gives a better control over entire process. See the current implementation of IRPS in fasm2 package for example. |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.