【问题标题】:Error when using label 'wait' in NASM macro在 NASM 宏中使用标签“等待”时出错
【发布时间】: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 非常感谢,这正是我想要的。

标签: assembly macros nasm


【解决方案1】:

是的,WAITFWAIT 是 x86_64 指令集的一部分。我确定您已尝试更改代码中的名称(阻止?HoldUp?)并且错误已被删除,这样也可以解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-11
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    • 2020-09-23
    • 2019-07-21
    • 2021-06-20
    • 1970-01-01
    相关资源
    最近更新 更多