home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / CRC.AZM / CRC.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  2.3 KB  |  82 lines

  1. ;----------------------------------------------------------------
  2. ;         This is a module in the ASMLIB library
  3. ;
  4. ; This module uses the character issued to it in register a and
  5. ; uses the following polynomial to generate a 16 bit cyclic-
  6. ; redundancy checksum. The checksum is able to distinguish between 
  7. ; two very similar text items since any differences in text quickly 
  8. ; show up in the checksum. This is useful for data integrity checking 
  9. ; in disk files or over modem lines etc.
  10. ;
  11. ; This module has 3 entry points which 
  12. ;
  13. ; 1) Clear any accumulated crc.
  14. ; 2) Add a character to the current crc.
  15. ; 3) Return the current crc value.
  16. ;
  17. ; A cyclic-redundancy-check number is generated by the ccitt 
  18. ; standard polynominal:
  19. ;   x^16 + x^15 + x^13 + x^7 + x^4 + x^2 + x + 1
  20. ;
  21. ; The routine for doing this is in 8080  and comes from the 
  22. ; 'EDN' magazine June 5 1979 issue Page 84. Written By Fred Gutman.
  23. ;
  24. ;            Written        R.C.H.        22/9/83
  25. ;            Last Update    R.C.H.        24/11/83
  26. ;----------------------------------------------------------------
  27. ;
  28.     name    'CRC'
  29.         public  clrcrc,addcrc,getcrc
  30. ;
  31. ; This entry point clears the current CRC
  32. ;
  33. clrcrc:
  34.     push    h
  35.     lxi    h,0            ; do a clear
  36.     shld    rem
  37.     pop    h
  38.     ret
  39. ; Return the accumulated CRC in the HL register
  40. ;
  41. getcrc:
  42.         lhld    rem
  43.         ret
  44. ;
  45. ; Add the character in A to the current running CRC.
  46. ;
  47. addcrc: 
  48.     push    h            ; Save this from harm
  49.     push    psw            ; Save the character too
  50.     sta     mess            ; Save.
  51. divp:
  52.     lhld    rem            ; get remainder
  53.         mov     a,h
  54.         ani     128            ; q-bit mask
  55.         push    psw            ; save status
  56.         dad     h            ; 2 x r(x)
  57.         lda     mess            ; message bit in lsb
  58.         add     l
  59.         mov     l,a
  60.         pop     psw
  61.         jz      qb2            ; if q-bit is zero
  62. qb:     mov     a,h
  63.         xri     0a0h            ; ms half of gen. poly
  64.         mov     h,a
  65.         mov     a,l
  66.         xri     97h            ; ls half of gen. poly
  67.         mov     l,a
  68. qb2:    shld    rem
  69.     pop    psw
  70.     pop    h
  71.         ret
  72. ;
  73. ; Data storage
  74. ;
  75.     dseg
  76. ;
  77. mess:   db      0       ; char for crc calc
  78. rem:    dw      0       ;crc remainder storage
  79. ;
  80.         end
  81.