描述
请使用此4选1数据选择器和必要的逻辑门实现下列表达式。
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
输入描述:
input A ,
input B ,
input C
输出描述:
output wire L
解题分析
根据逻辑表达式,可列出真值表如下:
A | B | C | L | |
0 | 0 | 0 | 0 | L=0 |
0 | 0 | 1 | 0 | |
0 | 1 | 0 | 0 | L=C |
0 | 1 | 1 | 1 | |
1 | 0 | 0 | 1 | L=~C |
1 | 0 | 1 | 0 | |
1 | 1 | 0 | 1 | L=1 |
1 | 1 | 1 | 1 |
将变量A、B接入4选1数据选择器选择输入端S0 S1。将变量C分配在数据输入端。从表中可以看出输出L与变量C的关系。
当AB=00时选通D0而此时L=0,所以数据端D0接0:当AB=01时选通D1,由真值表得此时L=C,即D1应接C:当AB为10和11时,D2和D3分别接~C和1。
所以可画出电路图如下:
A接S1,B接S0。
根据电路图和分析思路,将电路转换成Verilog代码描述如下:
data_sel U0(
.S0 (B),
.S1 (A),
.D0 (0),
.D1 (C),
.D2 (~C),
.D3 (1),
.Y (L)
);
参考代码
`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 U0(
.S0 (B),
.S1 (A),
.D0 (0),
.D1 (C),
.D2 (~C),
.D3 (1),
.Y (L)
);
endmodule
注:解题分析来源于网友,如有侵权,请告删之。