;By Dr. Imre Bartfai ; What you need is to define the polynomial. E. g. for the CCITT one: poly0 equ $21 poly1 equ $10 ; Do not forget to initialize <crcval> = <crch:crcl> before the 1st call ; e. g. with 0xFF or with zeroes, as the particular CRC algorithm ; requires. ;This subroutine calculates a 16-bit CRC ;-------- ; CrcUpd: update <crcval> using <W> ; ; CBLOCK crcblk crch crcl saved oldcch i ENDC CrcUpd mov saved, W ; j = W mov W, #8 ; W = 8 mov i, W ; i = W _loop mov W, crch mov oldcch, W ; temporary save clrb C ; clear carry for rlf rl crcl ; crc << 1 rl crch mov W, saved ; the char read xor oldcch, W ; test with old high sb oldcch.7 ; if bit set, apply mask ;*** WARNING: MPASM macro B is not supported yet. Replace manually. b _notset ; otherwise skip mov W, #poly0 xor crcl, W mov W, #poly1 xor crch, W _notset clrb C ; for rlf rl saved ; next bit of saved decsz i ;*** WARNING: MPASM macro B is not supported yet. Replace manually. b _loop ret ; ; End CrcUpd