我是汇编语言的新手,这是我的小程序。
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.如何使用核心转储文件gdb
?在此处输入图像描述
您的程序不包含结束它的代码。在代码中执行最后的nop
后,CPU 将继续执行之后的内存包含的任何内容,直到崩溃。若要解决此问题,请告诉操作系统终止进程。在 amd64 Linux 上,您可以使用以下代码:
mov eax,60 ; system call 60: exit
xor edi,edi ; set exit status to zero
syscall ; call the operating system