home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / crc_lib2 / src / crc_16.s next >
Encoding:
Text File  |  1995-01-08  |  6.1 KB  |  193 lines

  1. ;--------------------------------------------------------------------------
  2. ;        CRC_16.S
  3. ;        Assemblerroutinen (68000er) zur CRC-Berechnung;
  4. ;
  5. ;        (c) 1994 by Jan Kriesten, D-35043 Marburg, FidoNet: 2:244/4344
  6. ;
  7. ;        Die CRC-Tabelle fr CRC-16 ist hier enthalten;
  8. ;
  9.  
  10.     *** CRC-16
  11.     .GLOBL    Crc16Str, Crc16Blk, Crc16Upd, Crc16BlkUpd
  12.     .GLOBL    Crc16Short
  13.     .GLOBL    Crc16Tab
  14.  
  15.     .TEXT
  16.  
  17. ;--------------------------------------------------------------------------
  18. ;        Routinen zur CRC-16 Berechnung (CRC-16)
  19. ;        Polynom: x^16+x^15+x^2+1
  20. ;        Die Berechnung wird mit Hilfe einer Tabelle durchgefhrt, so daž
  21. ;        8 BIT gleichzeitig herangezogen werden k”nnen.
  22.  
  23.     .MODULE Crc16Str
  24.  
  25. ;        ->    a0:    - Adresse eines nullterminierten Strings;
  26. ;        <-    d0:    - CRC-16 ( 2 Byte unsigned );
  27.  
  28.         moveq        #-1, d0                ; d0 vorbesetzen
  29.         lea.l        Crc16Tab(pc), a1    ; Adresse der CRC-Tabelle nach a1
  30.  
  31.         bra.b        .LoopStart
  32.  
  33. .Loop:
  34.         eor.b        d0, d1            ; x = crc XOR (*msg)
  35.         add.w        d1, d1            ; mal 2, da auf long adressiert wird
  36.         move.w        (a1, d1.w), d1    ; entsprechender Tabelleneintrag nach d1
  37.  
  38.         lsr.w        #8, d0            ; d0 wird um 8 BIT rechts geschoben
  39.         eor.w        d1, d0            ; y = (crc >> 8) XOR x
  40.  
  41. .LoopStart:
  42.         moveq        #0, d1            ; d1 l”schen
  43.         move.b        (a0)+, d1        ; erstes Byte des Strings nach d1 ...
  44.         bne.b        .Loop            ; wenn d2 != 0, dann geht's weiter
  45.  
  46.         rts                            ; ... endlich schluss und zurck!
  47.         
  48.     .ENDMOD
  49.  
  50.     .MODULE Crc16Blk
  51.  
  52. ;        ->    a0:    - Adresse eines Datenblockes;
  53. ;            d0:    - L„nge des Datenblockes ( 4 Bytes unsigned )
  54. ;        <-    d0:    - CRC-16 ( 2 Byte unsigned );
  55.  
  56.         move.l        d0, d1            ; counter in d1 initialisieren
  57.         moveq        #-1, d0            ; d0 vorbesetzen
  58.  
  59.         cmp.l        #$ffff.w, d1    ; wenn die L„nge WORD ist
  60.         blo.w        Crc16Short        ; dann dbra benutzen
  61.  
  62.         bra.w        Crc16BlkUpd
  63.  
  64.     .ENDMOD
  65.  
  66.     .MODULE Crc16BlkUpd
  67.  
  68. ;        ->    a0:    - Adresse eines Datenblockes;
  69. ;            d0: - bisherige CRC-16
  70. ;            d1:    - L„nge des Datenblockes ( 4 Bytes unsigned )
  71. ;        <-    d0:    - CRC-16 ( 2 Byte unsigned );
  72.  
  73.         cmp.l        #$ffff.w, d1        ; wenn die L„nge WORD ist
  74.         blo.w        Crc16Short            ; dann dbra benutzen
  75.  
  76.         move.l        d1, d2                ; counter in d2 initialisieren
  77.  
  78.         lea.l        Crc16Tab(pc), a1    ; Adresse der CRC-Tabelle nach a1.
  79.  
  80.         bra.b        .LoopStart
  81.  
  82. .Loop:
  83.         moveq        #0, d1            ; d1 l”schen
  84.         move.b        (a0)+, d1        ; Zeichen holen
  85.         
  86.         eor.b        d0, d1            ; x = crc XOR (*msg)
  87.         add.w        d1, d1            ; mal 2, da auf word adressiert wird
  88.         move.w        (a1,d1.w), d1    ; entsprechender Tabelleneintrag nach d1
  89.  
  90.         lsr.w        #8, d0            ; d0 wird um 8 BIT rechts geschoben
  91.         eor.w        d1, d0            ; y = (crc >> 8) XOR x
  92.  
  93. .LoopStart:
  94.         subq.l        #1, d2            ; counter um 1 erniedrigen
  95.         bpl.b        .Loop            ; wenn d3 >= 0, dann geht's weiter
  96.  
  97.         rts                            ; ... endlich schluss und zurck!
  98.  
  99.     .ENDMOD
  100.  
  101.     .MODULE Crc16Short
  102.  
  103. ;        ->    a0:    - Adresse eines Datenblockes;
  104. ;            d0: - bisherige CRC-16
  105. ;            d1:    - L„nge des Datenblockes ( 2 Bytes signed )
  106. ;        <-    d0:    - CRC-16 ( 2 Byte unsigned );
  107.  
  108.         move.l        d1, d2                ; counter in d2 initialisieren
  109.  
  110.         lea.l        Crc16Tab(pc), a1    ; Adresse der CRC-Tabelle nach a1.
  111.  
  112.         bra.b        .LoopStart
  113.  
  114. .Loop:
  115.         moveq        #0, d1            ; d1 l”schen
  116.         move.b        (a0)+, d1        ; Zeichen holen
  117.  
  118.         eor.b        d0, d1            ; x = crc XOR (*msg)
  119.         add.w        d1, d1            ; mal 2, da auf word adressiert wird
  120.         move.w        (a1,d1.w), d1    ; entsprechender Tabelleneintrag nach d1
  121.  
  122.         lsr.w        #8, d0            ; d0 wird um 8 BIT rechts geschoben
  123.         eor.w        d1, d0            ; y = (crc >> 8) XOR x
  124.  
  125. .LoopStart:
  126.         dbra        d2, .Loop        ; counter um 1 erniedrigen und 
  127.                                     ; und bis -1.
  128.  
  129.         rts                            ; ... endlich schluss und zurck!
  130.     
  131.     .ENDMOD
  132.         
  133.     .MODULE Crc16Upd
  134.  
  135. ;        ->    d0:    - bisheriger CRC-16 (2 Byte unsigned;
  136. ;            d1:    - hinzuzufgendes Byte;
  137. ;        <-    d0:    - CRC-16 ( 2 Byte unsigned );
  138.  
  139.         lea.l        Crc16Tab(pc), a0    ; Adresse der CRC-Tabelle nach a1.
  140.  
  141.         andi.w        #$00ff, d1        ; ober Byte ausmaskieren
  142.         eor.b        d0, d1            ; x = crc XOR (*msg)
  143.         add.w        d1, d1            ; mal 2, da auf word adressiert wird
  144.         move.w        (a0,d1.w), d1    ; entsprechender Tabelleneintrag nach d1
  145.  
  146.         lsr.w        #8, d0            ; d0 wird um 8 BIT rechts geschoben
  147.         eor.w        d1, d0            ; y = (crc >> 8) XOR x
  148.  
  149.         rts                            ; ... endlich schluss und zurck!
  150.         
  151.     .ENDMOD
  152.  
  153. ;--------------------------------------------------------------------------
  154.  
  155.     .MODULE Crc16Tab:
  156.  
  157.         dc.w $0000, $1189, $2312, $329b, $4624, $57ad, $6536, $74bf
  158.         dc.w $8c48, $9dc1, $af5a, $bed3, $ca6c, $dbe5, $e97e, $f8f7
  159.         dc.w $1081, $0108, $3393, $221a, $56a5, $472c, $75b7, $643e
  160.         dc.w $9cc9, $8d40, $bfdb, $ae52, $daed, $cb64, $f9ff, $e876
  161.         dc.w $2102, $308b, $0210, $1399, $6726, $76af, $4434, $55bd
  162.         dc.w $ad4a, $bcc3, $8e58, $9fd1, $eb6e, $fae7, $c87c, $d9f5
  163.         dc.w $3183, $200a, $1291, $0318, $77a7, $662e, $54b5, $453c
  164.         dc.w $bdcb, $ac42, $9ed9, $8f50, $fbef, $ea66, $d8fd, $c974
  165.         dc.w $4204, $538d, $6116, $709f, $0420, $15a9, $2732, $36bb
  166.         dc.w $ce4c, $dfc5, $ed5e, $fcd7, $8868, $99e1, $ab7a, $baf3
  167.         dc.w $5285, $430c, $7197, $601e, $14a1, $0528, $37b3, $263a
  168.         dc.w $decd, $cf44, $fddf, $ec56, $98e9, $8960, $bbfb, $aa72
  169.         dc.w $6306, $728f, $4014, $519d, $2522, $34ab, $0630, $17b9
  170.         dc.w $ef4e, $fec7, $cc5c, $ddd5, $a96a, $b8e3, $8a78, $9bf1
  171.         dc.w $7387, $620e, $5095, $411c, $35a3, $242a, $16b1, $0738
  172.         dc.w $ffcf, $ee46, $dcdd, $cd54, $b9eb, $a862, $9af9, $8b70
  173.         dc.w $8408, $9581, $a71a, $b693, $c22c, $d3a5, $e13e, $f0b7
  174.         dc.w $0840, $19c9, $2b52, $3adb, $4e64, $5fed, $6d76, $7cff
  175.         dc.w $9489, $8500, $b79b, $a612, $d2ad, $c324, $f1bf, $e036
  176.         dc.w $18c1, $0948, $3bd3, $2a5a, $5ee5, $4f6c, $7df7, $6c7e
  177.         dc.w $a50a, $b483, $8618, $9791, $e32e, $f2a7, $c03c, $d1b5
  178.         dc.w $2942, $38cb, $0a50, $1bd9, $6f66, $7eef, $4c74, $5dfd
  179.         dc.w $b58b, $a402, $9699, $8710, $f3af, $e226, $d0bd, $c134
  180.         dc.w $39c3, $284a, $1ad1, $0b58, $7fe7, $6e6e, $5cf5, $4d7c
  181.         dc.w $c60c, $d785, $e51e, $f497, $8028, $91a1, $a33a, $b2b3
  182.         dc.w $4a44, $5bcd, $6956, $78df, $0c60, $1de9, $2f72, $3efb
  183.         dc.w $d68d, $c704, $f59f, $e416, $90a9, $8120, $b3bb, $a232
  184.         dc.w $5ac5, $4b4c, $79d7, $685e, $1ce1, $0d68, $3ff3, $2e7a
  185.         dc.w $e70e, $f687, $c41c, $d595, $a12a, $b0a3, $8238, $93b1
  186.         dc.w $6b46, $7acf, $4854, $59dd, $2d62, $3ceb, $0e70, $1ff9
  187.         dc.w $f78f, $e606, $d49d, $c514, $b1ab, $a022, $92b9, $8330
  188.         dc.w $7bc7, $6a4e, $58d5, $495c, $3de3, $2c6a, $1ef1, $0f78
  189.  
  190.     .ENDMOD
  191.  
  192.     .END
  193.