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] max0, min0, max1, min1;
always @(*) begin
    max0 = a >= b ? a : b;
    min0 = a < b ? a : b;
    max1 = c >= d ? c : d;
    min1 = c < d ? c : d;
    max = max0 >= max1 ? max0 : max1;
    min = min0 < min1 ? min0 : min1;
end
endmodule

 

Was this helpful?
Upvote
Downvote