4-to-1 Multiplexer and 1-to-4 Demultiplexer Verilog Code

verilog
multiplexer
demultiplexer
hdl
digital logic

This page provides Verilog HDL code for a 4-to-1 multiplexer and a 1-to-4 demultiplexer.

4 to 1 Multiplexer

Here’s the information for a 4-to-1 multiplexer:

Symbol:

4 to 1 multiplexer symbol

Truth Table:

Sel1Sel0Z
00a
01b
10c
11d

Verilog Code:

module mux4_1(I0,I1,I2,I3,s2,s1,y,en);
  input I0,I1,I2,I3,s2,s1,en;
  output y;
  assign y <= ((~s2)&(~s1)&en&I0)| ((~s2)&(s1)&en&I1)|(s2&(~s1)&en&I2)|(s2&s1&en&I3);
endmodule

Simulation Result:

4 to 1 multiplexer simulation result

1 to 4 De-multiplexer

Now, let’s move on to the 1-to-4 de-multiplexer:

Symbol:

1 to 4 demultiplexer

Truth Table:

aenSel1Sel0Y3Y2Y1Y0
10000000
11001000
10100100
10010010
10110001
01XX0000

Verilog Code:

module demux (s2,s1,I,en,y0,y1,y2,y3);
  input s2,s1,I,en;
  output y0,y1,y2,y3;
  assign y0 = (~s2)&(~s1)& I& en;
  assign y1 = (~s2)& s1& I& en;
  assign y2 = s2&(~s1)&  I & en;
  assign y3 = s2& s1 & I & en;
endmodule

Simulation Result:

1 to 4 demultiplexer simulation result

Verilog Code for 1 to 4 Demultiplexer

Verilog Code for 1 to 4 Demultiplexer

This article provides Verilog source code for a 1 to 4 DEMUX, accompanied by a block diagram and truth table for enhanced understanding.

verilog
demultiplexer
digital logic