*DECK LFGCKSM
IDENT LFGCKSM
COMMENT LFGCKSM - ROUTINE TO CALCULATE THE CHECKSUM
TITLE LFGCKSM - ROUTINE TO CALCULATE THE CHECKSUM
ENTRY LFGCKSM
*IF DEF,IMS
** LFGCKSM - CALCULATE CHECKSUM.
*
* JJ MCAFEE 75/07/01
* M. E. VATCHER 81/02/24
*
* LFGCKSM FORMS A CHECKSUM BY TAKING THE ONE"S COMPLEMENT OF
* THE INTEGER SUM OF N 16 BIT WORDS.
*
* LFGCKSM(BUFADD,BITPOS,NWDS,CKSM)
*
* ENTRY BUFADD ADDRESS OF BUFFER CONTAINING DATA
* BITPOS BIT POSITION (0-59) OF MOST SIGNIFICANT BIT OF
* FIRST WORD
* NWDS NUMBER OF 16 BIT WORDS TO CHECKSUM
*
* EXIT CKSM WORD WHERE CHECKSUM IS RETURNED, RIGHT JUSTIFIED
*
* METHOD
*
* GIVEN THE INPUT BUFFER DATA AND THE NUMBER OF 16 BIT WORDS
* IN THE BUFFER, CALCULATE THE CHECKSUM, MAPPING AND SHIFTING
* BITS AS NEEDED. REGISTERS USED: ALL B AND X REGISTERS, AND
* A1,A2,A4,A5,A6,A7.
*
*ENDIF
LFGCKSM DATA 0 ENTRY
B7=1
SB7 1
*
* PICK UP AND SAVE ENTRY PARAMETERS
*
SA2 X1 BUFFER ADDRESS ADDRESS
SA2 X2 BUFFER FWA
SA1 A1+B7
SA5 X1 STARTING BIT POSITION
SB2 X5 INTO B2
SA1 A1+B7
SA5 X1 NUMBER OF 16 BIT WORDS
SB3 X5 INTO B3
SA1 A1+B7 CKSUM STORAGE ADDRESS
SA5 X1 INTO A5
*
* FORM CONSTANTS AND SUCH
*
SB1 16
SB4 60 HANDY COUNT TO HAVE IN A 60 BIT MACHINE
MX6 0 CLEAR X6 FOR CHECKSUM
SB2 B2+B7 INCREMENT START BIT COUNT BY 1
LT B2,B1,SPEC WRAP AROUND START, SPECIAL PROCESS
*
*
* PICK UP WORDS AND DROP OUT 16 BIT CHECKSUM WORDS
*
*
CKS1 MX5 16 FORM MASK FOR 16 BIT WORD
LX5 B2,X5 SHIFT MASK
BX3 X5*X2 GET 16 BIT WORD FROM BUFFER
SB5 B4-B2 GET SHIFT COUNT TO POS. WORD IN LOW BITS
SB5 B5+B1
LX7 B5,X3 POSITION WORD IN LOW 16 BITS
IX6 X6+X7 INTEGER ADD FOR CHECKSUM
MX5 1 CHECK FOR OVERFLOW
LX5 17
BX5 X6*X5
ZR X5,CKS2 NONE, CONTINUE
MX5 44
BX6 -X5*X6 MASK OUT LOW 16 BITS
SX6 X6+B7 AND ADD IN OVERFLOW
*
* MOVE, SHIFT, REPOSITION AND START AGAIN
*
CKS2 SB3 B3-B7 SEE IF FINISHED
ZR B3,EXIT
SB2 B2-B1 DECREMENT START BY 16
GE B2,B1,CKS1 IF START .GE. 16, BACK TO MAIN LOOP
NZ B2,SPEC IF START .LT. 16, BUT .GT. 0, SPECIAL PROC.
SB2 B4 RESET START
SA2 A2+B7 GET NEXT BUFFER WORD
EQ CKS1 BACK TO MAIN LOOP
*
* SPECIAL PROCESSING FOR END WORD WRAPAROUND
*
SPEC MX5 16 FORM MASK
LX4 B2,X5 POSITION MASK
MX7 16
LX7 16 SET UP MASK MASK
BX4 X4*X7 NOW HAVE MASK FOR LOW BITS OF WD 1
BX3 X4*X2 GET LOW BITS
SB5 B1-B2 SEE HOW MANY TO MOVE
LX3 B5,X3 MOVE LOWER BITS TO ALLOW FOR UPPER BITS
LX5 B2,X5 POSITION MASK FOR UPPER BITS
BX5 -X7*X5 REMOVE ALL BUT UPPER BITS
SA2 A2+B7 GET NEW BUFFER WORD
BX4 X5*X2 AND PICK UP UPPER BITS
LX4 B5,X4 MOVE TO LOW POSITION
BX7 X3+X4 ADD TO UPPER BITS
IX6 X6+X7 INTEGER ADD FOR CHECKSUM
MX5 1 CHECK FOR OVERFLOW
LX5 17
BX5 X6*X5
ZR X5,SPEC1 NONE, CONTINUE
MX5 44
BX6 -X5*X6 MASK OUT LOW 16 BITS
SX6 X6+B7 AND ADD IN OVERFLOW
*
* RESET EVERYTHING
*
SPEC1 SB3 B3-B7
ZR B3,EXIT EXIT IF FINISHED
SB2 B4-B5 RESET B2 FOR NEXT WORD
EQ CKS1 GO BACK TO MAIN LOOP
*
* FINISHED, STORE CHECKSUM AND EXIT
EXIT MX7 16 TAKE COMPLEMENT OF SUM
LX7 16
BX6 -X6*X7
SA6 A5
EQ LFGCKSM
END