Using VHDL To Describe Adders
Using VHDL To Describe Adders
IF ___expression THEN
__statement;
__Statement;
__statement;
__statement;
ELSE
__statement;
__statement;
END IF;
BEGIN
statement;
END PROCESS;
entity half_adder is
port(
a : in std_logic;
b : in std_logic;
sum : out std_logic;
carry : out std_logic
);
end half_adder;
begin
end process;
end arch1;
Component:
A complete VHDL design entity that can be used as a part of
a higher-level file in a hierarchical design.
Port:
An input or output of a VHDL design entity or component.
Instantiate:
To use an instance of a component.
Example 2:
entity full_a is
port(
In1 : in std_logic;
In2 : in std_logic;
c_in : in std_logic;
c_out : out std_logic;
sum : out std_logic
);
end full_a;
architecture arch1 of full_a is
-- Component declarations
component half_adder
port (a, b: in std_logic;
sum, carry: out std_logic);
end component;
component or_2
port (a, b: in std_logic;
c: out std_logic);
end component;
-- Signal declarations
signal s1, s2, s3: std_logic;
begin
-- Component interconnections
H1: half_adder port map
(a => In1, b => In2,
sum => s1, carry => s2);
O1: or_2 port map (a => s2, b => s3, c => c_out);
end arch1;
entity full_add is
port(
a : in std_logic;
b : in std_logic;
c_in : in std_logic;
sum : out std_logic;
c_out : out std_logic
);
end full_add;
begin
end adder;
The following shows the VHDL file for a 4-bit parallel adder using the above
full adder components.
library IEEE;
library Libs;
use IEEE.std_logic_1164.all;
use Libs.VHDLPrims.all;
use Libs.mylib.all;
entity add4par is
port(
c0 : in std_logic;
a : in std_logic_vector(4 downto 1);
b : in std_logic_vector(4 downto 1);
c4 : out std_logic;
sum : out std_logic_vector(4 downto 1)
);
end add4par;
-- component declaration
component full_add
port(
a, b, c_in: in std_logic;
c_out, sum: out std_logic);
end component;
begin
adder2: full_add
port map ( a => a(2),
b => b(2),
c_in => c(1),
c_out => c(2),
sum => sum(2));
adder3: full_add
port map ( a => a(3),
b => b(3),
c_in => c(2),
c_out => c(3),
sum => sum(3));
adder4: full_add
end arch1;
In this example, the component ports of the full adder component are a, b,
c_in, c_out, and sum. The connect ports for the instance adder1 are a(1),
b(1), c0, c(1), and sum(1). The ripple carry from adder1 to adder2 is
achieved by mapping the port c_in to c(1), which is also mapped to the
port c_out of adder1. It is pretty obvious, you can see the similarities
inadder2, adder3, and adder4.
4. Lab Assignments