.sbttl crc calculation ; This routine will calculate the CRC for a string, using the ; CRC-CCIT polynomial. ; ; The string should be the fields of the packet between but ; not including the and the block check, which is ; treated as a string of bits with the low order bit of the ; first character first and the high order bit of the last ; character last -- this is how the bits arrive on the ; transmission line. The bit string is divided by the ; polynomial ; ; x^16+x^12+x^5+1 ; ; The initial value of the CRC is 0. The result is the ; remainder of this division, used as-is (i.e. not ; complemented). ; ; From 20KERMIT.MAC, rewritten for PDP11 by Brian Nelson ; 13-Jan-84 08:50:43 ; ; input: @r5 string address ; 2(r5) string length ; output: r0 crc crcclc::save ; save registers please clr r0 ; initialize the CRC to zero mov @r5 ,r3 ; get the string address now mov 2(r5) ,r4 ; get the string length beq 100$ ; oops, nothing to do then 10$: clr r1 ; get the next character please bisb (r3)+ ,r1 ; please avoid pdp11 sign extend cmpb parity ,#par$no ; did the packet have parity? beq 20$ ; no, leave bit seven alone bic #^C177 ,r1 ; yes, clear bit seven please 20$: ixor r0 ,r1 ; add in with the current CRC mov r1 ,r2 ; get the high four bits ash #-4 ,r2 ; and move them over to 3..0 bic #^C17 ,r2 ; drop any bits left over bic #^C17 ,r1 ; and the low four bits asl r1 ; times 2 for word addressing asl r2 ; times 2 for word addressing mov crctb2(r1),r1 ; get low portion of CRC factor ixor crctab(r2),r1 ; simple (limited modes for XOR) swab r0 ; shift off a byte from previous crc bic #^C377 ,r0 ; clear new high byte ixor r1 ,r0 ; add in the new value sob r4 ,10$ ; next please 100$: unsave ; pop saved r1-r5 return ; Data tables for CRC-CCITT generation crctab: .word 0 .word 10201 .word 20402 .word 30603 .word 41004 .word 51205 .word 61406 .word 71607 .word 102010 .word 112211 .word 122412 .word 132613 .word 143014 .word 153215 .word 163416 .word 173617 crctb2: .word 0 .word 10611 .word 21422 .word 31233 .word 43044 .word 53655 .word 62466 .word 72277 .word 106110 .word 116701 .word 127532 .word 137323 .word 145154 .word 155745 .word 164576 .word 174367