Вот почти все на ассемблере х86 (+)
unsigned short CRC (char *msg, int len)
{
// 0xFFFF initial & poly 0x1021 - CCITT CRC16
unsigned short crc=0xFFFF;
unsigned short poly=0x1021;
_asm {
mov esi,[msg]
l_char:
lodsb
mov dl,al
mov ax,[crc]
mov ecx,8
l_crc:
rcl dl,1
rcl ax,1
jnc no_xor
xor ax,[poly]
no_xor:
loop l_crc
mov [crc],ax
mov eax,[len]
dec eax
mov [len],eax
jnz l_char
mov ecx,16
mov ax,[crc]
l_augment:
shl ax,1
jnc no_xor1
xor ax,[poly]
no_xor1:
loop l_augment
mov [crc],ax
}
return crc;
}
int main(int argc, char* argv[])
{
unsigned short crc;
char *msg="123456789";
crc=CRC(msg,9);
printf("%04x\n",crc); // valid = 0xe5cc
return 0;
}