我正在尝试使用 x86 程序集编写一个可以在文本中搜索单词的程序。当文本中出现单词时,程序将通知用户。我在比较字符串时仍然遇到问题。有什么建议吗?
.model small
.stack 200h
.data
message1 db "Enter your text here: $"
text db 150,151 dup(0)
message2 db 10,13,"Enter the word that you want to find: $"
find db 20,21 dup(0)
yesmessage db 10,13,"The word is in the text$"
nomessage db 10,13,"Sorry the word is not in the text$"
.code
Start:
;Display message and key in strings
mov ax,seg message1
mov ds,ax
mov si,offset text
mov di,offset find
mov dx,offset message1
mov ah,09h
int 21h
mov dx,si
mov ah,0Ah
int 21h
mov ax,seg message2
mov ds,ax
mov dx,offset message2
mov ah,09h
int 21h
mov dx,di
mov ah,0Ah
int 21h
;compare strings
mov bx,00
mov bl,text+1
mov bh,find+1
cmp bl,bh
jne L1
add si,2
add di,2
L2:mov bl,byte ptr[si]
cmp byte ptr[di],bl
jne L1
inc si
inc di
cmp byte ptr[di],"$"
jne L2
mov ah,09h
mov dx,offset yesmessage
int 21h
L1:mov ah,09h
mov dx,offset nomessage
int 21H
mov ax,4c00h
int 21h
end start
预期的结果应该是:
示例 1:
在此处输入您的文字:他老了 输入您要查找的单词:old 这个词在文本中
示例 2:
在此处输入您的文字:他老了 输入您要查找的单词:年轻 对不起,这个词不在文本中