这个 CRC 实现有一个众所周知的名字吗?这段代码是用 C 语言编写的,但我认为这与用于 BBC micro 的磁带归档系统的 CRC 计算相同。但是 BBC 微文档没有指定 CRC 的名称。我也无法在http://reveng.sourceforge.net/crc-catalogue/16.htm或https://en.wikipedia.org/wiki/Cyclic_redundancy_check中找到任何明显的匹配项
inline unsigned long crc_cycle(unsigned long crc)
{
if (crc & 32768)
return (((crc ^ 0x0810) & 32767) << 1) + 1;
else
return crc << 1;
}
unsigned long crc_update(unsigned long crc, const byte *start, const byte *end)
{
for (const byte* p = start; p < end; ++p)
{
crc ^= *p++ << 8;
for(int k = 0; k < 8; k++)
crc = crc_cycle(crc);
assert((crc & ~0xFFFF) == 0);
}
return crc;
}
unsigned long crc(const byte *start, const byte* end)
{
return crc_update(0, start, end);
}
BBC Microcmputer Advanced User Guide的第 348 页也描述了此校验和,但也没有给出名称。该页面上的代码是 6502 程序集:
LDA #0
STA H \ Initialise the CRC to zero
STA L
TAY \ Initialise the data pointer
.nbyt LDA H \ Work data into CRC
EOR data,Y
STA H
LDX #8 \ Perform polynomial recycling
.loop LDA H \ Loop is performed 8 times, once for bit
ROL A Test if a bit is being cycled out
BCC b7z
LDA H \ Yes, add it back in *~8~5
EOR #8
STA H
LDA L
EOR #&l0
STA L
.b7z ROL L \ Always, rotate whole CRC left one bit
ROL H
DEX
BNE loop \Do once for each bit
INY \Point to next data byte
CPY #lblk \All done yet?
BNE nbyt
RTS \All done- H=CRC Hi, L=CRC