> CRC16  CRC16 test code : (2 mem% &FFF:"LOAD CRCs/htm "+~mem%:num%=&A6D 2 mem%=PAGE:num%=TOP-PAGE <: F @%=&90A P-"BASIC CRC-16: ";:S%=0:T%=:crc:T%=-T% Z"&";~S%;" in ";T%/100;"s"' d: n @%=&2040A x Asm1 max% num%=max% 7 gbpb(rd%,in%,mem%,num%,0) : Read block of data "/ crc : Update CRC ,8 gbpb(wr%,out%,mem%,num%,0) : Write block of data 67 num%&8000:-256="W":crc86:A$="80x86":N%=100: %>&8000:crcARM:A$="ARM":N%=10: '?&FFF7=&6C:crc65:A$="6502":N%=1: $?&FFF7=&C3:crc80:A$="Z80":N%=1  :  Asm2 >&8000: %?&FFF7=&6C:crc65ac:A$="ACORN":   : &5crc65: Calc 63:addr=&70:num=&72:crc=&74:P=01 0P%=Calc:[OPT P*2 : .bytelp DBLDX #8 :\ Prepare to rotate CRC 8 bits N:LDA (addr-8 &FF,X) :\ Fetch byte from memory X: bF\ The following code updates the CRC with the byte in A ---------+ lF\ If used in isolation, requires LDX #8 here | vB crc+1 :\ byte into CRC top byte | F.rotlp :\ | FASL crc+0:ROL A :\ Rotate CRC clearing bit 0 | FBCC clear :\ b15 was clear, skip past | FTAY :\ Hold CRC high byte in Y | ELDA crc+0: #&21:STA crc+0 :\ CRC=CRC &1021, XMODEM polynomic DTYA: #&10 :\ Get CRC high byte back from Y | F.clear :\ b15 was zero | FDEX:BNE rotlp :\ Loop for 8 bits | FSTA crc+1 :\ Store CRC high byte | F\ ---------------------------------------------------------------+ : 7INC addr+0:BNE next:INC addr+1 :\ Step to next byte  .next :  \ Now do a 16-bit decrement KLDA num+0:BNE skip :\ num.lo<>0, not wrapping from 00 to FF  LDEC num+1 :\ Wrapping from 00 to FF, dec. high byte * .skip 4HDEC num+0:BNE bytelp :\ Dec. low byte, loop until num.lo=0 >6LDA num+1:BNE bytelp :\ Loop until num=0 HRTS R ]:: \: f8crc65ac: Calc2 79:addr=&70:num=&72:crc=&74:P=01 pH=crc+1:L=crc z=P%=Calc:[OPT P*2 :\ Acorn CFS/RFS sample code 7LDY #0 :\ Point to first byte  .bytelp :LDA (addr),Y :\ Fetch byte from memory : F\ The following code updates the CRC with the byte in A ---------+ B H:STA H:LDX #8 :\ byte into CRC top byte | F.rotlp :\ | FLDA H:ROL A:BCC clear :\ b15 clear, skip past | BLDA H: #8:STA H :\ CRC=CRC &0810, ACORN polynomic DLDA L: #&10:STA L :\ | F.clear :\ b15 was clear | FROL L:ROL H :\ Rotate CRC, rotating b15 into b0 | FDEX:BNE rotlp :\ Loop for 8 bits | F\ ---------------------------------------------------------------+ : 5INY:BNE next:INC addr+1 :\ Step to next byte $ .next .: 8\ Now do a 16-bit decrement BILDA num+0:BNE skip :\ num.lo<>0, not wrapping from 00 to FF LJDEC num+1 :\ Wrapping from 00 to FF, dec. high byte V .skip `FDEC num+0:BNE bytelp :\ Dec. low byte, loop until num.lo=0 j4LDA num+1:BNE bytelp :\ Loop until num=0 tRTS ~ ]:: : : 5crc80: Calc 79:addr=&70:num=&72:crc=&74:P=01 P%=Calc:[OPT P*2 /LD HL,(addr):LD BC,(num) :\ Address, Count -LD DE,(crc) :\ Incoming CRC : 9\ Enter here with HL=>data, BC=count, DE=incoming CRC  .bytelp +PUSH BC :\ Save count 7LD A,(HL) :\ Fetch byte from memory : F\ The following code updates the CRC with the byte in A ---------+  FXOR D :\ XOR byte into CRC top byte | FLD B,8 :\ Prepare to rotate 8 bits | F.rotlp :\ | (FSLA E:ADC A,A :\ Rotate CRC | 2FJP NC,clear :\ b15 was zero | start of data 0-MOV EBX,[num] ; EBX= length of data :+MOV ECX,[crc] ; ECX= incoming CRC D/SHL ECX,16 ; Move CRC into b16-b31 N; X .bytelp b0MOV AL,[ESI] ; Fetch byte from memory l; vC; The following code updates the CRC with the byte in AL -----+ CSHL EAX,24 ; Move byte to b8-b15 | CXOR ECX,EAX ; XOR byte into top of CRC | CMOV AL,8 ; Prepare to rotate 8 bits | C.rotlp ; | CSHL ECX,1 ; Rotate CRC | CJNC clear ; b15 was zero | CXOR ECX,&10210000 ; If b15 was set, XOR with XMODEM polymonic C.clear ; | CDEC AL:JNZ rotlp ; Loop for 8 bits | C; ------------------------------------------------------------+ ; ,INC SI ; Point to next byte 5DEC EBX:JNE bytelp ; num=num-1, loop until num=0 3SHR ECX,16 ; Move CRC back into b0-b15  ,MOV [crc],ECX ; Store outgoing CRC RETF  .addr:DD 0 * .num:DD 0 4 .crc:DD 0 > ]:: H: