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:51:28 am PST
DIRECTORY
;
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. As written here, it requires that the sequence of halfwords to be checksummed begin on a word boundary. To do otherwise requires another Boolean argument for the 33rd (low order) address bit.
ComputeChecksumSoftware: PRIVATE PROC [
cs: CARD16 ← 0, nHalfWords: CARDINAL, p: POINTER]
RETURNS
[checksum: CARD16]
= INLINE {
FOR i: CARDINAL IN [0..nWords) DO
t: CARD16;
w: CARD16 = IF ODD[i] THEN LOOPHOLE[p^, Basics.LongNumber].lo ELSE LOOPHOLE[p^, Basics.LongNumber].hi;
cs ← ((cs ONESADD p^) LEFTROTATE 1)
IF cs > (t ← cs + w) THEN cs ← t + 1 ELSE cs ← t;
IF cs >= 100000B THEN cs ← cs*2 + 1 ELSE cs ← cs*2;
IF ODD[i] THEN p ← p + 1;
ENDLOOP;
IF cs = 177777B THEN cs ← 0;
RETURN[cs];
};
ComputeChecksumProc is machine code that efficiently implements the above.
ComputeChecksumProc: PRIVATE PROC [
cs: CARD16 ← 0, nHalfWords: CARDINAL, p: POINTER]
RETURNS
[checksum: CARD16]
= { NYI[] };
END.