`timescale 1ns/1ns
module comparator_4(
input [3:0] A ,
input [3:0] B ,
output wire Y2 , //A>B
output wire Y1 , //A=B
output wire Y0 //A<B
);
wire[3:0] y0,y1,y2;
genvar i;
for (i=0;i<4;i=i+1)
begin
comparator_1 u(.a(A[i]),.b(B[i]),.y0(y0[i]),.y1(y1[i]),.y2(y2[i]));
end
assign Y2=y2[3]||y1[3]&y2[2]||y1[3]&y1[2]&y2[1]||y1[3]&y1[2]&y1[1]&y2[0];
assign Y0=y0[3]||y1[3]&y0[2]||y1[3]&y1[2]&y0[1]||y1[3]&y1[2]&y1[1]&y0[0];
assign Y1=&y1;
endmodule
module comparator_1(
input a,
input b,
output y0, y1,y2
);
assign y2=a&~b;
assign y1=a~^b;
assign y0=~a&b;
endmodule