1: / 2: / 3: / routine to divide the two centennial numbers pointed 4: / to by r2 (the divisor) and r3 (the dividend). 5: / A pointer to the result is returned in r1. All other 6: / registers are preserved. If the divisor is zero, zero 7: / is returned and the carry bit is set. 8: / Remainder is returned in r4 and has the sign 9: / of the dividend. 10: / 11: / 12: / mov divisor,r2 13: / mov dividend,r3 14: / jsr pc,div3 15: / mov r1,result 16: / mov r4,remainder 17: / 18: / 19: div3: 20: mov r5,-(sp) 21: mov r3,-(sp) /dividend 22: mov r2,-(sp) /divisor 23: mov r0,-(sp) 24: tst -(sp) /result 25: / 26: / allocate space for result; allocate temps if necessary 27: / 28: clr r0 29: jsr pc,allocate 30: mov r1,0(sp) /result 31: / 32: / 33: / check for divisor zero 34: / 35: mov 4(sp),r2 /divisor 36: mov w(r2),r0 37: sub a(r2),r0 38: bne 1f 39: jmp eh 40: 1: 41: / 42: / compute sign of result and make arguments positive 43: / 44: clr divsign 45: mov r2,r1 46: jsr pc,length 47: jsr pc,allocate 48: mov r1,divisor 49: mov r2,r0 50: jsr pc,move 51: jsr pc,fsfile 52: jsr pc,backspace 53: bpl 1f 54: 2: 55: jsr pc,chsign 56: mov r1,divisor 57: com divsign 58: 1: 59: clr remsign 60: mov r3,r1 61: jsr pc,length 62: jsr pc,allocate 63: mov r1,dividend 64: mov r3,r0 65: jsr pc,move 66: jsr pc,fsfile 67: jsr pc,backspace 68: bpl 1f 69: 2: 70: jsr pc,chsign 71: mov r1,dividend 72: com divsign 73: com remsign 74: 1: 75: / 76: / 77: / find out how many digits in the quotient result 78: / 79: 1: 80: mov dividend,r2 81: mov divisor,r3 82: mov w(r2),r0 83: sub a(r2),r0 84: add a(r3),r0 85: sub w(r3),r0 86: jlo bugout 87: mov r0,divoffset 88: mov 0(sp),r1 /result 89: inc r0 90: jsr pc,seekchar 91: clr r0 92: mov dividend,r1 93: jsr pc,putchar 94: / 95: / load r5 with binary divisor for finding 96: / trial quotient digits. If leading digit of 97: / divisor is <10, it is scaled 98: / 99: clr magic 100: mov divisor,r1 101: jsr pc,fsfile 102: jsr pc,backspace 103: mov r0,r5 104: cmp r5,$10. 105: bge 2f 106: inc magic 107: 2: 108: mpy $100.,r5 109: jsr pc,backspace 110: add r0,r5 111: tst magic 112: beq 2f 113: mov r5,r4 114: mpy $100.,r4 115: jsr pc,backspace 116: add r0,r5 117: adc r4 118: asl r5 119: rol r4 120: dvd $25.,r4 121: mov r4,r5 122: 2: 123: / 124: / compute trial quotient digit 125: / 126: 1: 127: mov dividend,r1 128: jsr pc,fsfile 129: jsr pc,backspace 130: bec 9f; 4; 9: 131: mov r0,r3 132: mpy $100.,r3 133: mov r3,r2 134: jsr pc,backspace 135: add r0,r2 136: mpy $100.,r2 137: jsr pc,backspace 138: add r0,r3 139: adc r2 140: tst divoffset 141: bne 2f 142: add $1,r3 143: adc r2 144: 2: 145: / 146: tst magic 147: beq 3f 148: ashc $3,r2 149: 3: 150: mov r5,r0 151: tst divoffset 152: beq 2f 153: inc r0 154: 2: 155: dvd r0,r2 156: mov r2,trial 157: / 158: / 159: / multiply divisor by trial digit 160: / 161: mov divisor,r1 162: jsr pc,rewind 163: jsr pc,length 164: inc r0 165: mov divxyz,r1 166: jsr pc,rewind 167: clr -(sp) 168: 2: 169: mov divisor,r1 170: jsr pc,getchar 171: bes 2f 172: mov r0,r3 173: mpy trial,r3 174: add (sp),r3 /carry 175: clr r2 176: dvd $100.,r2 177: mov r2,(sp) /carry 178: mov r3,r0 179: mov divxyz,r1 180: jsr pc,alterchar 181: br 2b 182: 2: 183: mov divxyz,r1 184: mov (sp)+,r0 185: jsr pc,alterchar 186: 3: 187: / 188: / and subtract from dividend 189: / 190: jsr pc,rewind 191: mov divoffset,r0 192: mov dividend,r1 193: jsr pc,seekchar 194: clr -(sp) 195: / 196: 2: mov dividend,r1 197: jsr pc,lookchar 198: bes 2f 199: mov r0,r2 200: / 201: mov divxyz,r1 202: jsr pc,getchar 203: sub r0,r2 204: sub (sp),r2 205: clr (sp) 206: mov r2,r0 207: bpl 3f 208: add $100.,r0 209: mov $1.,(sp) 210: 3: mov dividend,r1 211: jsr pc,alterchar 212: br 2b 213: / 214: / put away the quotient digit 215: / 216: 2: 217: mov (sp)+,divcarry 218: mov 0(sp),r1 /result 219: jsr pc,backspace 220: mov trial,r0 221: jsr pc,alterchar 222: jsr pc,backspace 223: / 224: / and go for another digit 225: / 226: dec divoffset 227: bmi 1f 228: mov dividend,r1 229: dec w(r1) 230: cmp w(r1),a(r1) 231: bhis 9f; 4; 9: 232: jmp 1b 233: / 234: / fix up the result 235: / 236: 1: 237: tst divcarry 238: beq 1f 239: mov trial,r0 240: dec r0 241: jsr pc,alterchar 242: mov dividend,r1 243: mov $-1,r0 244: jsr pc,alterchar 245: mov divisor,r2 246: mov dividend,r3 247: jsr pc,add3 248: mov r1,-(sp) 249: mov r3,r1 250: jsr pc,release 251: mov (sp)+,dividend 252: 1: 253: mov 0(sp),r1 /result 254: jsr pc,rewind 255: clr divcarry 256: 1: 257: jsr pc,lookchar 258: bes 1f 259: bic $!377,r0 260: add divcarry,r0 261: clr divcarry 262: cmp r0,$100. 263: blt 2f 264: sub $100.,r0 265: inc divcarry 266: 2: jsr pc,alterchar 267: br 1b 268: / 269: 1: 270: tst divcarry 271: beq 1f 272: mov $1.,r0 273: jsr pc,alterchar 274: 1: 275: jsr pc,fsfile 276: 1: 277: jsr pc,backspace 278: bes 1f 279: bne 1f 280: mov r(r1),w(r1) 281: br 1b 282: 1: 283: / 284: / change sign of result if necessary 285: / 286: tst divsign 287: bpl 1f 288: jsr pc,chsign 289: 1: 290: mov dividend,r1 291: jsr pc,fsfile 292: 1: 293: jsr pc,backspace 294: bes 1f 295: bne 1f 296: mov r(r1),w(r1) 297: br 1b 298: 1: 299: bugout: 300: tst remsign 301: bpl 1f 302: mov dividend,r1 303: jsr pc,chsign 304: / 305: / clean up junk, restore registers, and return 306: / 307: 1: 308: mov divisor,r1 309: jsr pc,release 310: mov (sp)+,r1 311: mov (sp)+,r0 312: mov (sp)+,r2 313: mov (sp)+,r3 314: mov dividend,r4 315: mov (sp)+,r5 316: clc 317: rts pc 318: / 319: / 320: / 321: / 322: .bss 323: divisor: .=.+2 324: dividend: .=.+2 325: divxyz: .=.+2 326: divoffset:.=.+2 327: divcarry: .=.+2 328: divsign: .=.+2 329: trial: .=.+2 330: remsign: .=.+2 331: magic: .=.+2 332: .text 333: / 334: / 335: / 336: / routine to exponentiate the two centennial numbers 337: / pointed to by r2 (the base) and r3 (the exponent). 338: / A pointer to the result is returned in r1. 339: / 340: / mov base,r2 341: / mov exp,r3 342: / jsr pc,exp3 343: / mov r1,... 344: / 345: / 346: / save registers 347: / 348: exp3: 349: mov r3,-(sp) /exponent 350: mov r2,-(sp) /base 351: mov r0,-(sp) 352: / 353: / 354: 1: 355: mov $1,r0 356: jsr pc,allocate 357: mov r1,-(sp) /accumulated result 358: mov $1,r0 359: jsr pc,putchar 360: / 361: mov r2,r1 362: jsr pc,length 363: jsr pc,allocate 364: mov r1,-(sp) /powers of the base 365: mov r2,r0 366: jsr pc,move 367: / 368: mov r3,r1 369: jsr pc,length 370: jsr pc,allocate 371: mov r1,-(sp) /exponent 372: mov r3,r0 373: jsr pc,move 374: jsr pc,fsfile 375: clr exptemp 376: jsr pc,backspace 377: bpl 1f 378: inc exptemp 379: jsr pc,chsign 380: / 381: 1: 382: mov 0(sp),r1 383: jsr pc,length 384: beq 1f 385: mov sqtemp,r2 386: mov 0(sp),r3 387: jsr pc,div3 388: mov r1,0(sp) 389: mov r3,r1 390: jsr pc,release 391: mov r4,r1 392: jsr pc,length 393: jsr pc,release 394: tst r0 395: beq 2f 396: / 397: / 398: / 399: mov 2(sp),r2 400: mov 4(sp),r3 401: jsr pc,mul3 402: mov r1,4(sp) 403: mov r3,r1 404: jsr pc,release 405: 2: 406: mov 2(sp),r3 407: mov r3,r1 408: jsr pc,length 409: jsr pc,allocate 410: mov r1,r2 411: mov r3,r0 412: jsr pc,move 413: jsr pc,mul3 414: mov r1,2(sp) 415: mov r3,r1 416: jsr pc,release 417: mov r2,r1 418: jsr pc,release 419: br 1b 420: 1: 421: tst exptemp 422: beq 1f 423: mov 10(sp),r1 424: jsr pc,length 425: bne 2f 426: jmp eh 427: 2: 428: cmp r0,$1 429: blos 2f 430: mov 4(sp),r1 431: jsr pc,create 432: br 1f 433: 2: 434: jsr pc,rewind 435: jsr pc,getchar 436: cmp r0,$1 437: bgt 2f 438: mov 4(sp),r1 439: jsr pc,create 440: jsr pc,putchar 441: br 1f 442: 2: 443: mov 4(sp),r1 444: jsr pc,create 445: 1: 446: mov (sp)+,r1 447: jsr pc,release 448: mov (sp)+,r1 449: jsr pc,release 450: mov (sp)+,r1 451: / 452: mov (sp)+,r0 453: mov (sp)+,r2 454: mov (sp)+,r3 455: rts pc 456: / 457: .bss 458: exptemp: .=.+2 459: .text 460: /