P
Peng Yu
Guest
Hi,
The commended portion of the following code list isn't correct. If I
uncommend it, I'll get a error:
Error: assign.v(15): Range must be bounded by constant expressions
Although I can use the code segment
out[3:0] <= in[0];
out[7:4] <= in[1];
out[11:8] <= in[2];
out[15:12] <= in[3];
, I have to adjust the code if N != 4. Is there any solution to this
situation?
Thanks,
Peng
module assignment;
parameter N = 4;
reg [4 * N - 1:0] out;
reg [3:0] in[0:N - 1];
reg clock;
integer i;
always begin
@(posedge clock) begin
for(i = 0;i < N;i = i + 1)
in <= ~in;
/* for(i = 0;i < N;i = i + 1)
out[4 * i + 3:4 * i] <= in;
*/
out[3:0] <= in[0];
out[7:4] <= in[1];
out[11:8] <= in[2];
out[15:12] <= in[3];
end
end
initial begin
clock = 0; in[0] = 0; in[1] = 1; in[2] = 2; in[3] = 3;
$monitor("time=%0t,clock=%b,out=%h,in[0]=%h,in[1]=%h,in[2]=%h,in[3]=%h",
$time, clock, out, in[0], in[1], in[2], in[3]);
#100 $stop;
end
always
#10 clock = ~clock;
endmodule
The commended portion of the following code list isn't correct. If I
uncommend it, I'll get a error:
Error: assign.v(15): Range must be bounded by constant expressions
Although I can use the code segment
out[3:0] <= in[0];
out[7:4] <= in[1];
out[11:8] <= in[2];
out[15:12] <= in[3];
, I have to adjust the code if N != 4. Is there any solution to this
situation?
Thanks,
Peng
module assignment;
parameter N = 4;
reg [4 * N - 1:0] out;
reg [3:0] in[0:N - 1];
reg clock;
integer i;
always begin
@(posedge clock) begin
for(i = 0;i < N;i = i + 1)
in <= ~in;
/* for(i = 0;i < N;i = i + 1)
out[4 * i + 3:4 * i] <= in;
*/
out[3:0] <= in[0];
out[7:4] <= in[1];
out[11:8] <= in[2];
out[15:12] <= in[3];
end
end
initial begin
clock = 0; in[0] = 0; in[1] = 1; in[2] = 2; in[3] = 3;
$monitor("time=%0t,clock=%b,out=%h,in[0]=%h,in[1]=%h,in[2]=%h,in[3]=%h",
$time, clock, out, in[0], in[1], in[2], in[3]);
#100 $stop;
end
always
#10 clock = ~clock;
endmodule