gpt4 book ai didi

assembly - NASM 编程 - `int0x80` 与 `int 0x80`

转载 作者:行者123 更新时间:2023-12-04 15:03:53 30 4
gpt4 key购买 nike

我有一个简单的 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

那么这个程序 - 我写的原始程序,缺少空格 - 做什么?什么 int0x80 (没有空格)在 NASM 中是什么意思?
segment .text
global _start
_start:
mov eax, 1
mov ebx, 0
int0x80 ; no space...

最佳答案

NASM 给了我这个警告:

warning: label alone on a line without a colon might be in error



显然,错字被视为标签,您可以引用新的 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

关于assembly - NASM 编程 - `int0x80` 与 `int 0x80`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5427792/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com