VHDL实体和构造体
实体
实体(entity)用来描述电路的所有输入/输出引脚,其语法结构如下:
entity entity_name is
port(
port_name:signal_mode signal_type;
port_name:signal_mode signal_type;
.......
);
end entity_name;
端口的信号模式(signal_mode)是以下4种之一:in,out,inout,buffer。
in和out是单向引脚,而inout是双向引脚。buffer模式的引脚首先是一个输出引脚,但该输出信号可以供本电路内部使用。
out类型的端口是不能供电路内部使用的。信号的类型包括bit,std_logic和integer等。
例:
entity or2a is
port(
a,b:in bit;
x:out bit
);
end or2a;
从上面entity可知:电路有3个外部引脚,两个输入(a和b)和一个输出(x),数据类型bit。名称:or2a。
构造体
构造体(architecture)中的代码用来描述电路行为和实验功能,其语法结构如下:
architecture architeture_name of entity_name is
[declarations]
begin
(code)
end architecture_name;
从语法结构中可以看到,一个architecture包含两个部分:声明部分(可选),用于对信号和常量等进行声明:
代码部分(begin和end之间的部分),用来描述电路的行为(功能)。与entity一样,可以采用除VHDL关键字以外的任何
名称为architecture命名,并且允许和entity具有相同的名称。
例:与非门
architecture bhv of or2a is
begin
x<=a nand b;
end bhv;
从上面architecture中很容易看出:architecture的名称是bhv,它所描述的电路功能是对输入的a与b进行"与非"逻辑运算,运算
结果赋予输出信号x。需要注意的是,在本例中没有出现architecture的声明部分,代码部分也只包含了一条语句。