Macro Processor
A Macro instruction is the notational convenience for the programmer. For every occurrence of macro the whole macro body or macro block of statements gets expanded in the main source code. Thus Macro instructions makes writing code more convenient.
MACRO is defined as a single line abbreviation for a group of instruction.
Syntax :
Macro
{
Macro name
Macro name
} macro body
Features of Macro Processor:
- Macro represents a group of commonly used statements in the source programming language.
- Macro Processor replace each macro instruction with the corresponding group of source language statements. This is known as expansion of macros.
- Using Macro instructions programmer can leave the mechanical details to be handled by the macro processor.
- Macro Processor designs are not directly related to the computer architecture on which it runs.
- Macro Processor involves definition, invocation and expansion.
Macro Instruction:-
A macro instruction is a group of programming instructions that have been compressed into a simpler form and appear as a single instruction. When used, a macro expands from its compressed form into its actual instruction details. Both the name of the macro definition and other variable parameter attributes are included within the macro statement.
WHAT IS MACRO INSTRUCTION ARGUMENT ?
The macro facility presented thus for capable of inserting blocks of instructions in place of macro calls. all of the calls to any given macro will be replaced by identical blocks. this macro facility lacks flexibility.: there is no way for a specific macro call to modify the coding that replace it. an important extension of this facility consists of providing for arguments, or parameters, in macro calls.
corresponding macro dummy arguments will appear in macro definitions.
Example 1:
corresponding macro dummy arguments will appear in macro definitions.
CONDITIONAL MACRO EXPANSION:-
- The macro processor replaces each macro instruction with the corresponding group of source language statements. This is called macro expansion or expanding the macros
- Conditional assembly are frequently considered to be mechanisms that allow a single version of the source code for a program to be used to generate multiple versions of the executable.
- Most macro processors can also modify the sequence of statements generated for a macro expansion, depending on the arguments supplied in the macro invocation. Conditional Assembly is commonly used to describe this feature. It is also referred to as conditional macro expansion.
- Conditional Assembly can be achieved with the help of AIF and AGO statements.
1) AIF Statement
- It is used to specify the branching condition.
- This statements provides conditional branching facility.
- Syntax :AIF (condition) Label
- If condition is satisfied the label is executed else it continue with the next execution.
- It performs an arithmetic test and branches only if tested condition is true.
2) AGO Statement
- This statement provides the unconditional branching facilities.
- We do not specify the condition
- Syntax:
AGO. Label
- It specifies the label appearing on some other statement in the macro instruction definition.
- The macro processor continues the sequential processing of instructions with the indicated statement.
- These statements are directives to the macro processor and do not appear in macro expansion.
MACRO CALLS WITH MACRO:-
Macros are abbreviations of instruction sequence. Such abbreviation are also present within other macro definition.
Nested and Recursive Macros Calls
Macro bodies may also contain macro calls, and so may the bodies of those called macros, and so forth.
If a macro call is seen throughout the expansion of a macro, the assembler starts immediately with the expansion of the called macro. For this, its its expanded body lines are simply inserted into the expanded macro body of the calling macro, until the called macro is completely expanded. Then the expansion of the calling macro is continued with the body line following the nested macro call.
If a macro call is seen throughout the expansion of a macro, the assembler starts immediately with the expansion of the called macro. For this, its its expanded body lines are simply inserted into the expanded macro body of the calling macro, until the called macro is completely expanded. Then the expansion of the calling macro is continued with the body line following the nested macro call.
Example 1:
INSIDE MACRO SUBB A,R3 ENDM OUTSIDE MACRO MOV A,#42 INSIDE MOV R7,A ENDM
Post a Comment