这听起来很简单,但我无法克服
din : in std_logic_vector(13 downto 0);
sin : in std_logic_vector(3 downto 0);
.
.
.
if ( din(idx downto idx-3) XNOR sin(3 downto 0) ) then我得到了
** Error: Z:/lab_dig_2/1/prep/additionalQ/additionalQ.vhd(30):类型错误将infix表达式"xnor“解析为std.STANDARD.BOOLEAN类型。
错误
向量有特殊的运算符吗?我记得std_logic_vector是这类运算符的完美类型吗?
发布于 2013-12-04 11:06:26
表达式中的xnor对两个std_logic_vector类型进行操作,从而返回另一个std_logic_vector类型,但是if表达式需要一个boolean类型。
如果您希望在xnor结果不是全部为零的情况下为真,则可能希望将表达式更改为下面的表达式:
if (din(idx downto idx-3) XNOR sin(3 downto 0)) /= "0000" then编辑:有关VHDL-2008中隐式类型转换的更多信息
VHDL是一种强类型语言,设计器通常必须执行显式类型转换,以便结果匹配所需的类型,否则会生成错误。
然而,VHDL-2008增加了一些隐式浇铸,特别是条件运算符??,它可以转换为boolean类型。操作符在std_logic_1164系统包中声明为:
function "??" (l : std_ulogic) return boolean;条件操作将自动应用于if、elsif、until、assert和类似位置,如果表达式没有计算为boolean类型。因此,如果您使用的是VHDL-2008,那么可以编写:
signal test_sl : std_logic;
...
if test_sl then
...其中条件运算符??被隐式应用,就像写的那样:
if ?? test_sl thenA相当于以下内容,在VHDL-2002中也有效:
if (test_sl = '1') or (test_sl = 'H') then??运算符仅在std_ulogic类型的标准VHDL-2008中声明,因此也适用于std_logic类型。但是,可以在用户声明的函数中重载运算符以申请std_logic_vector,方法如下:
-- Or operation of ?? for all elements in arg
function "??" (arg : std_ulogic_vector) return boolean is
variable res_v : boolean;
begin
res_v := FALSE;
for idx in arg'range loop
res_v := res_v or (?? arg(idx));
end loop;
return res_v;
end function;如果声明了上述内容,则可以在std_logic_vector语句中将if隐式转换为布尔值,例如:
signal test_slv : std_logic_vector(3 downto 0);
...
if test_slv then
....甚至:
if din(idx downto idx-3) XNOR sin(3 downto 0) then不过,还是要注意一点,因为如果使用这样的技巧,代码对其他人的可读性可能会降低,从而更容易出错;但这是有可能的。
https://stackoverflow.com/questions/20372980
复制相似问题