Download presentation
Presentation is loading. Please wait.
Published byCatherine Snow Modified over 9 years ago
1
MACROS Suthida Chaichomchuen std@kmitnb.ac.th
2
Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive coding. To make an assembly program more readable.
3
Functions that implemented by macro Input/Output operation that load register and perform interrupt Conversions of ASCII and binary data Multiword arithmetic operation String-handling routines
4
Format of macro definition macronameMACRO [parameter list] [instructions] ENDM ;Define macro ;Body of macro ;End of macro
5
Simple macro definitions INITZMACRO;Define macro MOV AX,@data; Body MOV DS,AX ; of MOV ES,AX ; macro definition ENDM;End of macro
6
Simple macro definitions FINISHMACRO;Define macro MOV AX,4C00H ;Body of INT 21H ;macro definition ENDM;End of macro
7
Using parameter in Macros PROMPTMACROMESSAGE;dummy argument MOVAH,09H LEADX,MESSAGE INT 21H ENDM;End of macro
8
Using parameter in Macros MESSAGE2DB‘Enter the date as mm/dd/yy’ PROMPTMESSAGE2
9
Macro Comments PROMPTMACROMESSAGE ; This macro permits a display of messages MOVAH,09H;Request display LEADX,MESSAGE;prompt INT 21H ENDM
10
.LALL : List all - including the leading period. .SALL : suppress all - not list any source code of a macro expansion .XALL : default - list only the instructions that generate object code. Macro Listing directive
11
The LOCAL directive Used for define the data items and instruction labels within the macro definition itself. LOCALdummy-1, dummy-2,.. ;One or more dummy argument
12
Including Macros from a library Programs can use any of the cataloged macros by use an INCLUDE directive like this. INCLUDEPath and file name Example:INCLUDEF:\MACRO.LBY
13
The PURGE directive Use to delete the unwanted macros from the current assembly. PURGEMacro names Example:PURGEPROMPT, DIVIDE
14
Concatenation Used the ampersand (&) character tells the assembler to join text or symbols. STRMOVEMACROTAG REPMOVS&TAG ENDM
15
REPT : Repeat Directive IRP : Indefinite Repeat Directive IRPC : Indefinite Repeat Character Directive Repetition directive
16
Repeat a block of statements up to ENDM according to the number of times in the expression entry. REPTexpression Repetition directive : REPT
17
REPT4 DECSI ENDM REPT : Examples
18
N = 0 REPT5 N = N + 1 DBN ENDM REPT : Examples
19
Repeat a block of instructions up to ENDM. IRPdummy, Repetition directive : IRP
20
IRPN, DBN ENDM IRP : Examples
21
IRPREG, PUSHREG ENDM IRP : Examples
22
Repeat a block of statements up to ENDM. IRPCdummy, string Repetition directive : IRPC
23
IRPCN, 345678 DWN ENDM IRPC : Examples
24
IFxx(condition)... ELSE(optional)... ENDIF(end of IF) Conditional directives
25
IF : If the expression evaluates to a nonzero value, assemble the statements within the conditional block. IFE : If the expression evaluates to a zero, assemble the statements within the conditional block.
26
Conditional directives IF1 (no expression) : If processing pass 1, act on the statements in the conditional block. IF2 (no expression) : If processing pass 2, act on the statements in the conditional block.
27
Conditional directives IFDEF symbol : If the symbol is defined in the program or is declared as EXTRN, process the statements in the conditional block. IFNDEF symbol : If the symbol is not defined or is not declared as EXTRN, process the statements in the conditional block.
28
Conditional directives IFB : If the argument is blank, process the statements in the conditional block. The argument requires angle brackets. IFNB : If the argument is not blank, process the statements in the conditional block. The argument requires angle brackets.
29
Conditional directives IFIDN, : If the argument-1 string is identical to the argument-2 string, process the statements in the conditional block. The argument require angle brackets.
30
Conditional directives IFDIF, : If the argument-1 string is different to the argument-2 string, process the statements in the conditional block. The argument require angle brackets.
31
Conditional directives IF and IFE can use the relational operators : –EQ (equal) –NE (not equal) –LT (less than) –LE (less than or equal) –GT (greater than) –GE (greater than or equal)
32
FINISHMACRORETCODE MOVAH, 3CH IFNB MOVAL, RETCODE ENDIF INT21H ENDM Examples
33
INT21MACROFUNCTION, DXADDRES MOVAH, FUNCTN IFNB MOVDX, OFFSET DXADDRES ENDIF INT21H ENDM Examples
34
IFxx[condition]...(invalid condition) EXITM... ENDIF EXITM directives
35
IFCNTR ; Macro expansion terminated EXITM ENDIF Using IF and IFDEF conditions
36
IFIDN, REPMOVSB... Using IFIDN condition
37
IFIDN, REPMOVSW... Using IFIDN condition
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.