Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

EXPERIMENT:- 2

AIM: - Implement Half adder and Full adder using VHDL.

Code: -
1. Half Adder

--half adder using behavioral modeling


library ieee;
use ieee.std_logic_1164.all;

entity adder is
port (a, b: in std_logic;
sum, carry_out: out std_logic);
end adder;

architecture behavior of adder is


begin
ha: process (a, b)
begin
if a = '1' then
sum <= not b;
carry_out <= b;
else
sum <= b;
carry_out <= '0';
end if;
end process ha;

end behavior;
2. Full adder

--Full adder using Stuructural Modeling


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity HA is
Port ( A,B : in STD_LOGIC;
S,C : out STD_LOGIC);
end HA;

architecture dataflow of HA is
begin
S <= A XOR B;
C <= A AND B;
end dataflow;

entity ORGATE is
Port ( X,Y : in STD_LOGIC;
Z : out STD_LOGIC);
end ORGATE;

architecture dataflow of ORGATE is


begin
Z <= X OR Y;
end dataflow;

entity adder is
Port ( FA, FB, FC : in STD_LOGIC;
FS, FCA : out STD_LOGIC);
end adder;

architecture structural of adder is


component HA is
Port ( A,B : in STD_LOGIC;
S,C : out STD_LOGIC);
end component;

component ORGATE is
Port ( X,Y: in STD_LOGIC;
Z: out STD_LOGIC);
end component;

SIGNAL S0,S1,S2:STD_LOGIC;
begin
U1:HA PORT MAP(A=>FA,B=>FB,S=>S0,C=>S1);
U2:HA PORT MAP(A=>S0,B=>FC,S=>FS,C=>S2);
U3:ORGATE PORT MAP(X=>S2,Y=>S1,Z=>FCA);
end structural;

Circuit Diagram: -
Waveform: -

You might also like