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.
sum
和carry
不是有效的l值,因为它们是在always
块中驱动的。它们应声明为reg
。
reg sum, carry;
当端口没有用类型声明时,它会自动获得类型wire
。