MACROs IN ASSEMBLY LANGUAGE PROGRAMS Macro A MACRO
MACRO’s IN ASSEMBLY LANGUAGE PROGRAMS
Macro • A MACRO is a name given to one or more assembly language statements. We define a MACRO in our program or in a separate file and then use it in our program wherever we need it. When we invoke (or CALL) a MACRO, the code is actually inserted into the program at the location. • One advantage is that MACROs execute faster than a subroutine since there is no call or return instructions • MACRO can be placed anywhere in the program, they are typically placed at the beginning of the program, usually just before the. model directive. – MACROs are only assembled if they are called in the code segment, so placing a common MACRO in a source code that is never called does not increase the size of the obj or exe files. • MACROs, we may pass parameters similar to high level language functions.
Macro • MACROs are declared similarly to the procedure call by giving the MACRO a name and defining it as a MACRO, inserting the code, and identifying these end with endm as follows Macroname macro ; ; code here endm • Examples of a Macro: Allocate, Clear. Scr, Set. Cur, and Function 9 as macos
Examples • A macro may be called from the data segmnet to allocate memory Allocate Macro Array_Name, Numb. Bytes Array_Name DB Numbytes DUP (? ) Allocate endm. data allocate array 1, 20; allocate array 2, 50; generates Array 1 db 20 dup(? ) generates Array 2 db 50 dup(? )
Clear. Scr Macro Clear. Scr macro mov ah, 06 h mov bh, 07 h mov cx, 0 mov dx, 1847 h int 10 h endm
Set. Cur macro PASSING PARAMETERS Set. Cur macro row, col mov ah, 2 mov bh, 0 mov dh, row mov dl, col int 10 h endm ; ; row and col passed in declaration ; ; load function number ; ; video page 0 ; ; Load row info passed in by row ; ; Load column info passed in by col
Macro- Display Message PASSING PARAMETERS Function 9 macro msgaddress ; ; address passed in ; ; declaration mov ah, 9 lea dx, msgaddress int 21 h endm ; ; load function number ; ; load address of message
EXTERNAL MACRO’s IN ASSEMBLY LANGUAGE PROGRAMS • save the file with any name we wish using a. mac extension. The macro list was saved as externalmacro. mac • It also contains three separate macros that can be called individually. We may use one or as many as we like. – When we wish to use the macros in this file in our source code program, we place an include statement in our source code include externalmacro. mac
Externalmacro. mac
EXTERNAL MACRO’s IN ASSEMBLY LANGUAGE PROGRAMS
- Slides: 11