Macros and Directive
Macros and Directive
Macros:
• Macros are just like procedures, but they exist only until your code is
compiled, after compilation all macros are replaced with real instructions.
• When you invoke a macro procedure,a copy of its code is inserted directly into
the program at the location where it was invoked. This type of automatic code
insertion is also known as inline expansion.
• Macros are expanded during the assembler’s preprocessing step. In this step,
the preprocessor reads a macro definition and scans the remaining source code
in the program. At every point where the macro is called, the assembler inserts
a copy of the macro’s source code into the program
Using Macros:
• When you want to use a macro, you can just type its name. For example:
o MyMacro
• Macro is expanded directly in program's code. So if you use the same macro 100
times, the compiler expands the macro 100 times, making the output executable
file larger and larger, each time all instructions of a macro are inserted.
• In general, macros execute more quickly than procedures because procedures have
the extra overhead of CALL and RET instructions. There is, however, one
disadvantage to using macros: repeated use of large macros tends to increase a
program’s size because each call to a macro inserts a new copy of the macro’s
statements in the program.
• To pass parameters to macro, you can just type them after the macro name. For
example:
o MyMacro 1, 2, 3
Example:
• Unlike procedures, macros should be defined above the code that uses it.
• For Example
o .code
o mymacro macro p1,p2,p3
o mov ax,p1
o mov bx,p2
o mov cx,p3
o endm
o main proc
o mymacro 1,2,3
o mov ah,4ch
o int 21h
o main endp
o end
Q4: Write a Assembly Language program that convert this pseudo code
Using Conditional high level directives (.while .if and .Else).