I'm writing a proc that traverses a file path from the end to the start looking for the first '\' character.

ebx = the end of the string (null)


sub ebx, 1
mov ecx,
and ecx, 0ffffff00h
or ecx, 5ch ;'\' character
cmp ecx,

jne @B

ebx = last '\' in string

Is there a better way to do byte(word too) compares with 32-bit registers?

Posted on 2001-08-21 14:02:41 by ThoughtCriminal
This works, but it's not so good - what if the string has no "?

dec ebx
cmp byte ptr ,'"'
jne @B

If ecx is the length of the string:

dec ecx
js @F
cmp byte ptr ,'"'
jne @B
;Do something useful, we found a "

@@: ;No " is found!
Posted on 2001-08-21 14:10:05 by bitRAKE
Ahhh, thanks. It's been a while, so I'm getting a little slow.

Being a lone programmer, I skip a lot of error checking. This is being used in code to set up the program enviroment. I call GetModuleHandle to get the path where the program is being run from, then search back to the first '\' to strip off the exe name. GetModuleHandle will return a string like:


I cant be sure a user will install to the same directory as I would, but I can at least find where the exe is being run from. As long as I keep any additional files in the same or lower directory than the exe, I should be able to find the files.
Posted on 2001-08-21 14:30:01 by ThoughtCriminal
There many ways to do it, this one work for me,

mov edi,OFFSET FilePath
push edi
mov ecx,-1
xor eax,eax
repne scasb
not ecx ;this got string length
pop edi ;re-set pointer
mov eax,05ch ;chararcter you look for
repne scasb
or ecx,00h
jz @notfound
jmp @found

Btw I think 05ch is backslash not "

Best regards,

Posted on 2001-08-22 02:55:00 by czDrillard
This way you would find LAST " not the first :)
To use ecx for both index pointer and the end of the string
counter - add length to main ponter, negate counter.
Posted on 2001-08-22 06:49:46 by The Svin
Svin, he wanted to find the last ".
I'm writing a proc that traverses a file path from the end to the start looking for the first '' character.
I'm sure this could be interpreted differently, but I assume it's to find the last " - or the first ", begining at the end of the string and transversing to the start of the string. Isn't English confusing. :)
Posted on 2001-08-22 08:53:48 by bitRAKE