微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > verilo语法问题

verilo语法问题

时间:10-02 整理:3721RD 点击:

大家好,请问下面的语法哪里出错了,综合时提示第6行i is not a constant。
1. always @(data)
2. for (i=0;i<=9;i=i+1) begin
3.    if(i==6)
4.         tmpData[6]=0;
5.    else
6.          tmpData=data[(i*16+15) : (i*16)];
7.  end

觉得你是学计算机的,C语言转到verilog的。

那个显示的笑脸是怎么回事?
搞这么麻烦,你直接写出
assign tmpData[0] = data[15:0];
assign tmpData[1] = data[31:16];
……
之类不就好了么,直接,简单,明了。

可以参考Verilog标准2005 5.2.1小节:
Several contiguous bits in a vector net, vector reg, integer, or time variable, or parameter can be addressed
and are known as part-selects. There are two types of part-selects, a constant part-select and an indexed partselect.
A constant part-select of a vector reg or net is given with the following syntax:
vect[msb_expr:lsb_expr]
Both msb_expr and lsb_expr shall be constant integer expressions. The first expression has to address a
more significant bit than the second expression

如果想要使用变量,可以使用这种方式:
An indexed part-select of a vector net, vector reg, integer, or time variable, or parameter is given with the
following syntax:
reg [15:0] big_vect;
reg [0:15] little_vect;
big_vect[lsb_base_expr +: width_expr]
little_vect[msb_base_expr +: width_expr]
big_vect[msb_base_expr -: width_expr]
little_vect[lsb_base_expr -: width_expr]
The msb_base_expr and lsb_base_expr shall be integer expressions, and the width_expr shall be a
positive constant integer expression. The lsb_base_expr and msb_base_expr can vary at run time.


用generate,可以支持你的想法。



    generate是不可综合的。

你做的是chip, 写综合器的人如何知道那行有bug的代码到底应该综合成多长的silicon chain呢?
一个所谓array, 如果进silicon,长度必须固定。如果只是写软件,那只是一片memory,当然可以编译时再确定长度。



   可以综合



   乱写



generate是可综合的,请知晓。

genvar  i;
generate
for( i=0; i<=9; i=i+1 ) begin : TEST
   always @(data)
       tmpData[i]=(i==6) ? 0 : data[(i*16+15) : (i*16)];
end
endgenerate

不按格式来。综合器就拦截!

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top