nasmdoc: Document macro parameters range
authorCyrill Gorcunov <gorcunov@gmail.com>
Sat, 5 Jun 2010 07:24:59 +0000 (11:24 +0400)
committerCyrill Gorcunov <gorcunov@gmail.com>
Sat, 5 Jun 2010 07:24:59 +0000 (11:24 +0400)
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
doc/nasmdoc.src

index 8b6fb2d..fb62825 100644 (file)
@@ -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}