The macro directive allows the programmer to write a named block of source statements, then use that name in the source file to represent the group of statements. During the assembly phase, the assembler automatically replaces each occurrence of the macro name with the statements in the macro definition.

Macros are expanded on every occurrence of the macro name, so they can increase the length of the executable file if used repeatable. Procedures or subroutines take up less space, but the increased overhead of saving and restoring addresses and parameters can make them slower. In summary, the advantages and disadvantages of macros are,

Advantages of Macro

  • Repeated small groups of instructions replaced by one macro
  • Errors in macros are fixed only once, in the definition
  • Duplication of effort is reduced
  • In effect higher-leveler level instructions can be created
  • Programming is made easier error-processor prone
  • Generally quicker in execution than subroutines

Disadvantages of Macro

Large programs produce greater code size than procedures

When to use Macros?

  • To replace small groups of instructions not worthy of subroutines
  • To create a higher instruction set for specific applications
  • To create compatibility with other computers
  • To replace code portions that are repeated often throughout the program