GNU Info

Info Node: (nasm.info)Section 4.3

(nasm.info)Section 4.3


Next: Section 4.3.1 Prev: Section 4.2.2 Up: Chapter 4
Enter node , (file) or (file)node

4.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

Section 4.3.1
Overloading Multi-Line Macros
Section 4.3.2
Macro-Local Labels
Section 4.3.3
Greedy Macro Parameters
Section 4.3.4
Default Macro Parameters
Section 4.3.5
`%0': Macro Parameter Counter
Section 4.3.6
`%rotate': Rotating Macro Parameters
Section 4.3.7
Concatenating Macro Parameters
Section 4.3.8
Condition Codes as Macro Parameters
Section 4.3.9
Disabling Listing Expansion

automatically generated by info2www version 1.2.2.9