Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Question about different ways of describing MUX in Verilog

Status
Not open for further replies.

nervecell_23

Member level 1
Joined
Apr 26, 2013
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,565
For instance, to implement an registered 2-bits 5:1 MUX:

1) use 'case' statement:
Code:
reg [1:0] out;
wire [1:0] i_1, i_2, ... , i_5;

always@(posedge clk)
begin
    case(sel)
        3'b000: out <= i_1;
        3'b001: out <= i_2;
        ...
    endcase
end

I wonder whether the following 'array' style implementation would work or not:
Code:
wire [1:0] in [0:4];
wire [1:0] i_1, i_2, ... , i_5;
reg [1:0] out;

assign in[0] = i_1;
assign in[1] = i_2;
...
assign in[4] = i_5;

always@(posedge clk)
begin
    out <= in[sel];
end
 

Yes, an array works, but will result in out of range and indeterminate results if the sel exceeds the range of the [0:4] index. I'm pretty sure anything outside the range become don't cares, but verify that is the behavior in your synthesis tool.

Regards
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top