【问题标题】:int 21h ah 02h doesn't work for some reasonint 21h ah 02h 由于某种原因不起作用
【发布时间】:2019-09-30 21:41:08
【问题描述】:

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

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

; 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' 是我输入的字符串,然后按回车键。

【问题讨论】:

  • 它确实有效,但它覆盖了已经打印的那个。使用不同的字符,你会看到。
  • 例如将您的 second mov dl, 56 更改为 mov dl, 57 然后您应该看到 9 正在打印。这是用于终止输入的回车的副作用。
  • 我尝试将其更改为 57 - 没有任何变化。我尝试将其更改为 10(它必须是 \n) - 没有结果。还能有别的吗?
  • 在这里工作。 第二个你改了吗?
  • @Jester 是的。正如我所说,我尝试了不同的值,但我的机器上没有任何变化

标签: assembly dos x86-16 keyboard-input


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-28
    相关资源
    最近更新 更多