对象分类
- 信号:通过信号赋值语句改变值;
signal 信号名:数值类型 := 初始值;
- 常量:初始化后不能改变;
- 变量:通过变量赋值语句改变值;
- 文件:内部存储一组某种数据的对象;
对象类型
- 标量类型:单一不可再分,数值/枚举型
- 混合类型:数组型/记录型(数组内元素同一类型、记录内元素不同类型)
- 访问类型:对象的访问方式(类似指针)
- 文件类型:文件值为代表该文件的文件序号;
- 被保护类型:多进程访问同一变量时,提供原子访问与排他访问。
IEEE库数据类型转换函数
程序包 | 函数名 | 功能 |
---|---|---|
std_logic_1164 | to_stdlogicvector(A) | bit_vector转换为std_logic_vector |
std_logic_1164 | to_bitvector(A) | std_logic_vector转换为bit_vector |
std_logic_1164 | to_stdlogic(A) | 由bit转换为std_logic |
std_logic_1164 | to_bit(A) | std_logic类型转换为bit类型 |
std_logic_arith | conv_std_logic_vector(A,位长) | integer转换为std_logic_vector,A为整数 |
std_logic_arith | conv_integer | std_logic_vector转换为integer |
std_logic_arith | conv_unsigned(A,位长) | unsigned、signed、integer转换为指定位长的unsigned |
std_logic_arith | conv_signed(A,位长) | unsigned、signed、integer转换为指定位长的signed |
std_logic_unsigned | conv_integer(A) | std_logic_vector转换为integer |
例
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity conv is
port(
a1,a2 : in bit_vector(3 downto 0);
c1,c2,c3 : in std_logic_vector(3 downto 0);
b1,b2,b3 : integer range 0 to 15;
d1,d2,d3,d4 : out std_logic_vector(3 downto 0)
);
end entity conv;
architecture beve of conv is
begin
d1 <= to_stdlogicvector(a1 and a2);
d2 <= conv_std_logic_vector(b1,4) when conv_integer(b2)=9
else conv_std_logic_vector(b3,4);
d3 <= c1 when conv_integer(c2) = 8 else c3;
d4 <= c1 when c2 = 8 else c3;
end architecture beve;
转换函数conv_integer();
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity conv is
port(
input: in std_logic_vector(2 downto 0);
output: out std_logic_vector(7 downto 0)
);
end entity conv;
architecture beve of conv is
begin
process(input) begin
output <= (others => '0');
output(conv_integer(input))<='1';
end process;
end architecture beve;