Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— 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 ENDM Example: MACRO Terminate movah, 04Ch moval, [exCode] int21h 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 incv1 ENDM Inc2 Example program inc2.asm

8 Parameters (cont.) Actual parameters are the text that is actually used when substituting the macro Example: Inc2ax 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, 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: MACROIncNumop, count pushcx movcx, count @@Back: incop loop@@Back popcx ENDMIncNum

12 Local Labels (cont.) The LOCAL directive solves the problem: MACROIncNumop, count LOCAL@@Back pushcx movcx, count @@Back: incop loop@@Back popcx ENDMIncNum


Download ppt "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."

Similar presentations


Ads by Google