Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.30 KB | None | 0 0
  1. --- add1bit.vhd
  2.  
  3. library ieee;
  4. use ieee.std_logic_1164.all;
  5.  
  6. entity add1bit is
  7.     Port(
  8.         a: in STD_LOGIC;
  9.         b: in STD_LOGIC;
  10.         c_in: in STD_LOGIC;
  11.         sum: out STD_LOGIC;
  12.         c_out: out STD_LOGIC
  13.     );
  14. end add1bit;
  15.  
  16.  
  17. architecture behaviour of add1bit is
  18. begin
  19.     sum <= (a xor b) xor c_in;
  20.     c_out <= (a and b) or (c_in and (a xor b));
  21. end behaviour;
  22.  
  23. -------------------------------------------------------------------
  24.  
  25. --add4bit.vhd
  26.  
  27. library ieee;
  28. use ieee.std_logic_1164.all;
  29. use ieee.std_logic_arith.all;
  30. use ieee.std_logic_unsigned.all;
  31.  
  32. entity add4bit is
  33.     Port(
  34.         a_vec: in STD_LOGIC_VECTOR(3 downto 0);
  35.         b_vec: in STD_LOGIC_VECTOR(3 downto 0);
  36.         cin_vec: in STD_LOGIC;
  37.         sum_vec: out STD_LOGIC_VECTOR(3 downto 0);
  38.         cout_vec: out STD_LOGIC
  39.     );
  40. end add4bit;
  41.  
  42.  
  43. architecture behaviour of add4bit is
  44. component add1bit
  45.     Port(
  46.         a: in STD_LOGIC;
  47.         b: in STD_LOGIC;
  48.         c_in: in STD_LOGIC;
  49.         sum: out STD_LOGIC;
  50.         c_out: out STD_LOGIC
  51.     );
  52. end component;
  53.  
  54. signal c1, c2, c3: STD_LOGIC;
  55.  
  56. begin
  57.     stage0: add1bit port map(
  58.         a=>a_vec(0),
  59.         b=>b_vec(0),
  60.         c_in=>cin_vec,
  61.         sum=>sum_vec(0),
  62.         c_out=>c1
  63.     );
  64.     stage1: add1bit port map(
  65.         a=>a_vec(1),
  66.         b=>b_vec(1),
  67.         c_in=>c1,
  68.         sum=>sum_vec(1),
  69.         c_out=>c2
  70.     );
  71.     stage2: add1bit port map(
  72.         a=>a_vec(2),
  73.         b=>b_vec(2),
  74.         c_in=>c2,
  75.         sum=>sum_vec(2),
  76.         c_out=>c3
  77.     );
  78.     stage3: add1bit port map(
  79.         a=>a_vec(3),
  80.         b=>b_vec(3),
  81.         c_in=>c3,
  82.         sum=>sum_vec(3),
  83.         c_out=>cout_vec
  84.     );
  85. end behaviour;
  86.  
  87. -------------------------------------------------
  88.  
  89. --hex_decoder
  90.  
  91. library ieee;
  92. use ieee.std_logic_1164.all;
  93.  
  94. entity hexdecoder is
  95.     Port (
  96.         num: in STD_LOGIC_VECTOR(0 to 3);
  97.         leds: out STD_LOGIC_VECTOR(0 to 7)
  98.     );
  99. end hexdecoder;
  100.  
  101. --
  102. --     111
  103. --     2 3        
  104. --     243
  105. --     5 6
  106. --     777 8
  107. --
  108.  
  109. architecture Behaviour of hexdecoder is
  110. begin
  111.     with num select leds <=
  112.         "00000000" when "0000",
  113.         "00000000" when "0001",
  114.         "00000000" when "0010",
  115.         "00000000" when "0011",
  116.         "00000000" when "0100",
  117.         "00000000" when "0101",
  118.         "00000000" when "0110",
  119.         "00000000" when "0111",
  120.         "00000000" when "1000",
  121.         "00000000" when "1001",
  122.         "00000000" when "1010",
  123.         "00000000" when "1011",
  124.         "00000000" when "1100",
  125.         "00000000" when "1101",
  126.         "00000000" when "1110",
  127.         "00000000" when "1111";
  128. end Behaviour;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement