我有这个汇编程序,我需要在我输入的主字符串中找到子字符串。我的问题是,即使我输入了两个完全不同的单词,它总是输出“找到的单词”。我不知道我的循环或条件的哪一部分是错误的。请帮我弄清楚。另外,请建议一些可用于检查子字符串的字符串指令,以便我可以缩短我的代码。我真的很困惑如何cmpsb
有效,我只是尝试使用它。顺便说一句,我不知道如何使用调试器,这就是为什么我无法调试我的代码,而且我只是汇编语言的新手。
下面是我的代码的逻辑部分。
.data
prompt1 db "Input String: $"
prompt2 db 10,10, 13, "Input Word: $"
prompt3 db 10,10, 13, "Output: $"
found db "Word Found. $"
notfound db "Word Not Found. $"
invalid db 10,10, 13, "Invalid. $"
InputString db 21,?,21 dup("$")
InputWord db 21,?,21 dup("$")
actlen db ?
strlen dw ($-InputWord)
.code
start:
mov ax, @data
mov ds, ax
mov es, ax
;Getting input string
mov ah,09h
lea dx, prompt1
int 21h
lea si, InputString
mov ah, 0Ah
mov dx, si
int 21h
;Getting input word
mov ah,09h
lea dx, prompt2
int 21h
lea di, InputWord
mov ah, 0Ah
mov dx, di
int 21h
;To check if the length of substring is shorter than the main string
mov cl, [si+1]
mov ch, 0
add si, cx
mov bl, [di+1]
mov bh, 0
cmp bx, cx
ja invalid_length
je valid
jb matching
valid:
cld
repe cmpsb
je found_display
jne notfound_display
matching:
mov al, [si]
mov ah, [di]
cmp al, ah
je check
jne iterate
iterate:
inc si
mov dx, strlen
dec dx
cmp dx, 0
je notfound_display
jmp matching
check:
mov cl, [di+1]
mov ch, 0
mov ax, si
add ax, 1
cld
repe cmpsb
jne again
jmp found_display
again:
mov si, ax
dec dx
lea di, InputWord
jmp matching
invalid_length:
mov ah, 09h
lea dx, invalid
int 21h