I'd like to offer a strlen for small strings where speed isn't that important (and you can prefer small size).

Classical way:

xor ecx,ecx ;EDITED, forgot to add this line
mov edi,lpString
mov al,
inc ecx
test al,al
jnz @B

Something i tought up the other day:

xor eax,eax ;xor al,al
mov edi,lpString
or ecx,-1
repnz scasb
not ecx

Anybody got any thoughts on it? (Maybe how it compares speedwise to the classical, and other solutions)
Posted on 2003-02-28 09:52:36 by Joshua
In this section is several threads with whole bunch of
variations for your task.
Including versions with FPU and MMX.
Please, search.
Posted on 2003-02-28 11:09:59 by The Svin
Yes, but most are based on loop unrolling, which is great for speed, but bad for codesize (you require other versions if your stringlength isn't a multidude of 4 (or 8 or whatever)). I was just wondering about small solutions.
Posted on 2003-02-28 11:16:38 by Joshua
cool! :)

Perhaps you should add a cld to ensure that edi is incremented in scasb, and not decreased.
Posted on 2003-02-28 11:40:37 by david
Then I would choose 1st. Either with test al,al or with or al,al.
Though sometimes, when speed doesn't matter I still use chain
opcodes, it allows very compact code when well disigned.
Posted on 2003-02-28 11:47:17 by The Svin