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