?? comp.vhd
字號:
--4.14 函數(Function)
--下面用一個具體的例子來說明函數的編寫和調用方法,
--請讀者注意其所在VHDL程序中的位置,并與前面介紹的
--語法規范對照閱讀,則更容易記憶。
library ieee;
use ieee.std_logic_1164.all;
entity comp is
port(
A : in std_logic_vector(7 downto 0);
B : in std_logic_vector(7 downto 0);
C : out std_logic_vector(7 downto 0)
);
end comp;
architecture behave of comp is
function maxval(in1,in2:std_logic_vector)--函數開始
return std_logic_vector is --函數返回值的類型為std_logic_vector
variable temp:std_logic_vector(in1'length-1 downto 0);
begin
if in1>in2 then
temp:=in1;
else
temp:=in2;
end if
return temp; --函數返回值
end maxval; --函數結束
begin
C<=maxval(A,B);
end behave;
--再看一個VHDL中類型轉換函數的例子:
function bv2I(bv:bit_vector)
return integer is
variable result, abit : integer := 0;
begin
for I in bv'low to bv'high loop
abit := 0;
if(bv(I) = '1') then
abit := 2 ** (I - bv'low);
end if;
result := result + abit;
end loop;
return (result);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -