实现二选一选的功能
module MUX2_1( input x0, input x1, input sel, output y0, reg y0_out ); always(*) begin case(sel) 1'b0:y0_out=x0; 1'b1:y0_out=x1; default:y0_out=x0; endcase end assign y0=y0_out; endmodule
四选一选择器采用二选一模块实现(以下为自己设计,如有不对请多指正)
module MUX4_1( input a0, input a1, input a2, input a3, input a4, input a5, input sel0, input sel1, input sel2, output b0, output b1, output b2, output b_out ); MUX2_1 first(.x0(a0),.x1(a1),.sel(sel0),.y0(b0)); MUX2_1 second(.x0(a2),.x1(a3),.sel(sel1),.y0(b1)); assign sel2=sel1 sel0; MUX2_1 third(.x0(b0),.(b1),.sel(sel2),.y0(b2)); assign b_out=b2; endmodule