Reputation: 287
I am having a problem getting my head around of how to store an 8 bit unsigned integer that a user enters from a prompt. The code I have currently is:
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
The problem right now is that each time I run this it will only allow me to enter a single integer number like 1, 2, 3, etc. I am unable to enter in a double or triple digit number like 20 or 255. How do I go about this?
Upvotes: -1
Views: 1189
Reputation: 29022
mov ah, 1h ;Read character subroutine (will be stored in al)
Here it says that it reads exactly one char. 20 or 255 consist of two and respectively 3 chars. If you want to read in more than one char you'd have to put this in a loop or use the other API/INT-call from the comment above.
The loop variant may look like this - the loop unrolled for up to three chars
.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:
Upvotes: 1