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)
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)
Joshua,
In this section is several threads with whole bunch of
variations for your task.
Including versions with FPU and MMX.
Please, search.
In this section is several threads with whole bunch of
variations for your task.
Including versions with FPU and MMX.
Please, search.
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.
cool! :)
Perhaps you should add a cld to ensure that edi is incremented in scasb, and not decreased.
Perhaps you should add a cld to ensure that edi is incremented in scasb, and not decreased.
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.
Though sometimes, when speed doesn't matter I still use chain
opcodes, it allows very compact code when well disigned.