第六章VD中属性的描语句 属性:指设计实体、结构体、数据类型、信号等对象的特定特征。 VHDL的预定义属性分类: 数值类属性; 函数类属性 信号类属性 ●数据类型类属性; ●数据区间类属性 表示一个对象属性的书写格式: 对象”属性名 61数值类属性 用于返回有关常用数据类型、数组类型或块的特定值;还可用于返回数组的 长度或者数据类型的上下界等。 数值类属性分为三个子类: 数据类型的数值属性; 数组的数值属性; 曾块的数值属性
第六章 VHDL中属性的描述及定义语句 属性:指设计实体、结构体、数据类型、信号等对象的特定特征。 VHDL的预定义属性分类: ⚫数值类属性; ⚫函数类属性; ⚫信号类属性; ⚫数据类型类属性; ⚫数据区间类属性。 表示一个对象属性的书写格式: 对象’属性名 6.1 数值类属性 用于返回有关常用数据类型、数组类型或块的特定值;还可用于返回数组的 长度或者数据类型的上下界等。 数值类属性分为三个子类: 数据类型的数值属性; 数组的数值属性; 块的数值属性
611数值类型的数值属性 ●用来返回一个数据类型或子类型的边界值,此边界值通常是指上下限和左右限 ●数据类型的数值属性 (1)’lef返回一个数据类型或子类型最左端的值,即类型的左边界; (2)righ返回一个数据类型或子类型最右端的值,即类型的右边界 (3)’high:返回一个数据类型或子类型的高端值,即类型的上限值; (4)’low:返回一个数据类型或子类型的低端值,即类型的下限值; 如:定义一个数据类型 type numberis integer range 0 to 7; num ber left=o number’ right=7 number high=7 number low=0 如: type wordis array(15 downto O)of std_logic; word left= 15 word right=0 word high=15 wor Ow 0
6.1.1 数值类型的数值属性 ⚫用来返回一个数据类型或子类型的边界值,此边界值通常是指上下限和左右限 ⚫数据类型的数值属性: (1)’left: 返回一个数据类型或子类型最左端的值,即类型的左边界; (2)’right: 返回一个数据类型或子类型最右端的值,即类型的右边界; (3)’high: 返回一个数据类型或子类型的高端值,即类型的上限值; (4)’low: 返回一个数据类型或子类型的低端值,即类型的下限值; 如:定义一个数据类型 type number is integer range 0 to 7; number’left = 0 number’right = 7 number’high = 7 number’low = 0 如: type word is array (15 downto 0) of std_logic; word’left = 15 word’right = 0 word’high = 15 word’low = 0
●数据类型的数值属性并不限定数值的数据类型,适用于任何一种标量类型 例:枚举类型定义: type weekis(sunday, monday, tuesday, wednsday, thursay, friday, saturday); subtype sub_weekl is week range wednsday to friday subtype sub_week 2 is week range friday downto wednsday; 可得如下关系式: week left sunday weeknight=saturday week high =saturday weck’low= sunday sub_week1" leftwednsday Lb week 1’ight= friday sub_week1 high=friday sub_week1" low=wednsday sub week2 left=fric sub_week2 right=wednsday sub_week2 high=friday sub week2 low=wednsday
⚫数据类型的数值属性并不限定数值的数据类型,适用于任何一种标量类型 例:枚举类型定义: type week is (sunday, monday, tuesday, wednsday, thursay, friday, saturday); subtype sub_week1 is week range wednsday to friday; subtype sub_week2 is week range friday downto wednsday; 可得如下关系式: week’left = sunday week’right=saturday week’high= saturday week’low = sunday sub_week1’left=wednsday sub_week1’right=friday sub_week1’high=friday sub_week1’low=wednsday sub_week2’left=friday sub_week2’right=wednsday sub_week2’high=friday sub_week2’low=wednsday
612数组的数值属性 作用:返回数组类型的长度值 VHDL中预定义的数组的数值属性: length:返回一个限定性数组的长度值,即数组中元素的个数; 如:定义如下几个数组类型: type wordis array (15 downto o) of std_ logic, type dwordis array (31 downto O)of std _logic type matrixis array(0 to 7, 0 to 5)of std logic 可返回如下数值属性 word length=16 dword length=32 matrix length 1)=8 matrix length (2=6 matrix length=8
6.1.2 数组的数值属性 作用:返回数组类型的长度值 VHDL中预定义的数组的数值属性: ‘length:返回一个限定性数组的长度值,即数组中元素的个数; 如:定义如下几个数组类型: type word is array (15 downto 0) of std_logic; type dword is array (31 downto 0) of std_logic; type matrix is array ( 0 to 7, 0 to 5) of std_logic; 可返回如下数值属性: word’length = 16 dword’length =32 matrix’length(1) = 8 matrix’length(2) = 6 matrix’length = 8
例: library ieee; useieee.std_logic_1164.all; entity compare 1s port(input; in std_logic_vector(7 downto O); Input2: integer; g: out std _ logic) end compare, architecture rt1 of compare is function vector_to_int(a: in std_logic_vector)return integers variableresult, tmp: integer: =0; egin foriin a low to a' length-1loop tmp: =0; if (a(i)=1 )then tmp:=2*-a’low); eIs assert(a(i)=0) report no conversion severity warnings end if result=result+tmp; end loop return(result); end vector to int
library ieee; use ieee.std_logic_1164.all; entity compare is port(input1:in std_logic_vector(7 downto 0); input2: in integer; q: out std_logic); end compare; architecture rt1 of compare is function vector_to_int (a: in std_logic_vector) return integer is variable result, tmp: integer:=0; begin for i in a’low to a’length-1 loop tmp:=0; if (a(i)=‘1’) then tmp:=2 ** (i-a’low); else assert( a(i)=‘0’) report “no conversion” severity warning; end if; result:=result+tmp; end loop return (result); end vector_to_int; 例: