| function | procedure | |
|---|---|---|
| 반환값 | 1개 | X |
| inout | in만 가능 | in/out 모두 가능 |
| 용도 | 단순계산 | 로직수행 |
function 사용방법
function 함수이름(매개변수 : in 타입) return 반환타입 is
begin
-- 계산 로직
return 결과;
end function;
예시
function add(a : in integer; b : in integer) return integer is
begin
return a + b;
end function;
사용예시
signal a, b : integer := 5;
signal c : integer;
c <= add(a, b); -- add 함수 호출, c는 10이 됨
procedure
procedure는 process와 비교해보자
process(clk)
begin
if rising_edge(clk) then
q <= d;
end if;
end process;
이게 process라면
procedure copy_signal(signal a : in std_logic; signal b : out std_logic) is
begin
b <= a;
end procedure;
process(clk)
begin
if rising_edge(clk) then
copy_signal(d, q);
end if;
end process;
이게 procedure이다!