Checksum.mesa
For Dragon
Copyright © 1985 by Xerox Corporation. All rights reserved.
Forrest, October 4, 1980 2:03 PM
Russ Atkinson (RRA) January 29, 1985 0:37:17 am PST
Doug Wyatt, February 26, 1985 2:50:29 pm PST
Carl Hauser, October 28, 1986 11:17:50 am PST
Checksum: DEFINITIONS
= BEGIN
ComputeChecksum:
PROC [
cs:
CARD16 ← 0, nHalfWords:
CARDINAL, p:
POINTER]
RETURNS [checksum:
CARD16]
= ComputeChecksumProc[cs, nHalfWords, p];
... produces a checksum for nWords starting at p. Start with initial value cs (useful if forming a single checksum for discontinuous areas of memory). Note that since these checksums must agree with those computed in the existing world they are 16 bit checksums computed over an integral number of 16 bit halfwords, even though Dragon is a 32 bit machine.
I would like to add a mathematical definition of the checksum being computed-- chh.
ComputeChecksumSoftware is provided as documentation.
ComputeChecksumSoftware:
PRIVATE
PROC [
cs:
CARD16 ← 0, nHalfWords:
CARDINAL, p:
POINTER]
RETURNS [checksum:
CARD16]
= INLINE {
This fragment has not yet been converted for Dragon.
THROUGH [0..nWords)
DO
t: CARD16;
cs ← ((cs ONESADD p^) LEFTROTATE 1)
IF cs > (t ← cs + p^) THEN cs ← t + 1 ELSE cs ← t;
IF cs >= 100000B THEN cs ← cs*2 + 1 ELSE cs ← cs*2;
p ← p + 1;
ENDLOOP;
IF cs = 177777B THEN cs ← 0;
RETURN[cs];
};
ComputeChecksumProc is provided as an aid to processors required to compute checksum as part of their unimplemented instruction trap.
ComputeChecksumProc:
PRIVATE
PROC [
cs:
CARD16 ← 0, nHalfWords:
CARDINAL, p:
POINTER]
RETURNS [checksum:
CARD16]
END.