面向表格编程
`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 a_1 = A[3]>B[3] ? 1'b1 : 1'b0;
wire a_2 = A[3]==B[3] ? 1'b1 : 1'b0;
wire a_3 = A[3]<B[3] ? 1'b1 : 1'b0;
wire b_1 = A[2]>B[2] ? 1'b1 : 1'b0;
wire b_2 = A[2]==B[2] ? 1'b1 : 1'b0;
wire b_3 = A[2]<B[2] ? 1'b1 : 1'b0;
wire c_1 = A[1]>B[1] ? 1'b1 : 1'b0;
wire c_2 = A[1]==B[1] ? 1'b1 : 1'b0;
wire c_3 = A[1]<B[1] ? 1'b1 : 1'b0;
wire d_1 = A[0]>B[0] ? 1'b1 : 1'b0;
wire d_2 = A[0]==B[0] ? 1'b1 : 1'b0;
wire d_3 = A[0]<B[0] ? 1'b1 : 1'b0;
assign Y2 = a_1 || (a_2 && b_1 )|| (a_2 && b_2 && c_1) || (a_2 && b_2 && c_2 && d_1) ;
assign Y1 = a_2 && b_2 && c_2 && d_2;
assign Y0 = a_3 || (a_2 && b_3) || (a_2 && b_2 && c_3) || (a_2 && b_2 && c_2 && d_3) ;
endmodule