Macros (notes)

本文介绍了汇编语言中宏的基本概念、定义方法及与过程的区别。详细解释了宏如何在程序中被替换为实际指令,并通过示例展示了如何在宏内部使用局部标签。此外,还讨论了在多个程序中复用宏的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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    MACRO
	LOCAL label1, label2

	CMP  AX, 2
	JE label1
	CMP  AX, 3
	JE label2
	label1:
		 INC  AX
	label2:
		 ADD  AX, 2
ENDM

ORG 100h
MyMacro2
MyMacro2
RET

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值