安装
sudo add-apt-repository ppa:pgavin/ghdl
sudo apt-get update
sudo apt-get install ghdl gtkwave
仿真
rtl
add.v
library ieee;
use ieee.std_logic_1164.all;
entity ADD is
port (A,B:in bit;
SUM,CARRY:out bit);
end entity ADD;
architecture behave of ADD is
begin
SUM <=A xor B;
CARRY <= A and B;
end behave;
TB
library ieee;
use ieee.std_logic_1164.all;
entity tb is
end tb;
architecture beh of tb is
signal a_tb,b_tb,sum_tb,carry_tb: bit;
constant period : TIME := 10 ns;
component ADD
port (A,B:in bit;
SUM,CARRY:out bit);
end component;
begin
U0: ADD port map(
A=>a_tb,
B=>b_tb,
SUM=>sum_tb,
CARRY=>carry_tb
);
tb: process
–constant period : time :=20ns;
begin
a_tb <= ‘0’;
b_tb <= ‘1’;
wait for period;
assert ((sum_tb = ‘1’)and (carry_tb = ‘0’))
report “Test failed” severity error;
a_tb <=‘1’;
b_tb <=‘1’;
wait for period;
assert ((sum_tb = ‘0’)and (carry_tb = ‘1’))
report “Test failed” severity error;
wait;
end process;
end beh;
编译
分析
ghdl -a tb.vhd ADD.vhd
elab
ghdl -e tb
仿真
ghdl -r tb --vcd=tb.vcd
看波形
gtkwave tb.vcd
命令解析: