Provide an example of a Verilog module that implements a 4-to-1 multiplex…
Provide an example of a Verilog module that implements a 4-to-1 multiplexer (MUX) and explain its functionality.
Model answer
The mux_4to1 module implements a 4-to-1 multiplexer with four 1-bit inputs ( data_in[3:0] ) and two select signals ( select[1:0] ). The data_out output is 1-bit. The module uses a case statement to select one of the four input signals based on the select input. The behavior of the multiplexer is determined by the select input. When select is 2'b00 , the output is set to data_in[0] , i.e., the first input. When select is 2'b01 , the output is set to data_in[1] , i.e., the second input, and so on. If select has an invalid value, the default output is set to 1’b0. The always @(*) block ensures that the output data_out is updated whenever any of the inputs change.