题解 | #4位数值比较器电路#
4位数值比较器电路
https://www.nowcoder.com/practice/e02fde10f1914527b6b6871b97aef86d
`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 out0_xnor,out1_xnor,out2_xnor,out3_xnor,out0_not,out1_not,out2_not,out3_not, out0_and,out1_and,out2_and,out3_and,out4_and,out5_and,out6_and; xnor xonr0(out0_xnor,A[0],B[0]), xonr1(out1_xnor,A[1],B[1]), xonr2(out2_xnor,A[2],B[2]), xonr3(out3_xnor,A[3],B[3]); not not0(out0_not,B[0]), not1(out1_not,B[1]), not2(out2_not,B[2]), not3(out3_not,B[3]); and and0(out0_and,A[0],out0_not),//A[0]&&!B[0] and1(out1_and,A[1],out1_not),//A[1]&&!B[1] and2(out2_and,A[2],out2_not),//A[2]&&!B[2] and3(out3_and,A[3],out3_not),//A[3]&&!B[3] and4(out4_and,out3_xnor,out2_and),// and5(out5_and,out3_xnor,out2_xnor,out1_and), and6(out6_and,out3_xnor,out2_xnor,out1_xnor,out0_and), and7(Y1,out0_xnor,out1_xnor,out2_xnor,out3_xnor); or or0(Y2,out3_and,out4_and,out5_and,out6_and); nor nor0(Y0,Y1,Y2); endmodule