int 0x21 和 int 0x80 有什么区别? [英] What is the difference between int 0x21 and int 0x80?

查看:71
本文介绍了int 0x21 和 int 0x80 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近进入了低级编程并了解了系统中断.据我了解,两个中断都负责系统调用,但是我不明白两者之间的区别,以及何时使用哪个.希望得到解释.

I recently got into low level programing and learned about system interrupts. From what I understood, both interrupts are responsible for system calls, however I don't understand the difference between the two, and when to use which. Would love an explanation.

推荐答案

int 21h(以 MASM/TASM 语法拼写,因为这是 DOS 最普遍的汇编程序)是操作系统.您可以在 Internet 上轻松找到可用服务的文档.您可以从 DOS 程序访问的最重要的 DOS 服务的简短列表位于 http://spike.scu.edu.au/~barry/interrupts.html.

int 21h (spelled in MASM/TASM syntax, as this is the most widespread assembler for DOS) is the system call interrupt for DOS. You can find documentation of available services easily on the internet. A short list of the most important DOS services you can reach from DOS programs is at http://spike.scu.edu.au/~barry/interrupts.html.

另一方面,int 0x80(以gas 语法拼写,因为这是Linux 的本机"汇编程序)是32 位intel 处理器上Linux 的系统调用中断.你没有得到很好的关于如何使用它的表格,就像你在 DOS 中得到的那样,因为你通常不直接调用它.如果你想直接调用它,查看系统调用的手册页,找出需要设置的寄存器,以及在哪里可以找到结果.例如,您可以在 https://fedora.juszkiewicz.com.pl/中找到系统调用的编号syscalls.html .

On the other hand, int 0x80 (spelled in gas syntax, as this is the "native" assembler for Linux) is the system call interrupt for Linux on 32-bit intel processors. You don't get nice tables on how to use it, as you get for DOS, because you typically don't call it directly. If you want to call it directly, look at the manpage for syscall, to find out what registers you need to set, and where you will find the result. You can find the number for the syscalls for example at https://fedora.juszkiewicz.com.pl/syscalls.html .

您的程序在调用 int 21hint 0x80 时的行为不是由英特尔或 80386 处理器架构定义的.相反,int 指令要求处理器在入口点表(中断描述符表")中查找入口点,并跳转到该入口点.这种跳转可能包括从用户空间切换到内核空间(如果处理器运行在支持不同权限级别的模式下).DOS 设置入口点编号 21h 以指向提供大多数 DOS 服务的调度函数.另一方面,Linux/i386 设置入口点编号 0x80 以指向提供所有 linux 内核服务的调度函数.这意味着使用 int 0x80 的程序只有在 Linux(或兼容的,如适用于 Linux 的 windows 子系统,版本 1)环境中才能运行,而使用 int 21h 只有在 DOS(或兼容环境,如 DOSBox 或 OS/2 DOS 窗口)下执行时才有效.

The behaviour of your program, when it invokes int 21h or int 0x80, is not defined by Intel or the 80386 processor architecture. Instead, the int instruction asks the processor to look up an entry point into an entry point table (the "interrupt descriptor table"), and jumps to that entry point. This jump may include switching from user space to kernel space (if the processor runs in a mode that supports different privilege levels). DOS sets up the entry point number 21h to point to a dispatch function that offers most DOS services. On the other hand, Linux/i386 sets up entry point number 0x80 to point to a dispatch function that offers all linux kernel services. This means that a program that uses int 0x80 will only work if it is executed in a Linux (or compatible, like the windows subsystem for Linux, version 1) environment, whereas a program that uses int 21h will only work if it is executed under DOS (or a compatible environment like DOSBox or the OS/2 DOS window).

这篇关于int 0x21 和 int 0x80 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆