summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2010-06-05 11:24:59 +0400
committerCyrill Gorcunov <gorcunov@gmail.com>2010-06-05 11:24:59 +0400
commit640edfd78490a40c0544d4eba406bded5d32542a (patch)
tree13471f6ac6bbe31b7053cc6eaeb03edccdadd1e0
parent2f40375077d448b0fea238db726a1e58ad6da74a (diff)
downloadnasm-640edfd78490a40c0544d4eba406bded5d32542a.tar.gz
nasmdoc: Document macro parameters range
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r--doc/nasmdoc.src44
1 files changed, 43 insertions, 1 deletions
diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src
index 8b6fb2dc..fb628258 100644
--- a/doc/nasmdoc.src
+++ b/doc/nasmdoc.src
@@ -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}