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,
    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] max1, min1, max2, min2;
always@(*)begin
  if(a>b)begin
  max1<=a;
  min1<=b;
  end else begin
  max1<=b;
  min1<=a;
  end

  if(c>d)begin 
  max2<=c;
  min2<=d;
  end else begin
  max2<=d;
  min2<=c;
  end

  if(max1>max2)
    max=max1;
  else
    max=max2;

  if(min1>min2)
    min<=min2;
  else
    min<=min1;

end
endmodule

 

Was this helpful?
Upvote
Downvote