0

I am trying to input a three (say) digit number from the user through INT 21H (DOS) and save it in a resister. Normally what we do is to input a single character from the user. The corresponding code is:

MOV AH,1
INT 21H

The above code takes a single digit input from the user (from 0 to 9).the input is saved in the register AL

But what can I do if I want to input a multiple digit number from the user? (say 456)

Can anyone provide a sample code for that?

1 Answers1

0

See if this does what you want...

          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                     ;

Now, about that CLD instruction, be all kinds of careful, and make sure you do that.

THIS QUESTION on Stack Overflow has some important advice about it, and your very problem is precisely applicable

Community
  • 1
  • 1
User.1
  • 2,562
  • 3
  • 33
  • 40