Advertisement
Guest User

Untitled

a guest
Nov 7th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.17 KB | None | 0 0
  1. --------------------------------------------------
  2. --- A slice of addition: two bit add
  3. --- Initial 2-bit add that produces a sum and carry
  4. --------------------------------------------------
  5. LIBRARY IEEE;
  6. USE IEEE.std_logic_1164.all;
  7. USE IEEE.std_logic_arith.all;
  8.  
  9. ENTITY famakin_first_slice IS
  10. PORT (
  11.     OP_A :IN STD_LOGIC;
  12.     OP_B :IN STD_LOGIC;
  13.     SUM_Q :OUT STD_LOGIC;
  14.     CARRY_Q :OUT STD_LOGIC
  15.  );
  16. END famakin_first_slice;
  17.  
  18. ARCHITECTURE arch OF famakin_first_slice IS
  19. CONSTANT OP_C: STD_LOGIC:='0';
  20. BEGIN
  21. SUM_Q <= OP_A XOR OP_B XOR OP_C;
  22. CARRY_Q <= ((OP_A XOR OP_B) AND OP_C) OR (OP_A AND OP_B);
  23. END arch;
  24.  
  25.  
  26. --------------------------------------------------
  27. --- A slice of addition: three bit add
  28. --- Subsequent additions that use the carry of
  29. --- previous additions to produce a new sum and
  30. --- carry
  31. --------------------------------------------------
  32. library ieee;
  33. use ieee.std_logic_1164.all;
  34. use ieee.std_logic_arith.all;
  35.  
  36. entity famakin_fa_slice is
  37. port (
  38.       OP_A: in std_logic;
  39.       OP_B: in std_logic;
  40.       OP_C: in std_logic; ---this is the carry from the previous slice
  41.       SUM_Q: out std_logic;
  42.       CARRY_Q: out std_logic
  43.     );
  44. end famakin_fa_slice;
  45.  
  46. architecture arch of famakin_fa_slice is
  47. begin
  48.      SUM_Q <= OP_A xor OP_B xor OP_C;
  49.      CARRY_Q <= ((OP_A xor OP_B) and OP_C) or (OP_A and OP_B);
  50. end arch;
  51.  
  52. --------------------------------------------------------
  53. ---- Interslice register that holds the sum and carry
  54. ---- from a stage for one clock cycle and
  55. ---- also passes the sum, carry and MSBs over to the next
  56. ---- 4-bit stage addition.
  57. --------------------------------------------------------
  58. library ieee;
  59. use ieee.std_logic_1164.all;
  60.  
  61. entity reg_fa is
  62.  generic (P: integer:=16;
  63.       W: integer:=4;
  64.       E: integer:=8
  65.         );
  66.  port (CLK: in std_logic;
  67.        Reset: in std_logic;
  68.        EN: in std_logic;
  69.        OP_A: in std_logic_vector(P-1 downto 0);
  70.        OP_B: in std_logic_vector(P-1 downto 0);
  71.        OP_SUM: in std_logic_vector(W-1 downto 0);
  72.        OP_CARRY: in std_logic;
  73.        OP_AQ: out std_logic_vector(P-1 downto 0);
  74.        OP_BQ: out std_logic_vector(P-1 downto 0);
  75.        OP_SQ: out std_logic_vector(W-1 downto 0);
  76.        OP_C: out std_logic
  77.      );
  78. end reg_fa;
  79.  
  80. architecture arch of reg_fa is
  81. signal DA: std_logic_vector(P-1 downto 0);
  82. signal DB: std_logic_vector(P-1 downto 0);
  83. signal DS: std_logic_vector(W-1 downto 0);
  84. signal DC: std_logic;
  85.  
  86. begin
  87.    p_reg_fa: process(CLK)
  88. begin
  89.     if (CLK'event and CLK='1') then
  90.      
  91.        if(Reset='1') then
  92.           DA <= (others => '0');
  93.           DB <= (others => '0');
  94.       DS <= (others => '0');
  95.       DC <= '0';
  96.        elsif (EN='1') then
  97.       DA <= OP_A;
  98.           DB <= OP_B;
  99.       DS <= OP_SUM;
  100.       DC <= OP_CARRY;
  101.        else
  102.       DA <= DA;
  103.           DB <= DB;
  104.       DS <= DS;
  105.       DC <= DC;
  106.        end if;
  107.     end if;
  108. end process p_reg_fa;
  109.  
  110. OP_AQ <= DA;
  111. OP_BQ <= DB;
  112. OP_SQ <= DS;
  113. OP_C <= DC;
  114.  
  115. end arch;
  116.  
  117. -------------------------------------------
  118. ----- last slice register for the 4-stage
  119. ----- full adder that spits out the final
  120. ----- sum and the flag
  121. -------------------------------------------
  122. library ieee;
  123. use ieee.std_logic_1164.all;
  124.  
  125. entity reg_fa_lastslice is
  126.  generic (P: integer:= 16;
  127.       W: integer:= 4;
  128.       E: integer:= 8
  129.         );
  130.  port (CLK: in std_logic;
  131.        Reset: in std_logic;
  132.        EN: in std_logic;
  133.        OP_A: in std_logic; --sign bit
  134.        OP_B: in std_logic; --sign bit--
  135.        OP_SUM: in std_logic_vector(P-1 downto 0);
  136.        OP_CARRY: in std_logic;
  137.        OP_Q: out std_logic_vector(P-1 downto 0);
  138.        OP_F: out std_logic_vector(W-2 downto 0)
  139.     );
  140. end reg_fa_lastslice;
  141.  
  142. architecture arch of reg_fa_lastslice is
  143. signal DS: std_logic_vector(P-1 downto 0);
  144. signal DC: std_logic_vector(W-2 downto 0);
  145.  
  146. begin
  147.   p_reg_fa: process(CLK)
  148. begin
  149.     if (CLK'event and CLK='1') then
  150.      
  151.        if (Reset = '1') then
  152.            DS <= (others => '0');
  153.        DC <= (others => '0');
  154.        elsif (EN= '1') then
  155.        DS <= OP_SUM;
  156.        DC <= OP_A & OP_B & OP_CARRY;
  157.        else
  158.        DS <= DS;
  159.        DC <= DC;
  160.        end if;
  161.     end if;
  162. end process p_reg_fa;
  163. OP_Q <= DS;
  164. OP_F <= DC;
  165.  
  166. end arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement