Prev Problem
Next Problem

68. 4-bit Comparator

Back To All Submissions
Previous Submission
Next Submission

Solution of 4-bit comparator

How do you plan to solve it?

Divided code in 2 stage comparisons to make it simpler.

 

Code

/*Write your code here*/
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);

    wire [3:0] max_ab, min_ab;
    wire [3:0] max_cd, min_cd;

    assign max_ab = (a>b) ? a:b;
    assign min_ab = (a<b) ? a:b;

    assign max_cd = (c>d) ? c:d;
    assign min_cd = (c<d) ? c:d;

    assign max = (max_ab > max_cd) ? max_ab:max_cd;
    assign min = (min_ab < min_cd) ? min_ab:min_cd;

endmodule

 

Was this helpful?
Upvote
Downvote