当我们将 2 个值分配给同一个变量时会发生什么?

What happens when we assign 2 values to same variable?

我正在尝试做一个简单的断言来检查两个值是否相等。有人可以解释当我为同一个变量分配两个不同的值时的行为

logic src_sig ;
logic dest_sig;
logic alt_sig;

assign a = src_sig;
assign a = alt_sig;
assign b = dest_sig;

我的断言顺序是:

sequence check_seq(X,Y);
(X == Y);
endsequence

我的初始区块是:

initial begin

#100 @ (posedge clk) begin
src_sig <= 1;
dest_sig <=1;
alt_sig <= 0;
end

#10 @ (posedge clk) begin
src_sig <=1;
dest_sig <=0;
alt_sig <= 0;
end

#10 @ (posedge clk) begin
src_sig <= 0;
dest_sig <= 0;
alt_sig <= 1;
end

#10 @ (posedge clk) begin
src_sig <= 0;
dest_sig <= 1;
alt_sig <= 1;
end

#30 $finish;
end

我原以为第二个赋值会覆盖第一个赋值,或者它会同时赋值给 src_sigalt_sig。因此,它应该分别显示 2 次或 4 次违规。但我得到以下结果(3 次违规)。

"testbench.sv", 31: test.check_assert: started at 103ns failed at 103ns
    Offending '(a == b)'
"testbench.sv", 31: test.check_assert: started at 113ns failed at 113ns
    Offending '(a == b)'
"testbench.sv", 31: test.check_assert: started at 133ns failed at 133ns
    Offending '(a == b)'

请解释这里发生了什么?

编辑::完整代码

module test_gcc();
logic clk=0; 
logic src_sig,dest_sig,alt_sig;
assign a = src_sig;
assign a = alt_sig;
assign b = dest_sig;
initial begin 
clk = 0;
forever #1 clk=~clk;
end

sequence check_seq(X,Y);
(X == Y);
endsequence
property check_connection(M,N);
@(posedge clk)
($rose(M)||$rose(N)||$fell(M)||$fell(N)) |-> check_seq(M,N);
endproperty
check_assert : assert property (check_connection(a,b));
initial begin

#100 @ (posedge clk) begin
src_sig <= 1;
dest_sig <=1;
alt_sig <= 0;
end
#10 @ (posedge clk) begin
src_sig <=1;
dest_sig <=0;
alt_sig <= 0;
end

#10 @ (posedge clk) begin
src_sig <= 0;
dest_sig <= 0;
alt_sig <= 1;
end
#10 @ (posedge clk) begin
src_sig <= 0;
dest_sig <= 1;
alt_sig <= 1;
end
#30 $finish;
end
endmodule

ab 是 1 位的 wire,因为你没有声明它们。 (在 Verilog/SV 中,除非您指定 default_nettype none,否则未声明的对象是 wire

If you drive a wire from more than one place then a resolution function is executed in order to evaluate the value on the wire.

在您的情况下,wire a 上有两个 驱动程序 - 两个 assign 语句。 initial 块确保不同的值始终由两个 assign 语句驱动,因此在线路上的 解析值 始终是 1'bxwire a 上的值永远不会改变。

wire b 仅由一个 assign 语句驱动。 initial 块确保它的值在 101ns、111ns 和 131ns 时发生变化。 wire b 上的值在 121ns 时不变。

您已经编写了 property,以便仅在 wire awire b 发生变化时才检查 条件

  property check_connection(M,N);
    @(posedge clk)
    ($rose(M)||$rose(N)||$fell(M)||$fell(N)) |-> check_seq(M,N);
  endproperty

wire a 永远不会改变并且 wire b 在 121ns 时不会改变,因此在 121ns 时不会检查条件。