Design: Two-pass Macro Preprocessor
Pass 0 of Assembler Design: Two-pass Macro Preprocessor
The activities of a pass-0 macro processor is given in the following steps:
1. Read and examine the next source statement.
2. If MACRO statement, continue reading the source and copy the entire macro definition to the MDT. Go to Step 1.
3. If the statement is a pass-0 directive, execute it. Go to Step 1. (These directives are written to the new source file in a unique manner (different from normal directives). They are only needed for the listing in pass 2.
4. If the statement contains a macro name, it must perform expansion, that is, read model statements from the MDT corresponding to the call, substitute parameters, and write each statement to the new source file (or execute it if it is a pass-0 directive). Go to Step 1.
5. For any other statement, write the statement to the new source file. Go to Step 1.
6. If the current statement contains the END directive, stop (end of pass 0).
The assembler will be in one of the three modes: Design: Two-pass Macro Preprocessor
- In the normal mode, the assembler will read statement lines from the source file and write them to the new source file. There is no translation or any change in the statements. In the macro definition mode, the assembler will continuously copy the source file to the MDT.
- In the macro expansion mode, the assembler will read statements from the MDT, substitute parameters, and write them to the new source file. Nested macros can be implemented using the Definition and Expansion (DE) mode.
Pass 1 of Macro Processor – Processing Macro Definitions
1.Initialize MDTC and MNTC.
2. Read the next source statement of the program.
3.If the statement contains MACRO pseudo-op. go to Step 6.
4.Output the instruction of the program.
5. If the statement contains END pseudo-op, go to Pass 2, else go to Step 2.
6. Read the next source statement of the program.
7. Make an entry of the macro name and MTDC into MNT at location MNTC and increment the MNTC by 1.
8. Prepare the parameter (arguments) list array.
9. Enter the macro name into the MDT and increment the MTDC by 1.
10. Read the next card and substitute index for the parameters (arguments).
11. Enter the statement into the MDT and increment the MDT by 1.
12. If MEND pseudo-op found, go to Step 2, else go to Step 10.
Pass 2 of Macro Processor – Processing for Calls and Expansion of Macro
1.Read the next source statement copied bypass 1.
2.Search into the MNT for a record and evaluate the operation code.
3.If the operation code has a macro name, go to Step 5.
4.Write the statement to the expanded source file.
5.If END pseudo-op found, pass the entire expanded code to the assembler for assembling and stop. Else go to Step 1.
6. Update the MDTP to the MDT index from the MNT entry.
7. Prepare the parameter (argument) list array.
8. Increment the MDTP by 1.
9. Read the statement from the current MDT and substitute actual parameters (arguments) from the macro call.
10. If the statement contains MEND pseudo-op, go to Step 1, else write the expanded source code and go to Step 8.