Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在任务中传递内存:Verilog_Verilog - Fatal编程技术网

在任务中传递内存:Verilog

在任务中传递内存:Verilog,verilog,Verilog,我正在尝试这样做: 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; // o

我正在尝试这样做:

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
当我编译此文件时,会出现以下错误:

  • 对内存“b”的非法引用
  • 分配的非法LHS
  • 对内存“a2”的非法引用
  • 任务输出参数非法
  • 对内存“a1”的非法引用
  • 所以我想了解如何在任务中传递二维数组


    注:我以前从未使用过任务。

    在Verilog中不可能。您可能只需要在线“展开”任务

    另一种解决方案是展平阵列。例如:

    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
    

    Verilog中不支持二维数组。SystemVerilog支持它们作为任务的端口和参数。一个直接的错误是将输入/输出声明为
    output reg[1:0]b[1:0]
    。在verilog任务中,变量的名称应位于参数方向之后。因此,在不使用
    reg
    关键字的情况下,按
    output[1:0]b[1:0]
    进行操作。这不是这里的主要问题,只是一个旁白。:)有什么解决办法吗?。我还想了解为什么输入/输出后不需要reg或wire?Verilog的数据类型为
    reg
    wire
    ,在主透视图中只有两个。但是,wire仅由连续赋值
    assign
    语句驱动,因此永远不会出现
    wire
    。因此,输出参数隐式地为
    reg
    类型。就输入参数而言,它只是一个变量,必须读取其值。因此,它可以是
    reg
    wire
    。具有许多数据类型的Systemverilog需要在输入/输出参数中显式声明数据类型。你在找verilog任务/函数还是systemverilog任务/函数?哦,找到了。我只寻找verilog任务/功能。