2-to-1 Multiplexer: if Statement Discussion D7.1 Example 4
2-to-1 Multiplexer Multiplexers The Verilog if statement
Multiplexers A multiplexer is a digital switch: If s = 0, y = a; if s = 1, y = b
Multiplexers A multiplexer is a digital switch: If s = 0, y = a; if s = 1, y = b
// Example 4a: 2-to-1 MUX using logic equations module mux21a ( input wire a, input wire b, input wire s, output wire y ); assign y = ~s & a | s & b; endmodule
2-to-1 Multiplexer Multiplexers The Verilog if statement
Multiplexers A multiplexer is a digital switch: If s = 0, y = a; if s = 1, y = b if(s == 0) y = a; else y = b; Verilog
// Example 4b: 2-to-1 MUX using if statement module mux21b ( input wire a, input wire b, input wire s, output reg y ); if(s == 0) y = a; else y = b; endmodule
// Example 4c: 2-to-1 MUX using ? notation module mux21c ( input wire a, input wire b, input wire s, output reg y ); assign y = s ? b : a; endmodule Note shortcut if statement