题目
现在有一个现成的四选一数据选择器,示意图如下。请使用此四选一数据选择器和必要的逻辑门实现r如下表达式:L=A∙B+A∙~C+B∙C。
该四选一选择器的代码如下。
module data_sel(
input S0 ,
input S1 ,
input D0 ,
input D1 ,
input D2 ,
input D3 ,
output wire Y
);
assign Y = ~S1 & (~S0&D0 | S0&D1) | S1&(~S0&D2 | S0&D3);
endmodule
根据该四选一数据选择器,我们可以得到该四选一选择器的输出Y=1的真值表,如下。
S1 | S0 | D0 | D1 | D2 | D3 | Y |
---|---|---|---|---|---|---|
0 | 0 | 1 | x | x | x | 1 |
0 | 1 | x | 1 | x | x | 1 |
1 | 0 | x | x | 1 | x | 1 |
1 | 1 | x | x | x | 1 | 1 |
而对于我们要实现的表达式:L=A∙B+A∙~C+B∙C。其真值表如下。
A | B | C | Y |
---|---|---|---|
0 | 0 | 0 | 0 |
0 | 0 | 1 | 0 |
0 | 1 | 0 | 0 |
0 | 1 | 1 | 1 |
1 | 0 | 0 | 1 |
1 | 0 | 1 | 0 |
1 | 1 | 0 | 1 |
1 | 1 | 1 | 1 |
对比上述两个真值表,我们可以对该四选一数据选择器进行连接,将四选一数据选择器的S1连接到A,S0连接到B,D0连接0,D1连接C,D2连接~C,D3连接1。
S1 | S0 | D0 | D1 | D2 | D3 | Y |
---|---|---|---|---|---|---|
A | B | 0 | C | ~C | 1 | Y |
0 | 0 | 0 | x | x | x | 0 |
0 | 1 | x | 1 | x | x | 1 |
1 | 0 | x | x | 0 | x | 1 |
1 | 1 | x | x | x | 1 | 1 |
答案
`timescale 1ns/1ns
module data_sel(
input S0 ,
input S1 ,
input D0 ,
input D1 ,
input D2 ,
input D3 ,
output wire Y
);
assign Y = ~S1 & (~S0&D0 | S0&D1) | S1&(~S0&D2 | S0&D3);
endmodule
module sel_exp(
input A ,
input B ,
input C ,
output wire L
);
data_sel data_sel_inst(
.S0(B),
.S1(A),
.D0(1'b0),
.D1(C),
.D2(~C),
.D3(1'b1),
. Y(L)
);
endmodule