1 / 37

MACROS

MACROS. Suthida Chaichomchuen std@kmitnb.ac.th. 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.

tavia
Download Presentation

MACROS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 macroname MACRO [parameter list] [instructions] ENDM ;Define macro ;Body of macro ;End of macro

  5. INITZ MACRO ;Define macro MOV AX,@data ; Body MOV DS,AX ; of MOV ES,AX ; macro definition ENDM ;End of macro Simple macro definitions

  6. FINISH MACRO ;Define macro MOV AX,4C00H ;Body of INT 21H ;macro definition ENDM ;End of macro Simple macro definitions

  7. Using parameter in Macros PROMPT MACRO MESSAGE ;dummy argument MOV AH,09H LEA DX,MESSAGE INT 21H ENDM ;End of macro

  8. Using parameter in Macros MESSAGE2 DB ‘Enter the date as mm/dd/yy’ PROMPT MESSAGE2

  9. Macro Comments PROMPT MACRO MESSAGE ; This macro permits a display of messages MOV AH,09H ;Request display LEA DX,MESSAGE ;prompt INT 21H ENDM

  10. Macro Listing directive • .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.

  11. 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

  12. Including Macros from a library Programs can use any of the cataloged macros by use an INCLUDE directive like this. INCLUDE Path and file name Example: INCLUDE F:\MACRO.LBY

  13. The PURGE directive Use to delete the unwanted macros from the current assembly. PURGE Macro names Example: PURGE PROMPT, DIVIDE

  14. Concatenation Used the ampersand (&) character tells the assembler to join text or symbols. STRMOVE MACRO TAG REP MOVS&TAG ENDM

  15. Repetition directive • REPT : Repeat Directive • IRP : Indefinite Repeat Directive • IRPC : Indefinite Repeat Character Directive

  16. Repetition directive : REPT Repeat a block of statements up to ENDM according to the number of times in the expression entry. REPT expression

  17. REPT : Examples REPT 4 DEC SI ENDM

  18. REPT : Examples N = 0 REPT 5 N = N + 1 DB N ENDM

  19. Repetition directive : IRP Repeat a block of instructions up to ENDM. IRP dummy, <argument>

  20. IRP : Examples IRP N, <3, 9, 17, 25, 28> DB N ENDM

  21. IRP : Examples IRP REG, <AX, BX, CX, DX> PUSH REG ENDM

  22. Repetition directive : IRPC Repeat a block of statements up to ENDM. IRPC dummy, string

  23. IRPC : Examples IRPC N, 345678 DW N ENDM

  24. Conditional directives IFxx (condition) . . . ELSE (optional) . . . ENDIF (end of IF)

  25. 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 .

  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 <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.

  29. Conditional directives • IFIDN <arg-1>,<arg-2> : 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 <arg-1>,<arg-2> : 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. Examples FINISH MACRO RETCODE MOV AH, 3CH IFNB <RETCODE> MOV AL, RETCODE ENDIF INT 21H ENDM

  33. Examples INT21 MACRO FUNCTION, DXADDRES MOV AH, FUNCTN IFNB <DXADDRES> MOV DX, OFFSET DXADDRES ENDIF INT 21H ENDM

  34. EXITM directives IFxx [condition] . . . (invalid condition) EXITM . . . ENDIF

  35. Using IF and IFDEF conditions IF CNTR ; Macro expansion terminated EXITM ENDIF

  36. Using IFIDN condition IFIDN <&TAG>,<B> REP MOVSB . . .

  37. Using IFIDN condition IFIDN <&TAG>,<W> REP MOVSW . . .

More Related