
 1000  *SAVE S.NEW SQR ROUTINE
 1010  *--------------------------------
 1020  *      SQR (DAC)
 1030  *--------------------------------
 1040  ERR.SQ JMP AS.ILLERR  ILLEGAL QUANTITY
 1050  DP.SQR.0 RTS
 1060  DP.SQR LDA DAC.EXPONENT
 1070         BEQ DP.SQR.0  SQR(0)=0
 1080         LDA DAC.SIGN
 1090         BMI ERR.SQ   MUST BE POSITIVE
 1100         JSR MOVE.DAC.TEMP3 SAVE X
 1110  *---APPROX. ROOT OF .1 - 1-------
 1120         LDA DAC.HI   CONVERT TWO DIGITS TO BINARY
 1130         AND #$0F     SAVE LO DIGIT
 1140         CMP #5       01234 OR 56789
 1150         PHP          SAVE ANSWER
 1160         LDA DAC.HI   GET HI DIGIT
 1170         LSR
 1180         LSR
 1190         LSR
 1200         LSR          $01...$09
 1210         PLP          01234 OR 56789
 1220         ROL          $02...$13
 1230         TAX
 1240         LDA SQR.TBL,X
 1250         STA DAC.HI
 1260  *---TAKE HALF OF EXPONENT--------
 1270         LDA DAC.EXPONENT
 1280         SEC
 1290         SBC #$40     REMOVE OFFSET
 1300         ROR          DIVIDE BY TWO (KEEP SIGN)
 1310         PHP          SAVE ODD/EVEN BIT
 1320         CLC
 1330         ADC #$C0     RE-BIAS EXPONENT
 1340         STA DAC.EXPONENT
 1350         PLP
 1360         BCC .1       EVEN, DON'T MULT BY SQR(10)
 1370  *---ADJUST APPROX FOR ODD EXP----
 1380         LDA #CON.SQR10
 1390         LDY /CON.SQR10
 1400         JSR MOVE.YA.ARG.1
 1410         JSR DMULT
 1420  *---THREE NEWTON ITERATIONS------
 1430  .1     LDA #3
 1440         STA TEMP3
 1450  .2     JSR MOVE.DAC.TEMP2     TEMP2 = Y
 1460         JSR MOVE.TEMP3.ARG     GET X
 1470         JSR DDIV               X/Y
 1480         JSR MOVE.TEMP2.ARG
 1490         JSR DADD               X/Y+Y
 1500         LDA #CON.HALF
 1510         LDY /CON.HALF
 1520         JSR MOVE.YA.ARG.1
 1530         JSR DMULT              (X/Y+Y)/2
 1540         DEC TEMP3              ANY MORE?
 1550         BNE .2                 ...YES
 1560  *---ONE MORE NEWTON ITERATION----
 1570         JSR MOVE.DAC.TEMP2     TEMP2 = Y
 1580         JSR MOVE.TEMP3.ARG     GET X
 1590         JSR DDIV               X/Y
 1600         JSR MOVE.TEMP2.ARG
 1610         LDA #$FF
 1620         STA ARG.SIGN
 1630         JSR DADD               X/Y-Y
 1640         LDA #CON.HALF
 1650         LDY /CON.HALF
 1660         JSR MOVE.YA.ARG.1
 1670         JSR DMULT              (X/Y-Y)/2
 1680         JSR MOVE.TEMP2.ARG
 1690         JMP DADD               Y + (X/Y-Y)/2
 1700  *--------------------------------
 1710  SQR.TBL    .EQ *-2  (NO ENTRIES AT 0...1)
 1720             .HS 35.42.47.52.57.61.65.69.72
 1730             .HS 76.79.82.85.88.91.94.96.99
 1740  CON.SQR10  .HS 4131622776601683793320
 1750  CON.HALF   .HS 4050000000000000000000
 1760  *--------------------------------

