System verilog 在系统Verilog中初始化动态数组时出错
我想从函数返回一个动态数组。但我在声明动态数组时出错。有人能帮我定义一下吗。我没有什么具体的疑问System verilog 在系统Verilog中初始化动态数组时出错,system-verilog,dynamic-arrays,System Verilog,Dynamic Arrays,我想从函数返回一个动态数组。但我在声明动态数组时出错。有人能帮我定义一下吗。我没有什么具体的疑问 如果我的返回类型是动态数组(out_data),我是否需要像这样分配内存空间:pre_processing=new[temp_I.len()] 我在声明位temp\u I\u b[]时出错,是否需要以其他方式执行此操作 要返回数据(本例中为动态数组),是否需要使用return关键字 这方面的任何帮助都是非常值得赞赏的 module test1(); typedef bit [511:0] o
pre_processing=new[temp_I.len()]
位temp\u I\u b[]
时出错,是否需要以其他方式执行此操作return
关键字 module test1();
typedef bit [511:0] out_data[];
string a="A";
function out_data pre_processing(string temp_i);
bit temp_i_b[];
int k,d_zero,l;
bit d[];
bit tempor[];
out_data temp_out;
int n;
int T=0;
int i=0;
int size;
pre_processing= new [temp_i.len()] ;
temp_i_b=new[24](temp_i_b);
size =(temp_i.len())*4'd8;
$display(size);
$display(temp_i);
$display("%b",temp_i.atobin());//
foreach(temp_i_b[i]) begin
temp_i_b[i]=temp_i.atobin()[i];
//temp[3:0]=4'b1111
foreach(temp_i_b[i])
$display("temp[%d]=%d\n",i,temp_i_b[i]);
end
d=new[10](d);
temp_out=new [3] (temp_out);
tempor=new [512*3] (tempor);
l=temp_i.len()*8;//l=24
k=447-l;
if(k<0)
k=512+k;
do
begin
d[i]=l%2;
l=l/2;
i++;
end while(l>0);
T=l+1+k+d.size();
n=T/512;
d_zero=n*512-T;
temp_i_b={temp_i_b,1'b1};
foreach(tempor[i])
tempor[i]= temp_i_b << (k+d_zero);
foreach(d[i])
tempor[tempor.size()-1:0]={tempor[tempor.size()-1:0],d[d.size()-i-1]};
//end
foreach(tempor[i]) begin
foreach(temp_out[i]) begin
while(tempor[$size(tempor)-1:0]!=0) begin
temp_out[i]=tempor[$size(tempor)-1:$size(tempor)-512];
tempor[$size(tempor)-1:0]=tempor[$size(tempor)-1:0] << 512;
end
end
end
foreach(temp_out[i])
return temp_out;
endfunction
out_data my_q;
initial begin
my_q=pre_processing("111");
$display("%d",a.atoi());
$display("output=%b",my_q[0]);
end
endmodule
模块test1();
typedef位[511:0]输出数据[];
字符串a=“a”;
功能输出数据预处理(字符串温度i);
位温度i_b[];
int k,d_零,l;
位d[];
位时间[];
输出数据温度输出;
int n;
int T=0;
int i=0;
整数大小;
预处理=新的[temp_i.len()];
temp_i_b=新[24](temp_i_b);
大小=(temp_i.len())*4'd8;
$显示器(尺寸);
$display(temp_i);
$display(“%b”,temp_i.atobin())//
foreach(temp_i_b[i])开始
temp_i_b[i]=temp_i.atobin()[i];
//温度[3:0]=4'b1111
foreach(临时工
$display(“临时[%d]=%d\n”,i,临时i\u b[i]);
结束
d=新的[10](d);
临时输出=新[3](临时输出);
临时=新的[512*3](临时);
l=温度i.len()*8//l=24
k=447-l;
if(k0);
T=l+1+k+d.尺寸();
n=T/512;
d_zero=n*512-T;
temp_i_b={temp_i_b,1'b1};
foreach(临时[i])
临时的,临时的
如果我的返回类型是动态数组(out_data),我是否需要像这样分配内存空间(pre_processing=new[temp_I.len())
对。您需要为它分配内存
声明位temp_I_b[]时出错,是否需要以其他方式执行此操作
您需要在pre_processing=new[temp_i.len()]之前声明所有变量代码>
其他错误也很少-
- 如果没有索引,则无法访问动态数组:
tempor[]=temp\u i\u b谢谢您的帮助。我纠正了你提到的几点,效果很好。还有一个疑问,我正在向函数传递一个ASCII字符串,并试图将其转换为二进制值。但是内置函数“atobin()”在这种情况下不起作用。您对此有什么建议吗?有几个语法错误,而且您似乎不了解SystemVerilog中数组的工作原理。回顾第7.5节至第7.12节。您试图实现什么(最终目标,而不是具体的编译错误)?