题解 | #数据选择器实现逻辑电路#
数据选择器实现逻辑电路
http://www.nowcoder.com/practice/00b0d01b71234d0b97dd4ab64f522ed9
这样的思路感觉更加直观,代码如下:
`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 //需要计算的表达式为 L= (A & B) |(A & (~C))|(B & C) module sel_exp( input A , input B , input C , output wire L ); wire x1; wire x2; wire x3; //如果S1为1,D3为0,则data_sel中Y的表达式为 Y = ~S0 & D2; 可用此计算A & (~C) data_sel U1( .S0(C) , .S1(1) , .D0(0) , .D1(0) , .D2(A) , .D3(0) , .Y(x1) ); //如果S1为1,D2为0,则data_sel中Y的表达式为 Y = S0 & D3; 可用此计算A & B以及B & C data_sel U2( .S0(A) , .S1(1) , .D0(0) , .D1(0) , .D2(0) , .D3(B) , .Y(x2) ); data_sel U3( .S0(C) , .S1(1) , .D0(0) , .D1(0) , .D2(0) , .D3(B) , .Y(x3) ); or O1(L, x1, x2, x3); endmodule