Logic gates are fundamental building blocks of digital systems that allow or block data flow based on mathematical logic. The seven logic gates are categorized into basic gates (AND, OR, NOT), universal gates (NAND, NOR), and derived gates (XOR, XNOR). AND gate returns 1 when all inputs are 1, OR gate returns 1 when at least one input is 1, NOT gate inverts the input, NAND gate is the inverse of AND, NOR gate is the inverse of OR, XOR gate returns 1 when inputs are different (odd ones detector), and XNOR gate returns 1 when inputs are the same. These gates can be implemented in VHDL using data flow modeling with Boolean expressions and logical operators (and, or, not, nand, nor, xor, xnor).
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Logic Gates using VHDL
Added:Hello, everyone. Welcome to Neso Academy.
In the previous lecture, we implemented our first VHDL code in Vivado.
Where we learned how to create source files, how to write the VHDL code in Vivado code editor, how to generate the RTL schematic, and how to analyze the simulation waveforms.
And today, we are going to understand how to implement all seven logic gates in Vivado.
Now, logic gates are the building blocks of the digital systems.
Now, why we are calling these building blocks logic gates as logic gates?
Because they act like a real physical gate.
Just like a physical gate allows or blocks people, a logic gate allows or blocks the flow of data based on the mathematical logic.
Meaning, a logic gate makes logical decision to generate the output based on the mathematical logic of the input combination.
For example, an AND gate decides to generate the output if input A and input B both are active.
So, what are logic gates?
Logic gates allow or block the flow of data based on the mathematical logic.
And I hope you understand this. So, in this lecture, we will implement all seven logic gates using VHDL with the help of data flow modeling.
Why data flow modeling?
Because logic gates are based on Boolean equations. And we have already studied that data flow modeling is the most suitable choice for the Boolean expression.
Now, let's understand all seven logic gates one by one.
Starting with the first basic logic gate, the AND gate.
Logic gates are categorized into basic logic gates, universal logic gates, and derived logic gates.
Now, basic logic gates include AND gate, OR gate, NOT gate.
Now, why we are calling them as basic logic gates?
Because they are the fundamental building blocks for all digital circuits.
We can create any complex circuit by using these basic logic gates combination.
Where AND gate represents logical multiplication, OR gate represents logical addition, NOT gate represents logical inversion.
Now, let's get back to the AND gate.
AND gate returns one when all inputs are one.
So, in case of AND gate, output will be one when all inputs are one.
Let's understand this using the two input AND gate's truth table.
So, this is the truth table of two input AND gate. Here we have two inputs, A and B, and one output, Y.
For two inputs, we will have four input combinations, 00, 01, 10, 11.
Now, let's see the output for the first input combination.
Here output Y is equal to zero when both inputs, A and B, are zero because AND gate returns one when all inputs are one. And here both inputs are zero.
Therefore, the output is zero.
Now look at the second input combination. Now here A is zero and B is one.
In this case, output Y is zero. Because here we can see input A is zero.
Now in the third input combination, when A is one and B is zero, output will be zero.
Now look at the last and the fourth input combination, when both inputs A and B are one. Now in this case, output is one. Because here we can clearly see output is one when all inputs and here when both inputs are one.
So, I hope you understand this truth table.
Now the reason why we are calling this gate as an AND gate is because it acts like the English word and.
Here, output requires input A and input B both to be one in order to generate the output as one.
Therefore, we are calling this gate as the AND gate.
And I hope you understand this. Now let's see the symbol for the two input AND gate.
Now this is the symbol of the two input AND gate, which looks like a letter D.
Here we have two inputs, A and B, and output Y.
And I hope you understand what is the AND gate. Now let's see the second basic logic gate, OR gate.
OR gate returns one when at least one input is one.
So, in an OR gate, the output is one when any single input is active or one. Now, let's understand this using the two input OR gates truth table.
Here we can see we have four input combinations. Now, look at the first input combination.
When both inputs A and B are equal to zero, that's why the output Y is zero because as per the definition of the OR gate, output will be one when at least one input is one. And here in the first input combination, both inputs are zero.
Therefore, the output is zero.
Now, look at the second input combination.
A is zero, B is one.
Now, here B is one. Therefore, the output is one.
In the third input combination, A is one, B is zero. Now, here A is one.
Therefore, the output is one.
In the last input combination, both inputs are one. So, output is one.
And I hope you understand why we are calling this gate as the OR gate because it acts like the inclusive English word or in which output becomes one if input A or input B or both of them are one or active.
So, I hope you understand why we are calling this gate as the OR gate. Now, let's see the symbol for the OR gate.
Now, this is the symbol for the two input OR gate.
On the input side, it has a curved shape or a concave shape, which represents a funnel which takes multiple input combinations and generate a single output.
So, we are done with the OR gate. Now, let's understand the third basic logic gate.
NOT gate.
NOT gate returns the opposite value of the input. So, the output is the NOT of the input.
So, zero becomes one and one becomes zero.
In the truth table, when input is zero, output will be one and when input is one, output will be zero. So, NOT gate returns the opposite value of the input.
Now, let's see the symbol of the NOT gate.
It includes a triangle pointing to the right with a bubble at the end.
Now, what happens if we remove this bubble?
We are left with this triangle.
And this triangle represents a buffer.
Now, what is a buffer?
Buffer is a circuit which passes the same signal as it is.
So, in buffer, this input A will reflect as it is at the output Y.
So, by adding this bubble, we are inverting the input.
So, this bubble is performing the inversion operation of the input.
So, I hope you understand all three basic logic gates. Now, let's see the universal gates. Universal gates include NAND gate and NOR gate.
And why we are calling them as universal gates?
Because by using either NAND gates or NOR gates, we can implement any other logic gates or any other digital circuit in the universe. Therefore, we are calling them as universal gates.
Now, let's see the NAND gate.
Now, here the word NAND means NOT plus AND. So, NAND gate is the inverse of the AND gate. Therefore, it returns zero only when all inputs are one.
So, in NAND gate, output will be zero when all inputs are one.
Let's understand this using the truth table.
Here we have four input combinations.
And for four input combinations, the outputs are 1 1 1 0.
In the case of the AND gate, the outputs were 0 0 0 1.
So, NAND gate is the inverse of the AND gate.
In the truth table, we can see NAND gate returns zero when all inputs are one.
So, I hope you understand why NAND gate is the inverse of the AND gate. Now, let's see the symbol of the NAND gate.
NAND gate is the AND gate with inverted output. Here bubble represents the inversion of the AND gate.
So, we are done with the NAND gate. Now, let's see the second universal gate, NOR gate.
Now, the keyword NOR means not plus or. So, NOR gate is the inversion of the OR gate.
Therefore, NOR gate returns one only when all inputs are zero.
When all inputs are zero, then in the case of NOR gate, the output will be one.
Now, let's see the truth table.
Here we have four input combinations.
Now, look at the first input combination, when A is zero and B is zero. So, here both inputs are zero.
That's why the output is one. And as per the definition of the NOR gate, NOR gate returns one when all inputs are zero.
And for other input combinations, outputs are zero.
So, here outputs are 1 0 0 0.
And in the case of the OR gate, the outputs were 0 1 1 1.
So, NOR gate is the inverse of the OR gate. Now, let's see the symbol for the NOR gate.
So, NOR gate is the OR gate with the inverted output. Now, here the bubble represents the inversion of the OR gate.
So, I hope you understand the universal gates. Now, let's see the third category of the logic gates, derived gates.
Derived gates include XOR gate and XNOR gate.
Now, why we are calling them as derived gates?
Because they are derived using the basic logic gates, AND gate, OR gate, NOT gate.
Now, let's see the first derived logic gate, XOR gate.
XOR gate returns one when the inputs are different. So, in XOR gate, output will be one when all inputs are different.
Now, the word XOR means exclusive OR.
Here, output will be one if input A is one or input B is one.
Here, we are excluding the condition the output will be one when all inputs are one.
Therefore, XOR gate is an exclusive OR.
Now, to understand this in a better way, let's see the truth table.
Here, we have four input combinations.
Now, look at the first input combination. When both inputs A and B are equal to zero, which means both inputs A and B are same. Therefore, the output is zero.
In the second input combination, when A is zero and B is one. So, here both inputs are different. Therefore, output is one. In the third input combination, when A is one, B is zero.
Again, here we have different inputs.
Therefore, output is one.
In the last input combination, when A is one, B is one.
So, both inputs are same. That's why output is zero.
So, I hope you understand this truth table. Now, focus on these two input combinations for which the output is one. Now, in these two input combinations, there is a single one, which means odd number of one.
So, whenever there are odd number of ones in the input combinations, the output will be one. So, the XOR gate is also called as odd ones detector. And I hope you understand this. Now, let's see the symbol for the XOR gate. Now, the symbol includes the same OR gate along with the curved line. Now, this extra curved line represents the exclusiveness of the XOR gate.
So, I hope you understand the XOR gate.
Now, let's see the second derived logic gate, which is XNOR gate.
Now, XNOR gate is the inverse of the XOR gate, which means XNOR gate returns one when the inputs are same.
So, output will be one when inputs are same. Let's understand this using the truth table. Here in the four input combinations, look at the first input combination. When A is zero and B is zero, which means both inputs are same.
That's why the output is one.
In the second and in the third input combinations, both input combinations have different inputs. Therefore, the output is zero. In the last input combination, both inputs A and B are equal to one. Therefore, the output is one.
Now, in the case of the XOR gate, the outputs were 0 1 1 0.
But, in the case of XNOR gate, the outputs are 1 0 0 1. So, XNOR gate is the opposite of the XOR gate. Now, let's see the symbol of the XNOR gate.
Now, the symbol includes the XOR gate along with the bubble. So, XOR gate with inverted output.
So, I hope you understand all seven logic gates. Now, let's implement them using Vivado with the help of data flow modeling using VHDL.
So, we are in Vivado and this is the data flow modeling code for the seven logic gates. Now, if we want, we can change this light theme interface into a dark theme based on your Vivado version.
For that, go to tools and select settings.
Now, click on try the new Vivado IDE.
Then, click on okay. Now, click on this Vivado setting as okay.
Now, you just need to restart your software. Means, close the software and reopen it.
Now, after restarting our software, this is our new Vivado IDE.
Now, in order to change this light theme into a dark theme, go to tools, click on settings.
On the left-hand side, in the tool settings, click on text editor, then select VHDL.
Now, here we can see themes option.
Currently, it is a light theme. Change this light theme into a dark theme.
It will take only few seconds.
Just wait.
Now, this is our dark-themed interface.
Close this notification. Now, let's get back to the VHDL code.
Now, our code starts with IEEE library with standard logic package from the IEEE library. After library declaration, here we have entity. And here, I have named this entity as logic_gates.
Now, inside the entity, we will declare the input and output ports. Now, as discussed in the presentation, we have understood two input AND gate, two input OR gate, two input NAND gate, two input NOR gate, two input XOR gate, two input XNOR gate, and a NOT gate. Therefore, I have declared here two inputs A and B as standard logic data type. And to represent the seven outputs of the seven logic gates, here I have represented the seven signals. And and_d is representing the output of AND gate as standard logic data type.
Or_g signal is representing the output of an OR gate as standard logic data type. Not_g signal is representing the output of the not gate as standard logic data type. And similarly, here I have declared the remaining outputs.
Now, we can close this entity with the keyword end and with the name of the entity logic_gates.
After entity declaration, we will have our architecture.
Architecture name as dataflow because we are writing the Boolean equations of logic_gates is and after the keyword begin, we can write the Boolean expressions using the logical operators. Here we are using seven logical operators: and operator, or operator, not operator, nand operator, nor operator, exor operator, and exnor operator to represent the Boolean expressions.
Now, look at the first Boolean expression.
A and B.
We are assigning this A and B in the and_G signal.
Similarly, A or B and storing the result inside the signal or_G.
Not A means we are taking a complement of the signal A and storing the result inside the output signal not_G.
In the same way, we can perform other Boolean expressions for the other logic gates as well.
Now, I hope you understand this dataflow modeling code for all seven logic gates using the all seven logical operators.
Now, let's see the schematic diagram generated by Vivado. For that, go to RTL analysis.
Click on open elaborated design and select schematic.
So, this This the schematic diagram generated by Vivado. Here we have two inputs, A and B, and seven outputs representing the seven outputs of the seven logic gates. Now, let's verify the schematic. Here, output and {underscore} g is equal to A and B.
Output or {underscore} g is equal to A or B.
Now, for NAND gate and NOR gate, Vivado does not have any specific symbols.
Therefore, Vivado represents them using the complemented form of the AND gate and the complemented form of the OR gate. So, NAND {underscore} g is equal to the complement of A and B.
NOR {underscore} g is equal to the complement of A or B.
Now, the next output NOT {underscore} g is the complement of input signal A.
Similarly, we can see XOR gate output and XNOR gate output. Here, XOR {underscore} g is equal to A XOR B.
And XNOR {underscore} g is equal to A XNOR B.
So, I hope you understand this schematic diagram. Now, in data flow modeling, the Boolean expressions are directly converted into the schematic diagram.
Now, let's see the simulation waveforms generated by Vivado. For that, go to simulation, click on run simulation, and select run behavioral simulation.
Now, this is our simulation waveform window. Here we have our two inputs, A and B, and seven outputs. Now, let us verify our VHDL code for all four input combinations. For that, let me quickly assign the input values manually.
Now, how to do that? Let me show you.
Right click on signal A, select force constant to apply the values manually.
Now, select value radix as binary because we want to apply binary numbers zero and one.
Now, force value zero.
Then, click on okay. Similarly, for signal B, right click on signal B, select force constant.
Value radix as binary. And force value as zero. Now, this is our first input combination zero zero.
Similarly, you can assign other three input combinations as well. Let me quickly assign them.
Now, I have assigned all four input combinations and I've simulated each input combination for 100 nanoseconds.
Now, let's see the generated waveform.
Let me maximize this waveform.
And here we have all four input combinations.
Zero zero. Zero one.
One zero and one one.
Now, let's verify our code for one input combination. Let's say for zero one.
When A is equal to zero and B is equal to one.
Now, what will be zero and one?
It will be zero. And here we can see and underscore G is equal to zero, which is correct.
Now, what will be zero or one?
It will be one. And here we can see or underscore G is equal to one.
Which is correct.
Now, not of A, which is equal to not of zero.
Which will be one.
And here we can see not_g is equal to one.
Now, what will be zero NAND one?
It will be one. And here we can see NAND is equal to one.
Now, what about zero NOR one?
It should be zero. And here we can see NOR is equal to zero.
Now, what about zero XOR one?
Here we have a single one. And we all know that an XOR gate is the odd ones detector. Therefore, it will be one.
And if XOR is one, XNOR will be zero.
And here we can see XNOR is equal to zero.
Which means our code is absolutely correct. And I hope you understand the implementation of all seven logic gates using data flow modeling in Vivado.
So, in this lecture, we understood all seven logic gates. And we have also implemented them in Vivado using data flow modeling.
With that, we are done with this topic of logic gates using VHDL in Vivado. So, we are done with this lecture. I will see you in the next one. Thank you.
Related Videos

TOP 15 Data compression Interview Questions and Answers 2019 Part-2 | Data compression | Wisdom jobs
wisdomjobs
281 views•2019-06-28

CTS 158: 802.11w Management Frame Protection
ClearToSend
4K views•2019-02-04

NDSS 2019 Send Hardest Problems My Way: Probabilistic Path Prioritization for Hybrid Fuzzing
NDSSSymposium
496 views•2019-04-02

How realistic is Cities: Skylines?
CityBeautiful
159K views•2019-02-14

GUIs & TUIs: Choosing a User Interface for Your Python Project | Real Python Podcast
realpython
2K views•2025-04-04

The OSI Model - Explained by Example
hnasr
225K views•2019-05-12

Cloud Computing - Introduction
elithecomputerguy
98K views•2019-10-07

From Traveler's Dilemma to Dynamic Routing | Demystifying Networking
IITBombayJuly
5K views•2019-08-04
Trending

WOW! Judge TURNS THE TABLES on Trump in His OWN $10B LAWSUIT!!!
MeidasTouch
197K views•2026-07-23

Playstation NO DISC/NO BUY Fight Is Over...
DavidJaffeGames
4K views•2026-07-23

Steam and Xbox Just Dropped The Hammer On PlayStation
OhNoItsAlexx
9K views•2026-07-23

Americans Confused in Australia for 17 Minutes Straight
IWrocker
17K views•2026-07-23