verilog 阻塞赋值方式实现2选1多路选择器

2025-02-24 08:08:06
推荐回答(1个)
回答1:

module mux2_1(out,a,b,sel);
input a,b,sel;
output out;
reg out;
always@(a or b or sel)
begin
if(sel==0) out=a; //阻塞赋值
else out=b; //阻塞赋值
end
endmodule

//下面是一个简单的测试平台,可以根据不同的要求编写
module t_mux2_1;
reg a,b,sel;
wire out;
initial
begin
a=0;
b=1;
sel=0;
#100
sel=0;
end
mux2_1 u1(.a(a),.b(b),.sel(sel),.out(out));
endmodule