Advertisement
Guest User

Untitled

a guest
May 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.11 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5.  
  6. entity projektASK is
  7.     port (
  8.             A : in signed(15 downto 0);
  9.             B : in signed(15 downto 0);
  10.             Salu : in signed(3 downto 0);
  11.             LDF : in bit;
  12.             clk : in std_logic;
  13.             Y : out signed (15 downto 0);
  14.             C,Z,S,P : out std_logic
  15.             );
  16. end entity;
  17.  
  18. architecture rtl of projektASK is
  19.     begin
  20.         process (Salu, A, B, clk)
  21.             variable res, AA, BB,CC: signed (16 downto 0):= (others => '0');
  22.             variable CF,ZF,SF,PF : std_logic:= '0';
  23.             variable temp: signed (7 downto 0):= (others => '0');
  24.             begin
  25.             AA(16) := A(15);
  26.             AA(15 downto 0) := A;
  27.             BB(16) := B(15);
  28.             BB(15 downto 0) := B;
  29.             CC(0) := CF;
  30.             CC(16 downto 1) := "0000000000000000";
  31.            
  32.             case Salu is
  33.                 when "0000" => res := AA;
  34.                 when "0001" => res := AA + BB;
  35.                 when "0010" => res := AA - BB;
  36.                 when "0011" => if(AA = BB) then AA := res;
  37.                                                           BB := res;
  38.                                     end if;                
  39.                 when "0100" => if(AA >= BB) then AA := res;
  40.                                                             BB := res;
  41.                                     end if;
  42.                 when "0101" => if(AA > BB) then res :="00000000000000001";
  43.                                     else res := "00000000000000000";
  44.                                     end if;
  45.                 when "0110" => if(AA <= BB) then res :="00000000000000001";
  46.                                     else res := "00000000000000000";
  47.                                     end if;
  48.                 when "0111" => if(AA < BB) then res :="00000000000000001";
  49.                                     else res := "00000000000000000";
  50.                                     end if;
  51.                 when "1000" => AA :=  AA xor BB; -- or;            
  52.                 when "1001" => AA := shift_left(signed(AA), to_integer(signed(BB)));   
  53.                 when "1010" => AA := shift_right(signed(AA), to_integer(signed(BB)));              
  54.                 when OTHERS => res(16) := AA(16);      
  55.                 --res(15 downto 0) := AA(16 downto 1); 
  56.                 res(15 downto 0) := AA(15 downto 0);
  57.             end case;
  58.            
  59.             Y <= res(15 downto 0);
  60.             Z <= ZF;
  61.             S <= SF;
  62.             C <= CF;
  63.             P <= PF;
  64.             if (clk'event and clk='1') then
  65.                 if (LDF='1') then
  66.                     if (res = "00000000000000000") then
  67.                     ZF:='1';
  68.                     else ZF:='0';
  69.                     end if;
  70.                 if (res(15)='1') then SF:='1';
  71.                 else SF:='0'; end if;
  72.                 CF := res(16) xor res(15);
  73.                 end if;
  74.             end if;
  75.         end process;
  76. end rtl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement