在程序集8086语言中输入用户的多位数字

时间:2014-09-09 13:48:59

标签: assembly x86 dos

我试图通过INT 21H(DOS)从用户输入三个(比方)数字,并将其保存在一个寄存器中。通常我们所做的是从用户输入单个字符。相应的代码是:

MOV AH,1
INT 21H

以上代码从用户输入一位数字(从0到9)。输入保存在寄存器AL

但是,如果我想从用户输入多位数字,我该怎么办? (比如456)

有人可以为此提供示例代码吗?

1 个答案:

答案 0 :(得分:0)

看看这是否符合您的要求......

          Lea Di, The_Buffer      ;Define this somewhere
          CLD                     ;Incrementing direction

  Get_another_byte:

          Mov AH, 1               ;Ms.Dos code to get one char
          Int 21h                 ;Ms.Dos does that for us and puts it in AL

          Cmp AL, 0Dh             ;Did he hit the return key ?
          Je  He_is_done          ;Yes, now we can go on

          Stosb                   ;Else no put the byte in the buffer
          Jmp Get_another_byte    ;He's not done, so keep on


  He_is_done:

          Nop                     ;Blah
          Nop                     ;Blah
          Nop                     ;Blah
          Nop                     ;
          Nop                     ;
          Nop                     ;Replace this with your real stuff here
          Nop                     ;
          Nop                     ;
          Nop                     ;

现在,关于那个CLD指令,要小心谨慎,并确保你这样做。

Stack Overflow上的

THIS QUESTION有一些关于它的重要建议,你的问题非常适用

相关问题