题解 | #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 ); // A=B xnor xnor1(_A0XN_B0,A[0],B[0]); xnor xnor2(_A1XN_B1,A[1],B[1]); xnor xnor3(_A2XN_B2,A[2],B[2]); xnor xnor4(_A3XN_B3,A[3],B[3]); and and1(Y1, _A0XN_B0, _A1XN_B1, _A2XN_B2, _A3XN_B3); // A>B not not1(_NB0, B[0]); not not1(_NB1, B[1]); not not1(_NB2, B[2]); not not1(_NB3, B[3]); and and2(_GT3, A[3], _NB3); and and3(_GT2, _A3XN_B3, A[2], _NB2); and and4(_GT1, _A3XN_B3, _A2XN_B2, A[1], _NB1); and and5(_GT0, _A3XN_B3, _A2XN_B2, _A1XN_B1, A[0], _NB0); or or1(Y2, _GT0 , _GT1, _GT2, _GT3); //Y0 = ~(Y1|Y2); nor nor1(Y0, Y1, Y2); endmodule
其实只要厘清思路,这题不算难写。