2

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

要读取我使用的字符串int 21h, ah 0ah。当我在调试器中检查它时看起来不错。然后我的atoiitoa看起来也不错,只是在itoa中我int 21h, ah 02h用来显示一个字符,但由于某种原因它没有显示。所以我回到开头,注意到在(read string)int 21h, ah 02h之后写 (print char)没有结果。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

Screenshot
'8' 是我在开始时显示的字符。'123' 是我输入的字符串,然后按回车键。

4

1 回答 1

2

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

由于在程序退出之前输出第二个“8”是唯一剩下的事情,因此 DOS 提示符可能会覆盖第二个“8”。见截图

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

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

    ret
    MAIN ENDP
CSEG ENDS
END MAIN
于 2019-10-01T15:00:25.980 回答