This is my program:
data segment
str1 db "What is your name: $"
str2 db "How old are you? $"
str3 db 13,10, "Name Output is: $"
str4 db 13,10, "Age Output is: $"
Arr db 10 dup('$')
Arr2 db 10 dup('$')
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
mov ax, @data
mov ds, ax
lea dx, str1
mov ah, 09h
int 21h
mov ah, 10 ; string input sub-rountine
lea dx, Arr ; get offset address of array
mov arr,10
int 21h
mov dx,13
mov ah,2
int 21h
mov dx,10
mov ah,2
int 21h
lea dx, str2
mov ah, 09h
int 21h
mov ah, 10
lea dx, Arr2
mov arr, 11
int 21h
lea dx, str3
mov ah, 09h
int 21h
mov ch, 0
mov cl, Arr[1] ;cl = counter of character
mov si, 2
mov ah, 02h
output:
mov dl,Arr[si]
int 21h
inc si
mov dl,' '
loop output
mov ax, 4c00h
int 21h
It is successful in printing out the name but the age cannot print out because its input is kinda hard.
I want to input the name, age, the country and make its output printable in every code.
Please do read How buffered input works so you learn how to set up correctly for the DOS.BufferedInput function 0Ah.
Next could apply to your case (your own (full) name has well over 10 characters):
You say that the input for the age is "kinda hard". Well I see that you have a mix-up between the Arr and Arr2 buffers. That number 11 should go to the Arr2 buffer. Moreover the value 11 is wrong for a buffer that only comprises 10 bytes!
Don't do redundant work. The carriage return plus linefeed, that you now do following the input, does not need the carriage return at all. The cursor will already have been placed at the beginning of the line. Only the linefeed is necessary and you should use DL for it (not DX):
And you wouldn't even need to add these lines, if only you would store the matching control codes in your string definitions:
The output loop redundantly moves a space character into DL right before the
loopinstruction. Just remove that line.Summary
Next code uses the above suggested Arr1 and Arr2 buffers, and the modification to the text strings. If these buffers are each used only once then the lines that I have marked with an asterisk (*) can be omited.
Before you blindly copy/paste this, do observe the different ways of addressing the arrays. And did you notice that I did not use the length of the string as it was returned to us by DOS? Instead, I based my loops on the mandatory carriage return that DOS adds to our characters in the input buffer.