题目
某4位数值比较器的功能表如下。请用Verilog语言采用门级描述方式,实现此4位数值比较器。
信号 | 类型 | 输入/输出 | 位宽 |
---|
A | wire | Intput | 4 |
B | wire | Intput | 4 |
Y2 | wire | Output | 1 |
Y1 | wire | Output | 1 |
Y0 | wire | Output | 1 |
A与B大小关系关系 | Y0 | Y1 | Y2 |
---|
A > B | 0 | 0 | 1 |
A = B | 0 | 1 | 0 |
A < B | 1 | 0 | 0 |
答案
`timescale 1ns/1ns
module comparator_4(
input [3:0] A ,
input [3:0] B ,
output wire Y2 ,
output wire Y1 ,
output wire Y0
);
assign Y1 = (A[3]==B[3])&&(A[2]==B[2])&&(A[1]==B[1])&&(A[0]==B[0]);
assign Y0 = (A[3]<B[3])||((A[3]==B[3])&&(A[2]<B[2]))||((A[3]==B[3])&&(A[2]==B[2])&&(A[1]<B[1]))||((A[3]==B[3])&&(A[2]==B[2])&&(A[1]==B[1])&&(A[0]<B[0]));
assign Y2 = (~Y0) && (~Y1);
endmodule