Here's one in C (it's suprisingly hard to find algorithm that uses only 32bit registers)
Code:
inline
DWORD Crc32(LPVOID lpMemory, LONG lLength, DWORD dwCrc32)
{
if (! lLength) {
return dwCrc32;
}
__asm {
push ebx
mov edi, lLength
mov eax, DWORD PTR dwCrc32 // load initial parameter (dwCrc32)
mov edx, DWORD PTR lpMemory // load initial parameter pointer
add edx, edi
mov ecx, edi
shl ecx, 1
sub edi, ecx
// for (i = -len; i != 0 ; i ++)
$L278:
// dwCRC32 = crc32_tab[ (dwCRC32 ^ s[i + len]) & 0xff ] ^ (dwCRC32 >> 8)
mov ebx, DWORD PTR [edx + edi] // load parameter value (s[i])
xor ebx, eax // perform exclusive OR (dwCRC32 ^ s[i])
and ebx, 0xff // clear upper 24 bits
shr eax, 8 // shift dwCRC32 value (divide by 256)
xor eax, DWORD PTR [crc32_table + ebx*4] // exclusive OR with look up table
inc edi
jnz SHORT $L278
Pop ebx
}
}
... uhh, yea... as usual use it only in io & gl scripts