Go Back   FlashFXP Forums > >

Programming Need help with C/C++/Delphi? Ask here and make us all laugh.

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 08-05-2004, 08:54 AM   #1
darkone
Disabled
FlashFXP Registered User
ioFTPD Administrator
 
darkone's Avatar
 
Join Date: Dec 2001
Posts: 2,230
Default Assembler crc32

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
darkone is offline  
 

Tags
dwcrc32, dword, ebx, edi, mov


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:17 PM.

Parts of this site powered by vBulletin Mods & Addons from DragonByte Technologies Ltd. (Details)