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 (
    input  wire [7:0] a,
    input  wire [7:0] b,
    input  wire       sel,
    output reg  [7:0] y,
    output reg        sel_unknown
);

always @(*) begin
    // default values
    y = 8'h00;
    sel_unknown = 1'b0;

    // sel = 0
    if (sel === 1'b0) begin
        y = a;
    end

    // sel = 1
    else if (sel === 1'b1) begin
        y = b;
    end

    // sel = X or Z
    else begin
        y = 8'h00;
        sel_unknown = 1'b1;
    end
end

endmodule

 

Was this helpful?
Upvote
Downvote