我有一个简单的NASM程序,只调用了sys_exit
:
segment .text
global _start
_start:
mov eax, 1 ; 1 is the system identifier for sys_exit
mov ebx, 0 ; exit code
int 0x80 ; interrupt to invoke the system call
当我第一次写它时,我犯了一个错误,忘记在int
和0x80
之间加上空格:
int0x80
...但程序仍然可以顺利编译!
[prompt]> nasm -f elf MyProgram.asm
[prompt]> ld -o MyProgram MyProgram.o
当我运行它时,它只是给了我一个分段错误!
[prompt]> ./MyProgram
Segmentation fault
那么这个程序 - 我写的原始版本,缺少空格 - 是做什么的?在NASM中,int0x80
(没有空格)是什么意思?
segment .text
global _start
_start:
mov eax, 1
mov ebx, 0
int0x80 ; no space...
int 0x80
会发生什么? - user166390sys_write
系统调用,使它成为一个“Hello World”程序...就好像int0x80
根本不存在一样 :O - Richard JP Le Guenint0x80
没有中断,因此不会调用系统调用sys_exit
...所以执行继续超出程序结束进入未知的内存区域,导致段错误。但仍然有一个问题:int0x80
是什么,它不应该无法编译吗? - Richard JP Le Guen