Prev Problem
Next Problem

48. Safe MUX

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

 

Code

//==================================================
// Module: safe_mux2
// Description: 2:1 MUX that clamps output to 0 when
// sel is unknown (x/z) in simulation.
//==================================================
module safe_mux2 (
    input  wire [7:0] a,
    input  wire [7:0] b,
    input  wire       sel,
    output reg  [7:0] y,
    output reg        sel_unknown
);

    always @(*) begin
        if (sel === 1'b0) begin
            y = a;
            sel_unknown = 0;
        end
        else if (sel === 1'b1) begin
            y = b;
            sel_unknown = 0;
        end
        else begin
            // sel is x or z
            y = 8'h00;
            sel_unknown = 1;
        end
    end

endmodule

 

Was this helpful?
Upvote
Downvote