comparison examples/crc32.asm @ 57:2088fd998865

sbc09 directry clean up
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 23 Jul 2018 16:07:12 +0900
parents
children
comparison
equal deleted inserted replaced
56:4fa2bdb0c457 57:2088fd998865
1 ; 6809 CRC32 with tests
2 ;
3 ; Johann E. Klasek, j AT klasek at
4 ;
5 ; Testprogram, previous version submitted to http://beebwiki.mdfs.net/index.php/CRC-32#6809
6
7 org $100
8 lds #$8000
9
10 ; Calculate a ZIP 32-bit CRC from data in memory. This code is as
11 ; tight and nearly as fast as it can be, moving as much code out of inner
12 ; loops as possible. With the included optimisation, moving the whole
13 ; CRC in registers, the performane gain on average data is only slight
14 ; (estimated 2% but at losing clarity of implementation;
15 ; worst case gain is 18%, best case worsens at 29%)
16 ;
17 ; On entry, crc..crc+3 = incoming CRC
18 ; reg. U = start address of data
19 ; reg. X = number of bytes
20 ; On exit, crc..crc+3 = updated CRC
21 ; reg. U = points to first byte behind data
22 ; reg. X = 0
23 ; reg. Y = 0
24 ;
25 ; Value order in memory is H,L (big endian)
26 ;
27 ; Multiple passes over data in memory can be made to update the CRC.
28 ; For ZIP, initial CRC must be $FFFFFFFF, and the final CRC must
29 ; be EORed with $FFFFFFFF before being stored in the ZIP file.
30 ; Total 47 bytes (if above parameters are located in direct page).
31 ;
32 ; ZIP polynomic, reflected (bit reversed) from $04C11DB7
33 CRCHH EQU $ED
34 CRCHL EQU $B8
35 CRCLH EQU $83
36 CRCLL EQU $20
37 CRCINITH EQU $FFFF
38 CRCINITL EQU $FFFF
39
40 ; CRC 32 bit in DP (4 bytes)
41 crc EQU $80
42
43 ldu #s1 ; start address in u
44 ldb ,u+ ;
45 clra ; length in d
46 leax d,u ;
47 pshs x ; end address +1 to TOS
48 ldd #CRCINITL
49 std crc+2
50 ldx #CRCINITH
51 stx crc
52 ; d/x contains the CRC
53 bl:
54 eorb ,u+ ; XOR with lowest byte
55 ldy #8 ; bit counter
56 rl:
57 exg d,x
58 rl1:
59 lsra ; shift CRC right, beginning with high word
60 rorb
61 exg d,x
62 rora ; low word
63 rorb
64 bcc cl
65 ; CRC=CRC XOR polynomic
66 eora #CRCLH ; apply CRC polynomic low word
67 eorb #CRCLL
68 exg d,x
69 eora #CRCHH ; apply CRC polynomic high word
70 eorb #CRCHL
71 leay -1,y ; bit count down
72 bne rl1
73 exg d,x ; CRC: restore correct order
74 beq el ; leave bit loop
75 cl:
76 leay -1,y ; bit count down
77 bne rl ; bit loop
78 el:
79 cmpu ,s ; end address reached?
80 bne bl ; byte loop
81
82 std crc+2 ; CRC low word
83 stx crc ; CRC high word
84
85
86 realexit:
87 sync
88
89
90 s1: fcb 19,"An Arbitrary String"
91 ; CRC=$90415518
92
93 s2: fcb 26,"ZYXWVUTSRQPONMLKJIHGFEDBCA"
94 ; CRC32=$6632024D
95
96 enddata
97
98 end