我在 64 位 Linux 环境中运行我的代码,其中 Linux 内核是使用IA32_EMULATION和X86_X32 disabled构建的。
在《从头开始编程》一书中,第一个程序除了产生段错误之外什么都不做:
.section .data
.section .text
.globl _start
_start:
movl $1, %eax
movl $0, %ebx
int $0x80
Run Code Online (Sandbox Code Playgroud)
我将代码转换为使用 x86-64 指令,但它也会出现段错误:
.section .data
.section .text
.globl _start
_start:
movq $1, %rax
movq $0, %rbx
int $0x80
Run Code Online (Sandbox Code Playgroud)
我像这样组装了这两个程序:
as exit.s -o exit.o
ld exit.o -o exit
Run Code Online (Sandbox Code Playgroud)
运行./exit给出了Segmentation fault两个。我究竟做错了什么?
PS 我看过很多用gcc组装代码的教程,但是我想使用gas。
结合评论和答案,这是代码的最终版本:
.section .data
.section .text
.globl _start
_start: …Run Code Online (Sandbox Code Playgroud)