Create a circuit that has two 2-bit inputs A[1:0] and B[1:0], and produces an output z. The value of z should be 1 if A = B, otherwise z should be 0.
译:
创建一个电路,它有两个2位输入a[1:0]和B[1:0],并产生一个输出z。如果a = B, z的值应该是1,否则z应该是0。
第一种方法,与上一题呼应;
module top_module ( input [1:0] A, input [1:0] B, output z );
assign z =( ~(A[0]^B[0]) ) & ~(A[1]^B[1]);
endmodule
系统推荐的两种解法:
module top_module(
input [1:0] A,
input [1:0] B,
output z);
assign z = (A[1:0]==B[1:0]); // Comparisons produce a 1 or 0 result.
// Another option is to use a 16-entry truth table ( {A,B} is 4 bits, with 16 combinations ).
// There are 4 rows with a 1 result. 0000, 0101, 1010, and 1111.
endmodule
运行结果: