- Formally, macro instructions (often called macro) are single-line abbreviations for groups of instructions.
- For every occurrence of this one-line macroinstruction within a program, the instruction must be replaced by the entire block.
- The advantages of using macros are as follows:
o Simplify and reduce the amount of repetitive coding.
Reduce the possibility of errors caused by repetitive coding.
o Make an assembly program more readable.
- A Macro preprocessor can any program that processes its input data to produce output, which is used as an input to another program.
- The outputs of the macros processors are assembly programs that become inputs to the assembler.
- The macros processor may exist independently and called during the assembling process or be a part of the assembler implementation itself.
Difference between Macros and Subroutine
- Macros name in the mnemonic field leads to expansion only.
- Also, Macros completely handled by the assembler during assembly time.
- Macros definition and macro expansion executed by the assembler. So, the assembler has to know all the features, options, and exceptions associated with them.
- The hardware knows nothing about macros.
- Subroutine name in a call statement in the program leads to execution.
- Also, Subroutines completely handled by the hardware at runtime.
- Hardware executes the subroutine call instruction. So, it has to know how to save the return address and how to branch to the subroutine.
- The assembler knows nothing about subroutines.
Similarly, The macros processor generates a new copy of The subroutine call instruction assembled in the macro and places it in the program.the usual way and treated by the assembler as any other instruction.
Additionally, Macros processing increases the size of the Use of subroutines does not result into bulk resulting code but results in faster execution of object codes but has substantial overheads of the program for expanded programs.control transfer during execution.