I have a problem with STD operand in assembler. When i use it in the next source:

;------------------------------------------------------------------------------------------

IsProgRunning PROC
    LOCAL  ActivProgsCount:DWORD

    mov    dword ptr ActivProgsCount,0
   
    invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, NULL
    mov    SnapShotHandle,eax 
    mov    lppe.dwSize, sizeof lppe
    invoke Process32First, SnapShotHandle, addr lppe
    invoke Process32Next, SnapShotHandle, addr lppe

lab1384:
    invoke  lstrlen, addr lppe.szExeFile
    mov    esi, offset lppe.szExeFile
    add    esi, eax
    invoke  lstrlen, addr curprogname
    mov    edi, offset curprogname
    add    edi, eax
    mov    ecx, eax
    ;--------------------
;    std                            ;Here is a crash
    ;--------------------
    repe    cmpsb
    jne    lab1427   
    inc    dword ptr ActivProgsCount
    cmp    dword ptr ActivProgsCount, 1
    jbe    lab1427
    invoke  CloseHandle, SnapShotHandle
    mov    eax,dword ptr ActivProgsCount     
    cld
    RET

lab1427:
    invoke  Process32Next, SnapShotHandle, addr lppe
    cmp    eax,0
    jne    lab1384
    invoke  CloseHandle, SnapShotHandle
    mov    eax,dword ptr ActivProgsCount     
    cld

    RET
IsProgRunning ENDP

;------------------------------------------------------------------------------------------

When i delete STD operand and procedure work. This problem i have with Windows XP Professional Version 2002 Service pack 2.
It is strange for me that this problem is not present in other ms windows and ms windows versions.
Can anybody explain what is wrong !!! I want to use STD but i can not in this specific version of Windows XP
Posted on 2005-11-15 07:25:07 by martidim
After you are done with std, add cld.

Windows expect the direction flag to be cleared. You can't set it and expect it to work as it was.
Posted on 2005-11-15 09:08:26 by roticv
martidim, when using STD you must use CLD
  * before returning from a callback
  * before calling any external code
Posted on 2005-11-15 11:45:41 by f0dder