CRC-16-CCITT: Difference between revisions

From Bitchin100 DocGarden
Jump to navigationJump to search
(New page: == 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 ...)
 
 
(3 intermediate revisions by the same user not shown)
Line 4: Line 4:


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.
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 &lt;jhoger@pobox.com&gt;<br/>
Speaker To Machines, Inc.


== Code ==
== Code ==
Line 9: Line 14:
<pre>
<pre>
; XMODEM/CRC, YMODEM, ZMODEM CRC-16
; XMODEM/CRC, YMODEM, ZMODEM CRC-16
; Will CRC up to 256 bytes at a time.
; Will CRC up to 255 bytes at a time.
; Call multiple times to CRC more than 256 bytes.
; Call multiple times to CRC more than 255 bytes.
; Entry:
; Entry:
;    HL contains initial CRC value. Supply zero for initial block
;    HL contains initial CRC value. Supply zero for initial block
Line 47: Line 52:
RET
RET
</pre>
</pre>
[[Category:Model T Developer Reference]] [[Category:8085 Subroutine]]

Latest revision as of 14:35, 12 August 2011

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 255 bytes at a time.
; Call multiple times to CRC more than 255 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