primes.tal (691B)
1 ( Primes: 2 An integer greater than one is called a prime number 3 if its only positive divisors are one and itself. ) 4 5 |0100 ( -> ) @reset 6 7 #0000 INC2k 8 &loop 9 DUP2 not-prime ?&skip 10 DUP2 print/short #2018 DEO 11 &skip 12 INC2 NEQ2k ?&loop 13 POP2 POP2 14 ( halt ) #010f DEO 15 16 BRK 17 18 @not-prime ( number* -- flag ) 19 20 DUP2 ,&t STR2 21 ( range ) #01 SFT2 #0002 LTH2k ?&fail 22 &loop 23 [ LIT2 &t $2 ] OVR2 ( mod2 ) DIV2k MUL2 SUB2 ORA ?&continue 24 &fail POP2 POP2 #01 JMP2r &continue 25 INC2 GTH2k ?&loop 26 POP2 POP2 #00 27 28 JMP2r 29 30 @print ( short* -- ) 31 32 &short ( short* -- ) SWP print/byte 33 &byte ( byte -- ) DUP #04 SFT print/char 34 &char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO 35 36 JMP2r