int0x21和int0x80有什么区别?
我最近进入了低级编程并了解了系统中断。据我了解,两个中断都负责系统调用,但是我不明白两者之间的区别,以及何时使用哪个。想要一个解释。
回答
int 21h(用 MASM/TASM 语法拼写,因为这是 DOS 最普遍的汇编程序)是 DOS 的系统调用中断。您可以在 Internet 上轻松找到可用服务的文档。您可以从 DOS 程序访问的最重要的 DOS 服务的简短列表位于http://spike.scu.edu.au/~barry/interrupts.html。
另一方面,int 0x80(用gas 语法拼写,因为这是Linux 的“本机”汇编程序)是32 位英特尔处理器上Linux 的系统调用中断。你没有得到很好的关于如何使用它的表格,就像你在 DOS 中得到的那样,因为你通常不直接调用它。如果您想直接调用它,请查看syscall 的联机帮助页,了解您需要设置哪些寄存器,以及在哪里可以找到结果。例如,您可以在https://fedora.juszkiewicz.com.pl/syscalls.html找到系统调用的编号。
你的程序的行为,当它调用int 21h或者int 0x80,是不是英特尔或80386处理器架构定义。相反,该int指令要求处理器在入口点表(“中断描述符表”)中查找入口点,然后跳转到该入口点。这种跳转可能包括从用户空间切换到内核空间(如果处理器运行在支持不同权限级别的模式下)。DOS 设置入口点编号 21h 以指向提供大多数 DOS 服务的调度函数。另一方面,Linux/i386 设置入口点编号 0x80 以指向提供所有 linux 内核服务的调度函数。这意味着一个程序使用int 0x80仅当它在 Linux(或兼容的,如 Linux 的 windows 子系统,版本 1)环境int 21h中执行时才有效,而使用的程序仅在 DOS(或兼容的环境,如 DOSBox 或操作系统)下执行时才有效/2 DOS 窗口)。
- The **behaviour of the handlers** for `int 21h` and `int 0x80` is not defined by Intel. On the other hand the behaviour of `int 21h` and `int 0x80` is totally defined by Intel.(that's what you explained in details)
- There are "nice tables" of Linux system calls like https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md#x86-32_bit. But you don't need them because knowing the calling convention lets you know which arg goes where from the C prototype in the man page. i.e. the ABI rules are documented once, not for each syscall individually, including the value-range that means -errno (`-4095` to `-1`)