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] maxab,maxcd,minab,mincd;
  always @(*) begin
    maxab = (a>=b)? a:b;
    minab = (a<b) ? a:b;
    maxcd = (c>=d)? c:d;
    mincd = (c<d)? c:d;
    max = (maxab >= maxcd)? maxab:maxcd;
    min = (minab < mincd)? minab:mincd;
  end
endmodule

 

Was this helpful?
Upvote
Downvote