MACRO in Microprocessor YASH PAL, March 24, 2026March 24, 2026 MACRO in Microprocessor – A macro is a sequence of instructions to which a name is assigned. It is a very useful facility provided by many assemblers. When a macro is referenced by specifying its name, the macro assembler replaces the macro call with the sequence of instructions that define the macro. The format to define a macro is as follows:Macro_name MACRO (Parameter 1, Parameter 2,....] Instruction 1 Instruction 2 . . . Instruction n ENDMWhere, Macro_name is the name given to the macro, [Parameter 1, Parameter 2, …] is the optional list of parameters passed to the macro. MACRO and ENDM are reserved words to show the start and end of a macro.Let’s take an example to understand the macro in a microprocessor.Question – Define a macro which add the contents of two consecutive memory locations and stores the result in the next memory location. Explain the use of macro with a suitable example.Solution – Let us define a macro for the given task with a name ADDITIONADDITIONMACROADDRESSCOMMENTSLXIH, ADDRESS; Initialize memory pointerMOVA, M; Read first dataINXH; Increment memory pointerADDM; Add second data to the first dataINXH; Increment memory pointerMOVM, A; Store the resultDCXH; Decrement memory pointerDCXH; Decrement memory pointerENDMWhere ADDITION is the name of the macro defined, and ADDRESS is the parameter passed to the macro. Let us consider an example to understand the use of macros in a program. First, store the two numbers into memory locations XX50H and XX51H, then add these two numbers using macro ADDITION and store the result at XX52H.LXIH, XX50; Initialize memory pointerMOVA, 52H; First numberMOVM, A; Store first numberINXH; Increment memory pointerMMA, 3FH; Second numberMOVM, A; Store the second numberADDITIONXX50H; Call macro ADDITIONHLT; Stop the executionThe program will call the macro ADDITION and pass the address XX50H to the macro.Difference between Macro and SubroutineMacros and subroutines are differentiated as listed below:SubroutineMacroA subroutine is called by using the CALL instruction.Macro is called by specifying the name of the macro in the program as an instruction.Program execution is transferred to the first address of the subroutineWhen the program is compiled, the macro is replaced with real instructions. There is no transfer of execution.A program with a subroutine is slower in execution speed because program control is transferred from the main program to the subroutine and vice versa.A program with a macro is faster in execution speed because there is no transfer of program control.Subroutine physically exists in the memory.Macro exists only until the code is compiled.It is a feature of programming.It is a feature available in the assembler. engineering subjects Microprocessor microprocessor