I know SystemVerilog and now I'm trying to learn pure Verilog. I find the way reg
works to be rather odd. I thought wire
is used for signals that are continuously driven like the output of combinational logic, and reg
is used for signals that can retain their state, such as the output of flip flops or latches.
However I read that any signal assigned inside of an always
block must be reg
. Even if the behavior is modeling combinational logic, like in a case
statement, which leads to the following weird situation:
Example a:
assign y = s ? a : b;
Example b:
always @* begin
if (s)
y = a;
else
y = b;
end
In example a y
would be wire
whereas in example b y
must be reg
. However they both describe the same thing. My only explanation for this is that within a combinational always
it is possible to accidentally leave no specified output for some inputs, implying a latch which should be reg
so they force it to always be reg
.
Please help me understand the reasoning for how reg
works in Verilog.