Create a one-bit wide, 2-to-1 multiplexer. When sel=0, choose a. When sel=1, choose b.
译:
创建一个1位宽的2对1多路复用器。当sel=0时,选择a。当sel=1时,选择b。
个人解法:
module top_module(
input a, b, sel,
output out );
assign out = (sel==1)?b:a;
endmodule
官方解法:
module top_module (
input a,
input b,
input sel,
output out
);
assign out = (sel & b) | (~sel & a); // Mux expressed as AND and OR
// Ternary operator is easier to read, especially if vectors are used:
// assign out = sel ? b : a;
endmodule
运行结果: