For loop Verilog:转换的整数不适用于for循环
我正在用Verilog编写一个程序,它接受一个二进制值,将其转换为整数,然后打印“Hello,World!”这样的次数 但是,每当我运行程序时,都不会显示Hello,World。代码如下:For loop Verilog:转换的整数不适用于for循环,for-loop,binary,verilog,For Loop,Binary,Verilog,我正在用Verilog编写一个程序,它接受一个二进制值,将其转换为整数,然后打印“Hello,World!”这样的次数 但是,每当我运行程序时,都不会显示Hello,World。代码如下: // Internal Variable wire [0:4] two_times_rotate; // Multiply the rotate_imm by two (left shift) assign {two_times_rotate} = rotate_imm << 1; intege
// Internal Variable
wire [0:4] two_times_rotate;
// Multiply the rotate_imm by two (left shift)
assign {two_times_rotate} = rotate_imm << 1;
integer i, times_rotated;
// Convert two_times_rotate into an integer
always @( two_times_rotate )
begin
times_rotated = two_times_rotate;
end
initial
begin
for (i = 0; i < times_rotated; i = i + 1)
begin
$display("Hello, World");
end
end
assign {out} = in;
endmodule
//内部变量
导线[0:4]旋转两次;
//将rotate_imm乘以2(左移)
赋值{two_times_rotate}=rotate_immtimes_rotated
在计算for循环时的时间0为32'bX
。for循环正在检查i<32'bX
,这是错误的
根据您的更新,这可能是您的意图:
module immShifter( input [31:0] in, input [3:0] rotate_imm, output [31:0] out );
integer i, times_rotated;
always @*
begin
times_rotated = rotate_imm << 1;
for (i = 0; i < times_rotated; i++)
$display("Hello, World");
$display(""); // empty line as separate between changes to rotate_imm
end
assign out = in;
endmodule
模块immshift(输入[31:0]输入,输入[3:0]旋转\u imm,输出[31:0]输出);
整数i,乘以_旋转;
总是@*
开始
times\u rotated=rotate\u imm看起来代码的前几行是missing@jean28,我建议不要将assign
放在始终
块或初始
块中。大多数设计人员声明压缩数组采用(小端)[格式(即[31:0]
).那么我如何将其转换为整数,以便它检查正确的条件?@jean28,您希望正确的条件是什么?此时,所有内容都在时间0处运行。所有内容都在Verilog中并行运行,因此执行顺序取决于模拟器调度程序的突发奇想。
module immShifter(input[0:31] in, input[0:3] rotate_imm,
output[0:31] out);
// Internal Variable
wire [0:4] two_times_rotate;
reg [0:4] i;
// Multiply the rotate_imm by two (left shift)
assign {two_times_rotate} = rotate_imm << 1;
integer times_rotated, for_var;
// Convert two_times_rotate into an integer
always @( two_times_rotate )
begin
assign{times_rotated} = two_times_rotate;
end
initial
begin
assign{i} = 5'b00000;
assign{for_var} = times_rotated;
for (i = 5'b00000; i < times_rotated; i = i + 5'b00001)
begin
$display("Hello, World");
end
end
assign {out} = in;
endmodule
module immShifter( input [31:0] in, input [3:0] rotate_imm, output [31:0] out );
integer i, times_rotated;
always @*
begin
times_rotated = rotate_imm << 1;
for (i = 0; i < times_rotated; i++)
$display("Hello, World");
$display(""); // empty line as separate between changes to rotate_imm
end
assign out = in;
endmodule