对半加法器使用始终块时出错:sum不是有效的l值

  • 本文关键字:sum 有效 出错 加法器 verilog
  • 更新时间 :
  • 英文 :

module halfadder(a,B,sum,carry);
input a,B;
output sum,carry;
always@(a,B)
begin
sum=a^B;
carry=a&B;
end
endmodule

对于上面的代码,我得到错误:

: sum is not a valid l-value in tb_halfadder.ha.
: sum is declared here as wire.
: carry is not a valid l-value in tb_halfadder.ha.
: carry is declared here as wire.

sumcarry不是有效的l值,因为它们是在always块中驱动的。它们应声明为reg

reg sum, carry;

当端口没有用类型声明时,它会自动获得类型wire

最新更新