在此代码中比较CMP AL,1的目的是什么?

时间:2018-08-18 23:15:00

标签: assembly x86

    SUBTTL IOFUNC -- DO FUNCTION 1-12 I/O
    PAGE
    IOFUNC_RETRY:
    ASSUME  DS:NOTHING,ES:NOTHING
    invoke  restore_world

    procedure   IOFUNC,NEAR
    ASSUME  DS:NOTHING,ES:NOTHING

    ; Inputs:
    ;       DS:SI Points to FCB
    ;       AH is function code
    ;               = 0 Input
    ;               = 1 Input Status
    ;               = 2 Output
    ;               = 3 Output Status
    ;               = 4 Flush
    ;       AL = character if output
    ; Function:
    ;       Perform indicated I/O to device or file
    ; Outputs:
    ;       AL is character if input
    ;       If a status call
    ;               zero set if not ready
    ;               zero reset if ready (character in AL for input status)
    ; For regular files:
    ;       Input Status
    ;               Gets character but restores fcb_RR field
    ;               Zero set on EOF
    ;       Input
    ;               Gets character advances fcb_RR field
    ;               Returns ^Z on EOF
    ;       Output Status
    ;               Always ready
    ; AX altered, all other registers preserved

    MOV     WORD PTR [IOXAD+2],SS
    MOV     WORD PTR [IOXAD],OFFSET DOSGROUP:DEVIOBUF
    MOV     WORD PTR [IOSCNT],1
    MOV     WORD PTR [DEVIOBUF],AX

    IOFUNC2:
    TEST    [SI.fcb_DEVID],080H
    JNZ     IOTODEV
    JMP     IOTOFILE

    IOTODEV:
    invoke  save_world
    PUSH    DS
    PUSH    SS
    POP     ES
    PUSH    SS
    POP     DS
    ASSUME  DS:DOSGROUP
    XOR     BX,BX
    MOV     [IOCALL.REQSTAT],BX
    MOV     BYTE PTR [IOMED],BL

    MOV     BX,OFFSET DOSGROUP:IOCALL

    MOV     CX,(DEVRD SHL 8) OR DRDWRHL
    OR      AH,AH
    JZ      DCALLR
    MOV     CX,(DEVRDND SHL 8) OR DRDNDHL
    DEC     AH
    JZ      DCALLR
    MOV     CX,(DEVWRT SHL 8) OR DRDWRHL
    DEC     AH
    JZ      DCALLO
    MOV     CX,(DEVOST SHL 8) OR DSTATHL
    DEC     AH
    JZ      DCALLO
    DFLUSH:
    MOV     CX,(DEVIFL SHL 8) OR DFLSHL
    DCALLR:
    MOV     AH,86H
    DCALL:
    MOV     [IOCALL.REQLEN],CL
    MOV     [IOCALL.REQFUNC],CH
    MOV     CL,AH
    POP     DS
    ASSUME  DS:NOTHING
    CALL    DEVIOCALL
    MOV     DI,[IOCALL.REQSTAT]
    TEST    DI,STERR
    JZ      OKDEVIO
    MOV     AH,CL
    invoke  CHARHARD
    CMP     AL,1   // **this is my trouble**
    JZ      IOFUNC_RETRY
    ;Know user must have wanted ignore. Make sure device shows ready so
    ;that DOS doesn't get caught in a status loop when user simply wants
    ;to ignore the error.
    AND     BYTE PTR [IOCALL.REQSTAT+1], NOT (STBUI SHR 8)
    OKDEVIO: continues.........

我仍然找不到,在(CMP AL,1)指令中将AL与“ 1”进行比较的目的是什么?我已经完成了CHARHARD的过程,但是还是不明白。

我正在研究有关MS DOS编程的项目。

SUBTTL CHARHRD,HARDERR,ERROR -- HANDLE DISK 
ERRORS AND RETURN TO USER
PAGE
    procedure   CHARHARD,NEAR
ASSUME  DS:NOTHING,ES:NOTHING,SS:DOSGROUP

; Character device error handler
; Same function as HARDERR

    MOV     WORD PTR [EXITHOLD+2],ES
    MOV     WORD PTR [EXITHOLD],BP
    PUSH    SI
    AND     DI,STECODE
    MOV     BP,DS                   ;Device pointer is BP:SI
    CALL    FATALC
    POP     SI
    return
CHARHARD    ENDP

这是FATALC代码:

    FATALC:
    CMP     BYTE PTR [ERRORMODE],0
    JNZ     SETIGN                  ; No INT 24s if already INT 24
    MOV     [CONTSTK],SP
    PUSH    SS
    POP     ES
    ASSUME  ES:DOSGROUP
    CLI                             ; Prepare to play with stack
    INC     BYTE PTR [ERRORMODE]    ; Flag INT 24 in.    
    progress
    DEC     BYTE PTR [INDOS]        ; INT 24 handler might.      
    not return
    MOV     SS,[user_SS]
    ASSUME  SS:NOTHING
    MOV     SP,ES:[user_SP]         ; User stack pointer.     
    restored
    INT     int_fatal_abort         ; Fatal error interrupt vector, 
    must preserve ES
    MOV     ES:[user_SP],SP         ; restore our stack
    MOV     ES:[user_SS],SS
    MOV     SP,ES
    MOV     SS,SP
    ASSUME  SS:DOSGROUP
    MOV     SP,[CONTSTK]
    INC     BYTE PTR [INDOS]        ; Back in the DOS
    MOV     BYTE PTR [ERRORMODE],0  ; Back from INT 24
    STI

1 个答案:

答案 0 :(得分:2)

假设宏“ invoke”并不是很奇怪,它可以有效地检查FATALC的返回值;因此,如果FATALC返回的AL等于1,它将调用IOFUNC_RETRY,否则它将继续进入该其他奇怪的代码中.....

如果您不介意我的问题:那是2018年。为什么要学习在MS-DOS中编程?您参与时间旅行吗?