Advertisement
Guest User

Untitled

a guest
May 26th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.16 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_arith.all;
  4. use ieee.std_logic_unsigned.all;
  5.  
  6. entity calculator_core is port(
  7.     inc, sel, rst : in std_logic;
  8.     stageOut : out std_logic_vector(2 downto 0);
  9.     outputVal : out std_logic_vector(7 downto 0));
  10. end calculator_core;
  11.  
  12. architecture behavioral of calculator_core is
  13. signal temp : std_logic_vector (1 downto 0);
  14. signal result : std_logic_vector (7 downto 0);
  15. signal mode : std_logic_vector (1 downto 0);
  16. shared variable operand : std_logic_vector (7 downto 0);
  17. signal operandone : std_logic_vector (7 downto 0);
  18. signal operandtwo : std_logic_vector (7 downto 0);
  19. signal incflag : std_logic_vector(1 downto 0);
  20. begin
  21.     process(sel,rst,incflag)    -- process the opcode selection (sel button -- S3)
  22.     begin
  23.         if(sel'event and sel = '0') then
  24.             case mode(1 downto 0) is
  25.                 when "00" =>
  26.                     stageOut <= "001";
  27.                     mode <= "01";
  28.                 when "01" =>
  29.                     stageOut <= "010";
  30.                     mode <= "10";
  31.                 when "10" =>
  32.                     stageOut <= "011";
  33.                     mode <= "11";
  34.                 when "11" =>
  35.                     stageOut <= "000";
  36.                     mode <= "00";
  37.             end case;
  38.         end if;
  39.         -- reset the calc if rst is pressed
  40.         if(rst = '0') then
  41.             stageOut(2 downto 0) <= "000";
  42.             mode(1 downto 0) <= "00";
  43.             temp(7 downto 0) <= "00000000";
  44.             incflag(1 downto 0) <= "00";
  45.             operandtwo(7 downto 0) <= "00000000";
  46.         end if;
  47.         if(inc'event and inc = '0') then
  48.             operand := operand + 1;
  49.             outputVal <= operand;
  50.         end if;
  51.         if(mode = "01") then
  52.             operandone <= operand;
  53.             operand(7 downto 0) <= "00000000";
  54.         end if;
  55.         if(mode = "10") then
  56.             operandtwo <= operand;
  57.             operand(7 downto 0) <= "00000000";
  58.         end if;
  59.         if(mode = "11") then
  60.             temp <= operand mod 4;
  61.             if(sel'event and sel = '0') then
  62.                 case temp(1 downto 0) is
  63.                     when "00" =>
  64.                         result <= operandone + operandtwo;
  65.                     when "01" =>
  66.                         result <= operandone - operandtwo;
  67.                     when "10" =>
  68.                         result <= operandone XOR operandtwo;
  69.                     when "11" =>
  70.                         result <= operandone AND operandtwo;
  71.                 end case;
  72.             end if;
  73.             operand(7 downto 0) <= "00000000";
  74.         end if;
  75.         if(mode = "00") then
  76.             outputVal <= result;
  77.         end if;
  78.     end process;
  79. end behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement