mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-03-19 18:00:23 +08:00
nasmdoc: Document macro parameters range
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
parent
2f40375077
commit
640edfd784
@ -1,5 +1,5 @@
|
||||
\# --------------------------------------------------------------------------
|
||||
\#
|
||||
\#
|
||||
\# Copyright 1996-2010 The NASM Authors - All Rights Reserved
|
||||
\# See the file AUTHORS included with the NASM distribution for
|
||||
\# the specific copyright holders.
|
||||
@ -2558,6 +2558,48 @@ definition.
|
||||
|
||||
See \k{sectmac} for a better way to write the above macro.
|
||||
|
||||
\S{mlmacrange} \i{Macro Parameters Range}
|
||||
|
||||
NASM also allows you to expand parameters via special construction \c{%\{x:y\}}
|
||||
where \c{x} is the first parameter index and \c{y} is the last. Any index can
|
||||
be either negative or positive. Though the indices must never be zero.
|
||||
|
||||
For example
|
||||
|
||||
\c %macro mpar 1-*
|
||||
\c db %{3:5}
|
||||
\c %endmacro
|
||||
\c
|
||||
\c mpar 1,2,3,4,5,6
|
||||
|
||||
expands to \c{3,4,5} range.
|
||||
|
||||
Even more, the parameters can be reversed so that
|
||||
|
||||
\c %macro mpar 1-*
|
||||
\c db %{5:3}
|
||||
\c %endmacro
|
||||
\c
|
||||
\c mpar 1,2,3,4,5,6
|
||||
|
||||
expands to \c{5,4,3} range.
|
||||
|
||||
But even this is not the last. The parameters can be addressed via negative
|
||||
indices so NASM will count them reversed. The ones who know Python may see
|
||||
the analogue here.
|
||||
|
||||
\c %macro mpar 1-*
|
||||
\c db %{-1:-3}
|
||||
\c %endmacro
|
||||
\c
|
||||
\c mpar 1,2,3,4,5,6
|
||||
|
||||
expands to \c{6,5,4} range.
|
||||
|
||||
Note that NASM uses \i{comma} to separate parameters being expanded.
|
||||
|
||||
By the way, here is a trick - you might use the index \c{%{-1:-1}} gives
|
||||
you the \i{last} argument passed to a macro.
|
||||
|
||||
\S{mlmacdef} \i{Default Macro Parameters}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user