Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity ALU is
  6. port ( A : in signed(15 downto 0); --wejscie
  7. B : in signed(15 downto 0); --wejscie
  8. Salu : in bit_vector (3 downto 0);
  9. LDF : in bit; --zapis flag
  10. clk : in bit; --zegar
  11. Y : out signed (15 downto 0); --wyjscie
  12. C,Z,S,P : out std_logic --flagi (C-carry, z-zero, s-sign, p-parity)
  13. );
  14. end entity;
  15.  
  16. architecture rtl of ALU is
  17. begin
  18. process (Salu, A, B, clk)
  19. variable res, AA, BB,CC: signed (16 downto 0); --argumenty
  20. variable CF,ZF,SF,PF : std_logic; --flagi
  21. variable pp : integer; --bit parzystosci
  22. begin
  23. AA(16) := A(15);
  24. AA(15 downto 0) := A;
  25. BB(16) := B(15);
  26. BB(15 downto 0) := B;
  27. CC(0) := CF;
  28. CC(16 downto 1) := "0000000000000000";
  29. case Salu is
  30. when "0000" => res := AA; --MOV arg1,arg2
  31. when "0001" => res := AA + BB; --ADD arg1,arg2
  32. when "0010" => res := AA - BB; --SUB arg1,arg2
  33. when "0011" => if (CC = 0) then --ST4D arg1,arg2,arg3
  34. res(3 downto 0) := BB(3 downto 0);
  35. else
  36. res(3 downto 0) := BB(7 downto 4);
  37. end if;
  38. when "0100" => res := AA; --PUSH arg1
  39. when "0101" => res := AA; --POP arg1
  40. when "0110" => res(15 downto 0) := AA(7 downto 0)*BB(7 downto 0); --MUL arg1,arg2
  41. when "0111" => res := -AA; --NEG arg1
  42. when "1000" => res := AA; --JMP etykieta
  43. when "1111" => res(16) := AA(16);
  44. when others => null;
  45. res(15 downto 0) := AA(16 downto 1);
  46. end case;
  47.  
  48. Y <= res(15 downto 0);
  49. Z <= ZF;
  50. S <= SF;
  51. C <= CF;
  52. if (clk'event and clk='1') then
  53. if (LDF='1') then
  54. if (res = "00000000000000000") then ZF:='1';
  55. else ZF:='0';
  56. end if;
  57.  
  58. if (res(15)='1') then SF:='1';
  59. else SF:='0';
  60. end if;
  61. CF := res(16);
  62.  
  63. for i in 1 to 15 loop --sprawdzenie parzystosci
  64. if(res(i) = '1') then
  65. pp := pp+1;
  66. end if;
  67. end loop;
  68.  
  69. if(pp mod 2 =0) then
  70. PF := '1';
  71. else
  72. PF:= '0';
  73. end if;
  74.  
  75. end if;
  76. end if;
  77. end process;
  78. end rtl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement