函数 09h 中断 21h dx = 文本偏移量,ds = 文本段
如何在 C++ 中获取段和偏移量?
最佳答案
这个答案有几个先决条件:
- 您正在使用生成 16 位代码的编译器,因为 DOS 调用只能在 16 位模式下工作,并且
- 您的编译器获得了段的概念。
在这种情况下:
char string [] = "Hello World$";
call_int21h_9 (&string);
其中 call_int21h_9 类似于:
call_int21h_9 (FAR char *string)
// the FAR above is important and very compiler dependent, it tells the compiler
// that the pointer is a 32bit pointer (16 bit segment and 16 bit offset)
{
mov ah,9
lds dx,string ; this loads the DS:DX segment:offset from the value on the stack
int 21h
}
此外,根据段的设置和使用方式,有多种编译 16 位应用程序的方法。最常见的两个是 small
和 large
(编译器可能会称它们为其他名称):
- 小:所有段都是相同的值,数据+代码的总和<64k
- 大:所有代码和数据存在于多个段中,代码+数据<1Meg
还有其他段布局(一种数据,多种代码;一种代码和多种数据等),您需要查阅编译器文档以了解可用的内容。
当然,您最大的问题是获得一个支持 16 位的编译器。
为什么不直接使用 cout
或 printf
?
关于c++ - 在c++中使用21h中断的9个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2617907/