我目前正在尝试理解的概念汇编语言中的宏,特别是在 GNU 汇编器中,IA-32 (x86) 的 AT&T 语法。我大学的幻灯片内容如下:
# How to define a macro:
.macro write string
movl string, %esi
call printstr
.endm
# How to use a macro:
write aString
但是,这对我不起作用。我在用gcc编译我的代码。
.data
msg: .string "The result is %d.\n"
.text
.global main
.macro add_3 n
movl n, %eax
addl $3, %eax
.endm
main:
add_3 $39
pushl %eax
pushl $msg
call printf
popl %eax
popl %eax
movl $1, %eax
int $0x80
当我尝试编译它时,出现以下错误:
undefined reference to `n'
我究竟做错了什么?
要引用宏内部的参数,请在名称前面添加反斜杠。
例如:
.macro add_3 n
movl \n + 3, %eax
.endm
气体手册:https://sourceware.org/binutils/docs/as/Macro.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)