
/COPYRIGHT 1969, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/DIV
/DIVIDE A SIGNED 36-BIT DIVIDEND BY A SIGNED 18-BIT
/DIVISOR.  NEGATIVE ARGUMENTS MUST BE IN 2'S
/COMPLEMENT NOTATION.
/
/CALLING SEQUENCE:
/	LAC HIGH-ORDER DIVIDEND
/	JMS DIV
/	LAC LOW-ORDER DIVIDEND
/	LAC DIVISOR
/	NEXT INSTRUCTION		/RETURN IS MADE HERE
/
/RESULTS:C(AC) = QUOTIENT, C(%REM) = REMAINDER, LINK = 0
/
/
/RESTRICTIONS:IF THE MAGNITUDE OF THE HO DIVIDEND IS GREATER OR EQUAL TO
/	THE DIVISOR, THE LINK IS SET ON WITH NO DIVISION TAKING PLACE;
/	OTHERWISE, THE LINK IS SET TO 0.
/
DIV	0		/HIGH ORDER DIVIDEND IN AC
	SPA!CLL		/IS DIVIDEND POSITIVE?  ALWAYS CLEAR LINK
	CMA!CML		/NO, COMPLEMENT AC AND LINK
	DAC	%REM	/STORE HIGH-ORDER DIVIDEND
	JMS	%SDV5	/SAVE LINK WHICH HAS
%SDV5	0		/THE SIGN OF THE REMAINDER
	XCT*	DIV	/FETCH LOW ORDER DIVIDEND
	SZL		/WAS HIGH ORDER DIVIDEND POSITIVE?
	JMS	%SDNEG	/NO...MAKE LOW ORDER DIVIDEND POSITIVE
	DAC	%SQUO
/
/IF THE LINK BIT IS ON FROM NEGATING THE LOW ORDER DIVIDEND THE
/HIGH ORDER DIVIDEND WILL HAVE TO BE INCREMENTED.
/IF THE LINK BIT IS NOT ON INCREMENT LOCATION-DIV AND FETCH
/THE DIVISOR.
/
	SPL!CLL		/SKIP IF LINK NOT ON
	ISZ	%REM	/INCREMENT HIGH ORDER DIVIDEND
	NOP
/
	ISZ	DIV	/POINTER TO NEXT ARGUMENT
	XCT*	DIV	/FETCH DIVISOR
	DAC	%SDVS	/SAVE DIVISOR
	XOR	%SDV5	/EXCLUSIVE OR TO GET SIGN OF QUOTIENT
	DAC	%SDV4	/SAVE SIGN OF QUOTIENT
	LAC	%SDVS
	SMA		/SKIP IF ALREADY NEGATIVE
	JMS	%SDNEG	/NEGATE
	DAC	%SDVS	/DIVISOR
/
/NOW  COMPARE THE HIGH ORDER DIVIDEND (%SDVD)
/AND THE DIVISOR (%SDVS).  IF THE DIVIDEND IS GREATER THAN OR EQUAL
/TO THE DIVISOR EXIT WITH LINK = 1
/
	TAD	%REM	/ADD DIVIDEND
	ISZ	DIV	/INCREMENT TO EXIT ADDRESS
	SMA!CLA!STL	/DIVIDEND .GE. DIVISOR?
	JMP	%SDV0	/YES...RETURN WITH LINK SET TO 1
	LAW	-23	/SET UP LOOP COUNTER TO
	DAC	%SDV1	/PREPARE FOR DIVISION
	CLL
	JMP	%SDV2
/
%SDV3	LAC	%REM	/FETCH DIVIDEND
	RAL		/PICK UP NEXT BIT OF LOW DIVIDEND
	DAC	%REM	/SAVE DIVIDEND FOR NEXT TIME
	TAD	%SDVS	/ADD NEGATIVE DIVISOR
	SZL		/DIVIDEND GREATER THAN OR EQUAL TO DIVISOR?
	DAC	%REM	/YES...SAVE NEW DIVIDEND
/
/THE LINK BIT IS 1 IF DIVISIBLE, 0 OTHERWISE.  ROTATE THE
/LINK BIT INTO THE RIGHT SIDE OF %QUO (THIS BUILDS THE QUOTIENT).
/ROTATE THE NEXT BIT OF THE HIGH DIVIDEND FROM THE LEFT
/SIDE OF %QUO.
/
%SDV2	LAC	%SQUO	/LINK TO BIT 17 OF %QUO AND
	RAL		/BIT 0 TO LINK
	DAC	%SQUO	/BUILD QUOTIENT
	ISZ	%SDV1	/ARE WE FINISHED?
	JMP	%SDV3	/NO...LOOP AGAIN
	LAC	%SDV5	/FETCH REMAINDER SIGN BIT
	RAL		/ROTATE SIGN BIT INTO LINK
	LAC	%REM	/FETCH REMAINDER
	SZL		/SKIP IF POSITIVE
	JMS	%SDNEG	/NEGATE THE REMAINDER
	DAC	%REM
/
/PLACE SIGNED QUOTIENT IN AC AND EXIT
/
	LAC	%SDV4	/FETCH QUOTIENT SIGN BIT
	RAL		/SIGN BIT TO LINK
	LAC	%SQUO	/FETCH QUOTIENT
	SZL		/SKIP, CLEAR LINK, AND EXIT
	JMS	%SDNEG
	SKP!CLL
%SDV0	DZM	%REM
	JMP*	DIV
%SDVS	0
%REM	0
%SQUO	0
%SDV4	0
%SDV1	0
/
%SDNEG	0		/NEGATE ACCUMULATOR
	CMA!CLL		/COMPLEMENT ACCUMULATOR AND
	TAD	(1	/CLEAR LINK
	JMP*	%SDNEG	/RETURN
	.EOT
*U*?/2