Copyright (C) 2000-2012 |
GNU Info (nasm.info)Section 4.34.3. Multi-Line Macros: `%macro' ================================ Multi-line macros are much more like the type of macro seen in MASM and TASM: a multi-line macro definition in NASM looks something like this. %macro prologue 1 push ebp mov ebp,esp sub esp,%1 %endmacro This defines a C-like function prologue as a macro: so you would invoke the macro with a call such as myfunc: prologue 12 which would expand to the three lines of code myfunc: push ebp mov ebp,esp sub esp,12 The number `1' after the macro name in the `%macro' line defines the number of parameters the macro `prologue' expects to receive. The use of `%1' inside the macro definition refers to the first parameter to the macro call. With a macro taking more than one parameter, subsequent parameters would be referred to as `%2', `%3' and so on. Multi-line macros, like single-line macros, are case-sensitive, unless you define them using the alternative directive `%imacro'. If you need to pass a comma as _part_ of a parameter to a multi-line macro, you can do that by enclosing the entire parameter in braces. So you could code things like %macro silly 2 %2: db %1 %endmacro silly 'a', letter_a ; letter_a: db 'a' silly 'ab', string_ab ; string_ab: db 'ab' silly {13,10}, crlf ; crlf: db 13,10
automatically generated by info2www version 1.2.2.9 |