DOS int 21/AH=9 的常量返回值背后的基本原理是什么?(打印字符串中断) [英] What is the rationale behind the constant return value for DOS int 21 / AH=9? (print string interrupt)

查看:57
本文介绍了DOS int 21/AH=9 的常量返回值背后的基本原理是什么?(打印字符串中断)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此处查看 DOS int 21h 中断的规范 http://spike.scu.edu.au/~barry/interrupts.html

I was looking at the specifications for DOS int 21h interrupts here http://spike.scu.edu.au/~barry/interrupts.html

我不太了解汇编,但似乎 AL 寄存器是存储中断返回值的标准.例如,服务 01h(读取字符)将读取的字符存储在那里.服务 02h(将字符写入标准输出)将最后一个字符输出存储在那里.

I don't know much about assembly, but it seems like the AL register is the standard to store return values from an interrupt. For instance, service 01h (read character) stores the character read there. And service 02h (write character to stdout) stores the last character output there.

但是当谈到 AH=09h(将字符串写入标准输出)时,返回值总是 24h.这是为什么?

But when it comes to AH=09h (write string to stdout) the return value is ALWAYS 24h. Why is that?

首先我认为出于某种技术原因必须设置 SOME 值,但事实并非如此.有很多 DOS 服务根本没有指定返回值.还有一些将返回值存储在其他寄存器中,例如 2Ch(获取系统时间),而是将结果存储在 CH、CL、DH 和 DL 寄存器中,而不是 AL.

First I thought that SOME value has to be set for some technical reason, but that does not seem to be the case. There are lots of DOS services that don't specify a return value at all. And some store the return value in other registers, such as 2Ch (get system time) which instead stores the result in CH, CL, DH and DL registers instead of AL.

那为什么中断服务AH=09h会在AL中存一个值呢?为什么是 24 小时?

So why does interrupt service AH=09h store a value in AL? And why 24h?

推荐答案

更多细节:

你可以看到这里 这个系统调用在 MS-DOS v1.25 中的源代码:

You can see here the source code for this system call in MS-DOS v1.25:

PRTBUF: ;System call 9
        MOV     SI,DX
OUTSTR:
        LODSB
        CMP     AL,"$"
        JZ      RET20
        CALL    OUT
        JMP     SHORT OUTSTR

它在循环中使用 LODSB 指令从字符串中加载字节,将它们与 $ 进行比较,然后将它们写出.由于 LODSB 是硬连线加载到 AL 中,并且当看到 $ 时循环终止,这就是 AL.

It uses the LODSB instruction in a loop to load bytes from the string, compare them against $, and write them out. Since LODSB is hard-wired to load into AL, and the loop terminates when $ is seen, that's what's left in AL.

DOS API 规定 AX 不需要由系统调用保留(参见 MS-DOS 程序员参考手册,1.10.4,寄存器处理"),并且服务 09h 的返回值仅描述为无".因此,对于退出时 AL 应包含的内容,没有书面保证;它的内容只是未指定.其他版本的 DOS 可能有不同的行为,因此您显然不应依赖此类行为.

The DOS API specified that AX need not be preserved by system calls (see MS-DOS Programmer's Reference Manual, 1.10.4, "Treatment of Registers"), and the return value from service 09h is just described as "None". So there is no documented guarantee as to what AL should contain on exit; its contents are simply unspecified. Other versions of DOS may have behaved differently, so you obviously should not rely on such behavior.

这篇关于DOS int 21/AH=9 的常量返回值背后的基本原理是什么?(打印字符串中断)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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