int 21h ah 02h由于某些原因无法正常运行

时间:2019-09-30 21:41:08

标签: assembly dos x86-16 keyboard-input

我的任务是从终端(aka atoi )中读取一个数字,然后将其写回终端(aka itoa )。

要读取字符串,我使用int 21h, ah 0ah。在调试器中检查它似乎很好。然后我的 atoi itoa 看起来也不错,除了在 itoa 中我使用int 21h, ah 02h来显示一个字符,但是出于某种原因它不显示。因此,我回到开头,注意到在int 21h, ah 02h(读取字符串)之后立即写int 21h, ah 0ah(打印字符)没有结果。

; STACK SEGMENT
STSEG SEGMENT PARA STACK "STACK"
    DB 64 DUP (0)
STSEG ENDS

; DATA SEGMENT
DSEG SEGMENT PARA PUBLIC "DATA"
    startStr db "Enter a number : $"
    inputError db "Number has incorrect chars.", 10, "$"
    buffError db "Number is too big", 10, "$"
    bufferSize DB 16        ; 15 chars + RETURN
    inputLength DB 0        ; number of read chars
    buffer DB 16 DUP('?')   ; actual buffer
DSEG ENDS

; CODE SEGMENT

CSEG SEGMENT PARA PUBLIC "CODE"

    MAIN PROC FAR
        ASSUME cs: CSEG, ds: DSEG, ss:STSEG
        mov ax, DSEG
        mov ds, ax
        ;lea dx, startStr
        ;call WRITING
        ;call READING

        xor ax, ax
        xor dx, dx
        mov ah, 2
        mov dl, 56
        int 21h

;test display char before reading string - works fine


        xor dx, dx
        xor ax, ax
        lea dx, bufferSize
        mov ah, 10
        int 21h

; reading string - works fine

        xor ax, ax
        xor dx, dx
        mov ah, 2
        mov dl, 56
        int 21h

; trying to display char again - nothing

        ; call ATOI
        ; add ax, 15
        ; call ITOA
        ret
    MAIN ENDP
CSEG ENDS
END MAIN

Screenshoot
“ 8”是我一开始显示的字符。 “ 123”是我输入的字符串,然后按Enter。

1 个答案:

答案 0 :(得分:2)

一旦DOS缓冲输入功能0Ah收到 enter 键, 根据您的DOS仿真器的工作方式,光标将移动到当前行的开头还是下一行。

由于输出第二个“ 8”是程序退出前剩下的唯一内容,因此DOS提示符可能会覆盖第二个“ 8”。参见screenshot

尝试推迟终止程序。等一下钥匙。
同时打印与您的第一个字符不同的内容。

    mov dl, "*"
    mov ah, 02h  ; DOS.PrintChar
    int 21h
    mov ah, 00h  ; BIOS.GetKey
    int 16h

    ret
    MAIN ENDP
CSEG ENDS
END MAIN