0% found this document useful (0 votes)
57 views

Library IEEE Use IEEE - STD - LOGIC - 1164.ALL Use Ieee - STD - Logic - Unsigned - All Use Ieee - STD - Logic - Arith - All

The document describes a 4-bit adder entity and testbench. The adder entity named ADDER takes in two 4-bit inputs A and B along with a carry in CIN and outputs the sum bits S3, S2, S1, S0 and carry out COUT. The testbench entity ADDER_TB instantiates the ADDER and applies test inputs to A, B and CIN over time, with the outputs observed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Library IEEE Use IEEE - STD - LOGIC - 1164.ALL Use Ieee - STD - Logic - Unsigned - All Use Ieee - STD - Logic - Arith - All

The document describes a 4-bit adder entity and testbench. The adder entity named ADDER takes in two 4-bit inputs A and B along with a carry in CIN and outputs the sum bits S3, S2, S1, S0 and carry out COUT. The testbench entity ADDER_TB instantiates the ADDER and applies test inputs to A, B and CIN over time, with the outputs observed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

-- Uncomment the following library declaration if using

-- arithmetic functions with Signed or Unsigned values


--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating

-- any Xilinx leaf cells in this code.

--library UNISIM;

--use UNISIM.VComponents.all;

entity ADDER is

Port (

CIN : in STD_LOGIC;

A : in STD_LOGIC_VECTOR (3 downto 0);

B : in STD_LOGIC_VECTOR (3 downto 0);

S3, S2, S1, S0: out STD_LOGIC;

COUT: out STD_LOGIC

);

end ADDER;

architecture Behavioral of ADDER is

signal Z: STD_LOGIC_VECTOR(4 downto 0);

begin

-- Z<=(A3 & A2 & A1 & A0) + (B3 & B2 & B1 & B0) + CIN;

Z<= ("0" & A) + ("0" & B) + (CIN);

S0 <= Z(0);

S1 <= Z(1);

S2 <= Z(2);

S3 <= Z(3);

COUT <= Z(4);

end Behavioral;
entity ADDER_TB is

-- Port ( );

end ADDER_TB;

architecture Behavioral of ADDER_TB is

COMPONENT ADDER

Port ( CIN : in STD_LOGIC;

A : in STD_LOGIC_VECTOR (3 downto 0);

B : in STD_LOGIC_VECTOR (3 downto 0);

S3, S2, S1, S0: out STD_LOGIC;

COUT: out STD_LOGIC

);

end COMPONENT;
--inputs

signal CIN : STD_LOGIC;

signal A : STD_LOGIC_VECTOR(3 downto 0);

signal B : STD_LOGIC_VECTOR(3 downto 0);

--outpouts

signal S3 : STD_LOGIC;

signal S2 : STD_LOGIC;

signal S1 : STD_LOGIC;

signal S0 : STD_LOGIC;

signal COUT : STD_LOGIC;

--signal :Z STD_LOGIC_VECTOR(4 downto 0);

begin

UUT:ADDER PORT MAP (CIN => CIN, A => A, B => B,

S3 => S3, S2 => S2, S1 => S1, S0 => S0, COUT => COUT);

stim_proc: process

begin

wait for 10 ns;

A <= "1010";

wait for 10 ns;

B <= "1010";

wait for 10 ns;

CIN <= "1";

wait;

end process;

end Behavioral;

You might also like