2
outputstring macro x
        push ax
        push dx
        mov ah,9
        mov dx,offset x
        int 21h ;
        pop dx
        pop ax
        endm
inputstring macro x
        push ax
        push dx
        mov ah,0ah
        mov dx,offset x
        int 21h ;
        pop dx
        pop ax
        endm

display struc                ;struc
ex1 db 20,0,20 dup('$')   ;ex1
display ends
assume cs:code,ds:data
data segment
stu_temp display<>
question db "please input a string:",'$'
data ends
code segment
start:
mov ax,data
mov ds,ax
outputstring question
inputstring stu_temp.ex1
call next_line

outputstring stu_temp.ex1+2

mov ah,2
mov dl,9 
int 21h  ;ascii(9)=tab

outputstring stu_temp.ex1+2

mov ah,2
mov dl,9
int 21h  ;ascii(9)=tab

outputstring stu_temp.ex1+2


mov ax,4c00h
int 21h

next_line:  
    push dx
    push ax
    mov dl,0dh
    mov ah,2
    int 21h
    mov dl,0ah
    int 21h
    pop ax
    pop dx
    ret

code ends
end start

I think the result should be

xxxxx(your input) "tab" xxxxx(your input) "tab" xxxxx(your input)

for example,

input thank,

it should output "thank thank thank"

but i got this

enter image description here

i am confused for 2days

what is the solution to this problem? Any help is appreciated

what is the solution to this problem? Any help is appreciated

yuqcc
  • 76
  • 9
  • 2
    It is because when you use Int 21h/ah=0ah to read a string, the string returned includes the carriage return (0dh) ! So you are actually printing out `thank` each time which sends the cursor back to the beginning of the line. You will have to replace the carriage return with a `$` after reading the string in. – Michael Petch Jun 24 '20 at 01:27
  • 2
    To fix it you can modify your inputstring macro to look at the second byte of the buffer returned which is the number of characters read not including the carriage return. You can use that value to write a `$` over top of that carriage return. So after the `int 21h` in `inputstring` macro do `mov bl, [x+1]` `mov bh, 0` `mov [x+2+bx], '$'` – Michael Petch Jun 24 '20 at 01:36

1 Answers1

2

Like @Michael Petch said,

Int 21h/ah=0ah read a string, the string returned includes the carriage return (0dh)

So use

mov bl, [x+1] 
mov bh, 0 
mov [x+2+bx], '$'
yuqcc
  • 76
  • 9