我有一个向量signal tmp : std_logic_vector(15 downto 0)
我必须将它向左或向右移动 n 位。我怎样才能实现这个操作。我想到了串联操作,但我不知道如何使用它。
Use the ieee.numeric_std
库,以及您正在处理的数字的适当向量类型(unsigned
or signed
).
Then the operators are `sla`/`sra` for arithmetic shifts (ie fill with sign bit on right shifts and lsb on left shifts) and `sll`/`srl` for logical shifts (ie fill with '0's).
您将参数传递给运算符来定义要移位的位数:
A <= B srl 2; -- logical shift right 2 bits
---
Update:
---
I have no idea what I was writing above (thanks to Val for pointing that out!)
当然正确的换档方法signed
and unsigned
类型是与shift_left
and shift_right
函数定义在ieee.numeric_std
.
移位和旋转运算符sll
, ror
etc ,并且可以有有趣的意外行为 https://en.wikipedia.org/wiki/Arithmetic_shift#cite_note-9因为即使左移,算术移位也会复制结束位。
更多历史可以在这里找到:
http://jdebp.eu./FGA/bit-shifts-in-vhdl.html
然而,原来问题的答案仍然是
sig <= tmp sll number_of_bits;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)