Skip to content
The Computer Science
TheCScience
  • Engineering Subjects
    • Human Values
    • Computer System Architecture
    • Digital Communication
    • Internet of Things
  • NCERT Solutions
    • Class 12
    • Class 11
  • HackerRank solutions
    • HackerRank Algorithms Problems Solutions
    • HackerRank C solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
The Computer Science
TheCScience

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
ENDM

Where, 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 ADDITION

ADDITIONMACROADDRESSCOMMENTS
LXIH, ADDRESS; Initialize memory pointer
MOVA, M; Read first data
INXH; Increment memory pointer
ADDM; Add second data to the first data
INXH; Increment memory pointer
MOVM, A; Store the result
DCXH; Decrement memory pointer
DCXH; Decrement memory pointer
ENDM

Where 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 pointer
MOVA, 52H; First number
MOVM, A; Store first number
INXH; Increment memory pointer
MMA, 3FH; Second number
MOVM, A; Store the second number
ADDITIONXX50H; Call macro ADDITION
HLT; Stop the execution

The program will call the macro ADDITION and pass the address XX50H to the macro.

Difference between Macro and Subroutine

Macros and subroutines are differentiated as listed below:

SubroutineMacro
A 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

Post navigation

Previous post

TheCScience

We at TheCScience.com are working towards the goal to give free education to every person by publishing in dept article about Secondary, Senior-Secondary, and Graduation level subjects.

Pages

About US

Contact US

Privacy Policy

DMCA

Our Tools

Hosting - get 20% off

Engineering Subjects

Internet of Things

Human Values

Digital Communication

Computer System Architecture

Programming Tutorials

Data Structure and Algorithm

C

Java

NCERT

Class 12th

©2026 TheCScience | WordPress Theme by SuperbThemes