Programming:CRC16: Difference between revisions
From CPCWiki - THE Amstrad CPC encyclopedia!
More actions
CRC16 calculation |
PulkoMandy (talk | contribs) |
||
| Line 43: | Line 43: | ||
ret | ret | ||
</pre> | </pre> | ||
[[Category:Programming]] | |||
Latest revision as of 14:06, 13 August 2006
This code is untested and may not work as advertised or at all.
CRC16: ;Borrowed from http://zilog.sh.cvut.cz/~base/misc/z80bits.html ; and moddified to be a loop ;The arrow comments show what lines I added or commented out from the original. ;Inputs: de->data bc=number of bytes ;Outputs: hl=CRC16 push bc ;<---<<< push de ;<---<<< push af ;<---<<< ld hl,$FFFF push bc ;<---<<< CRC16_Read: ld a,(de) inc de xor h ld h,a ld b,8 CRC16_CrcByte: add hl,hl jr nc,CRC16_Next ld a,h xor $10 ld h,a ld a,l xor $21 ld l,a CRC16_Next: djnz CRC16_CrcByte ; dec c ;>>>---> pop bc ;<---<<< dec bc ;<---<<< push bc ;<---<<< ld a,b ;<---<<< or c ;<---<<< jr nz,CRC16_Read pop bc ;<---<<< pop af ;<---<<< pop de ;<---<<< pop bc ;<---<<< ret