全加器仿真quartus源文件和测试文件
时间: 2024-03-20 13:40:44 浏览: 66
siweijiafa_quartusII_caughta1j_四位全加器宏功能调用_
5星 · 资源好评率100%
以下是全加器的VHDL源文件和测试文件的代码:
全加器的VHDL源文件(full_adder.vhd):
```
library ieee;
use ieee.std_logic_1164.all;
entity full_adder is
port (
a, b, cin : in std_logic;
sum, cout : out std_logic
);
end full_adder;
architecture behavior of full_adder is
begin
sum <= a xor b xor cin;
cout <= (a and b) or (cin and (a xor b));
end behavior;
```
全加器的测试文件(full_adder_tb.vhd):
```
library ieee;
use ieee.std_logic_1164.all;
entity full_adder_tb is
end full_adder_tb;
architecture behavior of full_adder_tb is
component full_adder is
port (
a, b, cin : in std_logic;
sum, cout : out std_logic
);
end component;
signal a, b, cin, sum, cout : std_logic;
begin
uut : full_adder port map (a => a, b => b, cin => cin, sum => sum, cout => cout);
stim_proc : process
begin
a <= '0'; b <= '0'; cin <= '0'; wait for 10 ns;
a <= '0'; b <= '0'; cin <= '1'; wait for 10 ns;
a <= '0'; b <= '1'; cin <= '0'; wait for 10 ns;
a <= '0'; b <= '1'; cin <= '1'; wait for 10 ns;
a <= '1'; b <= '0'; cin <= '0'; wait for 10 ns;
a <= '1'; b <= '0'; cin <= '1'; wait for 10 ns;
a <= '1'; b <= '1'; cin <= '0'; wait for 10 ns;
a <= '1'; b <= '1'; cin <= '1'; wait for 10 ns;
wait;
end process;
result_proc : process
begin
wait for 80 ns;
assert sum = '0' and cout = '0' report "Test failed for case 1" severity error;
wait for 10 ns;
assert sum = '1' and cout = '0' report "Test failed for case 2" severity error;
wait for 10 ns;
assert sum = '1' and cout = '0' report "Test failed for case 3" severity error;
wait for 10 ns;
assert sum = '0' and cout = '1' report "Test failed for case 4" severity error;
wait for 10 ns;
assert sum = '1' and cout = '0' report "Test failed for case 5" severity error;
wait for 10 ns;
assert sum = '0' and cout = '1' report "Test failed for case 6" severity error;
wait for 10 ns;
assert sum = '0' and cout = '1' report "Test failed for case 7" severity error;
wait for 10 ns;
assert sum = '1' and cout = '1' report "Test failed for case 8" severity error;
wait;
end process;
end behavior;
```
注意:要在Quartus中运行此仿真,请确保将这两个文件添加到Quartus项目中并进行仿真设置。
阅读全文