Macros in Microprocessor

Macros in Microprocessor:

Macro is a group of instructions. The Macros in Microprocessor assembler generates the code in the program each time where the macro is ‘called’. Macros can be defined by MACRO and ENDM assembler directives. Creating macro is very similar to creating a new opcode that can be used in the program.

It is important to note that macro sequences execute faster than procedures because there are no CALL and RET instructions to execute. The assembler places the macro instructions in the program each time when it is invoked. This procedure is known as Macro expansion.

Comparison of Procedure and Macro:

Macros in Microprocessor

Passing Parameters in Macro:

In Macro, parameters are passed as a part of statement which calls Macro.

Local Variables in a Macro:

Body of the Macro can use local variables. A local variable defined in the Macro is available in the Macro, however it is not available outside the Macro. To define a local variable, LOCAL directive is used. Example shows how local variable is used as a jump address. If this jump address is not defined as a local, the assembler give an error message on the second and subsequent attempts to use the Macro

It is important to note that local variable or variables must be defined using LOCAL directive immediately after MACRO directive.

Placing Macro Definition in Their Own Module:

We have seen that macro definitions can be placed in the program files. It is possible to access macros from macro module. Macro module is a file which contains only macros that are to be included in other program files. A macro module file has extension. MAC or .INC. To include macro from macro module INCLUDE directive is used. If a file called MACMOD.MAC contains macro sequences, the INCLUDE statement is placed in the program file as INCLUDE C:\ MASM61 \ MACMOD.MAC. It is important to note that the macro file is on drive C, subdirectory MASM61 in this example. The INCLUDE statement includes the macros from the macro module in the program file just as if we had typed them.

Do not confuse with .LIB files. Here, PUBIC and EXTRN diiectives are not required.

Leave a Reply

Your email address will not be published. Required fields are marked *