项目场景:
This 4-to-1 multiplexer doesn’t work. Fix the bug(s).
You are provided with a bug-free 2-to-1 multiplexer:
module mux2 (
input sel,
input [7:0] a,
input [7:0] b,
output [7:0] out
);
问题描述
这个4:1多路复用器不能工作。修复bug(年代)。
您提供了一个无bug的2对1复用器:
module mux2 (
input sel,
input [7:0] a,
input [7:0] b,
output [7:0] out
);
Module Declaration
module top_module (
input [1:0] sel,
input [7:0] a,
input [7:0] b,
input [7:0] c,
input [7:0] d,
output [7:0] out );
原因分析:
对于2:1复用器,当sel =0 时 out = a,当sel = 1时out = b。二选一多路复用器组成一个四选一多路复用选择器。
由sel[0]可以确定第一层的选择是a与b中的一个,c与d中的一个,由sel与out的状态输入输出表可以看sel[1]决定的是选择ab还是cd,这样就可以通过两层选择来实现4:1多路选择器。如果还是难以理解,我们不妨利用穷举法将可能的情况一一列出。
解决方案:
module top_module (
input [1:0] sel,
input [7:0] a,
input [7:0] b,
input [7:0] c,
input [7:0] d,
output [7:0] out ); //
wire [7:0] mux0, mux1;
mux2 mux2_inst0 (
.sel (sel[0]),
.a (a),
.b (b),
.out (mux0)
);
mux2 mux2_inst1 (
.sel (sel[0]),
.a (c),
.b (d),
.out (mux1)
);
mux2 mux2_inst2 (
.sel (sel[1]),
.a (mux0),
.b (mux1),
.out (out)
);
endmodule