Calculating 16-bit CRCs (CRC-16) |
MDFS::Info.Comp.Comms.CRC8/htm | Search |
CRC8 is BBC BASIC test code with BASIC, 6502, Z80 and ARM code.
'C' code
BBC BASIC
6502
Z80
6809
PDP-11
32-bit 80x86
32016
ARM
Sample calling code
Multiple passes over data can be made, for instance, as an input file is
copied to an output file. The following code demonstrates how to do this,
copying from an open file on in% to an open file on out%,
calculating a CRC-16 as it goes.
REM mem%=buffer
REM max%=size of buffer
S%=0 :REM CRC starts as &0000
REPEAT
num%=EXT#in%-PTR#in% :REM Number of bytes to transfer
IF num%>max% THEN num%=max% :REM If more than size of buffer max%, use max%
PROCgbpb(rd%,in%,mem%,num%,0) :REM Read block of data
PROCcrc :REM Update CRC
PROCgbpb(wr%,out%,mem%,num%,0) :REM Write block of data
UNTIL PTR#in%=EXT#in% :REM Loop until all done
The CRC is calculated with one of the following subroutines:
Authored by J.G.Harston
Last update: 07-Jan-2013