Gates

AND, OR, NOT, NAND, NOR, XOR, XNOR

← RISC-V Released

Overview

Fundamental combinational logic primitives implemented in VHDL. These 1-bit gates serve as the structural building blocks for the arithmetic, shifting, and control logic across the rest of the RV32I core.

Complete Module Package Includes all 7 VHDL entities, unified GHDL testbench, test vectors, Vivado & Quartus projects.
Download ZIP ↓

AND

y = a AND b

Outputs high ('1') only when both inputs a and b are high.

Logic Symbol
AND gate logic symbol with inputs a, b and output y
Truth Table
a b y
0 0 0
0 1 0
1 0 0
1 1 1
and_gate.vhdl
--
--    This is a simple AND gate modeled in VHDL 
--
--    Created:    Winter 2022
--    Author: 	  Kevin Cloutier <kevincloutier@mac.com>
--
library ieee;
use ieee.std_logic_1164.all;

entity and_gate is

    port(
        -- INPUTS
       i_a : in std_logic;      
       i_b : in std_logic;
        
        --OUTPUT
        o_y : out std_logic
    );

end and_gate;


architecture and_gate_arch of and_gate is

 begin
    
    o_y <= i_a AND i_b;

end and_gate_arch; 

GHDL Simulation Waveform 10 ns / step
0ns10ns20ns30ns40nss_as_bs_y
FPGA Synthesis & Utilization Vivado / Quartus
LUTs / ALUTs 1 (2-input LUT)
Registers (FF) 0 (Combinational)
Logic Depth 1 Level
I/O Pins 3 (2 in, 1 out)

OR

y = a OR b

Outputs high ('1') when either inputs a or b are high.

Logic Symbol
OR gate logic symbol with inputs a, b and output y
Truth Table
a b y
0 0 0
0 1 1
1 0 1
1 1 1
or_gate.vhdl
--
--    This is a simple OR gate modeled in VHDL 
--
--    Created:    Winter 2022
--    Author: 	  Kevin Cloutier <kevincloutier@mac.com>
--
library ieee;
use ieee.std_logic_1164.all;

entity or_gate is

    port(
        -- INPUTS
        i_a : in std_logic;      
        i_b : in std_logic;
        
        --OUTPUT
       o_y : out std_logic
    );

end or_gate;


architecture or_gate_arch of or_gate is

 begin
    
    o_y <= i_a OR i_b;

end or_gate_arch; 

GHDL Simulation Waveform 10 ns / step
0ns10ns20ns30ns40nss_as_bs_y
FPGA Synthesis & Utilization Vivado / Quartus
LUTs / ALUTs 1 (2-input LUT)
Registers (FF) 0 (Combinational)
Logic Depth 1 Level
I/O Pins 3 (2 in, 1 out)

NOT

y = NOT a

Outputs high ('1') when input a is low.

Logic Symbol
NOT gate logic symbol with input a and output y
Truth Table
A Y
0 1
1 0
not_gate.vhdl
--
--    This is a simple NOT gate modeled in VHDL 
--
--    Created:    Winter 2022
--    Author: 	  Kevin Cloutier <kevincloutier@mac.com>
--
library ieee;
use ieee.std_logic_1164.all;

entity not_gate is

    port(
        -- INPUTS
        i_a : in std_logic;      
        
        --OUTPUT
        o_y : out std_logic
    );

end not_gate;


architecture not_gate_arch of not_gate is

 begin
    
    o_y <= not(i_a);

end not_gate_arch; 

GHDL Simulation Waveform 10 ns / step
0ns10ns20nss_as_y
FPGA Synthesis & Utilization Vivado / Quartus
LUTs / ALUTs 1 (1-input LUT)
Registers (FF) 0 (Combinational)
Logic Depth 1 Level
I/O Pins 2 (1 in, 1 out)

NAND

y = a NAND b

Outputs low ('0') only when all of its inputs are 1; otherwise, it outputs 1 ('1').

Logic Symbol
NAND gate logic symbol with inputs a, b and output y
Truth Table
a b y
0 0 1
0 1 1
1 0 1
1 1 0
nand_gate.vhdl
--
--    This is a simple NAND gate modeled in VHDL 
--
--    Created:    Winter 2022
--    Author: 	  Kevin Cloutier <kevincloutier@mac.com>
--
library ieee;
use ieee.std_logic_1164.all;

entity nand_gate is

    port(
        -- INPUTS
        i_a : in std_logic;      
        i_b : in std_logic;
        
        --OUTPUT
        o_y : out std_logic
    );

end nand_gate;


architecture nand_gate_arch of nand_gate is

 begin
    
    o_y <= not(i_a AND i_b);

end nand_gate_arch; 

GHDL Simulation Waveform 10 ns / step
0ns10ns20ns30ns40nss_as_bs_y
FPGA Synthesis & Utilization Vivado / Quartus
LUTs / ALUTs 1 (2-input LUT)
Registers (FF) 0 (Combinational)
Logic Depth 1 Level
I/O Pins 3 (2 in, 1 out)

NOR

y = a NOR b

Outputs high ('1') only when all of its inputs are low ('0').

Logic Symbol
NOR gate logic symbol with inputs a, b and output y
Truth Table
a b y
0 0 1
0 1 0
1 0 0
1 1 0
nor_gate.vhdl
--
--    This is a simple NOR gate modeled in VHDL 
--
--    Created:    Winter 2022
--    Author: 	  Kevin Cloutier <kevincloutier@mac.com>
--
library ieee;
use ieee.std_logic_1164.all;

entity nor_gate is

    port(
        -- INPUTS
        i_a : in std_logic;      
        i_b : in std_logic;
        
        --OUTPUT
        o_y : out std_logic
    );

end nor_gate;


architecture nor_gate_arch of nor_gate is

 begin
    
    o_y <= not(i_a OR i_b);

end nor_gate_arch; 

GHDL Simulation Waveform 10 ns / step
0ns10ns20ns30ns40nss_as_bs_y
FPGA Synthesis & Utilization Vivado / Quartus
LUTs / ALUTs 1 (2-input LUT)
Registers (FF) 0 (Combinational)
Logic Depth 1 Level
I/O Pins 3 (2 in, 1 out)

XOR

y = a XOR b

Outputs high ('1') only when the inputs are different.

Logic Symbol
XOR gate logic symbol with inputs a, b and output y
Truth Table
a b y
0 0 0
0 1 1
1 0 1
1 1 0
xor_gate.vhdl
--
--    This is a simple XOR gate modeled in VHDL 
--
--    Created:    Winter 2022
--    Author: 	  Kevin Cloutier <kevincloutier@mac.com>
--
library ieee;
use ieee.std_logic_1164.all;

library riscv;

entity xor_gate is

    port(
        -- INPUTS
        i_a : in std_logic;      
        i_b : in std_logic;
        
        --OUTPUT
        o_y : out std_logic
    );

end xor_gate;


architecture xor_gate_arch of xor_gate is
    signal and1_out  :  std_logic;
    signal nor1_out  :  std_logic;
    signal result  :  std_logic;

begin

     -- Using direct entity declaration, no component needed
	and1: entity riscv.and_gate 
        port map( 
            i_a  => i_a,
            i_b =>  i_b,

            o_y  => and1_out 
        );


	nor1: entity riscv.nor_gate 
        port map( 
            i_a  => i_a,
            i_b =>  i_b,

            o_y  => nor1_out 
        );

    nor2: entity riscv.nor_gate 
        port map( 
            i_a  => and1_out,
            i_b =>  nor1_out,

            o_y  => result 
        );

    o_y <= result;

end xor_gate_arch; 

GHDL Simulation Waveform 10 ns / step
0ns10ns20ns30ns40nss_as_bs_y
FPGA Synthesis & Utilization Vivado / Quartus
LUTs / ALUTs 1 (2-input LUT)
Registers (FF) 0 (Combinational)
Logic Depth 1 Level
I/O Pins 3 (2 in, 1 out)

XNOR

y = a XNOR b

Outputs high ('1') only when inputs are the same.

Logic Symbol
XNOR gate logic symbol with inputs a, b and output y
Truth Table
a b y
0 0 1
0 1 0
1 0 0
1 1 1
xnor_gate.vhdl
--
--    This is a simple XNOR gate modeled in VHDL 
--
--    Created:    Winter 2022
--    Author: 	  Kevin Cloutier <kevincloutier@mac.com>
--
library ieee;
use ieee.std_logic_1164.all;

library riscv;

entity xnor_gate is

    port(
        -- INPUTS
        i_a : in std_logic;      
        i_b : in std_logic;
        
        --OUTPUT
        o_y : out std_logic
    );

end xnor_gate;


architecture xnor_gate_arch of xnor_gate is
    signal nand1_out  :  std_logic;
    signal or1_out  :  std_logic;
    signal result  :  std_logic;

begin

     -- Using direct entity declaration, no component needed
	nand1: entity riscv.nand_gate 
        port map( 
            i_a  => i_a,
            i_b =>  i_b,

            o_y  => nand1_out 
        );


	or1: entity riscv.or_gate 
        port map( 
            i_a  => i_a,
            i_b =>  i_b,

            o_y  => or1_out 
        );

    nand2: entity riscv.nand_gate 
        port map( 
            i_a  => nand1_out,
            i_b =>  or1_out,

            o_y  => result 
        );


    o_y <= result;

end xnor_gate_arch; 

GHDL Simulation Waveform 10 ns / step
0ns10ns20ns30ns40nss_as_bs_y
FPGA Synthesis & Utilization Vivado / Quartus
LUTs / ALUTs 1 (2-input LUT)
Registers (FF) 0 (Combinational)
Logic Depth 1 Level
I/O Pins 3 (2 in, 1 out)