This is my first work with VHDL so it's surely something basic but just don't know what to do.
这是我第一次用VHDL工作,所以它肯定是基本的东西,但只是不知道该怎么做。
I have this code:
我有这个代码:
--this is in the architecture segment
type my_code is array(0 to 15) of integer;
signal code: my_code;
....
--here I use the array
code(count) <=0; --I save a value into the array on position defined by the count variable
if (code(0) = '0') then --fail line (want to do something if the first element is 0)
--do something
end if;
The compiler stops me because "can not have such operands in this context". The problem is on line with the if statement. What is wrong with that?
编译器阻止了我,因为“在这种情况下不能有这样的操作数”。问题与if语句一致。这有什么问题?
I am basically working on a digital lock like you write a code and it will open or remain closed if the code is wrong so I just want to check the array of pressed keys if the code in there is right.
我基本上是在编写一个数字锁,就像你编写代码一样,如果代码错误,它会打开或保持关闭状态,所以我只想检查按键的数组,如果那里的代码是正确的。
Sorry for bothering but I just don't get it. Thanks and have a nice day ^^
很抱歉打扰但我只是不明白。谢谢,祝你有愉快的一天^^
2 个解决方案
#1
1
You have an array of integers, so code(0)
must be an integer. You cannot compare an integer to character literal '0'
.
你有一个整数数组,所以代码(0)必须是一个整数。您无法将整数与字符文字“0”进行比较。
Either check for code(0) = 0
or redefine your array as type my_code is array(0 to 15) of bit;
You can use bit
or std_logic
, or any other type that has '0'
as valid element.
检查代码(0)= 0或重新定义数组my_code是数组(0到15)的位;您可以使用bit或std_logic,或任何其他具有'0'作为有效元素的类型。
#2
0
code is an array of integers. You are trying to compare it to a character literal '0', which has no interpretation as an enumeration literal in the context of integers. Try 0 instead.
code是一个整数数组。您正在尝试将其与字符文字“0”进行比较,该字符文字在整数上下文中没有作为枚举文字的解释。请尝试0。
Also the parentheses surrounding the expression (code(0) = '0')
are redundant.
表达式周围的括号(code(0)='0')也是多余的。
There is no operator defined to compare an integer to a type represented by a character literal in the code context (which you haven't display in your example, not having any context clauses visible nor other declarations).
没有运算符被定义为将整数与代码上下文中的字符文字所表示的类型进行比较(您未在示例中显示,没有任何上下文子句可见,也没有其他声明)。
The "=" equality operator to use is selected by comparing the input operands and result type. There is no operator visible by selection providing a left argument of integer and a right argument of some (not known from your code fragment) type represented by the character literal '0' as an enumeration literal.
通过比较输入操作数和结果类型来选择要使用的“=”相等运算符。通过选择提供左侧参数的整数和一些右侧参数(在您的代码片段中未知)类型由字符文字“0”表示为枚举文字,没有运算符可见。
Operators that can be selected among several possibilities based on operand type are said to be overloaded.
可以根据操作数类型在多种可能性中选择的运算符被称为过载。
After a bit of Googling and finding the answer to the general question raised by this Xilinx error message to always dwell on the immediate case I found a few places you can look to understand the issue.
经过一些谷歌搜索并找到这个Xilinx错误消息提出的一般性问题的答案,总是纠缠于眼前的情况后,我找到了一些地方,你可以看一下了解这个问题。
Reference texts:
参考文本:
There are two sub sections in IEEE Standard VHDL Language Reference Manual (the LRM, e.g. IEEE Std 1076-2008, -1993), entitled Subprogram overloading (operators on non predefined typed are functions) in the section Subprograms and packages, and The context of overload resolution in the section Scope and visibility.
IEEE标准VHDL语言参考手册(LRM,例如IEEE Std 1076-2008,-1993)中有两个子章节,题为子程序重载(非预定义类型的运算符是函数),在子程序和包中,以及范围和可见性部分中的重载决策。
VHDL: HARDWARE DESCRIPTION AND DESIGN, Lipsett, Schaefer and Ussery, 1989, Kluwer Academic Publishers.
VHDL:硬件描述和设计,Lipsett,Schaefer和Ussery,1989,Kluwer Academic Publishers。
Also Peter Ashenden and Jim Lewis's 3rd Edition of The Designer's Guide to VHDL, Morgan Kaufman, 2008.
Peter Ashenden和Jim Lewis的VHDL设计师指南第3版,Morgan Kaufman,2008年。
The solution can be either expanding or adding a context clause for missing references to overloaded operators or fixing (as in your case) a syntax error. Which of the two can be case specific.
解决方案可以是扩展或添加上下文子句,用于缺少对重载运算符的引用,也可以修复(如您的情况)语法错误。两者中的哪一个可以是特定于案例的。
#1
1
You have an array of integers, so code(0)
must be an integer. You cannot compare an integer to character literal '0'
.
你有一个整数数组,所以代码(0)必须是一个整数。您无法将整数与字符文字“0”进行比较。
Either check for code(0) = 0
or redefine your array as type my_code is array(0 to 15) of bit;
You can use bit
or std_logic
, or any other type that has '0'
as valid element.
检查代码(0)= 0或重新定义数组my_code是数组(0到15)的位;您可以使用bit或std_logic,或任何其他具有'0'作为有效元素的类型。
#2
0
code is an array of integers. You are trying to compare it to a character literal '0', which has no interpretation as an enumeration literal in the context of integers. Try 0 instead.
code是一个整数数组。您正在尝试将其与字符文字“0”进行比较,该字符文字在整数上下文中没有作为枚举文字的解释。请尝试0。
Also the parentheses surrounding the expression (code(0) = '0')
are redundant.
表达式周围的括号(code(0)='0')也是多余的。
There is no operator defined to compare an integer to a type represented by a character literal in the code context (which you haven't display in your example, not having any context clauses visible nor other declarations).
没有运算符被定义为将整数与代码上下文中的字符文字所表示的类型进行比较(您未在示例中显示,没有任何上下文子句可见,也没有其他声明)。
The "=" equality operator to use is selected by comparing the input operands and result type. There is no operator visible by selection providing a left argument of integer and a right argument of some (not known from your code fragment) type represented by the character literal '0' as an enumeration literal.
通过比较输入操作数和结果类型来选择要使用的“=”相等运算符。通过选择提供左侧参数的整数和一些右侧参数(在您的代码片段中未知)类型由字符文字“0”表示为枚举文字,没有运算符可见。
Operators that can be selected among several possibilities based on operand type are said to be overloaded.
可以根据操作数类型在多种可能性中选择的运算符被称为过载。
After a bit of Googling and finding the answer to the general question raised by this Xilinx error message to always dwell on the immediate case I found a few places you can look to understand the issue.
经过一些谷歌搜索并找到这个Xilinx错误消息提出的一般性问题的答案,总是纠缠于眼前的情况后,我找到了一些地方,你可以看一下了解这个问题。
Reference texts:
参考文本:
There are two sub sections in IEEE Standard VHDL Language Reference Manual (the LRM, e.g. IEEE Std 1076-2008, -1993), entitled Subprogram overloading (operators on non predefined typed are functions) in the section Subprograms and packages, and The context of overload resolution in the section Scope and visibility.
IEEE标准VHDL语言参考手册(LRM,例如IEEE Std 1076-2008,-1993)中有两个子章节,题为子程序重载(非预定义类型的运算符是函数),在子程序和包中,以及范围和可见性部分中的重载决策。
VHDL: HARDWARE DESCRIPTION AND DESIGN, Lipsett, Schaefer and Ussery, 1989, Kluwer Academic Publishers.
VHDL:硬件描述和设计,Lipsett,Schaefer和Ussery,1989,Kluwer Academic Publishers。
Also Peter Ashenden and Jim Lewis's 3rd Edition of The Designer's Guide to VHDL, Morgan Kaufman, 2008.
Peter Ashenden和Jim Lewis的VHDL设计师指南第3版,Morgan Kaufman,2008年。
The solution can be either expanding or adding a context clause for missing references to overloaded operators or fixing (as in your case) a syntax error. Which of the two can be case specific.
解决方案可以是扩展或添加上下文子句,用于缺少对重载运算符的引用,也可以修复(如您的情况)语法错误。两者中的哪一个可以是特定于案例的。