How to eliminate Verilog instance syntax error

Viewed 50

This code is of 4:1 mux from three 2:1 muxes, and I am getting this syntax error. How do I eliminate this error?

ERROR:HDLCompiler:806 - "D:\Verilog\muxx\mux4.v" Line 12: Syntax error near "[".
ERROR:HDLCompiler:806 - "D:\Verilog\muxx\mux4.v" Line 13: Syntax error near "[".
ERROR:HDLCompiler:806 - "D:\Verilog\muxx\mux4.v" Line 14: Syntax error near "[".

module fmux(

input [3:0] a,
input [1:0] s,
output o
);
wire x,y;


 muxx m0(.a[0](a[0]), .a[1](a[1]), .s(s[0]), .o(x));    //error
 muxx m1(.a[0](a[2]), .a[1](a[3]), .s(s[0]), .o(y));   //error
 muxx m2(.a[0](x), .a[1](y), .s(s[1]), .o(o));        //error

endmodule
1 Answers

The syntax error points to .a[0].

Assuming your muxx ports look like the following, then you can make your connections as follows:

module muxx (
    input [1:0] a,
    input s,
    output o
);
endmodule

module fmux (
    input [3:0] a,
    input [1:0] s,
    output o
);
    wire x,y;

    muxx m0 (.a(a[1:0]), .s(s[0]), .o(x));
    muxx m1 (.a(a[3:2]), .s(s[0]), .o(y));
    muxx m2 (.a({y, x}), .s(s[1]), .o(o)); 
endmodule
Related