Advertisement
kubpica

alu

May 24th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.15 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. entity Projekt is
  5. port (    A : in signed(15 downto 0);
  6. B : in signed(15 downto 0);
  7. Salu : in bit_vector (3 downto 0);
  8. LDF : in bit;
  9.  clk : in bit;  
  10. Y : out signed (15 downto 0);
  11. C,Z,S : out std_logic
  12. );
  13. end entity;
  14. architecture rtl of Projekt is
  15.    begin
  16. process (Salu, A, B, clk)
  17. variable res, AA, BB,CC: signed (16 downto 0);
  18. variable CF,ZF,SF : std_logic;
  19. begin
  20. AA(16) := A(15);
  21. AA(15 downto 0) := A;
  22. BB(16) := B(15);
  23. BB(15 downto 0) := B;
  24. CC(0) := CF;
  25. CC(16 downto 1) := "0000000000000000";
  26. case Salu is  
  27. when "0000" => res := AA;
  28. when "0001" => res := BB;
  29. when "0010" => res := AA + BB;
  30. when "0011" => res := AA - BB;
  31. when "1111" => res(16) := AA(16);
  32. when others => res := AA;
  33. res(15 downto 0) := AA(16 downto 1);
  34. end case;
  35. Y <= res(15 downto 0);
  36. Z <= ZF;
  37. S <= SF;
  38. C <= CF;
  39. if (clk'event and clk='1') then
  40. if (LDF='1') then
  41. if (res = "00000000000000000") then ZF:='1';
  42. else ZF:='0';
  43. end if;
  44. if (res(15)='1') then SF:='1';
  45. else SF:='0'; end if;
  46. CF := res(16) xor res(15);
  47. end if;
  48. end if;
  49. end process;
  50. end rtl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement