This is my code to search ih some string consists of one letter:
selectedWords BYTE "BICYCLE"
inputLetter BYTE 'Y'
cld
mov ecx, LENGTHOF selectedWords
mov edi, offset selectedWords
mov al, inputLetter ;Load character to find
repne scasb ;Search
jne notfound
But how to return the pointer to the letter in string?
If I want after to change one leter with some other. Its easy to do if you have pointer to the letter in string.
If
repne scasb
finds the element,EDI
points to the element after the first match. You have to decrement it to get the pointer to the desired element.You don't need to clear the direction flag (
cld
). It's very very unlikelikely that the direction flag is set without any involvement of your part. And if so, you should seit it back to the former status.If you don't like
repne scasb
you can scan the word with a "normal" comparison loopIf you read the documentation for
REP
andSCASB
you'll see that SCAS updatesedi
. Thus the location of the matching char is stored inEDI
.All you have to do is return
EDI
ifZF=1
and return 0 ifZF<>1
.