Code:
; W = CRC Message byte ; CRC16 - current 16-bit CRC check sum ; ; let CRC16 = abcd ; Message Byte = xy ; ; where abcd, xy are nibble variables ; ; Upon exit, ; ; a = c ^ (i1>>3) ^ i2 ; jmp = d ^ ((i1<<1)&$f) ^ (i2>>3) ; c = i1 ^ ((i2<<1)&0xf) ; d = i2 ; ; First compute the nibble array indices: ; i1 = a ^ x ; i2 = i1 ^ b ^ y ; ; ; Notation (I) : (J) is a byte with I= high nibble, J= low nibble ; CRC_Update xor W, CRC16_High ; (a^x):(b^y) mov Index, W ; and W, #$f0 ; W = (x^x):0 swap Index ; Index = (b^y):(a^x) xor Index, W ; Index = (a^b^x^y):(a^x) = i2:i1 ; High byte mov W, <>3) : (((i1<<1)&0xf) | (i2>>3)) xor W, CRC16_Low ; W = (i1>>3)^c : ((((i1<<1)&0xf) | ; (i2>>3)) ^ d) mov CRC16_High, W ; low nibble of high byte is done mov W, Index and W, #$f0 ; W = i2 : 0 xor CRC16_High, W ; High nibble is of high byte is done ; now low byte mov CRC16_Low, W ; Low = i2 : 0 add CRC16_Low, W ; Low = (i2<<1) : 0 mov W, <>Index ; W = i1 : i2 xor CRC16_Low, W ; Low = i1 ^ (i2<<1) : i2 retw 0