简体   繁体   English

VHDL转换操作

[英]VHDL SHIFT OPERATIONS

I have 2 std_logic_vector inputs (Operand1 and Operand2) and i am trying to shift Operand1 by the values in Operand2 and store it in a std_logic_vector output (Output1) 我有2个std_logic_vector输入(Operand1和Operand2),我试图将Operand1移位Operand2中的值,并将其存储在std_logic_vector输出(Output1)中

Output1 <= std_logic_vector(unsigned(Operand1) srl to_integer(unsigned(Operand2)));

Output1 <= std_logic_vector(unsigned(Operand1) sll to_integer(unsigned(Operand2)));

Output1 <= std_logic_vector(unsigned(Operand1) sra to_integer(unsigned(Operand2)));

I am able to get the first 2 lines to work, however the line with the sra returns this error "sra can not have such operands in this context." 我能够使前两行正常工作,但是带有sra的行会返回此错误“ sra在这种情况下不能有这样的操作数”。 Can anybody tell me if there is anything i am doing wrong. 有人可以告诉我我做错了什么吗?

From the comments it sounds like some of your signals are of type std_logic_vector and some are of type bit_vector, and without posting the declarations you are giving us a merry guessing game which is which. 从注释中听起来,您的某些信号的类型为std_logic_vector,而某些信号的类型为bit_vector,并且在不发布声明的情况下,您正在给我们提供一个欢乐的猜谜游戏。

So what is wrong? 那怎么了?

  1. There isn't enough info in the question. 问题中没有足够的信息。 Post the relevant declarations. 发布相关声明。

  2. The design is clearly wrong. 设计显然是错误的。 A big part of the design is the data types used, and these look to be badly chosen. 设计的很大一部分是使用的数据类型,这些数据类型似乎选择不当。

We don't have enough info peering through this tiny window onto the design to be able to fix it; 我们没有足够的信息通过这个很小的窗口浏览到设计上,无法对其进行修复。 so this is a wild guess : 所以这是一个疯狂的猜测:

Make Operand 1 Unsigned and operand 2 Integer or better Natural (if negative values would be a mistake) and the implementation will be much smoother, cleaner, simpler, easier to understand. 将操作数1设置为Unsigned ,将操作数2设置为Integer或更好的Natural (如果负值将是一个错误),则实现将更加流畅,简洁,简单并且易于理解。 And catch many more bugs earlier. 并尽早捕获更多错误。 These types are synthesisable and can be used as ports or signals or components in records (structs) if you desire. 这些类型是可综合的,并且可以根据需要用作端口或信号或记录(结构)中的组件。

And realise that SRA is not part of the VHDL language. 并认识到SRA不是VHDL语言的一部分。 It's a function, declared in some library. 它是在某些库中声明的函数。

So if you decide Operand1 is unsigned and Operand2 is natural (a subtype of integer) you can look at the numeric_std package and see if there is a declaration of SRA accepting those parameter types and returning the type you want. 因此,如果您确定Operand1是unsigned而Operand2是natural (整数的子类型),则可以查看numeric_std包,看看是否有SRA声明接受这些参数类型并返回所需的类型。

And if there isn't, there is nothing stopping you writing your own (which could be as simple as a wrapper calling the SRA you found, and converting the parameter types as you need). 如果没有,则没有什么可以阻止您编写自己的代码(这可能很简单,就像包装程序调用找到的SRA并根据需要转换参数类型一样)。 It will be just as much part of the VHDL language as the original one. 它将与原始VHDL语言一样多。

A package of useful functions and helpers that you have written will prove useful on future VHDL projects. 您编写的有用功能和助手包将对将来的VHDL项目证明很有用。

Try changing the last line to: 尝试将最后一行更改为:

Output1 <= std_logic_vector(unsigned(Operand1) sra to_integer(signed(Operand2)));

ie use signed instead of unsigned 即使用signed而不是unsigned

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM