要求:创建一个16位宽的9对1多路复用器。sel=0选择a,sel=1选择b,以此类推。对于未使用的情况(sel=9到15),将所有输出位设置为“1”。
由于位数较多采用三目运算符逻辑较为麻烦,此处可采用case语句:
代码如下:
module top_module(
input [15:0] a, b, c, d, e, f, g, h, i,
input [3:0] sel,
output [15:0] out );
always@(*)
case(sel)
4'd0:out = a;
4'd1:out = b;
4'd2:out = c;
4'd3:out = d;
4'd4:out = e;
4'd5:out = f;
4'd6:out = g;
4'd7:out = h;
4'd8:out = i;
default: out =16'hffff;
endcase
endmodule
仿真结果:

314

被折叠的 条评论
为什么被折叠?



