Prev Problem
Next Problem

68. 4-bit Comparator

Back To All Submissions
Previous Submission
Next Submission

Code

module maxmin4 (
    input [3:0] a,
    input [3:0] b,
    input [3:0] c,
    input [3:0] d,
    output [3:0] max,
    output [3:0] min
);
    reg [3:0] min01, min23, max01, max23, min_o, max_o;

    assign max = max_o;
    assign min = min_o;

    always @* begin
        min01 = (a < b) ? a : b;
        max01 = (a > b) ? a : b;
        min23 = (c < d) ? c : d;
        max23 = (c > d) ? c : d;
        min_o = (min01 < min23) ? min01 : min23;
        max_o = (max01 > max23) ? max01 : max23;
    end
endmodule

 

Was this helpful?
Upvote
Downvote