Easy Macros With Examples
Easy Macros With Examples
(10 Marks)
1. Nested Macros
1. A nested macro is a macro that calls another macro inside its body.
2. The macro that calls is the outer macro; the one being called is the inner macro.
3. When expanded, the inner macro expands first, then the outer macro completes.
4. It uses the Last In First Out (LIFO) method to expand the macros.
6. Nested macros are helpful in situations where repeated operations are required within other
operations.
7. Example:
MACRO INNER X
ADD AREG, X
MEND
MACRO OUTER A, B
MOVER AREG, A
INNER B
MEND
2. Conditional Macros
2. They use commands like AIF (Arithmetic IF) and AGO (Arithmetic Go To) to control the flow.
5. These macros are useful when we want to perform different tasks based on input values.
6. You can also use IF-ELSE-ENDIF and WHILE-ENDW structures for more complex conditions.
7. Example:
MOVER AREG, BA
SUB AREG, BB
AGO .OVER
.OVER MEND
TEST 5, 5, VALUE
3. Unconditional Macros
1. Unconditional macros always expand the same way no matter what the input is.
4. These macros save time and reduce writing the same code again and again.
6. Every time you call them, the exact same instructions are inserted.
7. Example:
MACRO LOADREG X
MOVER AREG, X
ADD AREG, B
MEND
LOADREG DATA1