📄 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 + -