home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p078 / 7.img / TUTOR.PLB / PRIME6.PLD < prev    next >
Encoding:
Text File  |  1990-12-11  |  1.0 KB  |  32 lines

  1.                          PRIME NUMBER RECOGNIZER
  2.  
  3. Here is an advanced example that defines combinational logic to recognize
  4. prime numbers.  The input A[5..0] represents an integer in the range 0..63
  5. to be tested for primality.  The output P is true if the input integer is
  6. prime.  See the reference guide for an explanation of this example.
  7.  
  8. | in:A[5..0], io:P
  9. |
  10. | Title:  "k-bit Prime Number Detection"
  11. |         "Author:  TSL"
  12. |
  13. | k = 6                        |Set the input bit width.
  14. |
  15. | n = 2 .. 2**k - 1:           |Select the next input value and
  16. | { j = 0                      |clear the number of divisors.
  17. |
  18. |   n>3: i=2..sqrt(n):         |Find how many integers divide the
  19. |     j = j + (n\i==0)         |input value evenly.
  20. |
  21. |   j==0:  P = A[k-1..0]==n    |If none do, attach a product term
  22. |   }                          |to the equation.
  23.  
  24. |Vectors:
  25. |{ Display (A[5..0])d, P
  26. |  Test A[5..0]
  27. |  End
  28. |  }
  29.  
  30. Todd S. Lehman, June 1988.
  31.  
  32.