Ax51 User's GuideAx51 Introduction Assembling Programs Writing Assembly Programs Control Statements Macro Processor Standard Macro Processor Standard Macro Controls Defining Standard Macros Calling Standard Macros Local Symbols Exiting a Macro Built-in Macros REPT IRP IRPC Standard Macro Operators NUL Operator & Operator < and > Operators % Operator ;; Operator ! Operator MPL Macro Processor MPL Macro Overview MPL Meta Character Defining MPL Macros Calling MPL Macros Local Symbols Expressions Common Functions Bracket Function Comment Function Escape Function METACHAR Function SET Function EVAL Function Comparison Functions Conditional Functions EXIT Function IF Function REPEAT Function WHILE Function Console I/O Functions String Functions LEN Function MATCH Function SUBSTR Function Advanced Literal Delimiters Blank Delimiters Identifier Delimiters Literal and Normal Modes C Preprocessor Exceptions Side-Effects Predefined Macros Examples Error Messages Appendix
Defining MPL Macros
The 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)
Macros Without Parameters
Macros 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:
Macros With Parameters
Macros 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: MOV A,@R1 MOV @R0,A INC R0 INC R1 DJNZ R2,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.
of your data.