A. 标准数据类型
1) 整数类型(INTEGER)
VARIBLE A: INTEGER RANGE -128 TO 128
范围 -(231-1) ~ +(231-1)
2#11111111# --binary, =255D
8#377#
16#FF#
2) 实数类型和浮点类型(REAL & FLOATING)
实数范围 -1.0E+38 ~ +1.0E+38
大多数EDA工具不支持浮点类型
16#<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />0F#E+0
16#FF.FF#E-1
3) 位类型(BIT)
TYPE BIT IS (‘0’, ‘1’)
4) 位矢量类型(BIT_VECTOR)
B”1111-1100” --长度为8
X”FBC” --长度为12, =B”1111-1011-1100”
O”371” --长度为9, =B”011-111-001”
5) 布尔类型(BOOLEAN)
6) 字符类型(CHARACTER)
‘A’, ‘a’, ‘B’, 大小写不敏感。
7) 字符串类型(TRING)
“VHDL”, “MULTI_SCREEN”
8) 物理类型(physical)
--时间类型
--The physics unit time is a predefined type
TYPE time IS RANGE -1E18 TO 1E18
UNITS
fs; -- Femto-second
ps = 1000 fs;
ns = 1000 ps;
us = 1000 ns;
ms = 1000 us;
sec = 1000ms;
min = 60 sec;
END UNITS
--another
--DISTANCE TYPE
TYPE distance IS RANGE 0 TO 1E16
UNITS
A;
nm = 10A;
um = 1000nm;
mm = 1000um;
cm = 10mm;
m = 1000 mm;
km = 1000m;
END UNITS;
9) 错误类型(NOTE,WARNING,ERROR,FAILURE)
10) 自然数、正整数类型(NATURAL & POSITIVE)
ENTITY_compare IS
PORT (a, b: INTEGER RANGE 0 to 9:=0;
c: out Boolean);
END compare;
B. 自定义数据类型
1) 枚举类型(ENUMERATED)
TYPE PCI_BUSstate IS
(Idle, busbusy, write, read, Back off); --PCI总线状态机变量
TYPE std_ulogic IS
(’U’, ‘X’, ‘1’, ‘0’, ‘Z’, ‘W’, ‘L’, ‘H’, ‘-‘);
TYPE boolean IS (false, true);
TYPE BIT IS (‘0’, ‘1’);
2) 整数类型(INTEGER)
TYPE digit IS INTEGER RANGE -128 TO 128
3) 实数类型和浮点类型(REAL & FLOATING)
4) 数组类型(ARRAY)
TYPE MYARRAY IS ARRAY (INTEGER 0 TO 9) OF STD_LOGIC
5) 存取类型(ACCESS)
TYPE line IS ACCESS string; --Line是指向字符串的指针
6) 文件类型(FILES)
TYPE text IS FILE OF string;
TYPE input-type IS FILE OF character;
7) 记录类型(RECODE)
--RECORD适于描写总线,通讯协议
TYPE PCI_BUS IS RECORD
ADDR: STD_LOCIG_VECTOR(31 DOWNTO 0);
DATA: STD_LOGIC_VECTOR(31 DOWNTO 0);
END RECORD;
SEGINAL DECODE1, DECODE2: PCI_BUS;
PCI_DEVICE1 <= DECODE1.ADDR;
PCI_DEVICE1RAM <= DECODE1.DATA;
8) 时间类型(TIME)
类型转换<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
A. 类型标记法
Variable I: integer;
Variable R: real;
I: = integer(r);
R:= real(i);
其他还有 NUMERIC_BIT中SIGNED、UNSIGNED 同 BIT_VECTOR间的转换。
UNMERIC_STD 中 SIGNED、UNSIGNED 同 STD_LOGIC_VECTOR 间的转换。
B. 函数转换法
Std_logic_arith程序包中:
CONV_STD_LOGIC_VECTOR(A,位长); --interger, signed, unsigned -> std_logic_vector
CONV_INTERGER(A); --signed, unsigned -> std_logic_vector
CONV_INTERGER(A); --signed, unsigned -> integer
Std_logic_unsigned程序包中:
CONV-INTEGER(A); --STD_LOGIC_VECTOR -> INTEGER
C. 常数实现
CONTSTANT TYPECONV-CON: typeconv_type := (‘0’|’L’ => ‘0’, ‘1’|’H’=>’1’);
SIGNAL B: BIT;
SIGNAL S: STD_LOGIC;
BIGIN
B <= TYPECONV-CON(S);
END;
数据类型的限定
A<= std_logic_vector(“01101001”); --数据前加上类型名
SUBTYPE std3bit is STD_LOGIC_VECTOR (0 to 2);
文章评论(0条评论)
登录后参与讨论