Search code examples
verilogsimulationhdlmodelsim

Verilog error in modelsim- near "=": syntax error, unexpected '=', expecting IDENTIFIER or TYPE_IDENTIFIER or NETTYPE_IDENTIFIER


I am facing following error in modelsim 10.4:

Error: (vlog-13069) D:/divya/verilog/pipelined alu/alu.v(5): near "=": syntax error, unexpected '=', expecting IDENTIFIER or TYPE_IDENTIFIER or NETTYPE_IDENTIFIER.

The code:

module func(output reg[15:0] out,input[15:0] a,b,input[3:0] select);


case(select)

0:out=a+b;

1:out=a-b;

2:out=a*b;

3:out=a;

4:out=b;

5:out=a&b;

6:out=a|b;

7:out=a^b;

8:out=~a;

9:out=~b;

10:out=a>>1;
11:out=a<<1;

default:out=16'hxxxx;

endcase

endmodule

Solution

  • When implementing combinational logic as you have above, you need to be sure you place the functional description inside a procedural block like an always @(*) or assign statement (which one of those you use depends on the length of the logic and other minor factors). Below is your code with a bit of formatting (remember, coding style isnt just about aesthetics; it also helps find bugs and makes reading code much easier!):

    module func(output reg [15:0] out,
                input [15:0] a, b,
                input [3:0] select); // I like to break up io on multiple lines to make it easier to read
    
      always @(*) begin // Need to put logic in a procedural block!
        case(select)
        0: out = a + b;
        1: out = a - b;
        2: out = a * b; // Note that this would take quite a bit of logic compared to all the other operations here, combinational multiply take alot of gates
        3: out = a;
        4: out = b;
        5: out = a & b;
        6: out = a | b;
        7: out = a ^ b;
        8: out = ~a;
        9: out = ~b;
        10: out = a >> 1;
        11: out = a << 1;
        default: out = 16'hxxxx;
        endcase
      end
    endmodule