介绍
从矢量移位器的名字就可以看出来,这是实现移位功能的。输出矢量是输入矢量移位后的结果,输出矢量的位宽是输入矢量的两倍,移位操作的次数是通过一个选择信号来实现的。
示例
在这里我举个例子吧。这里我设置输入信号是0110。通过改变sel信号,就可以实现不同的移位操作了。
设计文件
library ieee;
use ieee.std_logic_1164.all;
entity shifter is
port(input : in std_logic_vector(3 downto 0);
sel : in integer range 0 to 4;
output : out std_logic_vector(7 downto 0));
end shifter;
architecture shifter of shifter is
subtype vector is std_logic_vector(7 downto 0);
type matrix is array (4 downto 0) of vector;
signal row : matrix;
begin
row(0) <= "0000"&input;
G1 : for i in 1 to 4 generate
row(i) <= row(i-1)(6 downto 0) & '0';
end generate;
output <= row(sel);
end shifter;
仿真文件
library ieee;
use ieee.std_logic_1164.all;
entity tb_shifter is
end tb_shifter;
architecture shifter of tb_shifter is
component shifter
port(input : in std_logic_vector(3 downto 0);
sel : in integer range 0 to 4;
output : out std_logic_vector(7 downto 0));
end component shifter;
signal input : std_logic_vector(3 downto 0) := "0011";
signal sel : integer range 0 to 4 := 1;
signal output : std_logic_vector(7 downto 0);
begin
dut : shifter
port map(
input => input,
sel => sel,
output => output);
process
begin
input <= "0110";
sel <= 0;
wait for 20ns;
sel <= 1;
wait for 20ns;
sel <= 2;
wait for 20ns;
sel <= 3;
wait for 20ns;
sel <= 4;
wait for 20ns;
end process;
end architecture shifter;
仿真结果
结语
到这里就结束了。是不是很简单啊,当然了这个例子需要理解数组的概念,这个例子使用了1D, 2D数组,这需要我们人为的定义。
如果有什么问题欢迎大家留言奥。