BiteRider,

I was looking for inspiration in this asm file and found a potential bug.  I suggest you add the 'CLD' command as a safety precaution.  I'm currently writing a memory management sheme and I'm often chaning the direction flag's state.  Even though I call CLD after a STD based routine, some people may not, or may expect the StrLength to be transparent and call this routine before they are finished and ready to call STD again.  Either way, as Im sure you are aware, for StrLength to work correctly the direction flag must cleared.


; ==================================================================================================
; Title:  StrLength.asm
; Author:  G. Friedrich / J. Trudgen
; Version: 1.0.1
; Notes:  Version 1.0.0, September 2002
;            - First release.
;            - Version 1.0.1, Aug.06 - Added CLD (J. Trudgen)
; ==================================================================================================

include \masm32\ObjAsm32\code\ObjMem32\ObjMem32.cop

.code

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

align @WordSize
StrLength proc pString:Pointer
    push edi
    cld
    mov edi,         ;pString
    mov ecx, 0FFFFFFFFH
    xor al, al
    repne scasb
    not ecx
    mov eax, ecx
    dec eax
    pop edi
    ret 4
StrLength endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

end



Regards,
:NaN:
Posted on 2006-08-08 22:36:15 by NaN
Hi NaN
I can add the cld instruction, but note that windows APIs require that the direction flag is set to zero before calling them. If not, you can crash them. Following that rule, I decided to not include the flag resetting when I write the procedure. If you think it's necessary, I have no problem to include it.  ;)

Regards,

Biterider
Posted on 2006-08-09 05:07:08 by Biterider
Oh.. I've never realized that the APIs are sensitive to this as well.. Hmmm..  Well on that basis maybe I'm wrong and its not really a problem.  Thanks for the info  :lol:

Regards,
:NaN:
Posted on 2006-08-09 19:01:01 by NaN
Yup, preserving direction flag state is about as important as EBX,ESI,EDI, 4byte aligned stack, 4byte aligned structs, etc... :)
Posted on 2006-08-10 07:12:45 by f0dder

4byte aligned structs, etc... :)



Interesting :) Didn't knew structs needed to be aligned as well.
Posted on 2006-08-10 15:06:06 by Axial


4byte aligned structs, etc... :)



Interesting :) Didn't knew structs needed to be aligned as well.


Not all of them do, but some API calls will fail if the structs aren't aligned - can't remember off top of my head, though. It's common sense aligning anything speed-critical to it's "Native boundary"... I guess anything involving an API call won't be "speed critical" in this way, but oh well :)
Posted on 2006-08-10 15:54:51 by f0dder

Maybe WIN32_FIND_DATA is one. I had some weird unknown problem once using FindFirstFile/FindNextFile.
Posted on 2006-08-11 04:52:22 by Axial