Assembly NASM编程--`int0x80`与`int0x80`的比较`

Assembly NASM编程--`int0x80`与`int0x80`的比较`,assembly,syntax,interrupt,nasm,Assembly,Syntax,Interrupt,Nasm,我有一个简单的NASM程序,它只调用sys\u 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和0x8

我有一个简单的NASM程序,它只调用
sys\u 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...

NASM给了我这个警告:

警告:在没有冒号的行上单独使用标签可能会出错

显然,输入错误被视为标签,您可以像往常一样在程序中引用新的
int0x80
标签:

segment .text
    global _start
    _start:
        mov eax, 1 ; 1 is the system identifier for sys_exit
        mov ebx, 0 ; exit code
        int0x80 ; interrupt to invoke the system call

        jmp int0x80 ; jump to typo indefinitely

NASM支持不带冒号的标签,我经常将其用于数据声明:

error_msg   db "Ooops", 0
flag        db 0x80
nullpointer dd 0

您需要在此行末尾加一个冒号:

Segment .text:

global _start
_start:
    mov eax, 1
    mov ebx, 0
    int0x80 ; no space...

如果在@pst之后调用
int 0x80
,会发生什么情况?@pst-好主意!*尝试它*它似乎执行正常!即使我添加一个
sys\u write
系统调用,使其成为一个“Hello World”程序。。。这就像
int0x80
根本不存在:你是说分割错误消失了?@BoltClock-是的!seg错误可能是因为
int0x80
没有中断,因此没有调用系统调用
sys\u exit
。。。因此,执行过程会在程序结束后继续进入内存的未知区域,从而导致seg错误。但这仍然留下了一个问题:什么是
int0x80
,它不应该编译吗?