home *** CD-ROM | disk | FTP | other *** search
- page 58,132
-
-
- ; glcrc.asm
- ; contains: glcrc()
- ;
- ; The Greenleaf Comm Library
- ;
- ; Copyright (C) 1988-90 Greenleaf Software Inc. All Rights Reserved.
- ;
- include model.h
- include prologue.h
- name cglccrc
- pseg _cglcrc
-
- ;==>-- unsigned int glcrc(count,startvalue,buffer)
- ;
- ;; ARGUMENTS:
- ; (unsigned int) count - Size of buffer in bytes
- ; (unsigned int) startvalue - Initial value of CRC
- ; (char *) buffer - Pointer to buffer
- ;
- ;; DESCRIPTION:
- ; Calculate CRC X^16+X^12+X^5+1 for buffer of count length. Note:
- ; This function can be used to calculate the CRC for an entire
- ; buffer at once or for calculating a buffer a character at a time.
- ;
- ; Example for calculating the CRC of an entire buffer:
- ;
- ; unsigned int crcvalue;
- ; extern char *buffer;
- ;
- ; crcvalue=glcrc(1024,0,buffer);
- ;
- ; The return value (crcvalue) would be the CRC for the entire
- ; 1024 byte buffer.
- ;
- ; Example for calculating the CRC of a buffer one byte at a time with
- ; other processing in a loop.
- ;
- ; unsigned int crcvalue;
- ; extern char *buffer;
- ; int buffersize;
- ;
- ; crcvalue=0;
- ;
- ; while(buffersize--) {
- ; crcvalue=glcrc(1,crcvalue,buffer);
- ; .
- ; . (other processing)
- ; .
- ; }
- ; The CRC for the buffer can be found at this point in
- ; the variable crcvalue.
- ;
- ;; RETURNS:
- ; CRC for the buffer of length count
- ;
- ;; AUTHOR:
- ; "" 20-JUN-1988 14:07:52.76
- ;
- ;; MODIFICATIONS:
- ; 25-AUG-1988 11:09:22.83
- ; Added push ds (#127)
- ;;;
- cproc glcrc
- if _LDATA
- push ds
- lds bx,parm3_ ;DS:BX points to buffer
- else
- mov bx,parm3_ ;DS:BX points to buffer
- endif
- mov cx,parm1_ ;CX = number of bytes in buffer
- mov ax,parm2_ ;AX = Previous CRC
- loop2: xor ah,[bx] ;AH^=data byte
- mov dh,8 ;repeat 8 times
- loop1: shl ax,1 ;AX<<=1
- jnc glcrc1 ;if was not set
- xor ax,01021H ;AX^=0X1021
- glcrc1: dec dh ;decrement counter
- jnz loop1
- inc bx ;point to next byte in buffer
- loop loop2 ;do next byte if count != 0
- if _LDATA
- pop ds
- endif
- cproce
- endps
- end