Advertisement
Guest User

Untitled

a guest
May 24th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 10.22 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_ARITH.ALL;
  4. use IEEE.NUMERIC_STD.ALL;
  5.  
  6. entity FSM is
  7.     Port(Clk: in STD_LOGIC;
  8.           Reset: out STD_LOGIC;
  9.           Run: in STD_LOGIC;
  10.           MOP: in STD_LOGIC_VECTOR (3 downto 0);
  11.           Load_A: out STD_LOGIC;
  12.           Load_B: out STD_LOGIC;
  13.           Cin: out STD_LOGIC;
  14.           ALUop: out STD_LOGIC_VECTOR (2 downto 0);
  15.           Input_Select: out STD_LOGIC_VECTOR (2 downto 0);
  16.           out_state: out STD_LOGIC_VECTOR (3 downto 0));
  17. end FSM;
  18.  
  19. ARCHITECTURE Behavioral OF FSM IS
  20. SIGNAL y_present, y_next : STD_LOGIC_VECTOR(4 DOWNTO 0);
  21. CONSTANT S0  : STD_LOGIC_VECTOR(4 DOWNTO 0) := "10000";
  22. CONSTANT S1  : STD_LOGIC_VECTOR(4 DOWNTO 0) := "01000";
  23. CONSTANT S2  : STD_LOGIC_VECTOR(4 DOWNTO 0) := "00100";
  24. CONSTANT S3  : STD_LOGIC_VECTOR(4 DOWNTO 0) := "00010";
  25. CONSTANT S4  : STD_LOGIC_VECTOR(4 DOWNTO 0) := "00001";
  26.  
  27. BEGIN
  28.     PROCESS (RUN, y_present)
  29.     BEGIN
  30.         if RUN='0' then
  31.             y_next<=S0;
  32.         elsif RUN='1' then
  33.             CASE y_present IS
  34.                 WHEN S0 =>
  35.                     y_next <= S1;
  36.                 WHEN S1 =>
  37.                     y_next <= S2;
  38.                 WHEN S2 =>
  39.                     y_next <= S3;  
  40.                 WHEN S3 =>
  41.                     y_next <= S4;
  42.                 WHEN S4 =>
  43.                     y_next <= S4;
  44.                 WHEN OTHERS =>
  45.                     y_next <= S0;
  46.             END CASE;
  47.         END IF;
  48.     END PROCESS;
  49.            
  50.     process (Clk)
  51.     begin
  52.            
  53.         if(Clk'EVENT and Clk = '1') then
  54.             y_present <= y_next;
  55.         end if;
  56.     end PROCESS;
  57.                      
  58.      process (y_present, MOP)
  59.      begin
  60.      
  61.         if MOP = "0000" then -- nop
  62.             if y_present = S0 then
  63.                 out_state <= "0000";
  64.                 Input_Select <= "000";
  65.             elsif y_present = S1 then
  66.                 out_state <= "0001";
  67.                 Input_Select <= "100";
  68.             elsif y_present = S2 then
  69.                 out_state <= "0010";
  70.                 Input_Select <= "000";
  71.             elsif y_present = S3 then
  72.                 out_state <= "0100";
  73.                 Input_Select <= "000";
  74.             else
  75.                 out_state <= "1000";
  76.                 Input_Select <= "000";
  77.             end if;
  78.            
  79.                 Load_A <= '0';
  80.                 Load_B <= '0';
  81.                 Cin <= '0';
  82.                 ALUop <= "000";
  83.                 Reset <= '0';      
  84.  
  85.         elsif MOP = "0001" then -- clear
  86.             if y_present = S0 then
  87.                 out_state <= "0000";
  88.             elsif y_present = S1 then
  89.                 out_state <= "0001";
  90.             elsif y_present = S2 then
  91.                 out_state <= "0010";
  92.             elsif y_present = S3 then
  93.                 out_state <= "0100";
  94.             else
  95.                 out_state <= "1000";
  96.             end if;
  97.            
  98.                 Input_Select <= "000";
  99.                 Load_A <= '0';
  100.                 Load_B <= '0';
  101.                 Cin <= '0';
  102.                 ALUop <= "000";
  103.                 Reset <= '1';
  104.            
  105.         elsif MOP = "0010" then -- load A
  106.             if y_present = S1 then
  107.                 Input_Select <= "110";
  108.                 Load_A <= '1';
  109.             else
  110.                 Input_Select <= "000";
  111.                 Load_A <= '0';
  112.             end if;
  113.            
  114.             if y_present = S0 then
  115.                 out_state <= "0000";
  116.             elsif y_present = S1 then
  117.                 out_state <= "0001";
  118.             elsif y_present = S2 then
  119.                 out_state <= "0010";
  120.             elsif y_present = S3 then
  121.                 out_state <= "0100";
  122.             else
  123.                 out_state <= "1000";
  124.             end if;
  125.                
  126.                 Load_B <= '0';
  127.                 Cin <= '0';
  128.                 ALUop <= "000";
  129.                 Reset <= '0';
  130.            
  131.         elsif MOP = "0011" then -- load B
  132.            
  133.             if y_present = S1 then
  134.                 Input_Select <= "110";
  135.                 Load_B <= '1';
  136.             else
  137.                 Input_Select <= "000";
  138.                 Load_B <= '0';
  139.             end if;
  140.            
  141.             if y_present = S0 then
  142.                 out_state <= "0000";
  143.             elsif y_present = S1 then
  144.                 out_state <= "0001";
  145.             elsif y_present = S2 then
  146.                 out_state <= "0010";
  147.             elsif y_present = S3 then
  148.                 out_state <= "0100";
  149.             else
  150.                 out_state <= "1000";
  151.             end if;
  152.                
  153.                 Load_A <= '0';
  154.                 Cin <= '0';
  155.                 ALUop <= "000";
  156.                 Reset <= '0';
  157.            
  158.         elsif MOP = "0100" then -- BcopyA
  159.             if y_present = S1 then
  160.                 Load_B <= '1';
  161.             else
  162.                 Load_B <= '0';
  163.             end if;
  164.            
  165.             if y_present = S0 then
  166.                 out_state <= "0000";
  167.             elsif y_present = S1 then
  168.                 out_state <= "0001";
  169.             elsif y_present = S2 then
  170.                 out_state <= "0010";
  171.             elsif y_present = S3 then
  172.                 out_state <= "0100";
  173.             else
  174.                 out_state <= "1000";
  175.             end if;
  176.                
  177.                 Input_Select <= "000";
  178.                 Load_A <= '0';
  179.                 Cin <= '0';
  180.                 ALUop <= "000";
  181.                 Reset <= '0';
  182.        
  183.         elsif MOP = "0101" then -- Add2
  184.             if y_present = S3 then
  185.                 Load_B <= '1';
  186.                 ALUop <= "001";
  187.                 Input_Select <= "100";
  188.             else
  189.                 Load_B <= '0';
  190.                 ALUop <= "000";
  191.                 Input_Select <= "000";
  192.             end if;
  193.            
  194.             if y_present = S0 then
  195.                 out_state <= "0000";
  196.             elsif y_present = S1 then
  197.                 out_state <= "0001";
  198.             elsif y_present = S2 then
  199.                 out_state <= "0010";
  200.             elsif y_present = S3 then
  201.                 out_state <= "0100";
  202.             else
  203.                 out_state <= "1000";
  204.             end if;
  205.            
  206.             Load_A <= '0';
  207.             Cin <= '0';
  208.             Reset <= '0';
  209.            
  210.         elsif MOP = "0110" then -- Add21
  211.             if y_present = S3 then
  212.                 Load_B <= '1';
  213.                 ALUop <= "001";
  214.                 Input_Select <= "100";
  215.                 Cin <= '1';
  216.             else
  217.                 Load_B <= '0';
  218.                 ALUop <= "000";
  219.                 Input_Select <= "000";
  220.                 Cin <= '0';
  221.             end if;        
  222.            
  223.             if y_present = S0 then
  224.                 out_state <= "0000";
  225.             elsif y_present = S1 then
  226.                 out_state <= "0001";
  227.             elsif y_present = S2 then
  228.                 out_state <= "0010";
  229.             elsif y_present = S3 then
  230.                 out_state <= "0100";
  231.             else
  232.                 out_state <= "1000";
  233.             end if;
  234.  
  235.                 Load_A <= '0';
  236.                 Reset <= '0';
  237.            
  238.         elsif MOP = "0111" then -- Add3
  239.             if y_present = S1 then
  240.                 Input_Select <= "100";
  241.                 Load_A <= '0';
  242.                 Load_B <= '1';
  243.                 ALUop <= "001";
  244.             elsif y_present = S2 then
  245.                 Input_Select <= "100";
  246.                 Load_A <= '1';
  247.                 Load_B <= '0';
  248.                 ALUop <= "000";
  249.             elsif y_present = S3 then
  250.                 Input_Select <= "110";
  251.                 Load_A <= '0';
  252.                 Load_B <= '1';
  253.                 ALUop <= "001";
  254.             else
  255.                 Input_Select <= "000";
  256.                 Load_A <= '0';
  257.                 Load_B <= '0';
  258.                 ALUop <= "000";
  259.             end if;
  260.            
  261.             if y_present = S0 then
  262.                 out_state <= "0000";
  263.             elsif y_present = S1 then
  264.                 out_state <= "0001";
  265.             elsif y_present = S2 then
  266.                 out_state <= "0010";
  267.             elsif y_present = S3 then
  268.                 out_state <= "0100";
  269.             else
  270.                 out_state <= "1000";
  271.             end if;
  272.  
  273.                 Cin <= '0';
  274.                 Reset <= '0';
  275.            
  276.         elsif MOP = "1000" then -- SUB
  277.             if y_present = S1 then
  278.                 Input_Select <= "101";
  279.                 Load_B <= '1'; -- Select BitFlip B, add 1 => 2's complement -B
  280.                 Cin <= '1';
  281.                 ALUop <= "001";
  282.             else
  283.                 Input_Select <= "000";
  284.                 Load_B <= '0';
  285.                 Cin <= '0';
  286.                 ALUop <= "000";
  287.             end if;
  288.            
  289.             if y_present = S0 then
  290.                 out_state <= "0000";
  291.             elsif y_present = S1 then
  292.                 out_state <= "0001";
  293.             elsif y_present = S2 then
  294.                 out_state <= "0010";
  295.             elsif y_present = S3 then
  296.                 out_state <= "0100";
  297.             else
  298.                 out_state <= "1000";
  299.             end if;
  300.  
  301.                 Load_A <= '0';
  302.                 Reset <= '0';
  303.            
  304.         elsif MOP = "1001" then -- BINVB
  305.             if y_present = S1 then
  306.                 Input_Select <= "101";
  307.                 Load_B <= '1';
  308.             else
  309.                 Input_Select <= "000";
  310.                 Load_B <= '0';
  311.             end if;
  312.                    
  313.             if y_present = S0 then
  314.                 out_state <= "0000";
  315.             elsif y_present = S1 then
  316.                 out_state <= "0001";
  317.             elsif y_present = S2 then
  318.                 out_state <= "0010";
  319.             elsif y_present = S3 then
  320.                 out_state <= "0100";
  321.             else
  322.                 out_state <= "1000";
  323.             end if;
  324.            
  325.                 Load_A <= '0';
  326.                 Cin <= '0';
  327.                 ALUop <= "000";
  328.                 Reset <= '0';
  329.            
  330.         elsif MOP = "1010" then -- BAND
  331.             if y_present = S1 then
  332.                 Input_Select <= "100";
  333.                 Load_B <= '1';
  334.                 ALUop <= "101";
  335.             else
  336.                 Input_Select <= "000";
  337.                 Load_B <= '0';
  338.                 ALUop <= "000";
  339.             end if;
  340.            
  341.             if y_present = S0 then
  342.                 out_state <= "0000";
  343.             elsif y_present = S1 then
  344.                 out_state <= "0001";
  345.             elsif y_present = S2 then
  346.                 out_state <= "0010";
  347.             elsif y_present = S3 then
  348.                 out_state <= "0100";
  349.             else
  350.                 out_state <= "1000";
  351.             end if;
  352.            
  353.                 Load_A <= '0';
  354.                 Cin <= '1';
  355.                 Reset <= '0';
  356.            
  357.         elsif MOP = "1011" then -- BOR
  358.             if y_present = S1 then
  359.                 Input_Select <= "100";
  360.                 Load_B <= '1';
  361.                 ALUop <= "100";
  362.             else
  363.                 Input_Select <= "000";
  364.                 Load_B <= '0';
  365.                 ALUop <= "000";
  366.             end if;            
  367.            
  368.             if y_present = S0 then
  369.                 out_state <= "0000";
  370.             elsif y_present = S1 then
  371.                 out_state <= "0001";
  372.             elsif y_present = S2 then
  373.                 out_state <= "0010";
  374.             elsif y_present = S3 then
  375.                 out_state <= "0100";
  376.             else
  377.                 out_state <= "1000";
  378.             end if;
  379.  
  380.                 Load_A <= '0';
  381.                 Cin <= '0';
  382.                 Reset <= '0';
  383.            
  384.         elsif MOP = "1100" then -- BXOR
  385.             if y_present = S1 then
  386.                 Input_Select <= "100";
  387.                 Load_B <= '1';
  388.                 ALUop <= "110";
  389.             else
  390.                 Input_Select <= "000";
  391.                 Load_B <= '0';
  392.                 ALUop <= "000";
  393.             end if;
  394.            
  395.             if y_present = S0 then
  396.                 out_state <= "0000";
  397.             elsif y_present = S1 then
  398.                 out_state <= "0001";
  399.             elsif y_present = S2 then
  400.                 out_state <= "0010";
  401.             elsif y_present = S3 then
  402.                 out_state <= "0100";
  403.             else
  404.                 out_state <= "1000";
  405.             end if;
  406.            
  407.                 Load_A <= '0';
  408.                 Cin <= '1';
  409.                 Reset <= '0';
  410.            
  411.         elsif MOP = "1101" then -- BLSRA
  412.             if y_present = S1 then
  413.                 Input_Select <= "010";
  414.                 Load_B <= '1';
  415.             else
  416.                 Input_Select <= "000";
  417.                 Load_B <= '0';
  418.             end if;
  419.            
  420.             if y_present = S0 then
  421.                 out_state <= "0000";
  422.             elsif y_present = S1 then
  423.                 out_state <= "0001";
  424.             elsif y_present = S2 then
  425.                 out_state <= "0010";
  426.             elsif y_present = S3 then
  427.                 out_state <= "0100";
  428.             else
  429.                 out_state <= "1000";
  430.             end if;
  431.            
  432.                 Load_A <= '0';
  433.                 Cin <= '0';
  434.                 ALUop <= "000";
  435.                 Reset <= '0';
  436.            
  437.         elsif MOP = "1110" then -- BLSLA
  438.             if y_present = S1 then
  439.                 Input_Select <= "001";
  440.                 Load_B <= '1';
  441.             else
  442.                 Input_Select <= "000";
  443.                 Load_B <= '0';
  444.             end if;
  445.            
  446.             if y_present = S0 then
  447.                 out_state <= "0000";
  448.             elsif y_present = S1 then
  449.                 out_state <= "0001";
  450.             elsif y_present = S2 then
  451.                 out_state <= "0010";
  452.             elsif y_present = S3 then
  453.                 out_state <= "0100";
  454.             else
  455.                 out_state <= "1000";
  456.             end if;
  457.            
  458.                 Load_A <= '0';
  459.                 Cin <= '0';
  460.                 ALUop <= "000";
  461.                 Reset <= '0';
  462.            
  463.         elsif MOP= "1111" then -- BASRA
  464.             if y_present = S1 then
  465.                 Input_Select <= "011";
  466.                 Load_B <= '1';
  467.             else
  468.                 Input_Select <= "000";
  469.                 Load_B <= '0';
  470.             end if;
  471.            
  472.             if y_present = S0 then
  473.                 out_state <= "0000";
  474.             elsif y_present = S1 then
  475.                 out_state <= "0001";
  476.             elsif y_present = S2 then
  477.                 out_state <= "0010";
  478.             elsif y_present = S3 then
  479.                 out_state <= "0100";
  480.             else
  481.                 out_state <= "1000";
  482.             end if;
  483.            
  484.                 Load_A <= '0';
  485.                 Cin <= '0';
  486.                 ALUop <= "000";
  487.                 Reset <= '0';
  488.             end if;
  489.     end process;
  490. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement