过程语句 - VHDL 示例
过程是称为子程序的一组结构的一部分。过程是一小段代码,它们执行在整个代码中重复使用的操作。这有助于清理代码并实现可重用性。
过程可以接受输入并产生输出。它们通常比函数更复杂。不需要将任何信号传递给过程。在下面的示例中,有一个过程 p_INCREMENT_SLV,其目的是将标准逻辑向量增加 1 并生成带有结果的信号。
关于使用等待语句的附加说明:
可以在过程中使用等待语句,只要调用该过程的进程没有敏感度列表。在下面的示例中,该过程有一个 1 ns 的等待语句来说明这一点。这使得过程对于创建测试台代码很有用。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity example_procedure_simple is
end example_procedure_simple;
architecture behave of ex_procedure_simple is
signal r_TEST : std_logic_vector(7 downto 0) := X"42";
-- Purpose: Increments a std_logic_vector by 1
procedure p_INCREMENT_SLV (
signal r_IN : in std_logic_vector(7 downto 0);
signal r_OUT : out std_logic_vector(7 downto 0)
) is
begin
r_OUT <= std_logic_vector(unsigned(r_IN) + 1);
wait for 1 ns; -- Wait is OK here.
end p_INCREMENT_SLV;
begin
process is
begin
wait for 10 ns;
p_INCREMENT_SLV(r_TEST, r_TEST);
wait for 10 ns;
p_INCREMENT_SLV(r_TEST, r_TEST);
wait for 10 ns;
p_INCREMENT_SLV(r_TEST, r_TEST);
wait;
end process;
end behave;
VHDL