移位寄存器的VHDL描述

发布时间:2024-05-07
8位移位寄存器 library ieee;
use ieee.std_logic_1164.all;
entity shifter is
port (
data_in: in std_logic_vector(7 downto 0);--输入的数据
n: in std_logic_vector(2 downto 0);--移位的数量
dir: in std_logic--移动的方向 0:左 1:右
kind: in std_logic_vector(1 downto 0);--移动类型 00:算术移 01:逻辑移 10:循环移
clock: in bit;--手动时钟pulse
data_out: out std_logic_vector(7 downto 0)--移位的结果
);
end shifter;architecture behav of shifter is
begin
process (data_in, n, dir, kind)
variable x,y : std_logic_vector(7 downto 0);
variable ctrl0,ctrl1,ctrl2 : std_logic_vector (3 downto 0);
begin
if (clock'event and clock = '1')then--产生控制向量ctrl
ctrl0 := n(0) & dir & kind(1) & kind(0);
ctrl1 := n(1) & dir & kind(1) & kind(0);
ctrl2 := n(2) & dir & kind(1) & kind(0);
ctrl2 := n(2) & dir & kind(1) & kind(0);
case ctrl0 is
when 0000 | 0001 | 0010 | 0100 | 0101 | 0110 => x := data_in; --n=0时不移动
when 1000 => x := data_in(6 downto 0) & data_in(0);--算术左移1位
when 1001 => x := data_in(6 downto 0) & '0';--逻辑左移1位
when 1010 => x := data_in(6 downto 0) & data_in(7); --循环左移1位
when 1100 => x := data_in(7) & data_in(7 downto 1);-算术右移1位
when 1101 => x := '0' & data_in(7 downto 1);--逻辑右移1位
when 1110 => x := data_in(0) & data_in(7 downto 1);--循环右移1位
when others => null;
end case;
case ctrl1 is
when 0000 | 0001 | 0010 | 0100 | 0101 | 0110 => y := x; --n=0时不移动
when 1000 => y := x(5 downto 0) & x(0) & x(0);--算术左移2位
when 1001 => y := x(5 downto 0) & 00;--逻辑左移2位
when 1010 => y := x(5 downto 0) & x(7 downto 6);--循环左移2位
when 1100 => y := x(7) & x(7) & x(7 downto 2);--算术右移2位
when 1101 => y := 00 & x(7 downto 2);--逻辑右移2位
when 1110 => y := x(1 downto 0) & x(7 downto 2);--循环右移2位
when others => null;
end case;case ctrl2 is
when 0000 | 0001 | 0010 | 0100 | 0101 | 0110 => data_out <= y; --n=0时不移动
when 1000 => data_out <= y(3 downto 0) & y(0) & y(0) & y(0) & y(0); --算术左移4位
when 1001 => data_out <= y(3 downto 0) & 0000; --逻辑左移4位
when 1010 | 1110 => data_out <= y(3 downto 0) & y(7 downto 4);--循环左(右)移4位
when 1100 => data_out <= y(7) & y(7) & y(7) & y(7) & y(7 downto 4);--算术右移4位
when 1101 => data_out <= 0000 & y(7 downto 4);--逻辑右移4位
when others => null;
end case;
end if;
end process;
end behav;
上一个:喷雾剂灌装旋盖生产线企业在不断改进产品
下一个:济南供应金属波纹管径向刚度试验机

感应起电机正转、反转状态下的工作原理
固态硬盘是不是内存条,这是内存条还是固态硬盘
从电脑拆下来的硬盘怎么格式化掉,电脑硬盘怎么取下来
西安电子元器件批发市场
双通道内存插槽怎么插(双通道内存怎么插最优)
我国干法制粒机行业“既要金山银山,也要绿水青山”
金士顿480g固态硬盘价格表,金士顿固态硬盘500g多少钱一个
箬棕 龙鳞榈
ont8仓库怎么样,ont8仓库具体位置在哪呢?
6s安兔兔怎么看cpu,苹果6s怎么看CPU是台积电还是三星