1 / 12

Macros

Macros. Covers chapter 8, pages 300 – 314. Run-time vs. Assemble-time. Almost everything but the main body of an assembly-language program deals with assemble-time Header Equates Data Closing For the most part, the only run-time portion is the body. Run-time vs. Assemble-time (cont.).

moanna
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 Covers chapter 8, pages 300 – 314

  2. Run-time vs. Assemble-time • Almost everything but the main body of an assembly-language program deals with assemble-time • Header • Equates • Data • Closing • For the most part, the only run-time portion is the body

  3. Run-time vs. Assemble-time (cont.) • Programming the assembler • Directives – instructions to the assembler on how or what to assemble • Macros – programmer-defined directives

  4. Macros • Macros exist to • avoid repetition (or avoid typing) • increase clarity • avoid function call overhead • Macros work by substitution • Types of macros • Replacing • Repeating

  5. Replacing Macros • Syntax: MACRO <macro name> <parameters> <code or other macros> ENDM <macro name> • Example: MACRO Terminate mov ah, 04Ch mov al, [exCode] int 21h ENDM Terminate • Example program term.asm

  6. .lst File • Created by the /l tasm command-line switch • Contains everything but the kitchen sink: • program code • machine code • expanded macros • symbol table • macro table • group and segment table • Extremely useful for debugging code with macros

  7. Parameters • Formal parameters • only exist within the macro • do not represent immediate values or offsets • are text-replaced • Example: MACRO Inc2 v1 inc v1 inc v1 ENDM Inc2 • Example program inc2.asm

  8. Parameters (cont.) • Actual parameters are the text that is actually used when substituting the macro • Example: Inc2 ax • The text “ax” is the actual parameter • Example program shleft.asm

  9. Parameter Modifiers • Actual parameters • <> - forces parameter to contain spaces • % - forces evaluation first (use with “()”) • ! – “escapes” other two • Formal parameters • & - recognize next word as a parameter • Example program shleft2.asm • Example program asciiz.asm

  10. Repeating Macros • IRP – Instruction RePeat • Syntax: IRP <formal param>, <element, element, …> <instruction> ENDM • Repeats the instruction (in the source code itself) for every element • Example programs save.asm and save2.asm

  11. Local Labels • Consider the following: MACRO IncNum op, count push cx mov cx, count @@Back: inc op loop @@Back pop cx ENDM IncNum

  12. Local Labels (cont.) • The LOCAL directive solves the problem: MACRO IncNum op, count LOCAL @@Back push cx mov cx, count @@Back: inc op loop @@Back pop cx ENDM IncNum

More Related