我對Verilog HDL有一個奇怪的問題。 我在我的代碼中發現,如果我將一個變量乘以2,但是然後 將該值賦給同一個變量,它會全部搞砸了。 有時,simv程序甚至崩潰。我原本需要這樣做, ,因爲我有一個for循環移位或旋轉一定的數量。但是, 然後我發現不僅移動相同的變量不起作用,但 ,加法,減法,乘法或除法也不起作用。verilog分配給相同的變量不起作用
所以在我的代碼示例中,如果將a設置爲16'b0001_0000_1010_0101,並將b設置爲3,則可以獲得16'b0000_0000_0000_0000的輸出。請注意,我現在無視b ...我應該得到16'b0010_0001_0100_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;
[email protected](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
這是運行通氣後輸出(I剝離出來的錯誤的垃圾...):
out1 == 0010000101001010
op1In == 0001000010100101, op1Out == 0000000000000000
謝謝, Erik W.
謝謝,這樣做更有意義。 – Erik343
@ Erik343請接受關閉此問題的答案。 – sharvil111