从汇编中的键盘读取缓冲区
Read buffer from keyboard in Assembly
我需要使用缓冲区从键盘读取字符串。
在示例和文献的帮助下,我设法编写了这段代码,但是当我尝试打印出我插入的字符串时,它只给我消息 "Input your string again:".
我应该在我的代码中更改什么,以便打印我插入的内容?
.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
input DB "Input your string: "
nextLine db "$",13,10
nextLine 作用不大。把“$”放在后面13,10
.
最好也把输入文本划在同一行.
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
您已将“$”放在缓冲区的开头。尝试
mov di, cx
mov [bx+di], '$'
我需要使用缓冲区从键盘读取字符串。
在示例和文献的帮助下,我设法编写了这段代码,但是当我尝试打印出我插入的字符串时,它只给我消息 "Input your string again:".
我应该在我的代码中更改什么,以便打印我插入的内容?
.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
input DB "Input your string: " nextLine db "$",13,10
nextLine 作用不大。把“$”放在后面13,10
.
最好也把输入文本划在同一行.
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
您已将“$”放在缓冲区的开头。尝试
mov di, cx
mov [bx+di], '$'