Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use ieee.std_logic_unsigned.all;
  4. use IEEE.STD_LOGIC_ARITH.all;
  5.  
  6.  
  7.  
  8. entity cpu is
  9. Port (
  10. clk : in STD_LOGIC;
  11. update : in STD_LOGIC;
  12. ax : in STD_LOGIC_VECTOR(3 downto 0);
  13. opcode : in STD_LOGIC_VECTOR(3 downto 0);
  14. result_add : in STD_LOGIC_VECTOR(4 downto 0);
  15. result_mult : in STD_LOGIC_VECTOR(7 downto 0);
  16. result_not : in STD_LOGIC_VECTOR(3 downto 0);
  17. result_and : in STD_LOGIC_VECTOR(3 downto 0);
  18. result_or : in STD_LOGIC_VECTOR(3 downto 0);
  19. A : out STD_LOGIC_VECTOR(3 downto 0);
  20. B : out STD_LOGIC_VECTOR(3 downto 0);
  21. C : out STD_LOGIC_VECTOR(3 downto 0);
  22. D : out STD_LOGIC_VECTOR(3 downto 0);
  23. op_in1 : out STD_LOGIC_VECTOR(3 downto 0);
  24. op_in2 : out STD_LOGIC_VECTOR(3 downto 0) );
  25. end cpu;
  26.  
  27. architecture Behavioral of cpu is
  28.  
  29. signal BX, CX, DX : std_logic_vector(3 downto 0);
  30. begin
  31.  
  32. process(clk)
  33.  
  34. begin
  35.  
  36. if clk='1' AND clk'event then
  37.  
  38. case opcode is
  39. when "0000" => BX <= AX;
  40. when "0001" => CX <= AX;
  41. when "0010" => DX <= AX;
  42. when "0011" => BX <= "0000";
  43. when "0100" => CX <= "0000";
  44. when "0101" => DX <= "0000";
  45. when "0110" =>
  46. CX <= result_add,
  47. DX <= "0101";
  48. when "0111" =>
  49. CX <= result_mult,
  50. DX <= "0110";
  51. when "1000" =>
  52. CX <= result_not,
  53. DX <= "1101";
  54. when "1001" =>
  55. CX <= result_and,
  56. DX <= "0010";
  57. when "1010" =>
  58. CX <= result_or,
  59. DX <= "0011";
  60. when "1011" =>
  61. DX <= "000"&(bit4),
  62. CX <= LSB4;
  63. when "1100" =>
  64. DX <= MSB4,
  65. CX <= LSB4;
  66. when "1101" => CX <= NOT(AX);
  67. DX <= "0000";
  68. when "1110" => CX <= AX AND BX;
  69. DX <= "0000";
  70. when "1111" => CX <= AX OR BX;
  71. DX <= "0000";
  72. end case;
  73. end if;
  74. end process;
  75.  
  76.  
  77. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement