Menu

#62 add support for %@ to perform mmac selfref

open
nobody
None
1
2003-12-23
2003-12-23
No

I've added support for %@ to my local forked
version of NASM, to enable self-referencing
multi-line macros. This addresses SF #663166.

Up until now, the following would not work:

%MACRO mmac 0-1
%IF %0 == 0
mmac 00h
%ELSE
db %1
%ENDIF
%ENDMACRO

mmac ; fails
mmac 01h ; works

The reason for why it doesn't work is this:

%MACRO push 1
; do something with %1
push %1 ; here we don't want to invoke
; the "push" macro again
%ENDMACRO

Sometimes overloading could be used to do it:

%MACRO mmac 0
db 00h
%ENDMACRO

%MACRO mmac 1
db %1
%ENDMACRO

mmac ; works
mmac 01h ; works

And now, thanks to %@, self-references work:

%MACRO mmac 0-1
%IF %0 == 0
%@mmac 00h
%ELSE
db %1
%ENDIF
%ENDMACRO

mmac ; works
mmac 01h ; works

They also work when they are made indirectly:

%MACRO mmac 0-1
%IF %0 == 0
mmac2 00h
%ELSE
db %1
%ENDIF
%ENDMACRO

%MACRO mmac2 1
%@mmac %1
%ENDMACRO

mmac ; works
mmac 01h ; works

Attached find the necessary changes. They do
target a 0.98-derived preprocessor, though it
should be easy to port them to 0.98.x.

Btw, these changes also address SF #864194.

Discussion

  • nasm64developer

    nasm64developer - 2003-12-23
     
  • nasm64developer

    nasm64developer - 2003-12-23
    • priority: 5 --> 1
     
  • nasm64developer

    nasm64developer - 2007-09-23

    Logged In: YES
    user_id=804543
    Originator: YES

    I closed SF #663166 in favor of this one.

     

Log in to post a comment.