1: .globl fptrap 2: .globl _signal 3: .globl _exit 4: .globl _read 5: .globl _write 6: ldfps = 170100^tst 7: / 8: mov $fptrap,-(sp) 9: mov $4,-(sp) 10: jsr pc,_signal 11: cmp (sp)+,(sp)+ 12: 13: ldfps $240 14: 15: clr argflg 16: cmp (sp)+,$2 17: blt begin 18: tst (sp)+ 19: mov (sp),r2 20: jsr r5,atof; getch1 21: inc argflg 22: br begin1 23: begin: 24: tst argflg 25: beq 9f; jsr pc,_exit; 9: 26: jsr r5,atof; getch 27: begin1: 28: tstf fr0 29: cfcc 30: bpl 9f; jmp ouch; 9: 31: bne 9f; jsr pc,_exit; 9: 32: cmpf big,fr0 33: cfcc 34: bgt 9f; jmp ouch; 9: 35: / 36: movf $f100,fr1 37: cmpf fr0,fr1 38: cfcc 39: bge 1f 40: mov $pt,r3 41: 3: 42: cmp r3,$ptend 43: bhis 1f 44: movif (r3)+,fr1 45: cmpf fr1,fr0 46: cfcc 47: blt 3b 48: tst -(r3) 49: 3: 50: movif (r3),fr0 51: jsr r5,ftoa; wrchar 52: mov $'\n,r0 53: jsr r5,wrchar 54: tst (r3)+ 55: cmp r3,$ptend 56: blo 3b 57: movf $f100,fr0 58: / 59: 1: 60: divf $two,fr0 61: modf $one,fr0 62: movf fr1,fr0 63: mulf $two,fr0 64: addf $one,fr0 65: movif $tsiz8,fr1 66: movf fr1,fr5 67: movf fr0,nn 68: / 69: / 70: / 71: / clear the sieve table 72: / 73: 2: 74: mov $table,r3 75: 3: 76: cmp r3,$table+tabsiz 77: bhis 3f 78: clrb (r3)+ 79: br 3b 80: / 81: / run the sieve 82: / 83: 3: 84: movf nn,fr0 85: addf fr5,fr0 86: jsr r5,sqrt 87: movf fr0,v 88: / 89: movf nn,fr0 90: movif $3.,fr1 91: jsr pc,5f 92: movif $5.,fr1 93: jsr pc,5f 94: movif $7.,fr1 95: jsr pc,5f 96: movif $11.,fr1 97: mov $factab+2,r4 98: 4: 99: jsr pc,5f 100: mov (r4)+,kazoo 101: kazoo =.+2 102: addf $kazoo,fr1 103: cmp r4,$ftabend 104: blo 3f 105: mov $factab,r4 106: 3: 107: cmpf v,fr1 108: cfcc 109: bge 4b 110: br 1f 111: / 112: / 113: 5: 114: movf fr0,fr2 115: divf fr1,fr2 116: modf $one,fr2 117: mulf fr1,fr3 118: subf fr0,fr3 119: cfcc 120: bpl 3f 121: addf fr1,fr3 122: 3: 123: cmpf fr5,fr3 124: cfcc 125: ble 3f 126: movfi fr3,r0 127: ashc $-3.,r0 128: ash $-13.,r1 129: bic $177770,r1 130: bisb bittab(r1),table(r0) 131: addf fr1,fr3 132: br 3b 133: 3: 134: rts pc 135: / 136: / 137: / get one character form the argument string. 138: getch1: 139: movb (r2)+,r0 140: rts r5 141: / 142: / now get the primes from the table 143: / and print them. 144: / 145: 1: 146: / 147: movf nn,fr0 148: clr r3 149: br 4f 150: / 151: 1: 152: inc r3 153: inc r3 154: cmp r3,$tsiz8 155: bge 2b 156: / 157: 4: 158: / 159: jsr pc,prime 160: bec 3f 161: movf nn,fr0 162: jsr r5,ftoa; wrchar 163: mov $'\n,r0 164: jsr r5,wrchar 165: 3: 166: movf nn,fr0 167: addf $two,fr0 168: movf fr0,nn 169: br 1b 170: / 171: / 172: / 173: / 174: prime: 175: mov r3,r4 176: ashc $-3.,r4 177: ash $-13.,r5 178: bic $177770,r5 179: bitb bittab(r5),table(r4) 180: bne 1f 181: sec 182: 1: 183: rts pc 184: / 185: / 186: / 187: / 188: one = 40200 189: half = 40000 190: opower = 34400 191: power = 44000 192: f100 = 41710 193: / 194: / get one character from the console. 195: / called from atof. 196: / 197: getch: 198: mov $1,-(sp) 199: mov $ch,-(sp) 200: clr -(sp) 201: jsr pc,_read 202: add $6,sp 203: bec 9f; jsr pc,_exit; 9: 204: tst r0; bne 9f; jsr pc,_exit; 9: 205: mov ch,r0 206: rts r5 207: / 208: / 209: / write one character on the console 210: / called from ftoa. 211: / 212: wrchar: 213: tst iobuf 214: bne 1f 215: mov $iobuf+2,iobuf 216: 1: 217: movb r0,*iobuf 218: inc iobuf 219: cmp iobuf,$iobuf+514. 220: blo 1f 221: mov $512.,-(sp) 222: mov $iobuf+2,-(sp) 223: mov $1,-(sp) 224: jsr pc,_write 225: add $6,sp 226: mov $iobuf+2,iobuf 227: 1: 228: rts r5 229: / 230: .bss 231: iobuf: .=.+518. 232: .text 233: / 234: / 235: / read and convert a line from the console into fr0. 236: / 237: atof: 238: mov r1,-(sp) 239: movif $10.,r3 240: clrf r0 241: 1: 242: jsr r5,*(r5) 243: sub $'0,r0 244: cmp r0,$9. 245: bhi 2f 246: mulf r3,r0 247: movif r0,r1 248: addf r1,r0 249: br 1b 250: 2: 251: cmp r0,$' -'0 252: beq 1b 253: / 254: mov (sp)+,r1 255: tst (r5)+ 256: rts r5 257: / 258: / 259: ftoa: 260: mov $ebuf,r2 261: 1: 262: movf fr0,fr1 263: divf $ten,fr1 264: movf fr1,fr2 265: modf $one,fr2 266: movf fr3,-(sp) 267: mulf $ten,fr3 268: negf fr3 269: addf fr0,fr3 270: movfi fr3,-(r2) 271: movf (sp)+,fr0 272: tstf fr0 273: cfcc 274: bne 1b 275: 1: 276: mov (r2)+,r0 277: add $60,r0 278: jsr r5,*(r5) 279: cmp r2,$ebuf 280: blo 1b 281: tst (r5)+ 282: rts r5 283: / 284: / 285: / 286: / replace the f.p. number in fr0 by its square root 287: / 288: sqrt: 289: movf r0,r1 / a 290: tstf fr0 291: cfcc 292: beq 2f 293: bgt 1f 294: sec 295: rts r5 / sqrt(-a) 296: 1: 297: seti 298: movf fr0,-(sp) 299: asr (sp) 300: add $20100,(sp) 301: movf (sp)+,fr0 302: movif $2,r3 / constant 2 303: mov $4,r0 304: 1: 305: movf r1,r2 306: divf r0,r2 307: addf r2,r0 308: divf r3,r0 / x = (x+a/x)/2 309: dec r0 310: bgt 1b 311: 2: 312: clc 313: rts r5 314: / 315: / 316: buf: .=.+38. 317: ebuf: 318: / 319: / 320: / 321: / complain about a number which the program 322: / is unable to digest 323: ouch: 324: mov $2f-1f,-(sp) 325: mov $1f,-(sp) 326: mov $2,-(sp) 327: jsr pc,_write 328: add $6,sp 329: jmp begin 330: / 331: 1: <Ouch.\n> 332: 2: .even 333: / 334: / 335: one = 40200 336: two = 40400 337: four = 40600 338: six = 40700 339: ten = 41040 340: / 341: .data 342: bittab: .byte 1, 2, 4, 10, 20, 40, 100, 200 343: big: 056177; 177777; 177777; 177777 344: / 345: pt: 2.; 3.; 5.; 7.; 11.; 13.; 17.; 19.; 23.; 29.; 31.; 37.; 41.; 43. 346: 47.; 53.; 59.; 61.; 67.; 71.; 73.; 79.; 83.; 89.; 97. 347: ptend: 348: nl: <\n> 349: sp5: < > 350: .even 351: / 352: / 353: factab: 354: 41040; 40400; 40600; 40400; 40600; 40700; 40400; 40700 355: 40600; 40400; 40600; 40700; 40700; 40400; 40700; 40600 356: 40400; 40700; 40600; 40700; 41000; 40600; 40400; 40600 357: 40400; 40600; 41000; 40700; 40600; 40700; 40400; 40600 358: 40700; 40400; 40700; 40700; 40600; 40400; 40600; 40700 359: 40400; 40700; 40600; 40400; 40600; 40400; 41040; 40400 360: ftabend: 361: / 362: .bss 363: ch: .=.+2 364: t: .=.+8 365: n: .=.+8 366: v: .=.+8 367: nn: .=.+8 368: place: .=.+8 369: / 370: tabsiz = 1000. 371: tsiz8 = 8000. 372: table: .=.+tabsiz 373: argflg: .=.+2 374: .text