如何使用串联将std_logic_vector转换为std_logic_vector [英] How to shift a std_logic_vector by std_logic_vector using concatenation
问题描述
说我有2个std_logic_vectors:
Say I have 2 std_logic_vectors:
inputA : std_logic_vector(31 downto 0)
inputB: std_logic_vector(31 downto 0)
如何转换 inputA
通过 inputB
使用串联?
How do I shift inputA
by inputB
using concatenation?
我知道如何向左或向右移动1个位置,但无法弄清楚如何将N个位置向右(或向左)移动。
注意:这是无时钟电路,不能使用标准的vhdl移位运算符。
I know how to shift left or right by 1 place but can't figure out how to shift N places to the right (or left). Note: this is a clockless circuit, and can't use standard vhdl shift operators.
除串联以外的其他技术或构想也将受到赞赏。
Other techniques or ideas other than concatenation would be appreciated as well.
推荐答案
我更喜欢wjl的方法,但是鉴于您专门要求使用串联的方法,请尝试以下方法:
I prefer wjl's approach, but given you asked specifically for a method using concatenation, try this:
function variable_shift(i : std_logic_vector, num_bits : integer)
return std_logic_vector is
constant zeros : std_logic_vector(num_bits-1 downto 0) := (others => '0');
begin
return i(i'high-num_bits downto i'low) & zeros;
end function;
(可以写成第二个 std_logic_vector
表示 num_bits
参数,但由于它基本上是数字,因此我总是使用基于数字的类型)
(It could be written to take a second std_logic_vector
for the num_bits
parameter, but as it's fundamentally a number, I'd always use a number-based type for it)
这篇关于如何使用串联将std_logic_vector转换为std_logic_vector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!