Mux(Bugs mux4)

项目场景:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值