小弟刚学汇编,入门中。课题要求如题,判断字符串2是否是字符串1的字串。小弟的源码如下,但是始终输出的是no,改动了很多都还是有问题。求大神鉴定!并给出详细解释!谢谢
.model small
.stack
.data
sbuffer db 'How are you?$'
dbuffer db 'are$'
yes1 db 'yes$'
no1 db 'no$'
.code
.startup
mov si,offset sbuffer
mov di,offset dbuffer
cld
mov cx,10 ;比较10次
again: push cx
mov cx,3 ;字符串长度
push si ;si入栈
repz cmpsb ;开始比较
cmp cx,0 ;假如cx等于0,跳转到yes
jz yes
pop si ;si出栈
inc si ;指向下一个字符
mov di,offset dbuffer ;di初始化为第一个字符
pop cx ;cx出栈并且减1
dec cx
loop again ;循环
call no ;跳转到no
yes: mov dx,offset yes1
mov ah,9
int 21h
mov ah,4ch
int 21h
no: mov dx,offset no1
mov ah,9
int 21h
mov ah,4ch
int 21h
end
------解决方案--------------------------------------------------------
lea dx,str1
str_compare:
cmp [dx],0
jz str_isnot_equ
mov si,dx
lea di,str2
cld
repz cmpsb
jz str_is_equ
inc dx
jmp str_compare
str_is_not_equ:
......
str_is_equ:
....
------解决方案--------------------------------------------------------
pop cx ;cx出栈并且减1
dec cx //这里-1 这句不要
loop again ;循环 //loop 也会-1
如果加上dec cx的话
pop cx
dec cx
test cx,cx
jnz again
下面就不用加loop again了