Page 1 of 1

NASM - Official Recursive Macro Support!

Posted: Mon Nov 08, 2010 11:28 am
by SpooK
This is an official announcement regarding the rewrite/revamp of the NASM preprocessor, now available as part of the official/main NASM source code starting with NASM 2.10rc2.

This rewrite addresses issues with implementing recursive macros (%rmacro/%irmacro) as previously attempted, %exitmacro and also makes room for new directives.

New NASM Directives:
  • %rmacro: Recursive Macro, can be called arbitrarily deep (really high limit [2^20] set to catch infinite loops.)
  • %irmacro: Same as above, except case-insensitive like %imacro.
  • %exitmacro: Terminates the current macro invocation, much like %exitrep; can be nested in other preprocessor directives (e.g. %if/%endif) within the macro, with exception of another macro, of course.
  • %while/%endwhile/%exitwhile: A fusion between %rep and %if.
  • %comment/%endcomment: Comment block for long/multi-line comments. A little syntactic sugar, if you will.
  • %final: Causes rest of line after %final to be preprocessed after all other "normal" preprocessing is complete. Multiple %final directives work like the x86 stack, LIFO/FILO.
This rewrite also addresses efficiency issues with heavy/nested macro invocations.

Please help us test this rewrite further by downloading/compiling the NASM 2.10rc2 and testing it against your NASM code/snippets.

NASM 2.10rc2 is available for download (source and binaries) at http://www.nasm.us/pub/nasm/releasebuilds/2.10rc2/

Please note that the official documentation will be updated over the next few weeks as we approach an official/stable NASM 2.10 release.

If there are any questions/comments/concerns, please reply to this thread.

Thanks. -SpooK

Re: NASM - Official Recursive Macro Support!

Posted: Tue Nov 09, 2010 3:25 am
by qw
How much I appreciate NASM, I really dislike its preprocessor syntax. It continues to be expanded with new directives, straightly contradicting the NASM philosophy. Whoever invented "%elifnidni"?

Try to write this in NASM:

Code: Select all

#if defined FOO || BAR == some_value

Re: NASM - Official Recursive Macro Support!

Posted: Tue Nov 09, 2010 3:28 am
by Solar
Easy. Write it just like that and feed your source through the C precompiler first. 8)

(Half serious. I actually do prefer using the C preprocessor for the few ASM source files I have, because I - and most others - are quite familiar with its syntax, and I'm not a friend of heavy macro-ized ASM anyway.)

Re: NASM - Official Recursive Macro Support!

Posted: Tue Nov 09, 2010 3:32 am
by qw
Solar wrote:Easy. Write it just like that and feed your source through the C precompiler first. 8)
Actually, when I write for GAS I do use the C preprocessor. Haven't tried it with NASM though.

BTW I acknowledge that the NASM preprocessor is very powerful, much more powerful than the C preprocessor. It is just the syntax I don't like.