I want to obtain prime number in verilog. For this I used counter, which counts on the rising edge of every clock. Using the value of counter, I must get prime number. My question is how I can check the count value is prime or not. I can use for loop to check prime, but know that in verilog for loop is not a good way because it takes many clock cycles to finish for loop. I have to check the prime number without for loop. Can anyone help me to check the count is prime without loop.
module prime_clk ( input clk, input reset)
parameter N =1000; // size of array
reg [31:0] prime_number[0:N-1]; // memory array for product
integer k=0 ; // counter variable
integer result_done =1; // controller
integer count =0;
always @(posedge clk )
begin
count = count+1 ;
if (count%2 !=0 || count%3 !=0 )
begin
prime_number[k] <= count;
k <= k + 1;
end
end
endmodule
for-loop
you can check if a number is prime in one cycle, but max frequency of that module would be very low. Withoutfor-loop
you'll definitely need more than 1 (i.e. a lot) cycle.