Macros in the 8086 Microprocessor

In this tutorial, we will learn about the Macros in the 8086 Microprocessors. We will first define what the Macros mean, how they are useful, and how they are implemented in the assembly language program for the 8086 Microprocessor? By Monika Sharma Last updated : May 16, 2023

Macro

A Macro is a set of instructions grouped under a single unit. It is another method for implementing modular programming in the 8086 microprocessors (The first one was using Procedures).

The Macro is different from the Procedure in a way that unlike calling and returning the control as in procedures, the processor generates the code in the program every time whenever and wherever a call to the Macro is made.

A Macro can be defined in a program using the following assembler directives: MACRO (used after the name of Macro before starting the body of the Macro) and ENDM (at the end of the Macro). All the instructions that belong to the Macro lie within these two assembler directives.

Syntax to define a macro

The following is the syntax for defining a Macro in the 8086 Microprocessor:

Macro_name  MACRO  [ list of parameters ]
    Instruction 1
    Instruction 2
    - - - - - - - - - - -
    - - - - - - - - - - -
    - - - - - - - - - - -
    Instruction n
ENDM

And a call to Macro is made just by mentioning the name of the Macro:

Macro_name [ list of parameters]

It is optional to pass the parameters in the Macro. If you want to pass them to your macros, you can simply mention them all in the very first statement of the Macro just after the directive: MACRO.

The advantage of using Macro is that it avoids the overhead time involved in calling and returning (as in the procedures). Therefore, the execution of Macros is faster as compared to procedures. Another advantage is that there is no need for accessing stack or providing any separate memory to it for storing and returning the address locations while shifting the processor controls in the program.

But it should be noted that every time you call a macro, the assembler of the microprocessor places the entire set of Macro instructions in the mainline program from where the call to Macro is being made. This is known as Macro expansion. Due to this, the program code (which uses Macros) takes more memory space than the code which uses procedures for implementing the same task using the same set of instructions.

Hence, it is better to use Macros where we have small instruction sets containing less number of instructions to execute.





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.