Advertisement
Guest User

Untitled

a guest
May 27th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. entity adder_4bit is
  5.  
  6. port
  7. (
  8. -- Input ports
  9. a : in std_logic_vector(3 downto 0);
  10. b : in std_logic_vector(3 downto 0);
  11. cin : in std_logic;
  12.  
  13.  
  14. -- Output ports
  15. s : out std_logic_vector(3 downto 0);
  16. cout : out std_logic
  17. );
  18. end adder_4bit;
  19.  
  20.  
  21. architecture structural of adder_4bit is
  22. signal carries: std_logic_vector(4 downto 0);
  23.  
  24.  
  25. component fulladder is
  26.  
  27. port
  28. (
  29. -- Input ports
  30. a : in std_logic;
  31. b : in std_logic;
  32. cin : in std_logic;
  33.  
  34.  
  35. -- Output ports
  36. s : out std_logic;
  37. cout : out std_logic
  38. );
  39. end component;
  40. begin
  41. carries(0)<=cin;
  42. -- FA0: fulladder port map( a(0),b(0),carries(0),s(0),carries(1));
  43. -- FA1: fulladder port map( a(1),b(1),carries(1),s(1),carries(1));
  44. -- FA2: fulladder port map( a(2),b(2),carries(2),s(2),carries(2));
  45. -- FA3: fulladder port map( a(3),b(3),carries(3),s(3),carries(3));
  46. FAi: for i in 3 downto 0 generate
  47. FA: fulladder port map(a(i),b(i),carries(i),s(i),carries(i+1));
  48. end generate;
  49.  
  50. cout<=carries(4);
  51. end structural;
  52.  
  53.  
  54. test bench:
  55.  
  56.  
  57.  
  58. LIBRARY ieee;
  59. USE ieee.std_logic_1164.all;
  60.  
  61. ENTITY adder_4bit_vhd_tst IS
  62. END adder_4bit_vhd_tst;
  63. ARCHITECTURE adder_4bit_arch OF adder_4bit_vhd_tst IS
  64. -- constants
  65. -- signals
  66. SIGNAL a : STD_LOGIC_VECTOR(3 DOWNTO 0);
  67. SIGNAL b : STD_LOGIC_VECTOR(3 DOWNTO 0);
  68. SIGNAL cin : STD_LOGIC;
  69. SIGNAL cout : STD_LOGIC;
  70. SIGNAL s : STD_LOGIC_VECTOR(3 DOWNTO 0);
  71. COMPONENT adder_4bit
  72. PORT (
  73. a : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
  74. b : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
  75. cin : IN STD_LOGIC;
  76. cout : OUT STD_LOGIC;
  77. s : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
  78. );
  79. END COMPONENT;
  80. BEGIN
  81. i1 : adder_4bit
  82. PORT MAP (
  83. -- list connections between master ports and signals
  84. a => a,
  85. b => b,
  86. cin => cin,
  87. cout => cout,
  88. s => s
  89. );
  90.  
  91. always : PROCESS
  92.  
  93. -- ( )
  94. -- variable declarations
  95. BEGIN
  96. a<="0101";
  97. b<="1111";
  98. cin<='0'
  99. wait for 1 ns;
  100. a<=x"A";
  101. wait for 1 ns;
  102. b<=x"1";
  103. WAIT;
  104. END PROCESS always;
  105. END adder_4bit_arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement