I read a book about Assembly, and it has the next code:
.DATA
string1 db ’abcdfghi’,0
strLen EQU $ - string1
string2 db ’abcdefgh’,0
.CODE
.STARTUP
mov AX,DS ; set up ES
mov ES,AX ; to the data segment
mov ECX,strLen
mov ESI,string1
mov EDI,string2
cld ; forward direction
repe cmpsb
leaves ESI pointing to g in string1 and EDI to f in string2. Therefore, adding
dec ESI
dec EDI
leaves ESI and EDI pointing to the last character that differs. Then we can use,
ja str1Above
It is writen that we need:
dec ESI
dec EDI
becuase leaves ESI pointing to g in string1 and EDI to f in string2.
But why? When we arrive to 'f' in ESI
, and 'e' in EDI
, the repe
condition is not fulfill, and for that we would exit the loop, where 'f' is in ESI
, and 'e' is in EDI
. Why It say that we continue to scan the strings one more time?