【发布时间】:2020-06-24 00:51:40
【问题描述】:
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
我认为结果应该是
xxxxx(你的输入) "tab" xxxxx(你的输入) "tab" xxxxx(你的输入)
例如,
输入感谢,
它应该输出“谢谢谢谢”
但我明白了
我困惑了两天
解决这个问题的方法是什么?任何帮助表示赞赏
解决这个问题的方法是什么?任何帮助表示赞赏
【问题讨论】:
-
这是因为当你使用 Int 21h/ah=0ah 读取字符串时,返回的字符串中包含回车符(0dh)!因此,您实际上每次都打印出
thank,这会将光标发送回行首。读入字符串后,您必须将回车替换为 $。 -
要修复它,您可以修改输入字符串宏以查看返回的缓冲区的第二个字节,即读取的字符数,不包括回车符。您可以使用该值在该回车符上方写入
$。所以在inputstring宏中的int 21h之后做mov bl, [x+1]mov bh, 0mov [x+2+bx], '$'
标签: assembly x86-16 masm emu8086