`timescale 1ns/1ns
module comparator_4(
input [3:0] A ,
input [3:0] B ,
output Y2 , //A>B
output Y1 , //A=B
output Y0 //A<B
);
assign Y2 = (A[3]&(!B[3])) | ( !(A[3]^ B[3]) & (A[2]& (!B[2])))| (!(A[3:2]^ B[3:2]) & (A[1]&(!B[1]))) | (!(A[3:1]^ B[3:1]) & (A[0]&(!B[0])));
assign Y1 = !(A ^ B);
assign Y0 = (!A[3]&B[3]) | ( !(A[3]^ B[3]) & (!A[2]& B[2]))| (!(A[3:2] ^ B[3:2]) & (!A[1] & B[1])) | (!(A[3:1]^ B[3:1]) & (!A[0] & B[0]));
/*
always@(*)begin
if(A[3]> B[3]) begin
Y2 = 1'b1;
Y1 = 1'b0;
Y0 = 1'b0;
end
else if(A[3]< B[3]) begin
Y2 = 1'b0;
Y1 = 1'b0;
Y0 = 1'b1;
end
else begin
if(A[2]> B[2]) begin
Y2 = 1'b1;
Y1 = 1'b0;
Y0 = 1'b0;
end
else if(A[2]< B[2]) begin
Y2 = 1'b0;
Y1 = 1'b0;
Y0 = 1'b1;
end
else begin
if(A[1]> B[1]) begin
Y2 = 1'b1;
Y1 = 1'b0;
Y0 = 1'b0;
end
else if(A[1]< B[1]) begin
Y2 = 1'b0;
Y1 = 1'b0;
Y0 = 1'b1;
end
else begin
if(A[0]> B[0]) begin
Y2 = 1'b1;
Y1 = 1'b0;
Y0 = 1'b0;
end
else if(A[0]< B[0]) begin
Y2 = 1'b0;
Y1 = 1'b0;
Y0 = 1'b1;
end
else begin
Y2 = 1'b0;
Y1 = 1'b1;
Y0 = 1'b0;
end
end
end
end
end
*/
endmodule