Verilog does not allow ports to have default values. To be Verilog complient, change input [2:0]code=3'b000;
to input [2:0]code;
and never assign code
inside you gray_counter module.
SystemVerilog does allow it with ANSI style module headers per IEEE1800-2012 ยง 23.2.2.2 ANSI style list of port declarations. Same section for with the newer IEEE1800-2017. I could not fined examples in the LRMs, but it is clear form the syntax. I didn't find they same syntax in the older IEEE1800-2005. I didn't see the LRMs suggest default assignment is legal for non-ANSI headers; however I did noticed that simulators that support defaults with ANSI module headers are also supporting non-ANSI.
To enable SystemVerilog parsing, change the file extension from .v
to .sv
. Note that some simulators only supported a limited subset of SystemVerilog features. Ports with default values may not be supported on your simulator or synthesizer. If not, you must remove the default assignment.
Normally you want to drive all your inputs where it is instantiated. By giving assigning a default to an input, you make the connection optional. This is not common practice in the industry, partly because the full tool chain (simulator, synthesizer, linter, etc.) need to support it, and partly because coding/debugging practices.
With SystemVerilog you can assign an input a default, but in most cases you should not.