【问题标题】:GNU Assembler (Mac OS X 64-bit): Illegal instruction: 4 [duplicate]GNU 汇编程序(Mac OS X 64 位):非法指令:4 [重复]
【发布时间】:2012-06-24 14:33:09
【问题描述】:

我是 GNU Assembler 的新手,我正在尝试执行这段代码:

.globl _main
_main:
    movl $1, %eax
    movl $0, %ebx
    int $0x80

这个程序应该通过系统调用退出 (1) 退出。编译它(没有警告):

gcc test.s

但运行它会给我错误:Illegal instruction: 4

感谢您的帮助!

【问题讨论】:

    标签: macos assembly x86-64 system-calls gnu-assembler


    【解决方案1】:

    如果你正在编译一个 64 位的可执行文件,那么你应该这样写:

    movq $0x2000001, %rax
    movq $0, %rdi
    syscall
    

    Source.

    【讨论】:

    • 对,我刚刚注意到,如果我编译为 32 位,它就会运行。谢谢!
    猜你喜欢
    • 2015-01-09
    • 2023-03-16
    • 1970-01-01
    • 2011-07-23
    • 2010-11-08
    • 2018-06-28
    • 1970-01-01
    • 2017-09-03
    • 2018-03-20
    相关资源
    最近更新 更多