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

/*Write your code here*/
module maxmin4(
    input [3:0]a,b,c,d,
    output reg [3:0]max,min
);
  reg [3:0]max_01,max_23;
  reg [3:0]min_01,min_23;

  always@(*)begin
    max_01 = 4'd0;
    max_23 = 4'd0;
    min_01 = 4'd0;
    min_23 = 4'd0;

    max_01 = a > b? a : b;
    max_23 = c > d? c : d;

    min_01 = a < b? a : b;
    min_23 = c < d? c : d;

    max = max_01 > max_23? max_01 : max_23;
    min = min_01 < min_23? min_01 : min_23;
  end
endmodule

 

Was this helpful?
Upvote
Downvote