关于VHDL移位运算 下载本文

内容发布更新时间 : 2024/6/26 13:07:56星期一 下面是文章的全部内容请认真阅读。

http://hi.http://www.35331.cn//??·2μ???3?/blog/item/55404419c2b74fc4ad6e75d1.html

VHDL的类型限定过于强,以至于很多时候出问题都是类型错误……

VHDL语言本身的这几个运算符是对bitvector定义的,而我们一般都用std_logic_vector, 这样就很导致一般不能编译通过。

而更不爽的是ieee.numeric_bit或者numeric_std包中都有重载sll之类,但是很讨厌的是 他们都是对signed/unsigned定义,没办法,

要是想给std_logic_vector用这几个移位运算符(sll, srl, sla, sra, rol, ror) 只得这样:

o <= to_stdlogicvector(to_bitvector(i) sll 1);

呵呵,不想这么麻烦的话,用Verilog吧,尤其是SystemVerilog,用起来舒服多了~

修改:附另一种形式的完成测试程序: library ieee;

use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity test is port (

i: in std_logic_vector (10 downto 0); o: out std_logic_vector (10 downto 0) );

end entity test;

architecture a of test is begin

o <= std_logic_vector(unsigned(i) sll 1); end architecture a;

这个方法的好处是不会丢失X,因为unsigned和signed其实都是std_logic_vector。

这l两天在调试 数码管动态扫描时,要运用到移位运算,郁闷了两天,原来是数据类型错了,杯具!!以后细节要注意了!!呵呵 继续加油!

网上关于移位运算的好方法,

1.将要移位的变量转换为bit_vector类型 2.实现移位,并暂存

3.将所有移位暂存后的变量全部转换为integer类型 4.进行最后的interger类型的相加减。