Macros (notes)

来源:互联网 发布:哈尔滨淘宝代运营 编辑:程序博客网 时间:2024/04/30 04:42

http://www.emu8086.com/assembler_tutorial/asm_tutorial_10.html

 

1. like proc but not really.

exist only until the code  is compiled.

after compilation, all macros are replaced with real instructions.

 

2.definition:

 

name MACRO [parameters,...]

<instructions>

ENDM

 

Unlike proc, macros should be defined above the code that uses it.

 

3. Some important facts

 

  • use- "CALL MyProc" vs "MyMacro" (no CALL in using macro)
  • procedure is located at some specific address in memory. When using  it 100 times, the size grows very insignificantly. Macro is opposite because macro is expanded directly in program's code.
  • Different in the method of passing parameters
  • ENDM vs ENDP

4. Use LOCAL followed by names of variables, labels or procedure names in Macro

example:

MyMacro2    MACROLOCAL label1, label2
CMP  AX, 2JE label1CMP  AX, 3JE label2label1: INC  AXlabel2: ADD  AX, 2ENDMORG 100hMyMacro2MyMacro2RET

 

5. If using macros in several programs, put them in a INC file.