Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass array structure between two verilog modules

I am trying to pass a array structure as reg [0:31]instructionmem[0:31] between two modules.

I coded it as follows :

Module No 1:

       module module1(instructionmem);
            output reg [0:31]instructionmem[0:31];
            ------------------
            ----lines of code---

            ---------------
       endmodule 

Module No 2:

         module module2(instructionmem);
           input [0:31]instructionmem[0:31];
           --------------------------------
           -----line of code---------------
           -------------------------------
           endmodule

Testbench:

     module test_bench();
     wire [0:31]instructionmem[0:31];

     module1 m1(instructionmem);
     module2 m2(instructionmem);
     endmodule

I am getting errors for this implementation. So how can we send such array structures ?

like image 320
Nilesh Agrawal Avatar asked May 04 '13 01:05

Nilesh Agrawal


People also ask

How do I join multiple modules in Verilog?

You need to create an upper-level module or “top” module and then instantiate each module instance in there. For example, assuming you have three modules named A, B and C respectively, and you want to connect them, it might look like this : module top();

How do you access an array in Verilog?

Verilog arrays could only be accessed one element at a time. In Verilog arrays, we can also select one or more contiguous elements of an array. This is called a slice. An array slice can only apply to one dimension; other dimensions must have single index values in an expression.

Can modules be nested in Verilog?

Nested module declarations are only allowed in SystemVerilog. The nested module is only visible for instanciation within the module is contained. If you are looking to have two different module definitions with the same name, it's possible to do this in Verilog with libraries and the config construct.


1 Answers

This is not possible in Verilog. (See sec. 12.3.3, Syntax 12-4 of the Verilog 2005 standard document, IEEE Std. 1364-2005.)

Instead you should "flatten" the array and pass it as a simple vector, e.g.:

module module1(instructionmem);
  output [32*32-1:0] instructionmem;
  reg [31:0] instructionmem_array [31:0];

  genvar i;
  generate for (i = 0; i < 32; i = i+1) begin:instmem
    assign instructionmem[32*i +: 32] = instructionmem_array[i]; 
  end endgenerate
endmodule

module module2(instructionmem);
  input [32*32-1:0] instructionmem;
  reg [31:0] instructionmem_array [31:0];

  integer i;
  always @*
    for (i = 0; i < 32; i = i+1)
      instructionmem_array[i] = instructionmem[32*i +: 32];
endmodule

module test_bench(instructionmem);
  output [32*32-1:0] instructionmem;
  module1 m1(instructionmem);
  module2 m2(instructionmem);
endmodule
like image 160
CliffordVienna Avatar answered Oct 03 '22 09:10

CliffordVienna