Assembly 存储8位无符号整数

Assembly 存储8位无符号整数,assembly,Assembly,我在想如何存储用户从提示符输入的8位无符号整数时遇到了一个问题。我目前拥有的代码是: lea dx, StrPrompt ;load prompt to display to the user mov ah, 9h ;display string subroutine int 21h ;interrupt for MS-DOS routine mov ah, 1h ;Read character

我在想如何存储用户从提示符输入的8位无符号整数时遇到了一个问题。我目前拥有的代码是:

    lea dx, StrPrompt   ;load prompt to display to the user
    mov ah, 9h          ;display string subroutine 
    int 21h             ;interrupt for MS-DOS routine

    mov ah, 1h          ;Read character subroutine (will be stored in al)
    int 21h             ;Interrupt for MS-DOS
    sub al, 30h         ;Translate al from ASCII code to number
    mov num, al         ;Copy number to num (al will be overwritten later)

    lea dx, StrMsg      ;display the results to the user
    mov ah, 9h 
    int 21h

    mov al, num         ;move the n value to the al
    mov dl, al          ;display the number
    add dl, 30h         ;add 30h to the ASCII table
    mov ah, 2h          ;store interrupt code
    int 21h             ;interrupt for MS-DOS routine

现在的问题是,每次我运行它时,它只允许我输入一个整数,如1、2、3等。我无法输入两位数或三位数,如20或255。我该怎么做呢?

您可以强制用户始终按3个键。p、 e.数字25需要“0”、“2”和“5”。
在接收到第一个密钥并将其转换为[0,9]乘以100后,再存储到NUM.
在接收到第二个键并将其转换为[0,9]乘以10后再添加到NUM.
在收到第三个键并将其转换为[0,9]后,添加到NUM

mov ah, 1h          ;Read character subroutine (will be stored in al)
这里它说它读的是确切的一个字符。20或255分别由两个和三个字符组成。 如果您想读入多个字符,则必须将其放入循环中,或者使用上面注释中的另一个API/INT调用

循环变量可能如下所示-循环展开最多三个字符

.data
  num1 db 0
  num2 db 0
  num3 db 0
  numAll dw 0
.code
  [...]
mov ah, 1h          ;Read character subroutine (will be stored in al)
int 21h             ;Interrupt for MS-DOS
sub al, 30h         ;Translate al from ASCII code to number
mov num1, al         ;Copy number to num (al will be overwritten later)

mov ah, 1h          ;Read character subroutine (will be stored in al)
int 21h             ;Interrupt for MS-DOS
cmp al,13           ;check for return
je exit1            ;if return, do not ask further and assume one digit
sub al, 30h         ;Translate al from ASCII code to number
mov num2, al         ;Copy number to num (al will be overwritten later)

mov ah, 1h          ;Read character subroutine (will be stored in al)
int 21h             ;Interrupt for MS-DOS
cmp al,13           ;check for return
je exit2            ;if return, do not ask further and assume two digits
sub al, 30h         ;Translate al from ASCII code to number
mov num3, al        ;Copy number to num2 (al will be overwritten later)
[...]
exit2:
[...]
exit1:

使用“Int 21/AH=0Ah”,我们可以得到一个缓冲输入:[link]谢谢。这是一个很好的方法。然而,我现在有一个问题,那就是如何将所有整数附加到numAll变量上?我不确定您是否希望得到一个整数值或字符串。给定的解决方案输出一个从num1开始的字符串。LEA EDX、num1并调用INT21以零结尾的字符串输出将完成此操作。