Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.50 KB | None | 0 0
  1. -------------------------------------------------------------
  2. -- Author   : http://www.teahlab.com/
  3. --
  4. -- Name     : Four Bit Adder-Substractor
  5. --
  6. -- Structure:
  7. --
  8. --     This program is a structural VHDL design of the 4-bit
  9. --     Adder-Subtracter. By structural we mean that the
  10. --     circuit is constructed using XOR components and Full
  11. --     Adder components -- just like the actual physical
  12. --     Adder-Substractor.
  13. --
  14. --     Consequently, this VHDL circuit is designed in two
  15. --     stages. In stage one we define the XOR entity and then
  16. --     the Full Adder entity. Here we present a dataflow
  17. --     design of the Full Adder circuit. For the structural
  18. --     (RTL) design of the circuit, see the Full Adder page
  19. --     on Teahlab.com.
  20. --
  21. --     In stage two we build the structure of the
  22. --     Adder-Substractor using the components we build in
  23. --     stage one.
  24. --
  25. --     It is very important to learn structural design (RTL)
  26. --     strategies because as your assignments become larger
  27. --     and larger, knowledge of register transfer level (RTL)
  28. --     design strategies become indispensable.
  29. -------------------------------------------------------------
  30.  
  31.                         -- This is the XOR gate
  32. library ieee;
  33. use ieee.std_logic_1164.all;
  34. --
  35. entity xorGate is  
  36.    port( A, B : in std_logic;
  37.             F : out std_logic);
  38. end xorGate;
  39. --
  40. architecture func of xorGate is
  41. begin
  42.    F <= A xor B;
  43. end func;
  44. --*============================
  45.                         -- This is the FULL ADDER
  46. library ieee;
  47. use ieee.std_logic_1164.all;
  48. --
  49. entity Full_Adder is
  50.    port( X, Y, Cin : in std_logic;
  51.          sum, Cout : out std_logic);
  52. end Full_Adder;
  53. --Dataflow architecture.
  54. --See Full Adder on Teahlab.com for structural version
  55. architecture func of Full_Adder is
  56. begin
  57.    sum <= (X xor Y) xor Cin;
  58.    Cout <= (X and (Y or Cin)) or (Cin and Y);
  59. end func;
  60. --*============================*============================
  61.  
  62. --Now we build the four bit Adder Subtractor
  63. library ieee;
  64. use ieee.std_logic_1164.all;
  65. entity adderSubtractor is
  66.    port( mode             : in std_logic;
  67.           A3, A2, A1, A0  : in std_logic;
  68.           B3, B2, B1, B0  : in std_logic;
  69.           S3, S2, S1, S0  : out std_logic;
  70.                   Cout, V : out std_logic);
  71. end adderSubtractor;
  72. --Structural architecture
  73. architecture struct of adderSubtractor is
  74.  
  75.    component xorGate is             --XOR component
  76.        port( A, B : in std_logic;
  77.                 F : out std_logic);
  78.    end component;
  79.  
  80.    component Full_Adder is           --FULL ADDER component
  81.       port( X, Y, Cin : in std_logic;
  82.             sum, Cout : out std_logic);
  83.    end component;
  84.  
  85.    --interconnecting wires
  86.    signal C1, C2, C3, C4: std_logic; --intermediate carries
  87.    signal xor0, xor1, xor2, xor3 : std_logic; --xor outputs
  88.  
  89. begin
  90.    GX0: xorGate port map(mode, B0, xor0);
  91.    GX1: xorGate port map(mode, B1, xor1);
  92.    GX2: xorGate port map(mode, B2, xor2);
  93.    GX3: xorGate port map(mode, B3, xor3);
  94.  
  95.    FA0: Full_Adder port map(A0, xor0, mode,  S0, C1);-- S0
  96.    FA1: Full_Adder port map(A1, xor1, C1,  S1, C2);  -- S1
  97.    FA2: Full_Adder port map(A2, xor2, C2,  S2, C3);  -- S2
  98.    FA3: Full_Adder port map(A3, xor3, C3,  S3, C4);  -- S3
  99.  
  100.    Vout: xorGate port map(C3, C4, V);                -- V
  101.    Cout <= C4;                                       -- Cout
  102. end struct;
  103. ----------------------------------------------------------END
  104. ----------------------------------------------------------END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement