4
\$\begingroup\$

I am trying to write Verilog code for a 109-bit tree comparator, but I am still new to the generate loop.

Here is the block diagram for the 109-bit tree comparator.

I have written some code so far but I am not sure if this will work or if I can use 2-d arrays for g and l signals?

parameter NUM_OF_BITS = 220;
parameter NUM_OF_LEVELS = 7;
genvar i,x;
wire [NUM_OF_LEVELS:0][NUM_OF_BITS:0] g, l;
assign g[0] = in0;
assign l[0] = in1;
generate for (x=1; x<NUM_OF_LEVELS; x=x+1) begin: Ls
 for (i=0; i<NUM_OF_BITS/(2**x); i=i+1) begin: MCs
 mag_comp2_1 mc (g[x-1][2*i+1:2*i],l[x-1][2*i+1:2*i],g[x][i],l[x][i]);
 end
end
endgenerate
assign gt = g[7][0];
assign lt = l[7][0]; 
asked Jul 24, 2017 at 0:47
\$\endgroup\$
1
  • \$\begingroup\$ I am getting errors that g is not a memory & l is not a memory \$\endgroup\$ Commented Jul 24, 2017 at 5:03

1 Answer 1

1
\$\begingroup\$

The errors you are getting (g is not a memory) should point you to the issue which is that g is not correctly defined as a 2D array.

You declared your 2D arrays as:

wire [NUMBER_OF_ELEMENT-1:0][ELEMENT_WIDTH-1:0] name ;

Which is incorrect.

In Verilog, arrays are declared as:

wire [ELEMENT_WIDTH-1:0] name [NUMBER_OF_ELEMENT-1:0];

You declare the width of any element in a 2D array, then the name of the array, then the number of elements in the array after the name.

answered Jul 24, 2017 at 7:37
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.