其实其他人的回答都不是完全的门级描述,都有一定的行为级的抽象。 不如抽象到极致。 简单一点
````timescale 1ns/1ns
module comparator_4(
input [3:0] A ,
input [3:0] B ,
output reg Y2 , //A>B
output reg Y1 , //A=B
output reg Y0 //A<B
);
always @ (A or B)
begin
if(A>B)
begin
Y2=1;
Y1=0;
Y0=0;
end
else if (A<B)
begin
Y2=0;
Y1=0;
Y0=1;
end
else
begin
Y2=0;
Y1=1;
Y0=0;
end
end
endmodule