关于INT 21H, AH=031H未支持问题的技术咨询
解决INT 21H AH=31H(终止并驻留)不支持的问题
以下是我编写的汇编代码:
pusha macro ;macro to push pushf ;all registers push ax push bx push cx push dx push si push di push ds push es endm popa macro ;macro to pop pop es ;all program pop ds pop di pop si pop dx pop cx pop bx pop ax popf endm captureint macro intno,saveint,subroutine ;macro to make cli ;prog resident mov ah,35h ;to get vector mov al,intno ;address int 21h mov word ptr saveint,bx mov word ptr saveint+2,es mov ah,25h ;to set vector mov al,intno ;vector address lea dx,subroutine int 21h endm .model tiny .code org 0100h ;origin begin:jmp init oldint5 dd ? saveint8 dd ? saveint9 dd ? str1 db "A",06,"I",07,"T","06" count db 0 keyboard: pusha mov cs:count,0 ;always initialise count to zero mov ah,05h ;BIOS call to activate mov al,00h ;the original page(00) instead int 10h ;of screensaver page(01) popa jmp cs:saveint9 timer: pusha cmp cs:count,126 ;compare count with 126 (7sec delay) jbe exit8 mov ah,05h ;BIOS call to activate mov al,01h ;screen saver page(01) int 10h mov ax,cs mov ds,ax mov ax,0b900h ;address of screensaver page (page1) mov es,ax lea si,str1 mov di,1980 ; offset to display message mov cx,6 ;string length rep movsb ;string displayed byte by byte jmp next exit8: inc cs:count next: popa jmp cs:saveint8 init: cli ;clear interrupt captureint 8,saveint8,timer ;to get &set vector captureint 9,saveint9,keyboard ;address of timer&keyboard mov ah,31h ;to make program resident lea dx,init sti ;set interrupt int 21h
我已修复代码中的部分错误,目前仅遇到错误提示:INT 21H, AH=031H - Not supported yet,需要解决该DOS中断调用不支持的问题。
原因与解决办法
1. 运行环境不支持实模式DOS中断
INT 21H AH=31H是DOS实模式下的**终止并驻留(TSR)**调用,现代Windows命令提示符、WSL等环境不支持实模式DOS中断,仅能在以下环境正常运行:
- 纯MS-DOS系统(如MS-DOS 6.22)
- DOSBox(使用默认配置或更新到最新版本,确保实模式兼容)
- 虚拟机中运行的实模式DOS系统
2. 程序格式或参数错误
- 确认生成COM格式文件:代码使用
.model tiny和org 100h,符合COM程序标准,汇编链接时必须生成.COM文件(而非.EXE),TSR程序仅COM格式能正确驻留。 - 检查DX参数正确性:
AH=31H要求DX指定驻留内存的大小(从PSP的100h开始的字节数)。原代码中lea dx,init是正确的,因为init标签位于所有驻留代码(中断服务程序、变量)之后,确保这些内容被保留。若仍有问题,可替换为mov dx, $($表示当前指令的偏移,即驻留到int 21h之前的所有代码)。
3. 汇编器/链接器配置问题
使用MASM/TASM时,确保链接命令正确生成COM文件:
- MASM:
masm yourcode.asm;然后link /t yourcode.obj;(/t参数指定生成COM文件) - TASM:
tasm yourcode.asm;然后tlink /t yourcode.obj;
内容的提问来源于stack exchange,提问作者Nawaf
相关产品推荐
相关产品推荐

