int 21h ah 02h由于某些原因不起作用

问题描述 投票:1回答:1

我的任务是从终端(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。

assembly dos x86-16 keyboard-input
1个回答
1
投票

一旦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
© www.soinside.com 2019 - 2024. All rights reserved.