【发布时间】:2012-02-19 18:50:51
【问题描述】:
我最近开始阅读Programing From The Ground Up (PDF),但我在第一个程序中遇到了问题。程序很简单:
.section .data
.section .text
.globl _start
_start:
movl $1, %eax
movl $0, %ebx
int $0x80
但是在编译和运行时我得到了错误Illegal Instruction: 4。我确实编辑了程序,以便它能够正确编译(删除了两个 .sections 并将 _start 更改为 _main),因此可能会影响它。
我正在使用 x86_64 指令集(英特尔处理器)。
【问题讨论】:
-
这段代码对我来说很好(在 Linux 上)。你在什么操作系统上?虽然,你为什么打电话给
fork(2) 系统调用?也许,你需要exitsyscall (1)? -
啊,打错字了。我在 Mac OS 10.7 上。将其更改为 1 没有帮助。你是怎么编译的?我一直在使用
gcc。 -
编译正常,但链接时:
$ 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 -
如果你的代码在exit.s中,试试
as exit.s -o exit.o && ld exit.o -o exit -
能否有人指出.section data,.section text是什么意思,movl $1,%eax指令movl $1,%eax存储系统调用或者系统调用对应的值$1 存储在 $eax