Network 1 // MBUS_CRC - Calculate a CRC.
//
// Calculate CRC
//
// This subroutine calculates the CRC value for the message using the slightly
// faster table lookup method. The CRC is calculated on
modbusBufr using the
// first byte of this buffer as the byte count. The CRC is written into the
// buffer after the data.
//
// NOTE: This routine requires about 650 uSec per byte to calculate the
// CRC (i.e. 65 mSec for 100 bytes).
//
// Inputs: none
//
// Outputs: crc CRC value
//
//
LD SM0.0 //
BTI VB100, LW2 // get the byte count
MOVD &VB100, LD4 // get buffer address for CRC check
INCD LD4 // point to first message byte
XORD AC0, AC0 // clear temporary register
MOVD 16#FFFF, AC2 // initialize the CRC value to 0xFFFF
FOR AC1, +1, LW2 // for all bytes in the message
MOVB *LD4, AC0 // get the message byte
XORW AC2, AC0 // XOR CRC with data
ANDW 16#FF, AC0 // keep only the LSByte
SLW AC0, 1 // convert to an index into word table
MOVD &VB356, AC3 // get start of table address
+I AC0, AC3 // add index to table start
SWAP AC2 // swap bytes of CRC
ANDW 16#FF, AC2 // keep only the LSByte
XORW *AC3, AC2 // OR table value with CRC
INCD LD4 // point to the next message byte