#2
oped022022-10-16 12:49
|
TITLE SHOW ERR--Display DOS function call error messages
;Display a message based on an error code in AX
;All registers are preserved
;*****************************************************
DSEG SEGMENT PARA'DATA'
CR EQU 13
LF EQU 10
EOM EQU '$'
mess db 'which error did you get?','$'
monin label byte
max db 3 ;最多输入的字符数
act db ? ;在读入缓冲区时,此位置会自动存储输入数字的位数
mon db 3 dup(?);存储输入的数字,最多2个数字与一个回车
alfmon db '???',13,10,'$'
char db '?'
OUT_OF_RANGE DB 'Error code is not in vaild range(1-83)'
DB CR,LF,EOM
RESERVED DB 'Error code is reserved(36-79)',CR,LF,EOM
ER1 DB 'Invalid function number',CR,LF,EOM
ER2 DB 'File not found',CR,LF,EOM
ER3 DB 'Path not found',CR,LF,EOM
ER4 DB 'Too many open files',CR,LF,EOM
ER5 DB 'Access denied',CR,LF,EOM
ER6 DB 'Invalid handle',CR,LF,EOM
ER7 DB 'Memory control block destroyed',CR,LF,EOM
ER8 DB 'Insufficient memory',CR,LF,EOM
ER9 DB 'Invalid memory address',CR,LF,EOM
ER10 DB 'Invalid environment',CR,LF,EOM
ER11 DB 'Invalid format',CR,LF,EOM
ER12 DB 'Invalid access code',CR,LF,EOM
ER13 DB 'Invalid data',CR,LF,EOM
ER14 DB 'No such message',CR,LF,EOM
ER15 DB 'Invalid drive was specified' ,CR,LF,EOM
ER16 DB 'Attempted to remove the current directory',CR,LF,EOM
ER17 DB 'Not same device',CR,LF,EOM
ER18 DB 'No more files',CR,LF,EOM
ER19 DB 'Disk is write..protected',CR,LF,EOM
ER20 DB 'Unknown unit',CR,LF,EOM
ER21 DB 'Drive not ready',CR,LF,EOM
ER22 DB 'Unknown command',CR,LF,EOM
ER23 DB 'Data error (CRC)',CR,LF,EOM
ER24 DB 'Bad request structure length',CR,LF,EOM
ER25 DB 'Scek crror',CR,LF,EOM
ER26 DB 'Unknown media type',CR,LF,EOM
ER27 DB 'Sector not found',CR,LF,EOM
ER28 DB 'Printer out of paper',CR,LF,EOM
ER29 DB 'Write fault',CR,LF,EOM
ER30 DB 'Read fault',CR,LF,EOM
ER31 DB 'General failure',CR,LF,EOM
ER32 DB 'Sharing violation',CR,LF,EOM
ER33 DB 'Lock violation',CR,LF,EOM
ER34 DB 'Invalid disk change',CR,LF,EOM
ER35 DB 'FCB unavailable',CR,LF,EOM
ER80 DB 'File exists',CR,LF,EOM
ER81 DB 'Reserved',CR,LF,EOM
ER82 DB 'Cannot make',CR,LF,EOM
ER83 DB 'Fail on INT 24',CR,LF,EOM
ERTAB1 DW ER1,ER2,ER3,ER4,ER5,ER6,ER7,ER8,ER9,ER10
DW ER11,ER12,ER13,ER14,ER15,ER16,ER17,ER18
DW ER19,ER20,ER21,ER22,ER23,ER24,ER25,ER26
DW ER27,ER28,ER29,ER30,ER31,ER32,ER33,ER34
DW ER35
ERTAB2 DW ER80,ER81,ER82,ER83
DSEG ENDS
;*****************************************************
CSEG SEGMENT PARA 'CODE'
ASSUME CS:CSEG,DS:DSEG
SHOW_ERR PROC FAR
PUSH DS
SUB BX,BX
PUSH BX
;
MOV SI,DSEG ;initialize DS
MOV DS,SI
;
mov dx,offset mess
mov ah,9
int 21h
mov dl,13
mov ah,02
int 21h ;回车
mov dl,10
mov ah,02
int 21h ;换行
lea dx,monin
mov ah,0ah
int 21h ;键盘输入到缓冲区,(ds:dx+2)为输入字符串起始地址,注意此环境为小端地址
mov dl,13
mov ah,02
int 21h
mov dl,10
mov ah,02
int 21h
cmp act,0 ;若输入的字符数为0,cmp不保存结果直接影响符号位退出
je exit
cmp act,2
je two
mov al,mon
jmp conv
two:
mov al,mon+1
mov ah,mon
conv: ;将ASCII码转化为数字
xor ax,3030h ;Clear ASCII 3's,使用异或将输入的ascii码转化为数字
cmp ah,0
jnz ten1
jz loc
ten1:
cmp ah,1
jnz ten2
mov ah,0
add al,10
jmp loc
ten2:
cmp ah,2
jnz ten3
mov ah,0
add al,20
jmp loc
ten3:
cmp ah,3
jnz ten4
mov ah,0
add al,30
jmp loc
ten4:
cmp ah,4
jz res
JNZ ten5
ten5:
cmp ah,5
jz res
jnz ten6
ten6:
cmp ah,6
jz res
jnz ten7
ten7:
cmp ah,7
jz res
jnz ten8
ten8:
cmp ah,8
jnz O_O_R
mov ah,0
add al,80
jmp loc
exit: ret
loc: CMP AX,83 ;check for error code in range
JG O_O_R
CMP AX,0
JG IN_RANGE
mov dl,13
mov ah,02
int 21h
mov dl,10
mov ah,02
res: LEA DX,RESERVED
JMP SHORT DISP_MSG
O_O_R: LEA DX,OUT_OF_RANGE
JMP SHORT DISP_MSG
;ERROR CODE IS VALID,DETERMINE WITH TABLE TO USE
IN_RANGE:
CMP AX,35
JG TRY79
LEA BX,ERTAB1
DEC AX
JMP FORM_ADDR
TRY79:
CMP AX,79
JG LAST_4
LEA DX,RESERVED
JMP DISP_MSG
LAST_4:
LEA BX,ERTAB2
AND AX,3
FORM_ADDR:
SHL AX,1
ADD BX,AX
MOV DX,[BX]
DISP_MSG:
MOV AH,9
INT 21H
POP AX
RET
SHOW_ERR ENDP
;
CSEG ENDS
;*****************************************************
END SHOW_ERR
就是我在DOS里直接从键盘输入字符,通过数字返回相应的错误码
错误码范围在:
1~35 80~83
不在这个范围内的也会返回相应的语句
35~79返回Error code is reserved(36-79)
84及以上返回Error code is not in vaild range(1-83)
我的代码只能适用于十位数以上的数字,如果是0~9会返回Error code is not in vaild range(1-83)
想请问一下各位是哪里出错了