GNU Info

Info Node: (nasm.info)Section 4.3.7

(nasm.info)Section 4.3.7


Next: Section 4.3.8 Prev: Section 4.3.6 Up: Section 4.3
Enter node , (file) or (file)node

4.3.7. Concatenating Macro Parameters
-------------------------------------

   NASM can concatenate macro parameters on to other text surrounding
them.  This allows you to declare a family of symbols, for example, in
a macro definition. If, for example, you wanted to generate a table of
key codes along with offsets into the table, you could code something
like

     %macro keytab_entry 2
     
         keypos%1    equ     $-keytab
                     db      %2
     
     %endmacro
     
     keytab:
               keytab_entry F1,128+1
               keytab_entry F2,128+2
               keytab_entry Return,13

   which would expand to

     keytab:
     keyposF1        equ     $-keytab
                     db     128+1
     keyposF2        equ     $-keytab
                     db      128+2
     keyposReturn    equ     $-keytab
                     db      13

   You can just as easily concatenate text on to the other end of a
macro parameter, by writing `%1foo'.

   If you need to append a _digit_ to a macro parameter, for example
defining labels `foo1' and `foo2' when passed the parameter `foo', you
can't code `%11' because that would be taken as the eleventh macro
parameter. Instead, you must code `%{1}1', which will separate the
first `1' (giving the number of the macro parameter) from the second
(literal text to be concatenated to the parameter).

   This concatenation can also be applied to other preprocessor in-line
objects, such as macro-local labels (*Note Section 4.3.2::) and
context-local labels (*Note Section 4.7.2::). In all cases, ambiguities
in syntax can be resolved by enclosing everything after the `%' sign
and before the literal text in braces: so `%{%foo}bar' concatenates the
text `bar' to the end of the real name of the macro-local label
`%%foo'. (This is unnecessary, since the form NASM uses for the real
names of macro-local labels means that the two usages `%{%foo}bar' and
`%%foobar' would both expand to the same thing anyway; nevertheless,
the capability is there.)


automatically generated by info2www version 1.2.2.9