Advertisement
HimikoWerckmeister

CMPT250 ALU

Feb 21st, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. use IEEE;
  2. use IEEE.std_logic_1164_all;
  3. use IEEE.std_logic_arith.all;
  4.  
  5. entity alu is
  6. port(rs: in std_logic_vector(15 downto 0); rt: in std_logic_vector(15 downto 0); c0 in std_logic; sel: in std_logic_vector(2 downto 0);
  7. res: out std_logic_vector(15 downto 0); lt: out boolean; eq: out boolean);
  8. end alu;
  9.  
  10. architecture behav of alu is
  11.  
  12. begin
  13. variable RES: std_logic_vector(15 downto 0);
  14. variable Diff: std_logic_vector(15 downto 0);
  15. process is
  16.  
  17. case sel is
  18. when "000" =>
  19. RES := c0;
  20. when "001" =>
  21. RES := rs + c0;
  22. when "010" =>
  23. RES := res = rs - 1;
  24. when "011" =>
  25. RES := res + rt + c0;
  26. when "100" =>
  27. RES := rs + (not rt) + c0;
  28. when "101" =>
  29. RES := (rs and rt)
  30. when "110" =>
  31. RES := (not rs) + c0;
  32. when "111"
  33. RES := rt + c0;
  34.  
  35. end case;
  36. eq <= (rs = rt);
  37. --lt <= (rs < rt);
  38. Diff := rs- rt
  39. lt <= Diff(15);
  40. res <= RES;
  41.  
  42. begin
  43. wait on sel;
  44. end process
  45.  
  46.  
  47.  
  48.  
  49. end alu;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement