0 push 1 1 duplicate top of stack 2 add top two values 3 subtract 4 mutliplymultiply 5 integer divide top value bybby second value 6 push the second value without popping it 7 swap top two values c>7 while loop, runs until top of stack is 0 the loops ends at the first instruction >=c More to follow0,20,10,0,3,10,2,0,3,comp. test,20,2,1 generates the next prime less than ...n:
0 -- push 1. This means the current number is composite -- Even if it isn't, we still want to find a prime <n 20 -- while loop. This iterates until the composite tests returns 0 10 10 -- we have an positive number on the top of the stack ... 0 3 -- by subtracting 1 until it is 0, ... 2 -- and adding this to the last prime candidate ... -- we can get rid of it. 0 3 -- subtract 1 to get new prime candidate pc comp -- check if pc is composite 20 -- end of loop, top of stack is now [0, p], with p prime 2 -- add 0+p 1 -- duplicate the prime, such that we store the result, -- and can use the value to find the next prime 30,0,2,0,2,next prime,0,3,0,3,30,2 repeats this until the prime 2 is found:
30 30 -- while loop 0 2 -- add 1 0 2 -- add 1 np -- find the prime less than this 0 3 -- subtract 1 0 3 -- subtract 1 -- if the prime was 2, this is now 0 -- and the while loop terminates 2 -- add the 0 to the 2 to remove it