include "hwreg.h" proc prime(ubyte * arr) int cnt, j, k // assume the first prime is 2 and // add it to the list of primes cnt = 1 arr[0] = 2 for j=3 while cnt<32 step j+=2 do // we know all even numbers are not prime // since they are multiples of 2 which is // a prime, so skip all even numbers for k=0 while 1 step k+=1 do if arr[k] * arr[k] > j then // square root of j is > prime k // therefor no prime after prime k // can be a factor of j so j must // be prime // add j to the list of primes arr[cnt] = j cnt += 1 break endif if j % arr[k] == 0 then // prime k is a factor of j // so j cannot be a prime break endif done done endproc proc main() // NOTE: 0x120 is RAM located in RAM page 2 (the 3rd RAM page) // this RAM page is NOT available in the 16F84, for this // example to work you should run it on a 16F628 or a 16F876 // or a 16F877 prime(0x120) endproc proc intserv() endproc