Advertisement
Karolina99

ALU

May 11th, 2020
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.12 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. entity ALU is
  5.     port (
  6.         A : in signed(15 downto 0);
  7.         B : in signed(15 downto 0);
  8.         PC : inout signed (31 downto 0);
  9.         Salu : in bit_vector (3 downto 0);
  10.         LDF : in bit;
  11.         clk : in bit;
  12.         Y : out signed (15 downto 0);
  13.         C,Z,S : out std_logic
  14.        
  15.     );
  16. end entity;
  17.  
  18. architecture rtl of ALU is
  19. begin
  20.     process (Salu, A, B, clk)
  21.         variable res, AA, BB,CC: signed (16 downto 0);
  22.         variable CF,ZF,SF : std_logic;
  23.         variable t : integer range 0 to 16;
  24.         variable etykieta : signed (7 downto 0);
  25.         variable mul : signed (33 downto 0); -- #################zmiana
  26.         begin
  27.         etykieta(7 downto 0) := "00000100";
  28.         AA(16) := A(15);
  29.         AA(15 downto 0) := A;
  30.         BB(16) := B(15);
  31.         BB(15 downto 0) := B;
  32.         CC(0) := CF;
  33.    
  34.     CC(16 downto 1) := "0000000000000000";
  35.     case Salu is
  36.         when "0000" => res := AA;  -- MOV
  37.         when "0001" => res := BB;  -- MOV
  38.         when "0010" => res := AA + BB;  -- ADD
  39.         when "0011" => res := AA - BB;  -- SUB     
  40.         when "0100" => res := "000000000" & etykieta; -- #################zmiana
  41.                             PC <= PC rol to_integer(res);  -- #################zmiana
  42.                             res := "00000000000000000"; --BR etykieta -- #################zmiana
  43.         when "0101" => res := AA or BB; --OR
  44.         when "0110" => res := AA and BB; --AND
  45.        
  46.         when "0111" => res := AA + to_signed(1, 17); --INC
  47.         when "1000" => res := AA - to_signed(1, 17); --DEC
  48.         when "1001" =>  mul:= AA * BB;
  49.         res := mul(33 downto 17) ; --MUL  -- #################zmiana
  50.         when "1010" =>  res := "00000000000000000";
  51.         when "1011" =>  res := "00000000000000000";
  52.         when "1100" =>  res := "00000000000000000";
  53.         when "1101" =>  res := "00000000000000000";
  54.         when "1110" =>  res := "00000000000000000";    
  55.         when "1111" => res(16) := AA(16);      
  56.         res(15 downto 0) := AA(16 downto 1);
  57.     end case;
  58. Y <= res(15 downto 0);
  59. Z <= ZF;
  60. S <= SF;
  61. C <= CF;
  62. if (clk'event and clk='1') then
  63.     if (LDF='1') then
  64.         if (res = "00000000000000000") then ZF:='1';
  65.         else ZF:='0';
  66.         end if;
  67.     if (res(15)='1') then SF:='1';
  68.     else SF:='0'; end if;
  69.     CF := res(16) xor res(15);
  70.     end if;
  71. end if;
  72. end process;
  73. end rtl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement