home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-1.ZIP / GCOMM / GLCRC.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-08-14  |  3.0 KB  |  90 lines

  1.                 page    58,132
  2.  
  3.  
  4. ; glcrc.asm
  5. ; contains: glcrc()
  6. ;
  7. ; The Greenleaf Comm Library
  8. ;
  9. ; Copyright (C) 1988-90 Greenleaf Software Inc.  All Rights Reserved.
  10. ;
  11.                 include model.h
  12.                 include prologue.h
  13.                 name cglccrc
  14.                 pseg    _cglcrc
  15.  
  16. ;==>--  unsigned int glcrc(count,startvalue,buffer)
  17. ;
  18. ;;      ARGUMENTS:
  19. ;        (unsigned int) count      -    Size of buffer in bytes
  20. ;        (unsigned int) startvalue -    Initial value of CRC
  21. ;        (char *)       buffer     -    Pointer to buffer
  22. ;
  23. ;;      DESCRIPTION:
  24. ;        Calculate CRC X^16+X^12+X^5+1 for buffer of count length.  Note:
  25. ;        This function can be used to calculate the CRC for an entire
  26. ;        buffer at once or for calculating a buffer a character at a time.
  27. ;
  28. ;        Example for calculating the CRC of an entire buffer:
  29. ;
  30. ;               unsigned int crcvalue;
  31. ;               extern char *buffer;
  32. ;
  33. ;               crcvalue=glcrc(1024,0,buffer);
  34. ;
  35. ;         The return value (crcvalue) would be the CRC for the entire
  36. ;         1024 byte buffer.
  37. ;
  38. ;        Example for calculating the CRC of a buffer one byte at a time with
  39. ;        other processing in a loop.
  40. ;
  41. ;               unsigned int crcvalue;
  42. ;               extern char *buffer;
  43. ;               int buffersize;
  44. ;
  45. ;               crcvalue=0;
  46. ;
  47. ;               while(buffersize--) {
  48. ;                       crcvalue=glcrc(1,crcvalue,buffer);
  49. ;                               .
  50. ;                               .       (other processing)
  51. ;                               .
  52. ;               }
  53. ;               The CRC for the buffer can be found at this point in
  54. ;               the variable crcvalue.
  55. ;
  56. ;;      RETURNS:
  57. ;        CRC for the buffer of length count
  58. ;
  59. ;;      AUTHOR:
  60. ;        ""   20-JUN-1988  14:07:52.76
  61. ;
  62. ;;      MODIFICATIONS:
  63. ;           25-AUG-1988  11:09:22.83
  64. ;         Added push ds (#127)
  65. ;;;
  66.                 cproc   glcrc
  67.                 if      _LDATA
  68.                  push   ds
  69.                  lds    bx,parm3_       ;DS:BX points to buffer
  70.                 else
  71.                  mov    bx,parm3_       ;DS:BX points to buffer
  72.                 endif
  73.                 mov     cx,parm1_       ;CX = number of bytes in buffer
  74.                 mov     ax,parm2_       ;AX = Previous CRC
  75. loop2:          xor     ah,[bx]         ;AH^=data byte
  76.                 mov     dh,8            ;repeat 8 times
  77. loop1:          shl     ax,1            ;AX<<=1
  78.                 jnc     glcrc1          ;if was not set
  79.                 xor     ax,01021H       ;AX^=0X1021
  80. glcrc1:         dec     dh              ;decrement counter
  81.                 jnz     loop1
  82.                 inc     bx              ;point to next byte in buffer
  83.                 loop    loop2           ;do next byte if count != 0
  84.                 if      _LDATA
  85.                  pop    ds
  86.                 endif
  87.                 cproce
  88.                 endps
  89.                 end
  90.