Table of Contents
What is macro and how is it used?
Definition:
What is macro and how is it used? “Macro (abbreviated as “macroinstruction”), in computer science law or pattern that specifies how a specific input should be mapped to a replacement output.”
Macros help in making tasks less repetitive by representing complex sequences of key clicks, mouse movements, commands, or other types of input.
Explanation:
Macros are used to make a sequence of computer commands available to a program as a single program statement, making the program work less tedious and error-free. (Therefore, they are called “macros” because the “large” block of code extends from the “small” alphabetical order) with variations such as app, platform or other features.
There are programs in Assembly Language programs where certain set of instructions perform a repeatedly used function. For example, transferring data in a RAM is repeated over and over in the same system. But we don’t need to rewrite this code again and again whenever needed. Therefore, to reduce the time it takes to write code and to minimize possible errors, the concept of macros was born. Macros allow the developer to write a work (specified performance code) only once, and to request it whenever needed.
MACRO Directives:
- macro
- endm
- exitm
MACRO definition:
Every macro definition must have three parts, as follows:
Name MACRO dummy1, dummy2, dummyN
………..
…………
ENDM
The MACRO directives shows the beginning of the macro definition whereas, the ENDM directory indicates the end. What goes between MACRO and ENDM signals are called macro body.
Syntax:
Following is the syntax for macro definition:
%macro macro_name number_of_params
<macro body>
%endmacro
Where, number_of_params specifies the number parameters, macro_name specifies the name of the macro.
EXAMPLES:
To move a literal data into a file register data RAM is a widely applicable service. But there is no specified instruction for that. However we can use macro to do the job as shown in the given code below:
MOVLP MACRO K, MYREG
MOVL
MOVWF MYRBG
ENDM
The above is the macro definition. Note that dummy arguments of K and MYREG are mentioned in the body of macro.
The following are three examples of how to use the above macro:
- MOVLF 0x55, 0x20 ; send value 55H to loc 20H
- VAL_1 EQU 0x55
RAM_LOC EQU 0x20
MOVLF VAL_1, RAM_LOC
- MOVLF 0x55, PORTB ;send value 55H to Port B
The instruction “MOVLF 0x5, 0x20” invokes the macro. The assembler expands the macro by providing the following code in the .Ist file:
M MOVLW 5
M MOVWF 0x20
The M indicates that the code is from the macro.
-
What are the features of MACROs?
The features of macro includes the following:
- A group of commands grouped together and assigned a name.
- One or more arguments may apply to macro.
- By entering a macro name, the same group of commands can be repeated at any location of the program.
- The user program is made easy to read using macros.
- The user is more productive by keeping the text input time
USES OF MACRO:
Macro has various uses and applications which include the following:
- Macro programs have a variety of uses. The ability to select test modes (see lazy tests and non-volatile tasks) enables the construction of new syntactic structures (e.g. control structures) that are inseparable from those built into language.
- Next, macros make it possible to define data languages that are quickly integrated into code, meaning that constructions such as state-of-the-art machines can be done in a natural and efficient way.
- Macros can be used to introduce new binding structures. A well-known example is the conversion of let use of a function into a set of arguments.
- Macros are programs used to perform routes or tasks that are frequently used in Excel Macro recording works and also activates the sequence of actions of mice or keys of something you can do in Excel with keystrokes or mouse.
- Some of those actions include; cleaning data, formatting cells, creating tables or editing data in an Excel spreadsheet.
- The most frequently used sequence of commands can be described as macro.
- Now macro can be used instead of re-typing sequence.
- Sequences can only be corrected once, rather than always being typed each time.
- Through actual arguments, differences of the same concept are used.
- Macros are used to create complex tasks with easy operation.
- Useful macros libraries can be created. Editors can use these libraries without knowing much about the detailed code that macros stretch.
The above list is not exhaustive, and many reasons are mixed. The whole list can be summarized as the benefit of macros “modularity.” Of course, “modularity” also summarizes the benefits of systematic, operational, and systematic calls.
CONCLUSION:
A macro is a series of stored commands that perform an action or a series of actions. This feature can be used to add functionality or perform simple tasks, such as performing an action when a user clicks a command button.
Also read here