我的小 asm 程序有段错误

my little asm program has a segment fault

我是汇编语言的新手,这是我的小程序。

section .data
section .text

global _start
_start:
    nop ; make gdb happy
    ; put your experiments here
    mov eax,4
    ; put your expeirments here
    nop ; make gdb happy

section .bss

这段代码是用这些命令编译的:

nasm -f elf64 -g -F stabs 001.asm -o 001.o
ld -o test 001.o

但是当我运行时,它生成了一个带有段错误的核心转储文件。
1.Why 这个小程序有段错误?
2.How 到 gdb 这与核心转储文件有关吗? enter image description here

您的程序不包含结束它的代码。在你的代码中执行完最后的 nop 之后,CPU 继续执行它之后包含的任何内存,直到它崩溃。要解决此问题,请告诉操作系统终止您的进程。在 amd64 Linux 上,您可以使用以下代码:

mov eax,60  ; system call 60: exit
xor edi,edi ; set exit status to zero
syscall     ; call the operating system