;       SCCSID = @(#)crc32.asm	6.2 91/01/14
SCCSID      equ     "@(#)crc32.asm	6.2 91/01/14"
;
;	IBM/Microsoft Confidential
;
;	Copyright (c) IBM Corporation 1987, 1990
;	Copyright (c) Microsoft Corporation 1987, 1990
;
;	All Rights Reserved

;****************************************************************************
;*
;*  CRC - compute a 32 bit checksum of a sector
;*
;* unsigned long crc32(unsigned char far *, unsigned short);
;*
;* note: the unsigned short is assumed to be an EVEN number.
;*
;*   Inputs:	ds:si point to sector
;*		cx is length in bytes of sector
;*   Outputs:	dx:ax contain checksum
;*
;*
;* Adapted by Paul Bingman, NWSP, for Microsoft
;* from FAT file of the same name.  8/10/89
;*
;* Changed routine name to _crc32.
;*
;****************************************************************************

;-----------------------------------------------------------------------------
; Adjust the stack frame if you make this a FAR PROC!
;
; Stack frame definition (upside down):

;STKBASE	equ	2 + 2		; 2 for BP, 2 for RET (4 if far)
;SIOFF	equ	STKBASE + 2
;DSOFF	equ	STKBASE + 4
;CXOFF	equ	STKBASE + 0

;-----------------------------------------------------------------------------
ifdef MEDIUM_MODEL
.MODEL MEDIUM, PASCAL
else
.MODEL SMALL, PASCAL
endif

.286P

ifdef MEDIUM_MODEL
.CODE _TEXT
else
.CODE
endif



	PUBLIC	crc32
ifdef MEDIUM_MODEL
crc32  proc    near USES DI SI CX DS, pszhi:WORD, pszlow:WORD, count:WORD
else
crc32  proc         USES DI SI CX DS, pszhi:WORD, pszlow:WORD, count:WORD
endif


	; Load up registers from stack frame

	mov	cx, count
	mov	si, pszlow
	mov	ds, pszhi

	; Perform the CRC

	cld
	push	bx
	xor	ax,ax
	mov	bx,ax
	mov	dx,ax		; dx:bx is intermediate result
	shr	cx,1		; convert bytes in sector to words
crc1:
	lodsw			; get next word of sector
	adc	bx,ax		; add it in to sum and propogate
				; last carry
	adc	dx,0		; propogate carry to high word
	rcr	bx,1		; move bits around
	rcr	dx,1
	loop	crc1
	mov	ax,bx
	pop	bx

	; Return
	; CRC is in dx:ax

	ret	

crc32  endp
END

; end of crc.asm
