I tried making a 256-byte global const array, and telling the program to simply grab a byte out of it as needed. That worked, but when I looked at the list file I thought the way the compiler set it up was clumsy. Then I noticed that when my array was placed into the executable file, each byte of the array was expanded so that the upper byte (upper 6 bits, actually) made it into a RETLW operation. The compiler did that, but then just read the low byte as data and never used the code. So I thought maybe I could replace the 256 bytes of data with 256 RETLW lines in a function, and actually use the RETLW. In fact it was quite easy, and will undoubtedly be fast in operation. It looks like this. An initial function takes the call for an update of the CRC (new data is in incoming.input):
Code: Select all
void crc_bits(void)
{
WREG = incoming.input ^ incoming.checksum;
crc_lookup(); // Call is made with result of XOR operation in W
incoming.checksum = WREG; // Call returns with new CRC in W
}
Code: Select all
void crc_lookup(void)
{
asm {
BRW
RETLW 0
RETLW 0X5E
RETLW 0XBC
... etc etc
}