Copyright (C) 2000-2012 |
GNU Info (nasm.info)Section 4.3.44.3.4. Default Macro Parameters ------------------------------- NASM also allows you to define a multi-line macro with a _range_ of allowable parameter counts. If you do this, you can specify defaults for omitted parameters. So, for example: %macro die 0-1 "Painful program death has occurred." writefile 2,%1 mov ax,0x4c01 int 0x21 %endmacro This macro (which makes use of the `writefile' macro defined in *Note Section 4.3.3::) can be called with an explicit error message, which it will display on the error output stream before exiting, or it can be called with no parameters, in which case it will use the default error message supplied in the macro definition. In general, you supply a minimum and maximum number of parameters for a macro of this type; the minimum number of parameters are then required in the macro call, and then you provide defaults for the optional ones. So if a macro definition began with the line %macro foobar 1-3 eax,[ebx+2] then it could be called with between one and three parameters, and `%1' would always be taken from the macro call. `%2', if not specified by the macro call, would default to `eax', and `%3' if not specified would default to `[ebx+2]'. You may omit parameter defaults from the macro definition, in which case the parameter default is taken to be blank. This can be useful for macros which can take a variable number of parameters, since the `%0' token (see *Note Section 4.3.5::) allows you to determine how many parameters were really passed to the macro call. This defaulting mechanism can be combined with the greedy-parameter mechanism; so the `die' macro above could be made more powerful, and more useful, by changing the first line of the definition to %macro die 0-1+ "Painful program death has occurred.",13,10 The maximum parameter count can be infinite, denoted by `*'. In this case, of course, it is impossible to provide a _full_ set of default parameters. Examples of this usage are shown in *Note Section 4.3.6::. automatically generated by info2www version 1.2.2.9 |