/COPYRIGHT 1970, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
	/EDIT 06P  10-14-70
       .TITLE INTEGER ARITHMETIC LIBRARY ROUTINES
       .GLOBL EOJ
       .GLOBL .AD,.AE,.AF,.AY,.AZ,.CO
	.GLOBL INTEGE,INTNON
INTEGE=.
INTNON=.
TCA=CMA!IAC
	.IFDEF TIME%
	.GLOBL TIMON,TIMOFF
	.ENDC
/
/	    CONTENTS
/	    .AD	         INTEGER MULTIPLICATION
/	    .AE	         INTEGER DIVISION
/	    .AF	         REVERSE INTEGER DIVISION
/	    .AY	         INTEGER SUBTRACTION
/	    .AZ	         REVERSE INTEGER SUBTRACTION
/	    .CO	         INTEGER REMAINDER FROM .AE OR .AF (ABOVE)
       .EJECT
/		     INTEGER MULTIPLICATION  (.AD)
/	    CALLING SEQUENCE
/      JMS*   (.AD) 	SUBR CALL  (-A- REG CONTAINS MULTIPLICAND
/      LAC(*) ADDR		ADDR OF MULTIPLIER (LAC* IF INDIRECT)
/      NEXT   INSTRUCTION	SUB RETURN (PRODUCT IN -A- REG)
/
.AD    CAL    0	         /ENTRY-EXIT
	.IFDEF TIME%
	JMS* TIMON
	.DSA 1
	.ENDC
       DAC    INT03          /STORE MULTIPLICAND
       SPA	         /CHECK SIGN
       TCA	         /IF NEG, COMPLEMENT IT
AD01   RCL	         /B0 TO LINK
       DAC    INT04          /STORE ABSOLUTE MULTIPLICAND (X2)
	CMA		/STORE NEG. OF
	DAC INT06		/MULTIPLICAND
       XCT*   .AD	         /GET MULTIPLIER
       ISZ    .AD	         /BUMP EXIT ADDR
       DAC    INT05          /STORE MULTIPLIER
       SPA	         /CHECK SIGN
       TCA	         /IF NEG, COMPLEMENT MULTIPLIER
AD02   DZM    INT02          /CLEAR PRODUCT
	DAC INT07	/STORE ABSOLUTE VAL OF MULTIP.
	TAD INT06	/SWITCH LARGEST
	SPA		/FACTOR TO
	JMP .+7		/MULTIPLICAND
	LAC INT07
	DAC INT06
	LAC INT04
	DAC INT07
	LAC INT06
	DAC INT04
	LAC INT07		/RELOAD
AD03   SNA!CLL!RAR	         /IS MULIPLIER ZERO SHIFT MULTIPLIER (0 TO B0)
       JMP    AD04	         /YES-DO SIGN CONTROL AND EXIT
       DAC    INT06          /STORE NEW MULTIPLIER
       SNL	         /WAS B17 SET (LINK NON-ZERO)
       JMP    AD05	         /NO-DO NOT ADD MULTIPLICAND TO PRODUCT
       LAC    INT04          /YES, GET ABSOLUTE MULTIPLICAND
       TAD    INT02          /ADD TO PRODUCT
       DAC    INT02          /STORE PRODUCT
AD05   LAC    INT04          /SHIFT MULTIPLICAND LEFT
       RCL	         / FOR NEXT ADDITION
       DAC    INT04
       LAC    INT06          /GET NEW MULTIPLIER
       JMP    AD03	         /CYCLE
AD04   LAC    INT03          /GET ORIGINAL MULTIPLICAND
       XOR    INT05          /XOR W/ORIGINAL MULTIPLIER
       RAL	         /TEST FOR SIGNS ALIKE
       LAC    INT02          /YES-GET PRODUCT
       RCR!SZL	         /SHIFT IN POSITIVE SIGN
	TCA
	.IFDEF TIME%
	JMS* TIMOFF
	.DSA 1
	.ENDC
       JMP*   .AD	         /EXIT
       TCA	         /TWO@S COMPLEMENT
       .EJECT
/		     INTEGER DIVISION   (.AE)
/	    CALLING SEQUENCE
/      JMS*   (.AE) 	SUBR CALL (-A- REG CONTAINS DIVIDEND)
/      LAC(*) ADDR		ADDR OF DIVISOR (LAC* IF INDIRECT)
/      NEXT   INSTRUCTION	SUBR RETURN (QUOTIENT IN -A- REG)
/				  (REMAINDER IN GLOBL .CO)
.AE    CAL    0	         /ENTRY-EXIT
	.IFDEF TIME%
	JMS* TIMON
	.DSA 2
	.ENDC
       DAC    INT04          /STORE ORIG DIVIDEND
       SMA	         /TEST SIGN
       JMP    AE01	         /(POS)
       TCA	         /NEG-TAKE TWO@S COMP
AE01   DAC    INT03          /STORE ABSOLUTE DIVIDEND IN QUOTIENT
       XCT*   .AE	         /GET DIVISOR
       ISZ    .AE	         /BUMP EXIT
       DAC    INT05          /STORE ORIGINAL DIVISOR
       SMA	         /MAKE DIVISOR
       TCA
AE02   SNA	         /EXIT IF DIVISOR IS ZERO
	.IFUND TIME%
	JMP* .AE
	.ENDC
	.IFDEF TIME%
	JMP .CO-3
	.ENDC
       DAC    INT06          /STORE NEGATIVE DIVISOR
       DZM    .CO	         /CLEAR REMAINDER
       LAW    -22	         /SET COUNTER FOR 18 BITS
       DAC    INT02
AE03   LAC    INT03          /SHIFT QUOTIENT + REMAINDER LEFT 1 BIT
       RCL
       DAC    INT03
       LAC    .CO
       RAL
       DAC    .CO
       TAD    INT06          /SUBTRACT DIVISOR FROM REMAINDER
       SPA	         /IF NEG, DO NOT ADD TO QUOTIENT
       JMP    AE04
       DAC    .CO	         /STORE POS DIFF IN REMAINDER
       ISZ    INT03          /ADD ONE TO QUOTIENT
AE04   ISZ    INT02
       JMP    AE03	         /CYCLE 18 TIMES
       LAC    INT04          /DONE-SET SIGN - GET ORIG DIVIDEND
       XOR    INT05          /XOR W/ORIGINAL DIVISOR
       RAL	         /SET OR CLEAR LINK
       LAC    INT03          /GET QUOTIENT
       SZL	         /IF SIGNS ALIKE, EXIT
	TCA		/IF DIFFERENT, COMPLEMENT QUOTIENT
	.IFDEF TIME%
	JMS* TIMOFF
	.DSA 2
	.ENDC
       JMP*   .AE	         /EXIT
.CO    CAL    0	         /REMAINDER
       .EJECT
/		     REVERSE INTEGER DIVISION (.AF)
/	    CALLING SEQUENCE
/      JMS*   (.AF) 	SUBR CALL (A-REG CONTAINS DIVISOR)
/      LAC(*) ADDR		ADDR OF DIVIDEND (LAC* IF INDIRECT)
/      NEXT   INSTRUCTION	SUBR RETURN (QUOTIENT IN A-REG)
/				  (REMAINDER IN GLOBL .CO)
.AF    CAL    0	         /ENTRY-EXIT
	.IFDEF TIME%
	JMS* TIMON
	.DSA 3
	.ENDC
       DAC    INT05	         /STORE DIVISOR
       XCT*   .AF	         /LOAD DIVIDEND
       JMS    .AE	         /INTEGER DIVIDE (.AE)
       LAC    INT05
       ISZ    .AF	         /BUMP EXIT
	.IFDEF TIME%
	JMS* TIMOFF
	.DSA 3
	.ENDC
       JMP*   .AF	         /EXIT
       .EJECT
/		     INTEGER SUBTRACTION  (.AY)
/	    CALLING SEQUENCE
/      JMS*   (.AY) 	SUBR CALL (A-REG CONTAINS THE MINUEND)
/      LAC(*) ADDR		ADDR OF SUBTRAHEND (LAC* IF INDIRECT)
/      NEXT   INSTRUCTION	SUBR RETURN (DIFFERENCE IN A-REG)
/
.AY    CAL    0	         /ENTRY EXIT
	.IFDEF TIME%
	JMS* TIMON
	.DSA 4
	.ENDC
       DAC    INT02          /STORE MINUEND
       XCT*   .AY	         /GET SUBTRAHEND
       TCA	         /NEGATE
       TAD    INT02          /COMBINE (MINUEND - SUBTRAHEND)
       ISZ    .AY	         /BUMP EXIT
	.IFDEF TIME%
	JMS* TIMOFF
	.DSA 4
	.ENDC
       JMP*   .AY	         /EXIT
       .EJECT
/		     REVERSE INTEGER SUBTRACTION (.AZ)
/	    CALLING SEQUENCE
/      JMS*   (.AZ) 	SUBR CALL (A-REG CONTAINS THE SUBTRAHEND)
/      LAC(*) ADDR		ADDR OF MINUEND (LAC* IF INDIRECT)
/      NEXT   INSTRUCTION	SUBR RETURN (DIFFERENCE IN A-REG)
/
.AZ    CAL    0	         /ENTRY-EXIT
	.IFDEF TIME%
	JMS* TIMON
	.DSA 5
	.ENDC
       TCA	         /NEGATE SUBTRAHEND
       DAC    INT02          /STORE IT
       XCT*   .AZ	         /GET MINUEND
       ISZ    .AZ	         /BUMP EXIT
       TAD    INT02          /COMBINE (MINUEND - SUBTRAHEND)
	.IFDEF TIME%
	JMS* TIMOFF
	.DSA 5
	.ENDC
       JMP*   .AZ	         /EXIT
       .EJECT
/		     INTEGER STORAGE AND CONSTANTS
/
INT02  CAL    0	         /STORAGE
INT03  CAL    0	         /STORAGE
INT04  CAL    0	         /STORAGE
INT05  CAL    0	         /STORAGE
INT06  CAL    0	         /STORAGE
INT07	CAL 0		/STORAGE
EOJ
       .END
