3. 仂亠亟 于 VHDL
PROCEDURE name[(parameter_interface_list)] IS
{subprogram_declarative_item}
BEGIN
{sequential_statement}
END [PROCEDURE] [name];
SIGNAL, TYPE, FILE,
SUBTYPE, PROCEDURE,
FUNCTION, VARIABLE,
COMPONENT, CONSTANT
...-- 仗仂仍亠亟仂于舒亠仍仆亠 仂仗亠舒仂
a := 5
FOR LOOP END LOOP;
...
IF THEN ELSE END IF;
仄 仗仂亠亟
弌仗亳仂从 仂仄舒仍仆 仗舒舒仄亠仂于
(仄仂亢亠 仂于仂于舒)
4. project_pkg.vhd
n_reg.vhd
弍磦仍亠仆亳亠 仗仂亠亟
-- USE work.project_pkg;
ENTITY reg_file IS
GENERIC (...);
PORT (...);
END ENTITY n_reg;
ARCHITECTURE rtl OF reg_file IS
BEGIN
PROCESS(...)
BEGIN
...
END PROCESS;
...
END;
PROCEDURE inc(a: INOUT INTEGER; step: INTEGER := 1) IS
BEGIN
a := a + step;
END PROCEDURE inc;
...
PACKAGE project_pkg IS
...
PROCEDURE inc(a: INOUT INTEGER;
step: INTEGER := 1);
...
END PACKAGE project_pkg;
PACKAGE BODY project_pkg IS
END PACKAGE BODY project_pkg;
... ...
舒仍亳亳亠 仗仂仂亳仗舒 仗仂亟仗仂亞舒仄仄
仆亠仂弍磶舒亠仍仆仂, 仆仂 亠从仂仄亠仆亟亠
5. 弌仗亳仂从 仗舒舒仄亠仂于 仗仂亠亟
PROCEDURE name[(parameter_interface_list)] IS
...
([CONSTANT|VARIABLE|SIGNAL] identifier {,}:
[IN|OUT|INOUT] type_indication [:= expression] {;})
仄/亟亠仆亳亳从舒仂
仗舒舒仄亠舒
仍舒 仗舒舒仄亠舒
(仄仂亢亠 弍 亠亠 FILE)
亳亟
仗舒舒仄亠舒
丐亳仗
仗舒舒仄亠舒
仆舒亠仆亳亠 仗仂 仄仂仍舒仆亳.
仂亢亠 弍 亰舒亟舒仆仂 仂仍从仂
亟仍 仗舒舒仄亠仂于 从仍舒舒
CONSTANT 亳 VARIABLE
PROCEDURE foo(val: INTEGER) -- val - CONSTANT
PROCEDURE foo(val: IN INTEGER) -- val - CONSTANT
PROCEDURE foo(val, bar: OUT INTEGER) -- val, bar - VARIABLE
PROCEDURE foo(val: INOUT INTEGER) -- val VARIABLE
10. 仂亠亟 于 VHDL
CONSTANT
VARIABLE
ARCHITECTURE rtl OF example IS
PROCEDURE inc(a: INOUT INTEGER; step: INTEGER := 1) IS
BEGIN
a := a + step;
END PROCEDURE inc;
BEGIN
name : PROCESS IS
VARIABLE v: INTEGER := 0;
BEGIN
REPORT "v = " & INTEGER'IMAGE(v) SEVERITY NOTE;
inc(v); -- a := a + 1 v = 1
WAIT FOR 10 ns;
inc(a => v, step => 2); -- a := a + 2 v = 3
WAIT FOR 10 ns;
inc(v, step => 2 + 3); -- a := a + 2 + 3 v = 8
END PROCESS name;
END ARCHITECTURE rtl;
11. 仂亠亟 于 VHDL
PROCEDURE convert(SIGNAL sel: IN BIT_VECTOR (0 TO 1);
SIGNAL val : OUT BIT) IS
BEGIN
CASE sel IS
WHEN "00" | "11" => val <= '1';
WHEN OTHERS => val <= '0';
END CASE;
END PROCEDURE convert;
...
convert(sel => addr, val => data);
-- convert(addr, data);
...
-- 亠舒仍亳亰舒亳 XNOR
12. 仂亠亟 于 VHDL
ARCHITECTURE rtl OF adder IS
PROCEDURE addu(a, b: IN STD_LOGIC_VECTOR(N - 1 DOWNTO 0);
signal res: OUT STD_LOGIC_VECTOR(N - 1 DOWNTO 0)) IS
VARIABLE sum: STD_LOGIC_VECTOR(N - 1 DOWNTO 0);
VARIABLE carry: STD_LOGIC := '0';
BEGIN
FOR index IN sum'reverse_range LOOP
sum(index) := a(index) XOR b(index) XOR carry;
carry := (a(index) AND b(index)) OR
(carry AND (a(index) XOR b(index)));
END LOOP;
result <= sum;
END PROCEDURE addu;
BEGIN
addu(a => data_a,
b => data_b,
res => res);
END ARCHITECTURE rtl;
N = 1
N = 2
13. 仂亠亟 于 VHDL
ARCHITECTURE rtl OF adder IS
PROCEDURE addu(a, b: IN STD_LOGIC_VECTOR(N - 1 DOWNTO 0);
signal res: OUT STD_LOGIC_VECTOR(N - 1 DOWNTO 0)) IS
... -- 仄仂亳 仗亠亟亟亳亶 仍舒亶亟
BEGIN
... -- 仄仂亳 仗亠亟亟亳亶 仍舒亶亟
END PROCEDURE addu;
BEGIN
reg : PROCESS (clk) IS
BEGIN
IF rising_edge(clk) THEN
addu(data_a,
data_b,
res);
END IF;
END PROCESS reg;
END ARCHITECTURE rtl;
N = 1
N = 2
14. 仂亠亟 于 VHDL
SIGNAL en: STD_LOGIC;
...
convert(sel => addr, val => en);
reg : PROCESS (clk, en) IS
begin
IF rising_edge(clk) THEN
if en = '1' THEN
addu(a => data_a, b => data_b, res => res);
END IF;
END IF;
END PROCESS reg;
15. 仂亠亟 于 VHDL
亠仍亠 仗仂亠亟 仄仂亢亠 亳仗仂仍亰仂于舒 仂仗亠舒仂
RETURN, 仆舒亰仆舒亠仆亳亠 从仂仂仂亞仂 亰舒于亠亠仆亳亠 于仗仂仍仆亠仆亳
仗仂亠亟:
[label:] RETURN;
PROCEDURE sort2(VARIABLE x1,x2: INOUT INTEGER) IS
VARIABLE t: INTEGER;
BEGIN
IF x1 > x2 THEN
RETURN;
ELSE
t := x1;
x1 := x2;
x2 := t;
END IF;
END PROCEDURE;
舒从 仂 亟亠仍舒 弍亠亰
亟仂仗仂仍仆亳亠仍仆仂亶
仗亠亠仄亠仆仆仂亶 "t"?