Ric*_*uen 6 syntax assembly interrupt nasm
我有一个简单的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
Run Code Online (Sandbox Code Playgroud)
当我第一次写它时,我犯了一个错误,忘记了int和之间的空间0x80:
int0x80
Run Code Online (Sandbox Code Playgroud)
...但程序仍然编译没有问题!
[prompt]> nasm -f elf MyProgram.asm
[prompt]> ld -o MyProgram MyProgram.o
Run Code Online (Sandbox Code Playgroud)
当我运行它时它只给了我一个分段错误!
[prompt]> ./MyProgram
Segmentation fault
Run Code Online (Sandbox Code Playgroud)
那么这个程序 - 我写的原始程序,缺少的空间 - 是做什么的呢?int0x80在NASM 中(没有空格)是什么意思?
segment .text
global _start
_start:
mov eax, 1
mov ebx, 0
int0x80 ; no space...
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
NASM支持没有冒号的标签,我经常使用它来进行数据声明:
error_msg db "Ooops", 0
flag db 0x80
nullpointer dd 0
Run Code Online (Sandbox Code Playgroud)