Gates
AND, OR, NOT, NAND, NOR, XOR, XNOR
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.
AND
y = a AND b
Outputs high ('1') only when both inputs a and b are high.
| a | b | y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
--
-- 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;
OR
y = a OR b
Outputs high ('1') when either inputs a or b are high.
| a | b | y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
--
-- 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;
NOT
y = NOT a
Outputs high ('1') when input a is low.
| A | Y |
|---|---|
| 0 | 1 |
| 1 | 0 |
--
-- 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;
NAND
y = a NAND b
Outputs low ('0') only when all of its inputs are 1; otherwise, it outputs 1 ('1').
| a | b | y |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
--
-- 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;
NOR
y = a NOR b
Outputs high ('1') only when all of its inputs are low ('0').
| a | b | y |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
--
-- 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;
XOR
y = a XOR b
Outputs high ('1') only when the inputs are different.
| a | b | y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
--
-- 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;
XNOR
y = a XNOR b
Outputs high ('1') only when inputs are the same.
| a | b | y |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
--
-- 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;