;***************************************************************************************************
;
; void ReverseEndian32(void *dest, const void *src, DWORD len)
; void ReverseEndian64(void *dest, const void *src, DWORD len)
;
;***************************************************************************************************

.586
.model flat, c


;***************************************************************************************************
.code

ReverseEndian32     proc    uses ecx esi edi,   pDest:dword, pSrc:dword, len:dword

    mov     ecx, len
    mov     esi, pSrc
    mov     edi, pDest
    shr     ecx, 2
    jnz     MAINLOOP
    ret

  MAINLOOP:
    mov     eax, [esi]
    bswap   eax
    mov     [edi], eax
    add     esi, 4
    add     edi, 4
    sub     ecx, 1
    jnz     MAINLOOP
    ret

ReverseEndian32     endp


ReverseEndian64     proc    uses ecx esi edi,   pDest:dword, pSrc:dword, len:dword

    mov     ecx, len
    mov     esi, pSrc
    mov     edi, pDest
    shr     ecx, 3
    jnz     MAINLOOP
    ret

  MAINLOOP:
    mov     eax, [esi]
    mov     edx, [esi+4]
    bswap   eax
    bswap   edx
    mov     [edi+4], eax
    mov     [edi], edx
    add     esi, 8
    add     edi, 8
    sub     ecx, 1
    jnz     MAINLOOP
    ret

ReverseEndian64     endp

end
