使用串操作:
CMPSB|CMPSW|CMPSD
;字节串比较:DS:[ESI]-ES:[EDI]
;然后:ESI←ESI±1/2/4,EDI←EDI±1/2/4REPE|REPZ
;执行一次串指令,ECX减1;直到ECX=0或ZF=0
源程序如下:
;功能:比较两个字符串是否相等
;作者:王文堃
;创建时间:2016/4/19
INCLUDE vcIO.inc
.data
srcmsg BYTE 'My name is Nick, and my major is computer science',0ah,0
destmsg BYTE 'My name is Nick, and my major is computer sciee',0ah,0
str_output BYTE "两个字符串相等?(Y/N):%c",0ah,0
.code
main PROC
mov esi, offset srcmsg
mov edi, offset destmsg
mov ecx, lengthof srcmsg
cld ;地址增量传送
repz cmpsb ;repz执行一次串指令后ecx减一,直到ecx=0或者zf=0即不相等
jne FOUND
mov al, 'Y'
jmp DONE
FOUND:
mov al, 'N'
DONE:
invoke printf, offset str_output, al
ret
main ENDP
;子程序
END main