我的小asm程序有一个段错误

时间:2017-03-17 11:12:46

标签: linux assembly x86 nasm

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

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.为什么这个小程序有段错误?
2.如何使用核心转储文件gdbenter image description here

1 个答案:

答案 0 :(得分:3)

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

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