1
votes

I am using the Icarus compiler, and I'm doing a Mux 4:1.

The code is:

module mux (in,out,select);

input   [3:0] in;
input   [1:0] select;
output  reg out;

always@(select or in)
begin
    if (select == 2b'00)

        out = in[0];
    end 

    else if (select == 2b'01)
    begin
        out = in[1];
    end

    else if (select == 2b'10)
    begin   
        out = in[2];
    end

    else if (select == 2b'11)
    begin
        out = in[3];
    end

end
endmodule

But, I get this message from the compiler:

enter image description here

Is the problem because I'm using bit format inside "if" expression instead of "int" expression?

2

2 Answers

2
votes

The problem with your code is you are writing 2b'00 instead of 2'b00 and Icarus is getting confused thinking you are writing SystemVerilog code, which is not correct either. So either fix your literals, or write your code more efficently as Morgan has posted.

1
votes

Try (with verilog 2005 or later):

module mux (  
  input       [3:0] in,
  input       [1:0] select,
  output  reg       out
);
  always @* begin
    out = in[select];
  end
endmodule