Reputation: 78
org 100h
mov si, 0
mov di, 0
back:
cmp string[si], 'a'
inc si
jz found
jmp nfound
found:
inc di
nfound:
loop back
ret
string db 'n','a','n','b','o','N','a','n','a','w','a','g','o','s','h','t','b','o','Q','a','s','a','b'
I have also tried to define the string array like this:
string db "nan bo Nanawa gosht bo Qasab"
the jz coindition is never true, what seems to be the problem? If I remove the si increment instruction the condition does return true!
Upvotes: 0
Views: 52
Reputation: 8741
Comparison result is calculating by checking zero flag.
After cmp string[si], 'a'
if both are same, then zero flag will be set. So you should use jz found
immediately after comparison.
In your code you are using inc si
after comparison, and you lost the comparison result, in this case if the value of si
is zero after increment
then only zero flag will set.
Upvotes: 1
Reputation: 58447
If you read the description of INC
in Intel's manual you'll see:
Flags Affected
TheCF
flag is not affected. TheOF
,SF
,ZF
,AF
, andPF
flags are set according to the result.
So your jz found
instruction is branching based on the result of inc si
rather than the result of the cmp
. I suggest that you move the inc si
instruction to right before loop back
.
Upvotes: 1