.title CRC.MAC ;This routine will calculate the CRC for a file using the ;CRC-CCIT polynomial. .mcall .CSIGEN,.READW,.EXIT,.CLOSE,.SRESET,.PRINT ERRBYT=52 .macro ixor reg ,dst ; get around the mode restrictions for the hardware XOR instruction ; and fix for RT-11 systems that don't have the EIS chip option mov reg ,-(sp) ; it's much simpler to do this bic dst ,@sp ; for all RT-11 systems rather bic reg ,dst ; than to be selective bis (sp)+ ,dst ; done .endm ixor ; The CRC polynomial is ; ; 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 PDP-11 by Brian Nelson ; 13-Jan-84 08:50:43 ; ; From KRTPAK.MAC, rewritten as a command by Tim Shoppa START: .CSIGEN #DSPACE,#DEXT,,#LINBUF MOV R0,BUFF CLR INBLK CLR R1 MOV #LIST,R5 READ: .READW R5,#3,BUFF,#256.,INBLK BCC 2$ TSTB @#ERRBYT BEQ EOF MOV #INERR,R0 1$: .PRINT CLR R0 .EXIT 2$: MOV BUFF,R3 MOV #512.,R4 10$: clr r0 ; get the next character please bisb (r3)+ ,r0 ; please avoid PDP-11 sign extend ixor r1 ,r0 ; add in with the current CRC mov r0 ,r2 ; get the high four bits ash #-4 ,r2 ; and move them over to 3..0 bic #^c<17> ,r2 ; drop any bits left over bic #^c<17> ,r0 ; and the low four bits asl r0 ; times 2 for asl r2 ; word addressing mov crctb2(r0),r0 ; get low portion of CRC factor ixor crctab(r2),r0 ; ixor avoids hardware xor mode limits swab r1 ; shift off a byte from previous CRC bic #^c<377>,r1 ; clear new high byte ixor r0 ,r1 ; add in the new value sob r4 ,10$ ; next please INC INBLK BR READ EOF: .CLOSE #3 ;Now print the 16-bit CRC in Hex MOV #4,R2 MOV #HEXBUF+4,R0 ; 4 Hex digits 37$: MOV R1,R3 BIC #^C<17>,R3 ; Clear all but the low four bits CMP R3,#10. BLO 40$ ADD #7.,R3 40$: ADD #48.,R3 MOVB R3,-(R0) ROR R1 ROR R1 ROR R1 ROR R1 SOB R2,37$ .PRINT .SRESET JMP START DEXT: .WORD 0,0,0,0 BUFF: .WORD 0 INBLK: .WORD 0 CRC: .WORD 0 LIST: .BLKW 5 INERR: .ASCIZ /?CRC-F INPUT ERROR/ HEXBUF: .ASCII /XXXX / LINBUF: .BLKB 81. .EVEN crctab: .word 0 ,010201 ,020402 ,030603 ,041004 ,051205 ,061406 ,071607 .word 102010 ,112211 ,122412 ,132613 ,143014 ,153215 ,163416 ,173617 crctb2: .word 0 ,010611 ,021422 ,031233 ,043044 ,053655 ,062466 ,072277 .word 106110 ,116701 ,127532 ,137323 ,145154 ,155745 ,164576 ,174367 DSPACE =. .END START