Trailing-Edge
-
PDP-10 Archives
-
decuslib10-01
-
43,50161/madd.mp
There are no other files named madd.mp in the archive.
TITLE MADD MULTIPLE PRECISION ADDITION AND SUBTRACTION ROUTINES
SUBTTL V1 UWO 16-NOV-70
ENTRY MADD,MSUB
EXTERN MSHIFT,MNORM
MSUB: Z
MOVNS @1(16) ;NEGATE 2ND ARGUMENT
SKIPA
MADD: Z
MOVEM 17,STORE+17 ;SAVE
MOVEI 17,STORE ;THE
BLT 17,STORE+16 ;AC'S
MOVE 1,(16) ;AC1=ADDR OF FIRST CHARACTERISTIC WORD
MOVE 2,1(16) ;AC2=ADDR OF SECOND CHARACTERISTIC WORD
MOVE 0,@2(16) ;AC0=PRECISION
CAILE 0,200
JRST EROUT
SKIPN 0,1(1)
JRST ZERO ; WORD1 IS 0
SKIPN 0,1(2)
JRST ZERO1 ; WORD 2 IS 0
MOVEI 3,TEMP1
ADD 3,0
HRLZ 4,1
HRRI 4,TEMP1
BLT 4,(3)
MOVEI 3,TEMP2
ADD 3,0
HRLZ 4,2
HRRI 4,TEMP2
BLT 4,(3)
HRRZI 1,TEMP1
HRRZI 2,TEMP2
MOVE 3,3(16) ;AC3=CHAR WORD OF RESULT, ADDR.
MOVE 13,(1) ;AC13=FIRST CHARACTERISTIC WORD
MOVE 14,(2) ;AC14=SECOND CHARACTERISTIC WORD
SETZ 6,
JUMPG 13,.+3
MOVN 13,13 ;AC13=ABSOLUTE VALUE OF FIRST CHARACTERISTIC
AOJ 6, ;AC6=ONE MEANS FIRST CHAR NEGATED
JUMPG 14,.+3
MOVN 14,14 ;AC14=ABSOLUTE VALUE OF SECOND CHARACTERISTIC
SOJ 6, ;AC6 MINUS ONE MEANS SECOND CHAR NEGATED
CAMN 13,14 ;IF NOT EQUAL MUST SHIFT THE SMALLER NO.
JRST CHKSN
SUB 13,14
MOVE 15,13 ;IF THE DIFFERENCE BETWN THE ABSOLUTE
JUMPG 15,.+2 ;VALUES OF THE CHARACTERISTICS IS SO LARGE
MOVN 15,15 ;THAT THE SMALLER NO. IS SHIFTED OUT COMPLETELY
MOVE 14,0 ;THEN TAKE AN ERROR RETURN TO THE
IMULI 14,43 ;CALLING PROGRAM
SUB 14,15
JUMPG 14,CONT
MOVM 13, (1)
MOVM 14, (2)
CAMG 13, 14
JRST ZERO
JRST ZERO1
EROUT: HRLZI 17,STORE
BLT 17,17 ;RESTORE THE AC'S AND ERROR EXIT.
JRA 16,4(16)
CONT: JUMPL 13,.+4
MOVNM 13,SHIFT+3;SHIFT+3 IS NO. OF BITS AND DIRECTION
MOVEM 2,SHIFT+1
JRST SHIFT
MOVEM 13,SHIFT+3;AND SHIFT+1 IS ADDR OF SMALLER CHARACTERISTIC
MOVEM 1,SHIFT+1
SHIFT: JSA 16,MSHIFT
EXP 0,0,0
CHKSN: MOVE 16,0 ;IF SIGNS DIFF NEGATE SMALLER NO. AND ADD
MOVE 10,1
MOVE 11,2
COMP: AOJ 10,0 ;AC10=FIRST FRAC WORD FIRST NO. , ADDR
AOJ 11,0 ;AC11=ADDR FIRST FRAC, SEC NO
MOVE 12,(10) ;AC12=FIRST FRAC WORD FIRST NO.
CAMN 12,(11) ;TESTING FOR SMALLER ABS FRACTION
SOJG 16,COMP
CAML 12,(11)
JRST .+4
MOVE 13,1
MOVE 14,2
JRST .+3
MOVE 13,2 ;AC13=ADDR OF CHAR WORD OF SMALLER FRACT
MOVE 14,1 ;AC14=ADDR OF CHAR WORD OF LARGER FRACT
MOVE 16,(14) ;SET CHAR OF RESULT TO THAT OF LARGER NO.
MOVEM 16,(3)
CAIN 6,0 ;IF SIGNS THE SAME, GO TO KADD
JRST KADD
MOVE 15,3 ;AC15=ADDR OF N+1 WORD OF RESULT
ADD 15,0
ADD 14,0 ;AC14=ADDR OF N+1 WORD OF LARGER FRACT
ADD 13,0 ;AC13=ADDR OF N+1 WORD OF SMALLER FRACT
MOVE 16,0 ;AC16=COUNTER
MOVN 10,(13) ;TAKE 2'S COMPLEMENT OF N+1 WORD
SETZ 17,0 ;AC17 WILL CONTAIN ANY CARRIES
JRST .+2
XXX: SETCM 10,(13) ;TAKE ONE'S COMPLEMENT REST OF FRACT
ADD 10,(14)
ADD 10,17
TLZN 10,400000 ;STORE A POS RESULT, BUT IF POS, OVERFLOW
JRST .+3
SETZ 17,0
JRST .+2
MOVEI 17,1
MOVEM 10,(15)
SOJ 15,0
SOJ 13,0
SOJ 14,0
SOJG 16,XXX
MOVEM 3,NORM+1
JRST NORM
KADD: MOVE 10,0
ADD 10,1 ;AC10=ADDR OF NTH WORD, FIRST OPERAND
MOVE 11,0
ADD 11,2 ;AC11=ADDR OF NTH WORD, SECOND OPERAND
SETZ 17,0 ;AC17 WILL BE USED FOR CARRIES INTO NEXT
MOVE 12,0 ;SEQUENTIAL ADD. AC12=A COUNTER FOR LOOPING
MOVE 13,3 ;AC13=ADDR OF CHARACTERISTIC WORD OF RESULT
ADD 13,0 ;AC13=ADDR OF NTH WORD OF RESULT
GO: JFCL 17,.+1 ;CLEAR ALL FLAGS
MOVE 14,(10)
ADD 14,(11) ;ADD THE 2 WORDS INDICATED PLUS
ADD 14,17 ;ANY CARRY FROM PREVIOUS OPERATION
TLZ 14,400000 ;MAKE SURE SIGN BIT=0
MOVEM 14,(13) ;STORE IN RESULT+INDEX
JOV .+3 ;TEST FOR OVERFLOW
SETZ 17,0 ;IF NO OVERFLOW SET AC17=0
JRST .+2
MOVEI 17,1 ;IF OVERFLOW SET AC17=1
SOJ 10,0 ;DECREMENT AC'S SO THAT THEY WILL NOW
SOJ 11,0 ;POINT TO THE (N-1)TH WORD OF FRACTIONAL
SOJ 13,0 ;PART OF BOTH OPERANDS AND THE RESULT
SOJG 12,GO ;LOOP UNTIL ALL FRACTIONAL WORDS ADDED
JUMPE 17,NOVER ;IF THERE WAS A CARRY OUT OF THE FINAL
MOVE 17,(3) ;OPERATION, 1 MUST BE ADDED TO THE
JUMPG 17,.+3 ;CHARACTERISTIC OF THE RESULT AND THE
SOJ 17,0 ;WHOLE FRACTION SHIFTED RIGHT 1 BIT
JRST .+2
AOJ 17,0
MOVEM 17,(3)
MOVEM 3,OVFLOW+1
OVFLOW: JSA 16,MSHIFT
EXP 0,0,-1
MOVE 17,1(3)
TLO 17,200000
MOVEM 17,1(3)
JRST NORM+3
NOVER: MOVEM 3,NORM+1 ;MAKE RESULT ACCESSIBLE TO NORMALIZE ROUTINE
NORM: JSA 16,MNORM
EXP 0,0
MOVEM 2,ZIP+1
ZIP: JSA 16,MNORM
EXP 0,0
MOVEM 2,ZIP1+1
ZIP1: JSA 16,MNORM
EXP 0,0
OUT: HRLZI 17,STORE
BLT 17,17 ;RESTORE THE AC'S
JRA 16,5(16) ;RETURN TO CALLING SEQUENCE
STORE: BLOCK 20
TEMP1: BLOCK 201
TEMP2: BLOCK 201
ZERO1: MOVS 4,1
JRST .+2
ZERO: MOVS 4,2
MOVE 5,3(16)
ADD 5,0
HRRM 5,BLOX
HRR 4,3(16)
BLOX: BLT 4,.
JRST OUT
END