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

For the above code, I am getting error:

: 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.
toolic
  • 57,801
  • 17
  • 75
  • 117
  • Anyway, your `always` is not really necessary. Your sensitivity list is `a,B`. Your assignments are `a^B` and `a&B`. The definition of `assign` is that the value of the RHS is calculated and assigned to the LHS **whenever any of the RHS operands change**. So simple assignments will work here just the same – Tomerikoo Oct 22 '20 at 14:31

1 Answers1

0

sum and carry are not valid l-values because they are driven in a always block. They should be declared as reg.

reg sum, carry;

When a port is not declared with a type, it automatically gets a type of wire.

Light
  • 1,206
  • 1
  • 9
  • 16