Multiplexer Design using Verilog HDL
Last Updated :
15 Jul, 2025
The Verilog Hardware Description Language is an important language in the world of digital design where electronic systems are modeled using it. It provides a way of describing and simulating both the behavior and structure of digital circuits; hence, it is an important tool for engineers in hardware design and verification. Verilog HDL provides for the making of detailed specifications of complex digital systems through its syntax and constructs, hence assisting in its development and testing.
In this article, we are discussing Multiplexer Design. Below mentioned is the article in which we are going to discuss the problem.
Design of a 2:1 MUX using Verilog Hardware Description Language along with Testbench.
Concepts
A multiplexer is a combinational type of digital circuit that is used to transfer one of the available input lines to a single output and, which input has to be transferred to the output will be decided by the state(logic 0 or logic 1) of the select line signal. 2:1 Multiplexer has two inputs, one select line (to select one of the two inputs), and a single output.

Truth Table
Verilog HDL code of 2:1 MUX
Design
// define a module for the design
module mux2_1(in1, in2, select, out);
// define input port
input in1, in2, select;
// define the output port
output out;
// assign one of the inputs to the output based upon select line input
assign out = select ? in2 : in1;
endmodule :mux2_1
Testbench
module test;
reg in1, in2, select;
wire out;
// design under test
mux2_1 mux(.in1(in1), .in2(in2),
.select(select), .out(out));
// list the input to the design
initial begin in1=1'b0;in2=1'b0;select=1'b0;
#2 in1=1'b1;
#2 select=1'b1;
#2 in2=1'b1;
#2 $stop();
end
// monitor the output whenever any of the input changes
initial begin $monitor("time=%0d, input1=%b, input2=%b,
select line=%b, output=%b", $time,
in1, in2, select, out);
end
endmodule :test
Expected Output
time=0, input1=0, input2=0, select line=0, out=0
time=2, input1=1, input2=0, select line=0, out=1
time=4, input1=1, input2=0, select line=1, out=0
time=6, input1=1, input2=1, select line=1, out=1
Gate level /Structural Modeling
module mux4x1_gate_level(
input a,
input b,
input c,
input d,
input s0,
input s1,
output y
);
wire n1, n2, n3, n4, n5, n6;
not (n1, s1);
not (n2, s0);
and (n3, a, n1, n2);
and (n4, b, n1, s0);
and (n5, c, s1, n2);
and (n6, d, s1, s0);
or (y, n3, n4, n5, n6);
endmodule
Dataflow Modelling
module mux4x1(
input s0,
input s1,
input a,
input b,
input c,
input d,
output y
);
assign y = (a & (~s1) & (~s0)) |(b & (~s1) & s0) |(c & s1 & (~s0)) |(d & s1 & s0);
endmodule
What is Verilog HDL?
Verilog HDL is a high-level hardware description language that, through its modeling, simulation, and designing features, finds wide applications for digital circuits. It allows the engineer to describe both structure and behavior of digital systems even from logic gates, flip-flops, and multiplexers. Being an IEEE-standardized language (IEEE 1364), Verilog finds very important application in design, verification, and synthesis related to integrated circuits.
Verilog HDL allows designers to describe digital circuits using text formats, which in turn enable easier simulation, timing analysis, and subsequent physical implementation of such hardware. It finds extensive applications at the RTL for complex electronic systems designs.
What is Multiplexer?
MUX refers to a kind of digital circuitry where one out of several incoming signals is selected and forwarded towards one output line. This is mainly a sort of data selector or switch in which the signal input to be selected is determined by control signals. Multiplexers are some of the fundamental gadgets in the digital circuits of today's time factor owing to their efficiency in the routing and selection of data.
Thus, a MUX is a device with the following properties: selection lines represent control signals that select input to go through to output; several input lines where only one is relayed to the output line depending on those selection lines; an output line, the single line where the selected input signal is sent to.
Uses of Multiplexer
- Data Routing: Data is routed to various destinations with the use of multiplexers for better performance of the system.
- Demultiplexing: It splits a single data signal into multiple output signals.
- Logic Function Implementation: It implements AND, OR, XOR logic functions, and many more.
- Digital Systems Design: Used in designing complex systems such as microprocessors and memory units.
- Signal Selection: It allows for the selection of one signal out of multiple sources of data so that effective processing can be achieved.
- Resource Sharing: More than one device can share a single resource, like a data bus.
How to Connect Multiplexers?
- Cascading: Output of one multiplexer connected to the input of the other. The idea here is that with more and more MUXs cascading, you will be able to select from an even larger number of inputs.
- Parallel Connection: Several multiplexers connected in parallel handle multiple sets of inputs. Thus it simultaneously selects more data sources.
- Tree Structure: Arrange multiplexers in a tree-like or hierarchical fashion. At this structure, large numbers of inputs are dealt with comfortably, and routing of data within it is less painful.
- Hierarchical Approach: Construct larger multiplexers using smaller ones. For instance, using three 2-to-1 multiplexers, an 8-to-1 multiplexer can be realized, with outputs from the smaller MUXs feeding into a larger one and selection lines configured appropriately.
Advantages of Multiplexers
- Efficient Data Routing: The use of multiplexers provides that several data signals can be routed onto and using one channel owing to the fact that they optimize resource usage.
- Component Count Reduction: Fewer components will be involved in the selection and routing of the data, hence designing is simpler.
- Flexibility: They have flexibility and can thus easily be configured for different applications.
- Scalability: Multiplexers are easily scalable in that with the combination of many units, the input handling capability increases, hence increasing design flexibility.
Disadvantages of Multiplexers
- Increasingly Complex: Cascading several multiplexers and complicated structures make the circuits more complex; designing is increasingly difficult.
- Latency in Performance: Since the selection operation would be carried out by a multiplexer, delays would be caused and affect the performance of the system-particularly high-speed systems.
- It can draw power: these are not necessarily drawing power; however, in many usages, the rate of power consumption can increase.
- Propagation delay: because of the time delays that may take place in signal transmission on using a number of MUX, the overall performance of the circuit deteriorates.
Conclusion
Verilog HDL is important in the design and modeling of digital systems, thus helping engineers create elaborate and exacting circuits. Multiplexers form part of these designs, providing an effective system of data management and routing versatility that is fundamental to both simple and advanced systems. Understanding how to combine multiplexers-through cascading, parallel connections, or hierarchical structures-helps engineers optimize circuit layouts and performance.
Drawbacks of multiplexers are, for example, increased design complexity and propagation delays. Successful digital circuit design will have to balance these. As the technology will keep on evolving, so will Verilog find its place-along with multiplexers-in devising ingenious electronic solutions and increasing performance further in hardware.
Similar Reads
Digital Electronics and Logic Design Tutorials Digital Electronics and Logic Design are key concepts in both electronics and computer science. Digital systems are at the core of everything from basic devices like calculators to advanced computing systems. Digital systems use binary numbers (0s and 1s) to represent and process information.Logic g
4 min read
Number Systems
Boolean Algebra and Logic Gates
Logic Gates - Definition, Types, UsesLogic Gates are the fundamental building blocks in digital electronics. There are basically seven main types of logic gates that are used to perform various logical operations in digital systems. By combining different logic gates, complex operations are performed, and circuits like flip-flops, coun
10 min read
Basic Conversion of Logic GatesIn the Digital System, logic gates are the basic building blocks. Â In these logic gates, we can find the gates having more than one input, but will have only one output. The connection between the input and the output of a gate is based on some logic. Based on this logic, different gates are develop
6 min read
Realization of Logic Gate Using Universal gatesIn Boolean Algebra, the NAND and NOR gates are called universal gates because any digital circuit can be implemented by using any one of these two i.e. any logic gate can be created using NAND or NOR gates only.Implementation of AND Gate using Universal GatesImplementation using NAND GatesThe AND ga
6 min read
Canonical and Standard FormCanonical Form - In Boolean algebra, the Boolean function can be expressed as Canonical Disjunctive Normal Form known as minterm and some are expressed as Canonical Conjunctive Normal Form known as maxterm. In Minterm, we look for the functions where the output results in "1" while in Maxterm we loo
6 min read
Types of Integrated CircuitsIn this article, we will go through the Types of Integrated Circuits, we will start our article with the introductions of the ICs, then we will go through different types of ICs one by one, At last, we will conclude our article will their applications, advantages, disadvantages and some FAQs. Table
7 min read
Minimization Techniques
Minimization of Boolean FunctionsBoolean functions are used to represent logical expressions in terms of sum of minterms or product of maxterms. Number of these literals (minterms or maxterms) increases as the complexity of the digital circuit increases. This can lead to large and inefficient circuits. By minimizing Boolean functio
4 min read
Introduction of K-Map (Karnaugh Map)In many digital circuits and practical problems, we need to find expressions with minimum variables. We can minimize Boolean expressions of 3, 4 variables very easily using K-map without using any Boolean algebra theorems. It is a tool which is used in digital logic to simplify boolean expression. I
5 min read
5 variable K-Map in Digital LogicPrerequisite - Implicant in K-Map Karnaugh Map or K-Map is an alternative way to write a truth table and is used for the simplification of Boolean Expressions. So far we are familiar with 3 variable K-Map & 4 variable K-Map. Now, let us discuss the 5-variable K-Map in detail. Any Boolean Express
5 min read
Various Implicants in K-MapAn implicant can be defined as a product/minterm term in Sum of Products (SOP) or sum/maxterm term in Product of Sums (POS) of a Boolean function. For example, consider a Boolean function, F = AB + ABC + BC. Implicants are AB, ABC, and BC. There are various implicant in K-Map listed below :Prime Imp
5 min read
Don't Care (X) Conditions in K-MapsOne of the most important concepts in simplifying output expressions using Karnaugh Maps (K-Maps) is the 'Don't Care' condition. The 'Don't Care' conditions allow us to treat certain cells in a K-Map as either 0, 1, or to ignore them altogether, which can help in forming larger and more efficient gr
4 min read
Quine McCluskey MethodThe Quine McCluskey method also called the tabulation method is a very useful and convenient method for simplification of the Boolean functions for a large number of variables (greater than 4). This method is useful over K-map when the number of variables is larger for which K-map formation is diffi
8 min read
Two Level Implementation of Logic GatesThe term "two-level logic" refers to a logic design that uses no more than two logic gates between input and output. This does not mean that the entire design will only have two logic gates, but it does mean that the single path from input to output will only have two logic gates.In two-level logic,
9 min read
Combinational Circuits
Half Adder in Digital LogicA half adder is a combinational logic circuit that performs binary addition of two single-bit inputs, A and B, producing two outputs: SUM and CARRY. The SUM output which is the least significant bit (LSB) is obtained using an XOR gate while the CARRY output which is the most significant bit (MSB) is
3 min read
Full Adder in Digital LogicFull Adder is a combinational circuit that adds three inputs and produces two outputs. The first two inputs are A and B and the third input is an input carry as C-IN. The output carry is designated as C-OUT and the normal output is designated as S which is SUM. The C-OUT is also known as the majorit
5 min read
Half Subtractor in Digital LogicA half subtractor is a digital logic circuit that performs the binary subtraction of two single-bit binary numbers. It has two inputs, A and B, and two outputs, Difference and Borrow. The Difference output represents the result of subtracting B from A, while the Borrow output indicates whether a bor
4 min read
Full Subtractor in Digital LogicA Full Subtractor is a combinational circuit used to perform binary subtraction. It has three inputs:A (Minuend)B (Subtrahend)B-IN (Borrow-in from the previous stage)It produces two outputs:Difference (D): The result of the subtraction.Borrow-out (B-OUT): Indicates if a borrow is needed for the next
3 min read
Parallel Adder and Parallel SubtractorAn adder adds two binary numbers one bit at a time using carry from each step. A subtractor subtracts one binary number from another using borrow when needed. A parallel adder adds all bits at once, making addition faster. Similarly, a parallel subtractor subtracts all bits at the same time for quic
5 min read
Sequential Binary MultiplierIn this article, we are going to learn how a sequential binary multiplier works with examples. So for that, we also need to learn a few concepts related to the sequential circuit, binary multipliers, etc. Finally solving the examples using a sequential binary multiplier method.Sequential CircuitA se
12 min read
Multiplexers in Digital LogicIn this article we will go through the multiplexer, we will first define what is a multiplexer then we will go through its types which are 2x1 and 4x1, then we will go through the Implementation of the 2x1 mux and higher mux with lower order mux, at last we will conclude our article with some applic
10 min read
Event Demultiplexer in Node.jsNode.js is designed to handle multiple tasks efficiently using asynchronous, non-blocking I/O operations. But how does it manage multiple operations without slowing down or blocking execution? The answer lies in the Event Demultiplexer.The Event Demultiplexer is a key component of Node.js's event-dr
3 min read
Binary Decoder in Digital LogicA binary decoder is a digital circuit used to convert binary-coded inputs into a unique set of outputs. It does the opposite of what an encoder does. A decoder takes a binary value (such as 0010) and activates exactly one output line corresponding to that value while all other output lines remain in
5 min read
Encoder in Digital LogicAn encoder is a digital circuit that converts a set of binary inputs into a unique binary code. The binary code represents the position of the input and is used to identify the specific input that is active. Encoders are commonly used in digital systems to convert a parallel set of inputs into a ser
7 min read
Code Converters - Binary to/from Gray CodeIn this article, we will go through Code Converters - Binary to/from Gray Code, we will start our article by defining Code converters, Binary code and Gray code, and then we will go through the conversion of binary code to gray code and vice versa.Table Of ContentCode ConvertersBinary CodeGray CodeC
5 min read
Magnitude Comparator in Digital LogicA magnitude digital Comparator is a combinational circuit that compares two digital or binary numbers in order to find out whether one binary number is equal, less than, or greater than the other binary number. We logically design a circuit for which we will have two inputs one for A and the other f
7 min read
Sequential Circuits
Introduction of Sequential CircuitsSequential circuits are digital circuits that store and use the previous state information to determine their next state. Unlike combinational circuits, which only depend on the current input values to produce outputs, sequential circuits depend on both the current inputs and the previous state stor
7 min read
Difference between Combinational and Sequential CircuitIn digital electronics, circuits are classified into two primary categories: The combinational circuits and the sequential circuits. Where the outputs depend on the current inputs are called combination circuit, combinational circuits are simple and effective for functions like addition, subtraction
4 min read
Latches in Digital LogicLatch is a digital circuit which converts its output according to its inputs instantly. To implement latches, we use different logic gates. In this article, we will see the definition of latches, latch types like SR, gated SR, D, gated D, JK and T with its truth table and diagrams and advantages and
7 min read
Flip-Flop types, their Conversion and ApplicationsIn this article, we will go through the Flip-Flop types, their Conversion and their Applications, First, we will go through the definition of the flip-flop with its types in brief, and then we will go through the conversion of the flip-flop with its applications, At last, we will conclude our articl
7 min read
Conversion of Flip-Flop
Register, Counter, and Memory Unit
Counters in Digital LogicA Counter is a device which stores (and sometimes displays) the number of times a particular event or process has occurred, often in relationship to a clock signal. Counters are used in digital electronics for counting purpose, they can count specific event happening in the circuit. For example, in
4 min read
Ripple Counter in Digital LogicCounters play a crucial role in digital logic circuits, enabling tasks such as clock frequency division and sequencing. This article explores the concept of ripple counters, a type of asynchronous counter, their operation, advantages, and disadvantages in digital logic design. What is a Counter?Coun
5 min read
Ring Counter in Digital LogicA ring counter is a typical application of the Shift register. The ring counter is almost the same as the shift counter. The only change is that the output of the last flip-flop is connected to the input of the first flip-flop in the case of the ring counter but in the case of the shift register it
7 min read
General Purpose RegistersA register is a collection of flip-flops. Single bit digital data is stored using flip-flops. By combining many flip-flops, the storage capacity can be extended to accommodate a huge number of bits. We must utilize an n-bit register with n flip flops if we wish to store an n-bit word.General Purpose
8 min read
Shift Registers in Digital LogicPre-Requisite: Flip-FlopsFlip flops can be used to store a single bit of binary data (1 or 0). However, in order to store multiple bits of data, we need multiple flip-flops. N flip flops are to be connected in order to store n bits of data. A Register is a device that is used to store such informati
8 min read
Computer MemoryMemory is the electronic storage space where a computer keeps the instructions and data it needs to access quickly. It's the place where information is stored for immediate use. Memory is an important component of a computer, as without it, the system wouldnât operate correctly. The computerâs opera
9 min read
Random Access Memory (RAM)Random Access Memory (RAM) is a type of computer memory that stores data temporarily. When you turn off your computer, the data in RAM disappears, unlike the data on your hard drive, which stays saved. RAM helps your computer run programs and process information faster. This is similar to how the br
11 min read
Read Only Memory (ROM)Memory plays a crucial role in how devices operate, and one of the most important types is Read-Only Memory (ROM). Unlike RAM (Random Access Memory), which loses its data when the power is turned off, ROM is designed to store essential information permanently.Here, weâll explore what ROM is, how it
8 min read
LMNs and GATE PYQs
Practice Questions - Digital Logic & Design