Verilog Code Error: Range must be bounded by constant expressions
Verilog Code Error: Range must be bounded by constant expressions
我已经编写了一个 52 位乘法器的代码,我需要以标准形式(64 位数字的 IEEE 754 浮点标准)给出。所以之后我正在检查,它从 64 超过了多少位,所以我会把那个数字放入指数中。
module mul1(output reg [103:0] p,
output reg [51:0] c,
input [51:0] x,
input [51:0] y);
reg [103:0]a;
integer i;
always @(x , y)
begin
a=x;
p=0; // needs to zeroed
for(i=0;i<104;i=i+1)
begin
if(y[i])
p=p+a; // must be a blocking assignment
a=a<<1;
end
for(i=103;i>=0;i=i-1)
begin
if (p[i])
c=p[i:i-51];
break;
end
end
endmodule
它给出了一个错误:Range must be bounded by the constant expressions for the line: c=p[i:i-51];
我该如何解决这个问题?
你不能有变量 part/slice selection(可变宽度)。从变量 c 的角度考虑赋值。 c 是 52 位宽,所以你需要给它分配 p 的 52 位。循环只需要 select 哪 52 位。这就是变量 part-select 运算符的用途。这里有一个很好的解释:
Indexing vectors and arrays with +:
看起来像:
c=p[i+:52]
这意味着,select 从 p 开始(低位)i 上升到 i+52-1 并分配给 c。
module mul1(output reg [103:0] p,
output reg [51:0] c,
input [51:0] x,
input [51:0] y);
reg [103:0]a;
integer i;
always @(x , y) begin
a=x;
p=0; // needs to zeroed
for(i=0;i<104;i=i+1) begin
if(y[i]) begin
p=p+a; // must be a blocking assignment
end
a=a<<1;
end
for(i=103;i>=0;i=i-1) begin
if (p[i]) begin
c=p[i+:52];
break;
end
end
end
endmodule
此外,您需要在第二个循环中的 'if' 之后添加一个 'begin',并需要一个 'end' 来关闭 always 块。上面的代码为我编译。
我已经编写了一个 52 位乘法器的代码,我需要以标准形式(64 位数字的 IEEE 754 浮点标准)给出。所以之后我正在检查,它从 64 超过了多少位,所以我会把那个数字放入指数中。
module mul1(output reg [103:0] p,
output reg [51:0] c,
input [51:0] x,
input [51:0] y);
reg [103:0]a;
integer i;
always @(x , y)
begin
a=x;
p=0; // needs to zeroed
for(i=0;i<104;i=i+1)
begin
if(y[i])
p=p+a; // must be a blocking assignment
a=a<<1;
end
for(i=103;i>=0;i=i-1)
begin
if (p[i])
c=p[i:i-51];
break;
end
end
endmodule
它给出了一个错误:Range must be bounded by the constant expressions for the line: c=p[i:i-51]; 我该如何解决这个问题?
你不能有变量 part/slice selection(可变宽度)。从变量 c 的角度考虑赋值。 c 是 52 位宽,所以你需要给它分配 p 的 52 位。循环只需要 select 哪 52 位。这就是变量 part-select 运算符的用途。这里有一个很好的解释: Indexing vectors and arrays with +:
看起来像:
c=p[i+:52]
这意味着,select 从 p 开始(低位)i 上升到 i+52-1 并分配给 c。
module mul1(output reg [103:0] p,
output reg [51:0] c,
input [51:0] x,
input [51:0] y);
reg [103:0]a;
integer i;
always @(x , y) begin
a=x;
p=0; // needs to zeroed
for(i=0;i<104;i=i+1) begin
if(y[i]) begin
p=p+a; // must be a blocking assignment
end
a=a<<1;
end
for(i=103;i>=0;i=i-1) begin
if (p[i]) begin
c=p[i+:52];
break;
end
end
end
endmodule
此外,您需要在第二个循环中的 'if' 之后添加一个 'begin',并需要一个 'end' 来关闭 always 块。上面的代码为我编译。