| Copyright 1984 by the Massachusetts Institute of Technology

| This routine computes the 16 bit ones complement checksum of an
| array of words.
|
| Calling Sequence:
| word	buf[];
| int	nwords;
| int	resid;
| int	check;
|
| check = cksum(&buf, nwords, resid);
|
| Note: The actual checksum sent in the packet is
| generally the complement of the number returned.
| This (and the resid argument) are included so that
| scatter/gather operations may be used on packets.

.text

.globl	cksum

cksum:
	movl	d1,sp@-
	movl	d2,sp@-
	movl	a0,sp@-
	movl	sp@(16),a0
	movl	sp@(20),d1
	movl	sp@(24),d0
	movl	#0,d2
	subql	#1,d1

L1:	addw	a0@+,d0
	addxw	d2,d0
	dbf	d1,L1

	movl	sp@+,a0
	movl	sp@+,d2
	movl	sp@+,d1
	extl	d0
	rts


| This routine updates a 1's complement checksum. Its arguments
| are the old checksum and the difference between the new buffer
| and the old one; for example, if one modifies a single word,
| the value passed is (new-old).
|
| Calling sequence:
|
| int	diff, ocheck, ncheck;
|
| ncheck = acksum(diff, ocheck);

.globl	acksum

acksum:
	movl	d1,sp@-
	movl	#0,d1
	movl	sp@(12),d0
	addw	sp@(10),d0
	addxw	d1,d0
	extl	d0
	movl	sp@+,d1
	rts
