Skip to content
Related Articles

Related Articles

Improve Article

VHDL code for AND and OR Logic Gates

  • Last Updated : 22 May, 2020

Prerequisite – Introduction of Logic Gates
Design and implement the AND and OR logic gates using VHDL (VHSIC Hardware Description Language) programming language.

1. Logic Development for AND Gate :
The AND logic gate can be realized as follows –

The truth table for AND Gate is:



ABY = A AND B
000
010
100
111

Implementation –
Below is the implementation of the above logic in VHDL language.

-- VHDL Code for AND gate

-- Header file declaration

library IEEE;
use IEEE.std_logic_1164.all;

-- Entity declaration

entity andGate is

    port(A : in std_logic;      -- AND gate input
         B : in std_logic;      -- AND gate input
         Y : out std_logic);    -- AND gate output

end andGate;

-- Architecture definition

architecture andLogic of andGate is

 begin
    
    Y <= A AND B;

end andLogic; 

2. Logic Development for OR Gate :
The OR logic gate can be realized as follows –

The truth table for OR Gate is:

ABY = A OR B
000
011
101
111

Implementation –
Below is the implementation of the above logic in VHDL language.

-- VHDL Code for OR gate

-- Header file declaration

library IEEE;
use IEEE.std_logic_1164.all;

-- Entity declaration

entity orGate is

    port(A : in std_logic;      -- OR gate input
         B : in std_logic;      -- OR gate input
         Y : out std_logic);    -- OR gate output

end orGate;

-- Architecture definition

architecture orLogic of orGate is

 begin
    
    Y <= A OR B;

end orLogic;

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :