【发布时间】:2016-03-27 09:18:07
【问题描述】:
我在 NASM 中使用宏来定义一些重复的函数。我使用以下代码:
; System call numbers
%define SYS_fork 1
%define SYS_exit 2
%define SYS_wait 3
; define the macro
%macro SYSCALL 1
global %1
%1:
mov eax, SYS_%1
int 64 ; 64 is system call
ret
%endmacro
; call the macro to setup the functions
SYSCALL fork
SYSCALL exit
SYSCALL wait
这工作正常,除了最后一次调用创建名为wait 的宏。它给了我错误:
error: parser: instruction expected
wait 是 nasm 中的保留字吗?如果是这样,有没有办法仍然定义一个名为 wait 的函数?
【问题讨论】:
-
两个问题都是。 NASM manual 表示 标识符也可以以 $ 为前缀,表示它旨在作为标识符而不是保留字来读取。所以在你的宏中写着
%1:的那一行改成$%1: -
@MichaelPetch 非常感谢,这正是我想要的。