0

I am trying to do something like this:

module test;

reg [1:0] c [1:0];
reg [1:0] a1 [1:0];

 task mem_a;
 output reg [1:0] a [1:0];
 begin
  a[0]=0;
  a[1]=1;
  a[2]=2;
  a[3]=3;
 end
endtask

task mem_b;
 input reg [1:0] a2 [1:0];
 output reg [1:0] b [1:0];
 begin
  b=a2; // or some other manupulation 
 end
endtask

initial
begin
 mem_a (a1);
 mem_b (a1,c);
end

endmodule

When I compile this, I am getting errors as :

  1. Illegal reference to memory "b"
  2. Illegal LHS of assignment.
  3. Illegal reference to memory "a2"
  4. Illegal task output argument.
  5. Illegal reference to memory "a1".

So I want to understand how to pass 2-D arrays in tasks.

P.S: I have not used tasks before.

5
  • 1
    Two dimensional arrays are not supported in Verilog. SystemVerilog supports them as ports and arguments to tasks. Commented Nov 11, 2015 at 11:07
  • One immediate mistake is declaring inputs/outputs as output reg [1:0] b [1:0]. In verilog task, the name of variable is expected after the argument direction. So do it as output [1:0] b [1:0] without the reg keyword. This is not the main issue here, just a side comment. :) Commented Nov 11, 2015 at 11:10
  • Is any workaround possible?. Also I want to understand why reg or wire is not expected after inputs/outputs ? Commented Nov 11, 2015 at 11:20
  • 1
    Verilog either has reg or wire as datatype, only two in the main perspective. But, wire is driven by continuous assignments assign statements only, so wire is never expected. As a result, output arguments are implicitly of reg type. As far as input argument is concerned, it is simply a variable, whose value must be read. As a result, it can be reg or wire. Systemverilog having many datatypes requires explicit declaration of datatypes in input/output arguments. Are you looking for a verilog task/function or systemverilog task/function? Commented Nov 11, 2015 at 11:28
  • Oh got it. I am looking only for verilog task/function. Commented Nov 11, 2015 at 12:43

2 Answers 2

0

Not possible in Verilog. You're probably just going to have to 'unroll' the tasks inline.

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

Comments

0

An alternative solution is to flatten the arrays. For instance:

module test;

// reg [1:0] c1 [1:0] ends up as:
reg [2*2-1:0] c;
reg [2*2-1:0] a1;

task mem_a;
output reg [2*2-1:0] a;
begin
  a[2*0+:2]=2'd0;
  a[2*1+:2]=2'd1;
  //a[2]=2; // This was out of bounds
  //a[3]=3; // So was this
end
endtask

task mem_b;
input  reg [2*2-1:0] a2;
output reg [2*2-1:0] b;
begin
  b=a2; // or some other manipulation 
end
endtask

initial
begin
  mem_a (a1);
  mem_b (a1,c);
end

endmodule

Comments

Your Answer

Draft saved
Draft discarded

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.