Prev Problem
Next Problem

68. 4-bit Comparator

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

Use intermediate wires to split find maxes of 2 numbers and then find their max and min later.

 

Code

/*Write your code here*/
module maxmin4 (
    input [3:0] a,
    input [3:0] b,
    input [3:0] c,
    input [3:0] d,
    output wire [3:0] max,
    output wire [3:0] min
);
    wire [3:0] max1;
    wire [3:0] max2;
    wire [3:0] min1;
    wire [3:0] min2;
    assign max1 = (a>b)? a:b;
    assign max2 = (c>d)? c:d;
    assign max = (max1>max2)? max1:max2;
    assign min1 = (a>b)? b:a;
    assign min2 = (c>d)? d:c;
    assign min = (min1>min2)? min2:min1;
endmodule

 

Was this helpful?
Upvote
Downvote