Skip to content

Latest commit

 

History

History

Day-39

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

In this Verilog module:

  • num is a 32-bit input representing the number you want to check for primality.
  • is_prime is a 1-bit output that indicates whether the input number is prime (1) or not (0).

The module uses sequential logic to check for primality. It initializes i to 2 and is_prime_internal to 1 (assuming the number is prime) when the circuit is reset (rst is asserted). Then, in each clock cycle, it checks if i is less than or equal to the square root of num. If num is divisible by i, it sets is_prime_internal to 0 (indicating that the number is not prime). If not, it increments i.

The final assign statement checks if the input number is greater than 1 (since 0 and 1 are not prime) and returns the value of is_prime_internal. If the input number is less than or equal to 1, it directly outputs 0 as those numbers are not prime by definition.

In this Verilog testbench:

  • We instantiate the PrimeChecker module and connect its inputs and outputs.

  • We generate a clock signal (clk) using an always block.

  • We initialize the testbench, set the reset signal (rst) to 0, and provide different input numbers (num) to test various cases.

  • For each test case, we assert the reset signal (rst) to reset the Prime Checker module, wait for a few clock cycles, deassert rst, and then check the is_prime output. We use the $display statement to print the test results.