0
点赞
收藏
分享

微信扫一扫

HDLBits练习汇总-07-组合逻辑设计测试--选择器电路


2选1数据选择器

创建一个 1 位宽的 2 对 1 多路复用器。当sel=0时,选择a。当 sel=1 时,选择 b。

Module Declaration

module top_module( 
input a, b, sel,
output out );

答案:

module top_module( 
input a, b, sel,
output out );
assign out = (sel==0)?a:b;

2选1数据选择器(向量)

创建一个 100 位宽的 2 对 1 多路复用器。当sel=0时,选择a。当 sel=1 时,选择 b。
Module Declaration

module top_module( 
input [99:0] a, b,
input sel,
output [99:0] out );

答案:

module top_module( 
input [99:0] a, b,
input sel,
output [99:0] out );
assign out =(sel == 0)? a:b;

9选1数据选择器

创建一个 16 位宽的 9 对 1 多路复用器。sel=0 选择a,sel=1 选择b,等等。对于未使用的情况(sel=9 到15),将所有输出位设置为’1’。
Module Declaration

module top_module( 
input [15:0] a, b, c, d, e, f, g, h, i,
input [3:0] sel,
output [15:0] out );

答案:

module top_module( 
input [15:0] a, b, c, d, e, f, g, h, i,
input [3:0] sel,
output [15:0] out );
always @(*)begin
case(sel)
0:out = a;
1:out = b;
2:out = c;
3:out = d;
4:out = e;
5:out = f;
6:out = g;
7:out = h;
8:out = i;
default:out = 16'b1111_1111_1111_1111;

256选1数据选择器

创建一个 1 位宽、256 比 1 的多路复用器。256 个输入全部打包成一个 256 位的输入向量。sel=0 应该选择in[0], sel=1 选择位in[1], sel=2 选择位in[2]等。
Module Declaration

module top_module( 
input [255:0] in,
input [7:0] sel,
output out );

答案:

module top_module( 
input [255:0] in,
input [7:0] sel,
output out );
assign out = in[sel];

256选1数据选择器(向量)

创建一个4位宽,256对1的多路复用器。256个4位输入全部打包到一个1024位输入向量中。Sel =0应该选择[3:0]中的位,Sel =1选择[7:4]中的位,Sel =2选择[11:8]中的位,等等。
Module Declaration

module top_module( 
input [1023:0] in,
input [7:0] sel,
output [3:0] out );

答案:

module top_module( 
input [1023:0] in,
input [7:0] sel,
output [3:0] out );
assign out = in[sel*4+3 -:4];


举报

相关推荐

0 条评论