CRC-16-CCITT

From Bitchin100 DocGarden
Revision as of 22:25, 10 August 2011 by Jhoger (talk | contribs) (→‎Author)
Jump to navigationJump to search

Overview

The CRC-16-CCITT CRC is used in XMODEM/CRC, YMODEM, and ZMODEM.

This article includes 8085 code to compute this CRC on blocks as large as 256 characters. It can be called multiple times with the prior checksum to extend the CRC over larger blocks.

Author

John R. Hogerhuis <jhoger@pobox.com>
Speaker To Machines, Inc.

Code

; XMODEM/CRC, YMODEM, ZMODEM CRC-16
; Will CRC up to 256 bytes at a time.
; Call multiple times to CRC more than 256 bytes.
; Entry:
;    HL contains initial CRC value. Supply zero for initial block
;    DE contains a pointer to the value to CRC
;    B contains the number of bytes to CRC.
;      nb: B must be non-zero. No checking is performed here.

; Exit:
;    HL contains the CRC
;    DE points just past the last CRC'ed character
;    B is zero
;    C is zero
;    A, flags are undefined


CALC_CRC16:		LDAX		D
			XRA		H
			MOV		H,A

			MVI		C,8
FOR_CRC_BIT:		DAD		H
			JNC		NEXT_CRC_BIT
			MVI		A,$10
			XRA		H
			MOV		H,A
			MVI		A,$21
			XRA		L
			MOV		L,A

NEXT_CRC_BIT:		DCR		C
			JNZ		FOR_CRC_BIT

			INX		D
			DCR		B
			JNZ		CALC_CRC16
			RET