Prev Problem
Next Problem

68. 4-bit Comparator

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

module maxmin4 (
    input [3:0] a,
    input [3:0] b,
    input [3:0] c,
    input [3:0] d,
    output reg [3:0] max,
    output reg [3:0] min
);
    reg [3:0] max_ab, min_ab, max_cd, min_cd;
    always @ (a or b or c or d) begin
        max_ab = (a >= b) ? a : b;
        min_ab = (a  <  b) ? a : b;

        max_cd = (c >= d) ? c : d;
        min_cd = (c  <  d) ? c : d;
        // Final
        max = (max_ab >= max_cd) ? max_ab : max_cd;
        min = (min_ab  <  min_cd) ? min_ab : min_cd;
    end
endmodule

 

Was this helpful?
Upvote
Downvote