【问题标题】:int $0x80 in Programming From The Ground Upint $0x80 从头开始​​编程
【发布时间】: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) 系统调用?也许,你需要exit syscall (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

标签: assembly x86-64


【解决方案1】:

如果您使用的是 x86-64,则需要稍微更改 ABI,请参阅this。有关差异的非常好的总结,请参阅this 帖子。

【讨论】:

    猜你喜欢
    • 2011-07-22
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 2016-12-03
    • 1970-01-01
    相关资源
    最近更新 更多