.TITLE CRC16 ; ;+ ; This routine caculates a CRC-16 polynomial (using a 32-word lookup ; algorithm). It is shown as a Fortran-callable integer function. ; ; Call with: JSR PC,CRC16 ; ; 2(R5) -> Address of start of message ; 4(R5) -> Address of size of message ; ; Exit with: R0 -> CRC-16 value ;- ; ; Define 32-word CRC generator table. ; CRCTBL: .WORD 000000,140301,140601,000500,141401,001700,001200,141101 .WORD 143001,003300,003600,143501,002400,142701,142201,002100 .WORD 000000,146001,154001,012000,170001,036000,024000,162001 .WORD 120001,066000,074000,132001,050000,116001,104001,042000 CRC16:: CLR R0 ;Clear CRC value register MOV 2(R5),R2 ;Get the buffer address MOV @4(R5),R1 ;Get the buffer length 1000$: MOVB (R2)+,R3 ;Get next character XOR R0,R3 ;Exclusive-OR old CRC and character MOV R3,R4 ;Save value for later BIC #177760,R3 ;Clear extraneous bits ASL R3 ;Make into a word index MOV CRCTBL(R3),R3 ;Get the modifier word BIC #177417,R4 ;Clear extraneous bits ASR R4 ;Make into a word index ASR R4 ; ... ASR R4 ; ... MOV CRCTBL+40(R4),R4 ;Get the modifier word XOR R4,R3 ;Get the total modifier CLRB R0 ;Clear low byte old CRC SWAB R0 ;Move high to low XOR R3,R0 ;Exclusive-OR modifier and old SOB R1,1000$ ; loop until done RETURN ;Return to caller .END