Prev Problem
Next Problem

50. 3-Way Selector

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

 

Code

//==================================================
// Module: selector3
// Description: 3-way selector using sel[1:0].
//==================================================
module selector3 (
    input  wire [7:0] a,
    input  wire [7:0] b,
    input  wire [7:0] c,
    input  wire [1:0] sel,
    output reg  [7:0] y
);

    always @(*) begin
        if (sel == 2'b00)
            y = a;
        else if (sel == 2'b01)
            y = b;
        else if (sel == 2'b10)
            y = c;
        else
            y = 8'h00;  // Default for invalid sel (2'b11 or x/z)
    end

endmodule

 

Was this helpful?
Upvote
Downvote