编程基础中的int $0x80

3
我最近开始阅读 《从零开始编程》(PDF),但在第一个程序中遇到了问题。这个程序非常简单:
.section .data
.section .text

.globl _start

_start:
    movl    $1, %eax
    movl    $0, %ebx
    int     $0x80

但是在编译和运行时,我遇到了错误 非法指令: 4。我已经编辑了程序,以便它可以正确编译(删除了两个 .section 并将 _start 更改为 _main),所以这可能会影响它。
我正在使用 x86_64 指令集(Intel 处理器)。

这段代码在我的Linux系统上运行良好。你用的是什么操作系统?不过,为什么要调用fork(2)系统调用呢?也许你需要exit(1)系统调用? - kharvd
啊,那是个输入错误。我正在使用Mac OS 10.7。将其更改为1并没有帮助。你是如何编译的?我一直在使用 gcc - Jumhyn
编译没问题,但链接时出现以下警告: $ ld exit -o exit/ ld: warning: -macosx_version_min not specificed, assuming 10.7/ Undefined symbols for architecture x86_64:/ "start", referenced from:/ -u command line option/ (maybe you meant: _start)/ ld: symbol(s) not found for inferred architecture x86_64 - Jumhyn
如果你的代码在exit.s文件中,尝试使用as exit.s -o exit.o && ld exit.o -o exit进行编译。 - kharvd
有人能指出 .section data,.section text 的含义以及 movl $1,%eax 的意思吗?指令 movl $1,%eax 是存储系统调用还是将值 $1 对应的系统调用存储在 $eax 中? - Registered User
1个回答

3
如果您正在使用x86-64,您需要稍微修改ABI,请参见此处。有关差异的非常好的摘要,请参见此篇文章

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接