Macro Definition & Call
It has been aforementioned that a macro consists of a name, a set of formal parameters, and a body of codes.
A macro can be defined by enclosing a set of statements between a macro header and a macro end statement.
The formal structure of a macro includes the following features:
Macro prototype statement: Specifies the name of the macro and name and type of formal parameters.
Model statements: Specify the statements in the body of the macro from which assembly language statements are to be generated during expansion.
Macro preprocessor statement: Specifies the statement used for performing the auxiliary function during macro expansion A macro prototype statement can be written as follows: <name_of_macro> [<formal parameter spec> [,…]]
where [<formal parameter spec> [,…]] defines the parameter name and its kind, which are of the following form:
- A macro can be called by writing the name of the macro in the mnemonic field of the assembly language. The syntax of a typical macro call can be of the following form:
<name_of_macro> [<actual_parameter_spec> [,…]]
- The MACRO directive in the mnemonic field specifies the start of the macro definition and it should compulsorily have the macro name in the label field.
- Also, The MEND directive specifies the end of the macro definition.
- Moreover, The statements between MACRO and MEND directives define the body (model statements) of the macro and can appear in the expanded code.
INCR&MEM_VAL, &INC_VAL, ®
INCR A, B
- A macro call in a program leads to macro expansion. To expand a macro, the name of the macro placed in the operation field, and no special directives are necessary. During macro expansion, the macro name statement in the program is replaced by the sequence of assembly statements. So, Let us consider the following example:
INCR A, B, AREG
- Also, The preceding example uses a statement that calls the macro. The assembly code sequence INCR A,B, AREG is an example of the macro call, with A and B being the actual parameters of the macro.
- While passing over the assembly program, the assembler recognizes INCR as the name of the macro, expands the macro, and places a copy of the macro definition (along with the parameter substitutions). The expanded code for the code is as below.
+ MOVER REG A
+ ADDREG B
+ MOVEM REG A
- Moreover, The statements marked with a ‘+’ sign in the preceding label field denote the expanded code and differentiate them from the original statements of the program.