汇编中的宏(IA32,AT&T语法)

lam*_*kie 3 x86 assembly gcc gnu-assembler

我目前正在尝试理解汇编语言的概念.我大学的幻灯片说明如下:

# How to define a macro:
.macro write string
    movl string, %esi
    call printstr
.endm

# How to use a macro:
write aString
Run Code Online (Sandbox Code Playgroud)

但是,这对我不起作用.我正在使用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
Run Code Online (Sandbox Code Playgroud)

当我尝试编译它时,我收到以下错误:

undefined reference to `n'
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Blu*_*Ice 5

在宏中使用时,尝试使用反斜杠前缀参数名称.例如:

movl \n, %eax


来源:迈克尔