Lost Tech Archive |
;A Very Fast Linear CRC Routine ;by Ivars Vilums & Aubrey McIntosh - 1984 ;------------------------------------------------------------------ ;8086 assembly language ;------------------------------------------------------------------ ;Magic Constant - change for other polynomials PCONSTANT EQU 08003H ;constant xor'd if parity odd ;during crc. ;8003H is for Bisync Protocol CRC ;------------------------------------------------------------------ ;CRC routines ;============= ;reverses bit order of byte in AL ; destroys AH REVBYTE PROC NEAR MOV AH,AL ;save it MOV BX,OFFSET REVTABLE AND AL,0FH ;mask for lo nybble XLAT ;flip nybble XCHG AL,AH ;get other nybble SHR AL,1 SHR AL,1 SHR AL,1 SHR AL,1 XLAT SHL AH,1 SHL AH,1 SHL AH,1 SHL AH,1 OR AL,AH RET REVTABLE: DB 0,8,4,0CH ;table of reverse nybbles DB 2,0AH,6,0EH DB 1,9,5,0DH DB 3,0BH,7,0FH REVBYTE ENDP ;------------------- ;insert argument into crc and return new value ADDTOCRC PROC NEAR CALL REVBYTE XOR AH,AH MOV DH,CRCHI MOV DL,CRCLO ;really starts here XCHG DH,DL ;create struct. 2 in place XOR AL,DL ;create mask for struct. 3 ;and test for struct. 1 XCHG DL,AH ;clear out DL JP PDONE ;XOR all bits is same as parity XOR DX,PCONSTANT ;xor struct. 1 if needed PDONE: XOR AH,AH ;clear out the reg again SHL AX,1 ;position and place struct. 3 XOR DX,AX SHL AX,1 XOR DX,AX MOV CRCLO,DL MOV CRCHI,DH RET ADDTOCRC ENDP ;------------------- |