查看: 77|回覆: 0

汇编语言关于2号功能函数的坑点

[複製鏈接]

5

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2011-7-30
發表於 2019-10-13 21:58:00 | 顯示全部樓層 |閲讀模式

汇编语言的2号功能函数有小小的坑点,需要格外注意一下。

mov ah,2
int 21h

某些dos版本下,该功能函数会返回一个值并存在al中。

如果不注意这一点,有时候就会出错。比如如下代码:

DATAS SEGMENT
    ;此处输入数据段代码  
DATAS ENDS

STACKS SEGMENT
    ;此处输入堆栈段代码
STACKS ENDS

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
    MOV AX,DATAS
    MOV DS,AX
    mov ax,3633H
    call print
    MOV AH,4CH
    INT 21H
print proc
	push dx
	mov dl,ah
	;入口参数是ax
	mov ah,2
	int 21h
	mov dl,al
	mov ah,2
	int 21h
	pop dx
	ret
print endp
CODES ENDS
    END START

理想的输出结果应该是63,而实际输出为66。

以下是debug过程的部分截图,可以验证该说法。

也可以参考如下文章:
http://www.delorie.com/djgpp/doc/rbinter/id/65/25.html

文章内容

Category: DOS kernel
INT 21 - DOS 1+ - WRITE CHARACTER TO STANDARD OUTPUT

	AH = 02h
	DL = character to write
    (某些版本存在返回值)
Return: AL = last character output (despite the official docs which state
		nothing is returned) (at least DOS 2.1-7.0)
Notes:	^C/^Break are checked, and INT 23 executed if pressed
	standard output is always the screen under DOS 1.x, but may be
	  redirected under DOS 2+
	the last character output will be the character in DL unless DL=09h
	  on entry, in which case AL=20h as tabs are expanded to blanks
	if standard output is redirected to a file, no error checks (write-
	  protected, full media, etc.) are performed
SeeAlso: AH=06h,AH=09h


来源:https://www.cnblogs.com/kevinbruce656/p/11668623.html
回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部