
 1000  *SAVE S.DP18 DIVIDE
 4220  *--------------------------------
 4230  *  DAC = ARG / DAC
 4240  *--------------------------------
 4250  DDIV   JSR SWAP.ARG.DAC  ...CHANGE TO DAC = DAC/ARG
 4260  DDIVR  LDA ARG.EXPONENT  CHECK FOR ZERO DENOMINATOR
 4270         BEQ .2            ...X/0 IS ILLEGAL
 4280  *---FORM SIGN OF QUOTIENT--------
 4290         LDA DAC.SIGN
 4300         EOR ARG.SIGN
 4310         STA DAC.SIGN
 4320  *---COMPUTE EXPONENT OF QUOTIENT-
 4330         SEC
 4340         LDA DAC.EXPONENT
 4350         BEQ .0       ...0/X=0
 4360         SBC ARG.EXPONENT
 4370         CLC
 4380         ADC #$40     ADJUST OFFSET
 4390         STA DAC.EXPONENT
 4400  *---CHECK OVER/UNDERFLOW---------
 4410         BPL .3       ...NEITHER
 4420         ASL          SEE WHICH...
 4430         BPL .1       ...OVERFLOW
 4440  .0     LDA #0       ...UNDERFLOW, SET RESULT = 0
 4450         STA DAC.SIGN
 4460         STA DAC.EXPONENT
 4470         RTS
 4480  .1     JMP AS.OVRFLW
 4490  .2     JMP AS.ZRODIV     DIVISION BY ZERO ERROR
 4500  *---SET UP QUOTIENT LOOP---------
 4510  .3     SED          DECIMAL MODE
 4520         LDA #0
 4530         STA MAC+9    CLEAR FIRST QUOTIENT DIGIT
 4540         LDX #20      DO 20 DIGITS
 4550         BNE .5       ...ALWAYS
 4560  *---CONTINUE QUOTIENT LOOP-------
 4570  .4     LDA DAC.HI
 4580         PHP          SAVE ZERO STATUS
 4590         LSR
 4600         LSR
 4610         LSR
 4620         LSR
 4630         PHA          DAC LEFT EXTENSION
 4640         JSR SHIFT.DAC.LEFT.ONE
 4650         JSR SHIFT.MAC.LEFT.ONE
 4660         PLA          DAC LEFT EXTENSION
 4670         PLP          SEE IF FIRST TWO DIGITS = 0
 4680         BEQ .9       ...YES, SO QUOTIENT IS ALSO ZERO
 4690  *---SUBTRACT WHILE POSSIBLE------
 4700  .5     INC MAC+9    COUNT 1 SUBTRACTION
 4710         PHA          DAC LEFT EXTENSION
 4720         SEC          DO A TRIAL SUB
 4730         LDY #9
 4740  .7     LDA DAC.HI,Y
 4750         SBC ARG.HI,Y
 4760         STA DAC.HI,Y
 4770         DEY
 4780         BPL .7
 4790         PLA          DAC LEFT EXTENSION
 4800         SBC #0
 4810         BCS .5       NO BORROW
 4820  *---OVERSHOT, SO RESTORE---------
 4830         LDY #9       BORROW,SO ADD IT BACK IN
 4840         CLC
 4850  .8     LDA DAC.HI,Y
 4860         ADC ARG.HI,Y
 4870         STA DAC.HI,Y
 4880         DEY
 4890         BPL .8
 4900         DEC MAC+9    BACK OFF QUOTIENT DIGIT, TOO
 4910  *---NEXT DIGIT-------------------
 4920  .9     DEX          ALL DIGITS?
 4930         BNE .4       ...NOT YET, KEEP GOING
 4940  *---ADJUST EXP, CHECK OVERFLOW---
 4950         CLD          BINARY MODE
 4960         INC DAC.EXPONENT  ADJUST FOR OFFSET
 4970         BPL .10      ...NO OVERFLOW PROBLEM
 4980         LDA MAC      COULD BE OVERFLOW
 4990         AND #$F0
 5000         BNE .1       ...OVERFLOW
 5010  *---COPY QUOTIENT TO DAC---------
 5020  .10    LDY #9
 5030  .11    LDA MAC,Y
 5040         STA DAC.HI,Y
 5050         DEY
 5060         BPL .11
 5070         JMP NORMALIZE.DAC
 5080  *--------------------------------
 5090  *   SHIFT 20 DIGITS IN MAC RIGHT ONE PLACE
 5100  *--------------------------------
 5110  SHIFT.MAC.LEFT.ONE
 5120         LDY #4
 5130  .1     ASL MAC+9
 5140         ROL MAC+8
 5150         ROL MAC+7
 5160         ROL MAC+6
 5170         ROL MAC+5
 5180         ROL MAC+4
 5190         ROL MAC+3
 5200         ROL MAC+2
 5210         ROL MAC+1
 5220         ROL MAC
 5230         DEY
 5240         BNE .1
 5250         RTS
 5260  *--------------------------------

