| |||||||||||
Technical Support On-Line Manuals A166 User's Guide | Defining MPL MacrosThe DEFINE MPL function creates a macro. The syntax for DEFINE function is: %DEFINE (macro-name <[>parameter-list<]>) (macro-body) %*DEFINE (macro-name <[>parameter-list<]>) (macro-body) Where
Note
Macros Without ParametersMacros that have no parameters (or arguments) are defined as follows: %*DEFINE (macro-name) (macro-body) The definition requires the macro-name and the macro-body that is expanded when the macro is called. For example, the following macro definition: %*DEFINE (my_asdf) (asdf) when called with: %my_asdf expands to: asdf Macros With ParametersMacros that have parameters (or arguments) are defined as follows: %*DEFINE (macro-name <[>parameter-list<]>) (macro-body) The parameter-list lists the formal parameters that are passed to the macro. Parameters from the parameter-list are used in the macro-body to fill in values when the macro is called. This allows you to design generic macros that produce code for many operations. Parameters in the parameter-list are specified by unique identifiers (that you choose) which are separated by macro delimiters (which are typically parentheses and commas). The parameter-list is enclosed within parentheses and individual parameters are separated by commas. This is only a convention and not a requirement. The only requirement of the parameter-list specification is that macro parameters are passed in the same way and with the same delimiters that are used when the macro is defined. For example, the parameter-list in the following macro definition: %*DEFINE (BMOVE (src, dst, cnt)) (...) is (src, dst, cnt). To call this macro, the parameters must be specified with the same delimiters. For example: %BMOVE (1, 2, 3) However, there is no reason that the parameters must be enclosed within parentheses or that they must be separated by commas. For example: %*DEFINE (BMOVE src dst cnt) (...) To call this macro, the parameters must be specified as follows: %BMOVE 1 2 3 Parameters in the macro-body are represented with the parameter name preceded by the meta character (%src, %dst, and %cnt in the above example). The following macro definition shows a more complete example.
%*DEFINE (BMOVE (src, dst, cnt)) LOCAL lab (
MOV R2,#%cnt
MOV R1,#%src
MOV R0,#%dst
%lab: MOVB [R0+],[R1]
ADD R1,#1
CMPD1 R2,#0
JMP CC_NZ, %lab
)
Parameters may be used any number of times and in any order within the macro-body. If a parameter has the same name as the macro and is used in the macro-body, the parameter is expanded (instead of calling the macro). If a macro has the same name as one of the parameters, the macro cannot be called within the macro-body because this would lead to infinite recursion. | ||||||||||
| |||||||||||