Roger Federer
Roger Federer

Reputation: 17

logic operations on multidimensional arrays in verilog

I have a multidimensional array as below.

reg [3:0] varname [`KEY-1:0];

I want to check if atleast one element in the array is equivalent to 4'b1111 or 4'b1110

What is the easiest and best way we can do this?

Upvotes: 0

Views: 832

Answers (1)

Adhamzhon Shukurov
Adhamzhon Shukurov

Reputation: 713

If 'KEY is small and constant that you know, then it is better to use simple logic for each row (example for i-th row)

if((varname[i] && 4'b1111) || (varname[i] && 4'b1110) )

If 'KEY is variable or quite large number then it is better to use different method, i would try using

output reg equivalent_detected;
reg counter;
initial
begin
     equivalent_detected = 1'b0;
     counter = 0;
end

always@(posedge clk)
begin

if((varname[counter] && 4'b1111) || (varname[counter] && 4'b1110) )
     equivalent_detected <= 1'b1;
counter <= counter + 1;

end // end of always block

You can use the above codes in your module If you use equivalent_detected as your output then whenever you get 1 it means you detected 4'b1111 or 4'b1110. You can further improve this code and make it better, I just wanted to give you some idea.

Upvotes: 1

Related Questions