Documente Academic
Documente Profesional
Documente Cultură
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity barrel is
PORT(datain:in std_logic_vector(7 downto 0);
opcode:in std_logic_vector(2 downto 0);
count:in std_logic_vector(2 downto 0);
dataout:out std_logic_vector(7 downto 0)
);
end barrel;
dataout<=datain;
elsif opcode="100"then
dataout<=datain;
elsif opcode="101"then
dataout<=datain;
elsif opcode="110"then
dataout<=datain;
end if;
--this case indicates input data in shifted by 1 bit
when "001"=>
if opcode="000"then --shift right logical
dataout<="0"&datain( 7 downto 1);
elsif opcode="001"then --shift right arithmetic
dataout<=datain(7)& datain(7 downto 1);
elsif opcode="010"then --rotate right
dataout<=datain(0) & datain(7 downto 1);
elsif opcode="100"then --shift left logical
dataout<=datain(6 downto 0) &"0";
elsif opcode="101"then --shift left arithmetic
dataout<=datain(7)&datain(5 downto 0) &"0";
elsif opcode="110"then--rotate left
dataout<=datain(6 downto 0) & datain(7);
end if;
--this case indicate that input data is shifted by 2 bits
when "010"=>
if opcode="000"then
dataout<="00" & datain(7 downto 2);
elsif opcode="001"then
dataout<=datain(7)&datain(7)&datain(7 downto 2);
elsif opcode="010"then
dataout<=datain(1 downto 0)&datain(7 downto 2);
elsif opcode="100"then
dataout<=datain(5 downto 0) &"00";
elsif opcode="101"then
dataout<=datain(7)&datain(4 downto 0)&"00";
elsif opcode="110"then
dataout<=datain(5 downto 0)&datain( 7 downto 6);
end if;
--this case indicates that data is shifted by 3 bits
when "011"=>
if opcode="000"then
dataout<="000" &datain( 7 downto 3);
elsif opcode="001"then
dataout<=datain(7)&datain(7)&datain(7)&datain(7 downto 3);
elsif opcode="010"then
dataout<=datain(2 downto 0) &datain( 7 downto 3);
elsif opcode="100"then
dataout<=datain(4 downto 0) &"000";
elsif opcode="101"then
dataout<=datain(7)&datain(3 downto 0)&"000";
elsif opcode="110"then
dataout<=datain(4 downto 0 )&datain( 7 downto 5);
end if;
--this case indicates that input data is shifted by 4 bits
when "100"=>
if opcode="000"then
dataout<="0000" & datain(7 downto 4);
elsif opcode="001"then
dataout<=datain(7)&datain(7)&datain(7)&datain(7)&datain(7 downto 4);
elsif opcode="010"then
dataout<=datain(3 downto 0) &datain( 7 downto 4);
elsif opcode="100"then
dataout<=datain(3 downto 0) &"0000";
elsif opcode="101"then
dataout<=datain(7)&datain(2 downto 0) & "0000";
elsif opcode="110"then
dataout<=datain(3 downto 0)&datain( 7 downto 4);
end if;
--this case indicates that input data is shifted by 5 bits
when "101"=>
if opcode="000"then
dataout<="00000" &datain( 7 downto 5);
elsif opcode="001"then
dataout<=datain(7)&datain(7)&datain(7)&datain(7)&datain(7)&datain(7 downto 5);
elsif opcode="010"then
dataout<=datain(4 downto 0) & datain(7 downto 5);
elsif opcode="100"then
dataout<=datain(2 downto 0) &"00000";
elsif opcode="101"then
dataout<=datain(7)&datain(1 downto 0 )& "00000";
elsif opcode="110"then
elsif opcode="101"then
dataout<=datain(7)&"0000000";
elsif opcode="110"then
dataout<=datain(0)&datain( 7 downto 1);
end if;
end case;
end process;
end Behavioral;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY BARREL_SHIFTER IS
PORT(
SHLR
RIGHT
I
);
END BARREL_SHIFTER;
SIGNAL D
SIGNAL B
SIGNAL P
SIGNAL X,A,Y
COMPONENT MUX2_1 IS
PORT(
A,B :IN STD_LOGIC;
SEL :IN STD_LOGIC;
OUTPUT :OUT STD_LOGIC);
END COMPONENT;
BEGIN
--TO DECIDE WHETHER TO GET LEFT OR RIGHT OPERATION
-- RIGHT->0,LEFT->1 (A,B,SEL,OUT)
--IF SEL->0 THEN OUT->A SEL->1 THEN OUT->B
--BITREVERSAL OPERATION ON INPUT BITS
OR LOGICAL
--STAGE 1
--STAGE 2
--STAGE 3
--LAYER 4
--STAGE 5
END ARCH;