门级 Verilog 和行为 Verilog 可以混合使用吗?

Can gate level verilog and behavioral Verilog be mixed?

我一直在研究一个非常简单的 verilog 示例。可以在门模块中使用阻塞表达式吗?

我不知道out=0;这句话在那个模块里是对还是错。这个模块会被模拟吗?

module what_is_it (in1, in2, in3, out);
 output out;
 input in1, in2, in3;
out = 0;
 and a1(a1_o, in1, in3);
 and a2(a2_o, in2, ~in3);
 or o1(out, a1_o, a2_o);
endmodule

此语法无效。即使您添加 assign 关键字来消除可能的编译错误,out 也将是未定义的。

让我们暂时忽略 out = 0。您可以将模块重写为

module what_is_it (in1, in2, in3, out);
   output out;
   input in1, in2, in3;

   assign out = (in1 && in3) || (in2 && ~in3);
endmodule

通过这种表示,out连续 赋值(Section 10.3, IEEE Std 1800-2012)更清楚输入端口的逻辑组合。

在此之前添加 (assign) out = 0 是没有意义的,因为您会连续驱动来自两个不同来源的相同信号。

如果你想要一个阻塞赋值,你应该将你的逻辑包装在一个组合的 always 块中。请参阅下面的示例。

module what_is_it (in1, in2, in3, out);
   output reg out;
   input in1, in2, in3;

   always @(*) begin
       out = 0;
       out = (in1 && in3) || (in2 && ~in3);
   end
endmodule