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);

    task minmax;
      input [3:0]w,x,y,z;
      output [3:0]m,n;
       reg [3:0]m1,m2,n1,n2;

       begin

       m1 = w>x ? w : x;
       n1 = w<x ? w : x;

       m2 = y>z ? y : z;
       n2 = y<z ? y : z;

       m = m1>m2 ? m1 : m2;
       n = n1<n2 ? n1 : n2;
       end
    endtask
       reg [3:0]x1,x2;
    always @* begin
      minmax(a,b,c,d,x1,x2);
      max = x1;
      min = x2;

    end   
endmodule  

 

Was this helpful?
Upvote
Downvote