macros suthida chaichomchuen [email protected]. purposes to simplify and reduce the amount of...
TRANSCRIPT
![Page 2: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/2.jpg)
PurposesTo simplify and reduce the amount of repetitive coding.
To reduce errors caused by repetitive coding.
To make an assembly program more readable.
![Page 3: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/3.jpg)
Functions that implemented by macro
Input/Output operation that load register and perform interrupt
Conversions of ASCII and binary data
Multiword arithmetic operationString-handling routines
![Page 4: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/4.jpg)
Format of macro definition
macronameMACRO [parameter list][instructions]ENDM
;Define macro;Body of macro;End of macro
![Page 5: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/5.jpg)
Simple macro definitions
INITZ MACRO ;Define macroMOV AX,@data ; BodyMOV DS,AX ; ofMOV ES,AX ; macro definitionENDM ;End of macro
![Page 6: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/6.jpg)
Simple macro definitions
FINISH MACRO ;Define macroMOV AX,4C00H ;Body ofINT 21H ;macro definitionENDM ;End of macro
![Page 7: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/7.jpg)
Using parameter in Macros
PROMPT MACRO MESSAGE;dummy argumentMOV AH,09HLEA DX,MESSAGEINT 21HENDM ;End of macro
![Page 8: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/8.jpg)
Using parameter in Macros
2MESSAGE DB ‘Enter the date as mm/dd/yy’
PROMPT 2
![Page 9: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/9.jpg)
Macro Comments
PROMPT MACRO MESSAGE; This macro permits a display of messages
MOV AH,09H ;Request displayLEA DX,MESSAGE ;promptINT 21HENDM
![Page 10: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/10.jpg)
.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
![Page 11: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/11.jpg)
The LOCAL directive
Used for define the data items and instruction labels within the macro definition itself.
LOCAL dummy-1, dummy-2, . . ;One or more dummy argument
![Page 12: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/12.jpg)
Including Macros from a library
Programs can use any of the cataloged macros by usean INCLUDE directive like this.
INCLUDE Path and file name
Example: INCLUDE F:\MACRO.LBY
![Page 13: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/13.jpg)
The PURGE directive
Use to delete the unwanted macros from the currentassembly.
PURGE Macro names
Example: PURGE PROMPT, DIVIDE
![Page 14: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/14.jpg)
Concatenation
Used the ampersand (&) character tells the assembler to join text or symbols.
STRMOVE MACRO TAGREP MOVS&TAGENDM
![Page 15: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/15.jpg)
REPT : Repeat DirectiveIRP : Indefinite Repeat Directive
IRPC : Indefinite Repeat Character Directive
Repetition directive
![Page 16: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/16.jpg)
Repeat a block of statements up to ENDM according to the number of times in the expression entry.
REPT expression
Repetition directive : REPT
![Page 17: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/17.jpg)
REPT 4DEC SI
EEEE
REPT : Examples
![Page 18: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/18.jpg)
N = 0REPT 5
N = N + 1DB N
EEEE
REPT : Examples
![Page 19: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/19.jpg)
Repeat a block of instructions up to ENDM.
IRP dummy, <argument>
Repetition directive : IRP
![Page 20: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/20.jpg)
IRP N, <3, 9, 17, 25, 28>DB N
ENDM
IRP : Examples
![Page 21: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/21.jpg)
IRP REG, <AX, BX, CX, DX>PUSH REG
ENDM
IRP : Examples
![Page 22: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/22.jpg)
Repeat a block of statements up to ENDM.
IRPC dummy, string
Repetition directive : IRPC
![Page 23: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/23.jpg)
IRPC N, 345678DW N
ENDM
IRPC : Examples
![Page 24: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/24.jpg)
IFxx (condition) . . .
EEEE (optional) . . .
ENDIF (end of IF)
Conditional directives
![Page 25: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/25.jpg)
Conditional directives
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 .
![Page 26: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/26.jpg)
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 .
![Page 27: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/27.jpg)
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.
![Page 28: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/28.jpg)
Conditional directives
IFB <argument> : If the argument is blank, process the statements in the conditional block. The argument requires angle brackets.
IFNB <argument> : If the argument is not blank, process the statements in the conditional block. The argument requires angle brackets.
![Page 29: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/29.jpg)
Conditional directives
- - 1 2IFIDN <arg >,<arg > : EEE EEEEE EEE-E EEEEEE EE E1
- 2dentical to the argument string, processthest at ement s i n t he condi EEEEEE EEE EEEEEEEE EEEEEEE EE. glebr acket s.
![Page 30: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/30.jpg)
Conditional directives
- - 1 2IFDIF <arg >,<arg > : I - 1f the argument string is d
- 2ifferent to the argument string, processthest at ement s i n t he condi tionalblock. The ar gument r equi r e an glebr acket s.
![Page 31: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/31.jpg)
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)
![Page 32: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/32.jpg)
FINISH MACRO RETCODEMOV AH, 3CHIFNB <RETCODE>
MOV AL, RETCODEENDIFINT 21HENDM
Examples
![Page 33: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/33.jpg)
INT21 MACRO FUNCTION, DXADDRESMOV AH, FUNCTNIFNB <DXADDRES>
MOV DX, OFFSET DXADDRESENDIFINT 21HENDM
Examples
![Page 34: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/34.jpg)
IFxx [condition] . . . (invalid condition)
EEEEE . . .
ENDIF
EXITM directives
![Page 35: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/35.jpg)
IF CNTR ; Macro expansion terminated
EXITMENDIF
Using IF and IFDEF conditions
![Page 36: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/36.jpg)
IFIDN <&TAG>,<B>REP MOVSB. . .
Using IFIDN condition
![Page 37: MACROS Suthida Chaichomchuen std@kmitnb.ac.th. Purposes To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive](https://reader034.vdocuments.site/reader034/viewer/2022042616/56649f325503460f94c4d771/html5/thumbnails/37.jpg)
IFIDN <&TAG>,<W>REP MOVSW. . .
Using IFIDN condition