Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables verilog分配给同一变量不起作用_Variables_Crash_Verilog_Assign_Hdl - Fatal编程技术网

Variables verilog分配给同一变量不起作用

Variables verilog分配给同一变量不起作用,variables,crash,verilog,assign,hdl,Variables,Crash,Verilog,Assign,Hdl,我在Verilog HDL上遇到了一个奇怪的问题。 我在我的代码中发现,如果我把一个变量乘以两,那么 把那个值赋给同一个变量,它就会搞砸。 有时,simv程序甚至崩溃。我本来需要这样做的, 因为我有一个用于移动或旋转一定量的for循环。但是 然后我发现,不仅移动同一个变量不起作用,而且 此外,加法、减法、乘法或除法也不起作用 在我的代码示例中,如果将a设置为16'b0001_0000_1010_0101,将b设置为3, 然后得到16'b0000_0000_0000_0000_0000的输出。请注

我在Verilog HDL上遇到了一个奇怪的问题。 我在我的代码中发现,如果我把一个变量乘以两,那么 把那个值赋给同一个变量,它就会搞砸。 有时,simv程序甚至崩溃。我本来需要这样做的, 因为我有一个用于移动或旋转一定量的for循环。但是 然后我发现,不仅移动同一个变量不起作用,而且 此外,加法、减法、乘法或除法也不起作用

在我的代码示例中,如果将a设置为16'b0001_0000_1010_0101,将b设置为3, 然后得到16'b0000_0000_0000_0000_0000的输出。请注意,我现在忽略了b。。。我应该得到16'b0010\U 0001\U 0100\U 1010。。。但有些地方出了问题

这是我的代码文件test.v:

// ALU module.
module test(in1, in2, out1);

input [15:0] in1;
input [15:0] in2;

output reg [15:0] out1;

// Variables for shifting right and for rotating left or right.
reg [15:0] shiftedValue;

always@(in1, in2)
begin

assign shiftedValue = in1;

assign shiftedValue = shiftedValue * 2;

assign out1 = shiftedValue;

// This display value is correct!
// but it's still wrong in the test bench.
$display("out1 == %b", out1);

end

endmodule

module testStim;

reg [15:0] a;
reg [15:0] b;
wire [15:0] c;

// create ALU instance.
test myTest(a, b, c);

initial
begin

a = 16'b0001_0000_1010_0101;
b = 3;

#10
$display("op1In == %b, op1Out == %b", a, c);

$finish;

end

endmodule
这是运行simv后的输出(我去掉了错误的垃圾…):

谢谢,
Erik W.

您已经完成了所谓的程序性连续作业

常规连续作业与程序性连续作业的区别在于:

  • 连续分配只能驱动线/网数据类型。程序分配只能驱动reg数据类型,不能驱动网络
  • 连续赋值应出现在程序块外部(始终,初始等),而后者必须出现在程序块内部
  • 每次右侧表达式更改时,都会执行连续赋值。程序分配取决于always block的灵敏度列表
只要
始终
块结束,
assign
语句的效果就被删除。您必须添加
deassign
语句以保留值(我认为这不是真正的意图),或者从代码中删除
assign
语句。如下图所示:

shiftedValue = in1;
shiftedValue = shiftedValue * 2;
out1 = shiftedValue;

有关
assign
deassign
的详细信息,请访问和链接。

谢谢,这更有意义。@Erik343请接受答案以结束此问题。
shiftedValue = in1;
shiftedValue = shiftedValue * 2;
out1 = shiftedValue;