Google
 

Trailing-Edge - PDP-10 Archives - BB-H580E-SB_1985 - dpdiv.mac
There are 7 other files named dpdiv.mac in the archive. Click here to see a list.
; UPD ID= 2056 on 10/24/79 at 3:08 PM by WRIGHT                         
TITLE	DPDIV FOR LIBOL V12C
SUBTTL	DOUBLE PRECISION DIVIDES		AL BLACKINGTON/CAM



	SEARCH	COPYRT
	SALL

;COPYRIGHT (C) DIGITAL EQUIPMENT CORPORATION 1974, 1985
;ALL RIGHTS RESERVED.
;
;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
;ONLY  IN  ACCORDANCE  WITH  THE  TERMS  OF  SUCH LICENSE.

;DMN	21-SEP-79	[606] FIX 4-WORD DIVIDE WHEN SIGN IS DIFFERENT
;V10******
;	5/10/75		/DBT	ADD BIS CODE
;***********

	SEARCH	LBLPRM
	%%LBLP==:%%LBLP
	BIS==:BIS

	HISEG

	.COPYRIGHT		;Put COPYRIGHT statement in .REL file.

ENTRY DIV.12	;DIVIDE ONE WORD BY TWO WORDS
ENTRY DIV.21	;DIVIDE TWO WORDS BY ONE WORD
ENTRY DIV.22	;DIVIDE TWO WORDS BY TWO WORDS
IFN BIS,<
ENTRY DIV.41	;DIVIDE FOUR WORDS BY ONE WORD
ENTRY DIV.42	;DIVIDE FOUR WORDS BY TWO WORDS
ENTRY DVI41.	;DIVIDE FOUR WORDS BY ONE WORD, SAVE REMAINDER
ENTRY DVI42.	;DIVIDE FOUR WORDS BY ONE WORD, SAVE REMAINDER
>

;CALLING SEQUENCE:
;	MOVE	16,[Z AC,OPERAND]
;	PUSHJ	17,DIV.12/DIV/21/DIV.22

;ENTER WITH DIVIDEND IN ACCUMULATORS AC&AC+1 FOR DIV.21&DIV.22,
;	AND ACCUMULATOR AC FOR DIV.12.
;EXIT WITH QUOTIENT IN AC'S AC&AC+1,
; REMAINDER IN AC+2&AC+3 FOR DIV.12, DIV.22,  REMAINDER IN AC+2 FOR DIV.21

FSIGN==1B18	;SIGN FLAG JAMMED INTO PA


EXTERNAL OVFLO.
H1=13
H2=14
Q=4
QI=16
PA=16
PP=17

RS=15
TA=5
TB=TA+1
TC=TB+1
TD=TC+1
TE=TD+1

IFE	BIS,<

DIV.21:	SKIPN	TD,0(PA)	;IS DIVISIOR ZERO?
	JRST	OVRFLO		;YES--SIZE ERROR

	LDB	RS,[POINT 4,PA,12]; GET OPERAND AC
	PUSH	PP,	(RS)		;DO IT THIS WAY SO WE DON'T
	MOVE	TB,	1(RS)		; WIPE OUT THE FIRST WORD
	POP	PP,	TA		; OF THE OPERAND.

	PUSHJ	PP,DIV21X	;DO THE DIVISION

	MOVEM	TA,0(RS)	;STASH HIGH PART
	MOVEM	TB,1(RS)	;STASH LOW PART
	MOVEM	TC,2(RS)	;STASH REMAINDER
	POPJ	PP,
DIV.12:	LDB	RS,[POINT 4,PA,12]; GET OPERAND AC
	MOVE	TA,0(RS)	;GET OPERAND
	MULI	TA,1		;CONVERT TO DOUBLE PRECISION
	JRST	DIV220

DIV.22:	LDB	RS,[POINT 4,PA,12]; GET OPERAND AC
	PUSH	PP,	(RS)		;DO IT THIS WAY SO WE DON'T
	MOVE	TB,	1(RS)		; WIPE OUT THE FIRST WORD
	POP	PP,	TA		; OF THE OPERAND.

DIV220:	SKIPGE	TD,0(PA)	;IS DIVISOR NEGATIVE?
	JRST	DIV22B		;YES

	MOVE	TE,1(PA)	;NO--GET LOW-ORDER PART OF DIVISOR

DIV22A:	TLZ	TE,1B18		;INSURE LOW-ORDER PART OF DIVISOR IS POSITIVE

	JUMPN	TD,DIV22C	;IS HI-ORDER PART OF DIVISOR ZERO?
	JUMPE	TE,OVRFLO	;YES--IS LOW-ORDER PART ZERO ALSO?

	TLNN	RS,FSIGN	;POSITIVE SIGN?
	SKIPA	TD,TE		;YES
	MOVN	TD,TE		;NO

	PUSHJ	PP,DIV21X	;DO THE DIVIDE

	MULI	TC,1		;CONVERT REMAINDER TO 2-WORDS
	MOVEM	TA,0(RS)	;STASH
	MOVEM	TB,1(RS)	;  QUOTIENT
	MOVEM	TC,2(RS)	;STASH
	MOVEM	TD,3(RS)	;  REMAINDER
	POPJ	PP,

DIV22B:	SETCA	TD,		;DIVISOR IS NEGATIVE--GET MAGNITUDE
	TLO	RS,FSIGN	;SET SIGN TO NEGATIVE
	MOVE	TE,1(PA)	;GET LOW-ORDER PART OF DIVISOR
	TLO	TE,1B18		;BE SURE IT'S ALSO NEGATIVE
	MOVMS	TE		;GET IT'S MAGNITUDE
	JUMPG	TE,DIV22A	;IF POSITIVE NOW--OK

				;MUST HAVE BEEN ZERO
	AOJGE	TD,DIV22A	;IF HI-ORDER NOW POSITIVE--OK

	JRST	OVRFLO		;IT WASN'T--TROUBLE
;DIVIDEND IS NOW UNSIGNED IN TA&TB, DIVISOR UNSIGNED IN TD&TE

DIV22C:	JUMPGE	TA,DIV22E	;IS DIVIDEND POSITIVE?
	TLC	RS,FSIGN	;NO--COMPLEMENT SIGN OF RESULT
	SETCA	TA,		;COMPLEMENT HI-ORDER PART OF DIVIDEND
	TLO	TB,1B18		;BE SURE LOW-PART AGREES IN SIGN
	MOVMS	TB		;NOW GET IT'S MAGNITUDE

	JUMPG	TB,DIV22F	;WAS LOW-ORDER PART ZERO?
				;YES--BUMP HI-ORDER PART
	AOJL	TA,OVRFLO	;TOO BIG?
DIV22E:	TLZ	TB,1B18		;BE SURE LOW-ORDER PART IS POSITIVE

DIV22F:	MOVE	H1,TA		;SAVE DIVIDEND
	MOVE	H2,TB

	IDIV	TA,TD		;DIVIDE HIGH-ORDER PARTS
	MOVE	Q,TA		;SAVE QUOTIENT
	SKIPA	QI,Q		;CREATE FIRST INCREMENT

DIV22G:	MOVE	TA,Q
	LSH	QI,-1		;DIVIDE INCREMENT BY 2
	SKIPN	QI		;SAFETY
	MOVEI	QI,1		;	VALVE

	MOVE	TB,TA		;COMPUTE
	IMUL	TA,TD		; Q
	MUL	TB,TE		; TIMES
	ADD	TA,TB		; DIVISOR

	SUBM	H1,TA		;COMPUTE
	SUBM	H2,TC		; REMAINDER
	SKIPGE	TC
	SUBI	TA,1
	TLZ	TC,1B18

	JUMPL	TA,DIV22I	;IS REMAINDER NEGATIVE?
	CAMG	TA,TD		;NO--IS IT GREATER THAN DIVISOR?
	JRST	DIV22J		;MAYBE

DIV22H:	ADD	Q,QI		;REMAINDER GREATER THAN DIVISOR, TRIAL QUOTIENT TOO SMALL
	JRST	DIV22G

DIV22I:	SUB	Q,QI		;REMAINDER NEGATIVE, TRIAL QUOTIENT TOO BIG
	JRST	DIV22G

DIV22J:	CAME	TA,TD
	JRST	DIV22K
	CAML	TC,TE
	JRST	DIV22H
;ANSWER TO DIV.22 HAS BEEN FOUND


DIV22K:	SKIPL	0(RS)		;IS DIVIDEND NEGATIVE?
	JRST	DIV22N		;NO
	SETCA	TA,		;YES--NEGATE REMAINDER
	MOVNS	TC
	TLZ	TC,1B18
	SKIPN	TC
	ADDI	TA,1

DIV22N:	MOVE	TD,Q		;GET QUOTIENT
	TLNE	RS,FSIGN	;NO--IS SIGN TO BE NEGATIVE?
	MOVNS	TD
	MULI	TD,1

DIV22L:	SKIPL	TA		;IS REMAINDER NEGATIVE?
	TLZA	TC,1B18		;NO--FORCE LOW-PART TO BE POSITIVE
	TLO	TC,1B18		;YES--FORCE LOW-PART TO BE NEGATIVE

DIV22P:	SKIPL	TD
	TLZA	TE,1B18
	TLO	TE,1B18

	MOVEM	TD,0(RS)	;STASH
	MOVEM	TE,1(RS)	;  QUOTIENT
	MOVEM	TA,2(RS)	;STASH
	MOVEM	TC,3(RS)	;  REMAINDER

	POPJ	PP,

;DO DIVIDE OF 2-WORD BY 1-WORD. DIVIDEND IN TA&TB, DIVISIOR IN TD.
;RETURN WITH QUOTIENT IN TA&TB, REMAINDER IN TC.

DIV21X:	JUMPGE	TA,DIV21Y	;POSITIVE DIVIDEND?
	SETCA	TA,		;NO--
	MOVMS	TB		;  GET
	TLZ	TB,1B18		;  MAGNITUDE
	SKIPN	TB		;  OF
	ADDI	TA,1		;  DIVIDEND

	PUSHJ	PP,DIV21Y	;DO DIVISION

	MOVNS	TC		;NEGATE REMAINDER
	SETCA	TA,		;NEGATE
	MOVNS	TB
	TLZ	TB,1B18		;  THE
	SKIPN	TB		;  DOUBLE
	ADDI	TA,1		;  PRECISION
	TLNE	TA,1B18
	TLO	TB,1B18		;  QUOTIENT

	POPJ	PP,

DIV21Y:	TLZ	TB,1B18		;BE SURE LOW-SIGN AGREES
	MOVE	TC,TB		;SAVE LOW-PART
	IDIV	TA,TD		;GET HIGH-PART OF QUOTIENT
	DIV	TB,TD		;GET LOW-PART OF QUOTIENT
	SKIPGE	TB
	SUBI	TA,1

	POPJ	PP,

>	;END OF NON-BIS
;DIVISION OVERFLOW -- SET INDICATOR

OVRFLO:	SETOM	OVFLO.
	POPJ	PP,

IFN	BIS,<

DIV.21:	MOVE	H1,(PA)			;GET OPERAND
	ASHC	H1,-^D35		;EXTEND SIGN
	LDB	RS,PACFL.##		;GET AC FIELD
	DMOVE	TC,(RS)			;GET SECOND OPERAND
	MOVE	TA,TC			;PROPAGATE THE SIGN
	ASHC	TA,-^D70
	JOV	.+1			;CLEAR OVERFLOW.
	DDIV	TA,H1			;DIVIDE
	JOV	OVRFLO			;CHECK OVERFLO
	DMOVEM	TA,(RS)			;STORE RESULT
	MOVEM	TD,2(RS)		;AND REMAINDER
	POPJ	PP,

DIV.12:	LDB	RS,PACFL.##			;GET AC
	MOVE	TD,(RS)			;GET OP 1
	MOVE	TA,TD			;PROPAGATE THE SIGN.
	ASHC	TA,-^D70
	MOVE	TC,TA
	JOV	.+1			;CLEAR OVERFLOW.
	DDIV	TA,(PA)
	JOV	OVRFLO
	DMOVEM	TA,(RS)			;STORE QUOTIENT
	DMOVEM	TC,2(RS)		;AND REMAINDER
	POPJ	PP,

DIV.22:	LDB	RS,PACFL.##		;GET AC
	DMOVE	TC,(RS)			;GET OP
	MOVE	TA,TC			;PROPAGATE THE SIGN.
	ASHC	TA,-^D70
	JOV	.+1			;CLEAR OVERFLOW.
	DDIV	TA,(PA)
	JOV	OVRFLO
	DMOVEM	TA,(RS)
	DMOVEM	TC,2(RS)
	POPJ	PP,

;DIVIDES THE FOUR WORD INTEGER IN ACC 0-3
;LEAVING THE QUOTIENT IN ACC 0-3, REMAINDER IN ACC 4&5

DIV.41:	MOVE	H1,(PA)		;GET OPERAND
	ASHC	H1,-^D35	;EXTEND SIGN
	JRST	DIV.4X		;COMMON CODE

DIV.42:	DMOVE	H1,(PA)		;INCASE (PA) = 6
DIV.4X:	DMOVE	4,2		;COPY LOW ORDER 2 WORDS
	DMOVE	2,0		;COPY HIGH ORDER 2 WORDS
	ASHC	0,-^D70		;EXTEND THE SIGN
	JOV	.+1		;CLEAR OVERFLOW.
	DDIV	0,H1		;DIVIDE HIGH ORDER 2 WORDS
	JOV	OVRFLO
	DDIV	2,H1		;AND LOW ORDER
	JUMPN	0,RET.1##	;[606] IF THE HIGH ORDER PART
	JUMPN	1,RET.1		;[606]  IS ZERO
	JUMPGE	2,RET.1		;[606] BUT THE LOW ORDER PART IS NEGATIVE
	SETOB	0,1		;[606] EXTEND THE SIGN
	POPJ	PP,
;ROUTINES CALLED BY:
;	MOVEI	15,<ADDRESS.OF.FOUR-WORD.NUMBER>
;	MOVEI	16,[POWER OF 10]
;	PUSHJ	PP,ROUTINE
;	<RETURN HERE>, WITH 2-WORD REMAINDER SAVED IN 0(15) AND 1(15).

DVI41.:	MOVE	H1,(PA)		;GET OPERAND
	ASHC	H1,-^D35	;EXTEND SIGN
	JRST	DIVI4X

DVI42.:	DMOVE	H1,(PA)		;GET OPERAND

;USE 6 ACS - 4 THRU 11
;AC15 WILL EITHER POINT TO AC0, OR %TEMP

DIVI4X:	DMOVE	10,2(15)	;COPY LOW ORDER 2 WORDS
	DMOVE	6,(15)		;COPY HIGH ORDER 2 WORDS
	ASHC	4,-^D70		;EXTEND THE SIGN
	JOV	.+1		;CLEAR OVERFLOW
	DDIV	4,H1		;DIVIDE HIGH ORDER 2 WORDS
	JOV	OVRFLO
	DDIV	6,H1		;AND LOW ORDER
	DMOVEM	10,(15)		;SAVE REMAINDER
	POPJ	PP,		;RETURN


>	;END OF BIS

END