macros

37
MACROS Suthida Chaichomchuen [email protected]

Upload: tavia

Post on 28-Jan-2016

22 views

Category:

Documents


0 download

DESCRIPTION

MACROS. Suthida Chaichomchuen [email protected]. Purposes. To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive coding. To make an assembly program more readable. Functions that implemented by macro. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: MACROS

MACROS Suthida Chaichomchuen

[email protected]

Page 2: MACROS

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

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

Format of macro definition

macronameMACRO [parameter list][instructions]ENDM

;Define macro;Body of macro;End of macro

Page 5: MACROS

Simple macro definitions

INITZ MACRO ;Define macroMOV AX,@data ; BodyMOV DS,AX ; ofMOV ES,AX ; macro definitionENDM ;End of macro

Page 6: MACROS

Simple macro definitions

FINISH MACRO ;Define macroMOV AX,4C00H ;Body ofINT 21H ;macro definitionENDM ;End of macro

Page 7: MACROS

Using parameter in Macros

PROMPT MACRO MESSAGE;dummy argumentMOV AH,09HLEA DX,MESSAGEINT 21HENDM ;End of macro

Page 8: MACROS

Using parameter in Macros

2MESSAGE DB ‘Enter the date as mm/dd/yy’

PROMPT 2

Page 9: MACROS

Macro Comments

PROMPT MACRO MESSAGE; This macro permits a display of messages

MOV AH,09H ;Request displayLEA DX,MESSAGE ;promptINT 21HENDM

Page 10: MACROS

.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

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

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

The PURGE directive

Use to delete the unwanted macros from the currentassembly.

PURGE Macro names

Example: PURGE PROMPT, DIVIDE

Page 14: MACROS

Concatenation

Used the ampersand (&) character tells the assembler to join text or symbols.

STRMOVE MACRO TAGREP MOVS&TAGENDM

Page 15: MACROS

REPT : Repeat DirectiveIRP : Indefinite Repeat Directive

IRPC : Indefinite Repeat Character Directive

Repetition directive

Page 16: MACROS

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

REPT 4DEC SI

EEEE

REPT : Examples

Page 18: MACROS

N = 0REPT 5

N = N + 1DB N

EEEE

REPT : Examples

Page 19: MACROS

Repeat a block of instructions up to ENDM.

IRP dummy, <argument>

Repetition directive : IRP

Page 20: MACROS

IRP N, <3, 9, 17, 25, 28>DB N

ENDM

IRP : Examples

Page 21: MACROS

IRP REG, <AX, BX, CX, DX>PUSH REG

ENDM

IRP : Examples

Page 22: MACROS

Repeat a block of statements up to ENDM.

IRPC dummy, string

Repetition directive : IRPC

Page 23: MACROS

IRPC N, 345678DW N

ENDM

IRPC : Examples

Page 24: MACROS

IFxx (condition) . . .

EEEE (optional) . . .

ENDIF (end of IF)

Conditional directives

Page 25: MACROS

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

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

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

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

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

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

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

FINISH MACRO RETCODEMOV AH, 3CHIFNB <RETCODE>

MOV AL, RETCODEENDIFINT 21HENDM

Examples

Page 33: MACROS

INT21 MACRO FUNCTION, DXADDRESMOV AH, FUNCTNIFNB <DXADDRES>

MOV DX, OFFSET DXADDRESENDIFINT 21HENDM

Examples

Page 34: MACROS

IFxx [condition] . . . (invalid condition)

EEEEE . . .

ENDIF

EXITM directives

Page 35: MACROS

IF CNTR ; Macro expansion terminated

EXITMENDIF

Using IF and IFDEF conditions

Page 36: MACROS

IFIDN <&TAG>,<B>REP MOVSB. . .

Using IFIDN condition

Page 37: MACROS

IFIDN <&TAG>,<W>REP MOVSW. . .

Using IFIDN condition