首页 > 解决方案 > 将始终块用于半加器时出错:总和不是有效的左值

问题描述

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.

标签: verilog

解决方案


sum并且carry不是有效的左值,因为它们是在一个always块中驱动的。它们应该被声明为reg.

reg sum, carry;

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


推荐阅读