Advertisement
redsees

Untitled

Nov 16th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.13 KB | None | 0 0
  1.  
  2. ***Single Bit***
  3.  
  4. library IEEE;
  5. use IEEE.STD_LOGIC_1164.ALL;
  6. use IEEE.STD_LOGIC_ARITH.ALL;
  7. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  8.  
  9. -- Uncomment the following lines to use the declarations that are
  10. -- provided for instantiating Xilinx primitive components.
  11. --library UNISIM;
  12. --use UNISIM.VComponents.all;
  13.  
  14. entity ADDONE is
  15. Port ( a : in std_logic;
  16. b : in std_logic;
  17. cin : in std_logic;
  18. s : out std_logic;
  19. end ADDONE;
  20.  
  21. architecture Behavioral of ADDONE is
  22.  
  23. begin
  24. s<=(a xor (b xor cin));
  25.  
  26. end Behavioral;
  27.  
  28. ***Mux 2 to 1***
  29.  
  30. library IEEE;
  31. use IEEE.STD_LOGIC_1164.ALL;
  32. use IEEE.STD_LOGIC_ARITH.ALL;
  33. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  34.  
  35. entity MUX_2_1 is
  36. Port ( a,b,S : in std_logic;
  37. O : out std_logic;
  38. end MUX_2_1;
  39.  
  40. architecture Behavioral of MUX_2_1 is
  41.  
  42. begin
  43. if (S='0') then
  44.     O <= a;
  45. else
  46.     O <= b;
  47. end if;
  48.  
  49. end Behavioral;
  50.  
  51. ***OverAll Process***
  52.  
  53. library IEEE;
  54. use IEEE.STD_LOGIC_1164.ALL;
  55. use IEEE.STD_LOGIC_ARITH.ALL;
  56. use IEEE.STD_LOGIC_UNSIGNED.ALL
  57.  
  58.  
  59. entity all_me is
  60. Port ( a,b: in std_logic_vector(3 downto 0);
  61. Cin : in std_logic;
  62. Sel:in std_logic;
  63. O : out std_logic_vector(3 downto 0);
  64. Cout: out std_logic;
  65. end all_me;
  66.  
  67. architecture Behavioral of all_me is
  68. signal s0,g,p,c : std_logic_vector(3 downto 0);
  69.  
  70. begin
  71. g(0) <= a(0) and b(0);
  72. g(1) <= a(1) and b(1);
  73. g(2) <= a(2) and b(2);
  74. g(3) <= a(3) and b(3);
  75. p(0) <= a(0) or b(0);
  76. p(1) <= a(1) or b(1);
  77. p(2) <= a(2) or b(2);
  78. p(3) <= a(3) or b(3);
  79. c(1) <= g(0) or (p(0) and Cin);
  80. c(2) <= g(1) or (p(1) and c(1));
  81. c(3) <= g(2) or (p(2) and c(2));
  82. Cout <= g(3) or (p(3) and c(3));
  83. bit1: ADDONE port map (a=>a(0), b=>b(0), s=>s0(0), cin=>Cin);
  84. bit2: ADDONE port map (a=>a(1), b=>b(1), s=>s0(1), cin=>c(1));
  85. bit3: ADDONE port map (a=>a(2), b=>b(2), s=>s0(2), cin=>c(2));
  86. bit4: ADDONE port map (a=>a(3), b=>b(3), s=>s0(3), cin=>c(3));
  87. E <= a(0) xor b(0);
  88. F <= a(1) xor b(1);
  89. G <= a(2) xor b(2);
  90. H <= a(3) xor b(3);
  91. bit5: MUX_2_1 port map (a=>E,b=>s0(0),S=>Sel,O=>O(0));
  92. bit6: MUX_2_1 port map (a=>F,b=>s0(1),S=>Sel,O=>O(1));
  93. bit7: MUX_2_1 port map (a=>G,b=>s0(2),S=>Sel,O=>O(2));
  94. bit8: MUX_2_1 port map (a=>H,b=>s0(3),S=>Sel,O=>O(3));
  95.  
  96. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement