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?

At first compare a and b,then c and d ,finally compare both the results.

 

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]max01,min01,min23,max23;
always@*
begin
    max01=(a>b)?a:b;
    min01=(a<b)?a:b;
    max23=(c>d)?c:d;
    min23=(c<d)?c:d;
     max=(max01>max23)?max01:max23;
     min=(min01<min23)?min01:min23;
end
endmodule

 

Was this helpful?
Upvote
Downvote