二选一多路器为数字电路中讲过,如果SEL=1,out=a;如果SEL=0,out=b;
真值表达式如下:
SEL | out |
1 | a |
0 | b |
用verilog语言有两种写法:
module mux2(
input SEL,
input a,
input b,
output reg out
);
always @ (*)
if(SEL)
out = a;
else
out = b;
endmodule
RTL视图如下
第二种仿真代码写法如下
module mux2(
input SEL,
input a,
input b,
output out
);
assign out=(SEL==1)?a:b;
endmodule
RTL视图如下: