Assembly code snippets

Back to the snippets overview

Details

TitleLong string length
AuthorThe Svin
Submitted by:The Svin
Date added:2002-02-20 06:00:41
Date modified:2002-02-20 06:00:41

Comments

Calculates lenth of ASCIIZ string.
Desinged working with bitRake.
So you can put © BiS since ©SB is for Sound Bluster :)
Especially effective with long string for example in databases.
Strings'd better be align 16 (to decrease the cache misses)
Format for M32lib

Snippet

.586
.MMX
.model flat,stdcall
option casemap:none
.code
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
LongStrLen proc Arg1
lpString equ [esp+4]
        mov eax,lpString
        pxor mm(0),mm(0)
        pxor mm(1),mm(1)
@@:
        pcmpeqb mm(0),[eax+0]
        pcmpeqb mm(1),[eax+8]
        packsswb mm(0),mm(1)
        add eax,16
        packsswb mm(0),mm(0)
        movd ecx,mm(0)
        test ecx,ecx
        je @B
        sub eax,16+1
@@:
        inc eax
        cmp byte ptr [eax],0
        jne @B
        sub eax,lpString
        emms
        ret 4

OPTION PROLOGUE:DEFAULT
OPTION EPILOGUE:DEFAULT

LongStrLen endp

    end