Hi all!
I wrote a little function for reversing string, that reverses the input buffer (no need in second buffer) and works approx 1.5 times faster than szRev function from masm32.lib. May be somebody will find it usefull.
StrReverse proc lpString:LPSTR
mov eax,lpString ; put string address in EAX
mov edx,eax ; same in EDX
@@: ; move EDX to the end of string
add edx,1
cmp byte ptr [edx],0
jne @B
sub edx,1 ; return EDX to last not null character
@@:
mov cl,byte ptr [eax] ; swap EAX and EDX, moving from two brinks
mov ch,byte ptr [edx] ; in opposite directions
mov [eax],ch ; while EAX is less than EDX
mov [edx],cl
add eax,1
sub edx,1
cmp eax,edx
jl @B
ret
StrReverse endp
lamer,
String reversal is a topic which has been exhaustively plowed over. Ratch
http://www.masmforum.com/simple/index.php?topic=2869.0
Why do we have two equal labels ("@@") and Masm doesn't complain?
What is @B? I've seen this more times and I don't understand it...
Thanks..
@@: is an anonymous label, @F (forward) refers to next @@:, and @B (back) refers to the previous @@:. See Predefined Symbols here:
http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ReferenceGuide/Chap_03.htm
And Anonymous Labels here:
http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ProgrammersGuide/Chap_07.htm
Ratch,
It's impossible to keep track of each topic - otherwise you just have either to give up your work or to desert your family (or to be a moderator :bg).
I just wanted to share...
By the way, the topic of string reversing was started at October 1, and I wrote the procedure much before - just saw it today and decided to post.
Next time will search before posting.
Regards
lamer,
Compliments, the algo looks nicely thought out. :U
MichaelW,
Have you seen this thread? Ratch
http://win.asmcommunity.net/board/index.php?topic=22540.0
hutch--,
Thanks for compliments :lol
As I see the proc can be improved (there is no need in EBX at all), so I post an improved version. It is advisable to look at your own code after a couple of months :bg