我需要从带有缓冲区的键盘读取字符串。
在示例和文献的帮助下,我设法编写了这段代码,但是当我尝试打印出我插入的字符串时,它只是给我一条消息“再次输入你的字符串:”。
我的代码应该更改一下,以便打印我插入的内容?
.model small
stack 100h
.data
;reading buffer
buffSize DB 255 ;Number of maximum characters than can be read
read DB ? ;Number of characters that was read
buffer DB 255 dup (?) ;Read characters are placed here
;Other data
input DB "Input your string: $",13,10
.code
Start:
MOV ax,@data
MOV ds,ax
MOV ah,9
MOV dx, OFFSET input
INT 21h ;Prints input string
MOV ah, 0Ah
MOV dx, OFFSET buffSize
INT 21h ;Text is read
MOV bx, OFFSET buffer ;Address of buffer is inserted to bx
MOV cl, read ;Content of read is inserted to cl
MOV ch, 0 ;In cl there is a number of inserted characters
MOV byte ptr [ds:bx], '$'
MOV ah, 9
MOV dx, OFFSET buffer
INT 21h
MOV ah,4Ch
INT 21h
END Start
答案 0 :(得分:2)
input DB "Input your string: " nextLine db "$",13,10
nextLine 不会做太多。将“$”置于后面13,10
Best还会在同一行上划分输入文字。
input db "Input your string: $"
nextLine db 13,10,"$"
buffSize DB 255 ;Number of maximum characters than can be read read DB ? ;Number of characters that was read buffer DB 25 dup (?) ;Read characters are placed here
如果允许输入255个字符,还应该定义一个足够大的缓冲区! 25 dup (?)
远小于255的规定大小。
要重新打印输入,请在文字后面添加 $ :
mov bx, OFFSET buffer ;Start of the text
add bl, read ; plus the number of characters in the text
adc bh, 0 ;Maybe there was a carry from previous addition!
mov byte ptr [bx], "$" ;DOS needs string $-terminated
mov ah, 09h ;DOS.DisplayString
mov dx, OFFSET buffer
int 21h
答案 1 :(得分:0)
你把'$'放在缓冲区的开头。尝试
mov di, cx
mov [bx+di], '$'