3
我目前试图理解汇编语言中的宏的概念。我大学的幻灯片如下:汇编语言中的宏(IA32,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'
我究竟在做什么错?
尝试使用宏内部时,它们与前置反斜杠参数名。即'movl \ n,%eax' – Michael
这确实有用,非常感谢! – lambdarookie
哪里投票? – johnfound