3

Suppose I have an array like this:

parameter n=100;
reg array[0:n-1];

How would one get the logic-OR value of each and every bit in the array? The resulted circuit must be combinatorial.

This is a follow up question from this one. (see discussion below the answer)

3
  • 1
    Tim's answer shows a packed array declaration. It's very helpful to know the difference between this and an unpacked array. Commented May 18, 2013 at 4:11
  • Ok, so a packed array is something like reg [9:0] packed; and an unpacked array is reg unpacked [0:9];. I got that but what are the differences between the two? Commented May 18, 2013 at 10:53
  • 1
    In short, reg [9:0] packed; will be accessed as a single value whereas reg unpacked [9:0] cannot. So packed = 6; is valid but unpacked = 6; is not. I should have noted that packed/unpacked are SystemVerilog terms but the concept is the same in Verilog. Commented May 18, 2013 at 20:31

1 Answer 1

6

I don't know if this meets your design requirements, but you might have a much easier time with a hundred bit bus reg [n-1:0] array; than by using an array of 1 bit wires. Verilog does not have the greatest syntax to support arrays. If you had a bus instead you could just do assign result = |array;

If you must use an array, than I might consider first turning it into a bus with a generate loop, and then doing the same:

parameter n=100;
reg array[0:n-1];
wire [n-1:0] dummywire;

genvar i; 
generate 
  for (i = 0; i < n; i = i+1)  begin
    assign dummywire[i] = array[i];
  end  
endgenerate  

assign result = |dummywire;

I'm not aware of a more elegant way to do this on arrays.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.