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?

compare a,b and c,d seperately, compare the results of both

Code

/*Write your code here*/
module maxmin4(
    input [3:0] a,b,c,d,
    output [3:0] max,min
);
    wire [3:0] maxab, minab, maxcd, mincd;
    assign maxab = (a >= b) ? a : b;
    assign minab = (a < b) ? a : b;
    assign maxcd = (c >= d) ? c : d;
    assign mincd = (c < d) ? c : d;
    assign max = (maxab >= maxcd) ? maxab : maxcd;
    assign min = (minab < mincd) ? minab : mincd;
endmodule

 

Was this helpful?
Upvote
Downvote