Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

TITLE SHOWERR --Display DOS function call error messages ;Dispaly a message based on an…

  1. User

    TITLE SHOW_ERR --Display DOS function call error messages ;Dispaly 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 '$' ; OUT_OF_RANGE DB 'Error code is not in valid 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 blocks destroyed',CR,LF,EOM ER8 DB'Insufficient memory',CR,LF,EOM ER9 DB'Invalid memory block 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' DB 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'Seek error',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 unavaliable',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 PUSH AX ;save input error number CMP AX,83 ;check for error code in range JG O_O_R CMP AX,0 JG IN_RANGE 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 ;error code 1 --35? JG TRY79 LEA BX,ERTAB1 ;yes,POINT to ERTAB1 DEC AX JMP FORM_ADDR TRY79: CMP AX,79 ;error code 36 -- 79 ? JG LAST_4 LEA DX,RESERVED ;yes,display message JMP DISP_MSG LAST_4: LEA BX,ERTAB2 ;error code 80 -- 83 AND AX,3 FORM_ADDR: SHL AX,1 ;POINT to correct offset ADD BX,AX MOV DX,[BX] ;put message addr into DX DISP_MSG: MOV AH,9 ;display message string INT 21H POP AX RET ;return to calling program SHOW_ERR ENDP ; CSEG ENDS ; END SHOW_ERR

  2. Assistant

    This program displays error messages based on an error code passed in the AX register. The error codes and their corresponding messages are stored in the data segment. The program checks if the error code is within a valid range, and then looks up the appropriate message in a table. The message is then displayed using the INT 21H function 9.

    To use this program, you can call the SHOW_ERR procedure, passing the error code in the AX register. The program will display the corresponding error message.

    Note that this program assumes that the display device is the standard output and that the data and code segments are both the default segments.

  3. User

    修改使其能从键盘接受一个单字节错误号输入

  4. Assistant

    下面是修改后的代码,使其能够从键盘接受一个单字节错误号输入:

    .MODEL SMALL
    .DATA
        CR     EQU      13
        LF     EQU      10
        EOM    EQU      '$'
    
        ; Error messages
        OUT_OF_RANGE   DB 'Error code is not in valid range (1-83)', 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
        ; ...
    
    .CODE
        ORG 100h
    
    START:
        MOV AX, @DATA
        MOV DS, AX
    
        ; Prompt the user for an error code
        MOV AH, 9
        LEA DX, PROMPT
        INT 21h
    
        ; Read a single byte from the keyboard
        MOV AH, 1
        INT 21h
        SUB AL, '0'  ; Convert ASCII to number
    
        ; Call the SHOW_ERR procedure with the error code
        MOV AH, AL
        CALL SHOW_ERR
    
        ; Terminate the program
        MOV AH, 4Ch
        INT 21h
    
    SHOW_ERR PROC
        PUSH AX
    
        CMP AX, 83  ; Check for error code in range
        JG OUT_OF_RANGE
        CMP AX, 0
        JG IN_RANGE
    
    OUT_OF_RANGE:
        LEA DX, OUT_OF_RANGE
        JMP DISP_MSG
    
    IN_RANGE:
        CMP AX, 35  ; Check error code 1 -- 35?
        JG TRY79
        LEA BX, ERTAB1  ; Yes, POINT to ERTAB1
        DEC AX
        JMP FORM_ADDR
    
    TRY79:
        CMP AX, 79  ; Check error code 36 -- 79?
        JG LAST_4
        LEA DX, RESERVED  ; Yes, display message
        JMP DISP_MSG
    
    LAST_4:
        LEA BX, ERTAB2  ; Error code 80 -- 83
        AND AX, 3
    FORM_ADDR:
        SHL AX, 1  ; POINT to correct offset
        ADD BX, AX
        MOV DX, [BX]  ; Put message address into DX
    
    DISP_MSG:
        MOV AH, 9  ; Display message string
        INT 21h
    
        POP AX
        RET
    
    SHOW_ERR ENDP
    
    .DATA
    PROMPT DB 'Enter error code (1-83): $'
    
    .DATA?
    ERTAB1 DW ER1, ER2, ER3 ; ...
    ERTAB2 DW ER80, ER81, ER82, ER83
    
    END START
    

    这个修改后的代码会提示用户输入一个介于1到83之间的错误码。然后,它会调用SHOW_ERR过程来显示相应的错误消息。请注意,这个程序假设显示设备为标准输出,数据和代码段都是默认段。

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.