.model small
.stack 100h
.data
address_req1 DB 10, 13, " Enter Shipping Address (Line 1): $"
address_req2 DB 10, 13, " (Line 2): $"
address_req3 DB 10, 13, " (Line 3): $"
add_input1 DB 25, 0, 23 dup ('$')
add_input2 DB 25, 0, 23 dup ('$')
add_input3 DB 25, 0, 23 dup ('$')
.code
ACCEPT_STRING PROC
mov ah, 09h ;display request address1
lea dx, address_req1
int 21h
mov ah, 0ah ;accept address1
lea dx, add_input1
int 21h
mov ah, 09h ;display request address2
lea dx, address_req2
int 21h
mov ah, 0ah ;accept address2
lea dx, add_input2
int 21h
mov ah, 09h ;display request address3
lea dx, address_req3
int 21h
mov ah, 0ah ;accept address3
lea dx, add_input3
int 21h
ret
ACCEPT_STRING ENDP
PRINT_STRING PROC
mov ah, 09h
lea dx, add_input1 + 2
int 21h
mov ah, 09h
lea dx, add_input2 + 2
int 21h
mov ah, 09h
lea dx, add_input3 + 2
int 21h
ret
PRINT_STRING ENDP
MAIN PROC FAR
mov ax, @data
mov ds, ax
call ACCEPT_STRING
call PRINT_STRING
mov ax, 4c00h
int 21h
MAIN ENDP
END MAIN
The system is expected to request 3 lines of input from user one by one (in which it is successful). However, the output is incorrect (no garbage lines, just the strings are jumbled up)
Dylan Khor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
17
To sum up the discussion in the comments:
(Otherwise the question will be left forever open, and future readers will have to read through tens of comments to find the answer)
When printing a string with MS-DOS interrupt 21h, function 09h, the string needs to be terminated with a dollar sign (‘$’).
When reading a string with MS-DOS interrupt 21h, function 0ah, the string is ended with a Carriage Return. (ASCII control character name ‘CR’, ASCII code 13 in decimal, 0Dh in hexadecimal.)
When the CR character is printed, it causes the cursor to move to the beginning of the current line, but not to the next line.
Therefore after printing a string that was previously read, you must print a Linefeed (ASCII control character name ‘LF’, ASCII code 10 in decimal, 0Ah in hexadecimal) to move to the next line, otherwise the next string you print will be printed on the same line as the previous one.
1