Professional Documents
Culture Documents
Assignment 2 Chaitanya T19175
Assignment 2 Chaitanya T19175
Assignment 2 Chaitanya T19175
EMBEDDED SYSTEMS
1.Write a VHDL program to model a two input AND gate and a two input XOR gate using dataflow
style of modeling. Save the program files in your working library.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity and1 is
port(a,b : in std_logic;
o: out std_logic);
end and1 ;
architecture df of and1 is
begin
o <= a and b;
end df;
Test bench
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity tb is
end tb;
architecture dx of tb is
begin
b => r_b,
o =>r_o);
process is
begin
end process;
end dx;
Two input xor gate:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity xor1 is
port(a,b : in std_logic;
o: out std_logic);
end and1 ;
architecture df of xor1 is
begin
o <= a xor b;
end df;
Test bench
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity tb is
end tb;
architecture dx of tb is
b => r_b,
o =>r_o);
process is
begin
end process;
end dx;
2.Use the models of the AND gate and XOR gate created in problem 1 to
develop the structural model of a half adder.
Half adder: code
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity ha is
port(a,b : in std_logic;
end ha;
architecture df of ha is
component and1
o1 : out std_logic);
end component;
component xor1
port(ax,bx:in std_logic;
ox:out std_logic);
end component;
begin
end df;
and1:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity and1 is
port(a1,b 1: in std_logic;
end and1 ;
architecture df of and1 is
begin
o <= a and b;
end df;
xor1:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity xor1 is
port(ax,b x: in std_logic;
end xor1 ;
architecture df of xor1 is
begin
o <= a xor b;
end df;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity half_adder is
port(a,b : in std_logic;
end half_adder;
architecture df of half_adder is
begin
s <= a and b;
c <= a xor b;
end df;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity half_adder is
port(a,b : in std_logic;
end half_adder;
architecture df of half_adder is
begin
uux :process(a,b)
begin
if a='1' then
if b='1' then
s <= '1';
c <= '1';
else
s <= '1';
c <= '0';
end if;
else
if b = '1' then
s <= '1';
c <= '0';
else
s <= '0';
c <= '0';
end if;
end if;
end process;
end df;
5.Use the model of the half adder developed in problem 2 to develop the
model of a single bit full adder.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity full_adder is
Port (af,bf,ci : in std_logic;
end full_adder;
architecture st of full_adder is
signal ct:std_logic;
signal st:std_logic;
signal ct2:std_logic;
component ha
port(a,b:in std_logic;
s,c:out std_logic);
end component;
component or1
port(ar,br:in std_logic;
o3:out std_logic);
end component;
begin
end st;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity ha is
port(a,b : in std_logic;
end ha;
architecture df of ha is
component and1
o1 : out std_logic);
end component;
component xor1
port(ax,bx:in std_logic;
ox:out std_logic);
end component;
begin
end df;
and1:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity and1 is
port(a1,b 1: in std_logic;
architecture df of and1 is
begin
o <= a and b;
end df;
xor1:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity xor1 is
port(ax,b x: in std_logic;
end xor1 ;
architecture df of xor1 is
begin
end df;
or1:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity xor1 is
port(ar,b r: in std_logic;
architecture df of xor1 is
begin
o 3<= ar or br;
end df;
6. Use the model of the single bit full adder developed in problem 5 to develop
the model of a four bit ripple carry adder.
Ripple carry adder code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity ripple_adder is
end ripple_adder;
component full_adder is
end component;
begin
end rip;
Full adder:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity full_adder is
end full_adder;
architecture st of full_adder is
signal ct:std_logic;
signal st:std_logic;
signal ct2:std_logic;
component ha
port(a,b:in std_logic;
s,c:out std_logic);
end component;
component or1
port(ar,br:in std_logic;
o3:out std_logic);
end component;
begin
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity ha is
port(a,b : in std_logic;
end ha;
architecture df of ha is
component and1
o1 : out std_logic);
end component;
component xor1
port(ax,bx:in std_logic;
ox:out std_logic);
end component;
begin
end df;
and1:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity and1 is
port(a1,b 1: in std_logic;
end and1 ;
architecture df of and1 is
begin
o <= a and b;
end df;
xor1:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity xor1 is
port(ax,b x: in std_logic;
end xor1 ;
architecture df of xor1 is
begin
end df;
or1:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity xor1 is
port(ar,b r: in std_logic;
end xor1 ;
architecture df of xor1 is
begin
o 3<= ar or br;
end df;
entity decoder is
Port ( s : in STD_LOGIC_VECTOR (2 downto 0);
y : out STD_LOGIC_VECTOR (7 downto 0));
end decoder;
entity mac is
9. Consider the same problem in problem no. 8. Devise a sequence of inputs values for the
MAC that can cause the sum in the accumulator to overflow.
entity mac_test is
end entity mac_test;
architecture bench_behavioral of mac_test is
signal x_real, x_imag, y_real, y_imag, s_real, s_imag : u_sfixed(0 downto -15);
port map ( clk, reset, x_real, x_imag, y_real, y_imag, s_real, s_imag, ovf );
s <= (s_real, s_imag);
clock_gen : process is
begin
after 2 * Tpw_clk;
-- first sequence
wait;