Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use IEEE.STD_LOGIC_ARITH.ALL;
- use IEEE.NUMERIC_STD.ALL;
- entity FSM is
- Port(Clk: in STD_LOGIC;
- Reset: out STD_LOGIC;
- Run: in STD_LOGIC;
- MOP: in STD_LOGIC_VECTOR (3 downto 0);
- Load_A: out STD_LOGIC;
- Load_B: out STD_LOGIC;
- Cin: out STD_LOGIC;
- ALUop: out STD_LOGIC_VECTOR (2 downto 0);
- Input_Select: out STD_LOGIC_VECTOR (2 downto 0);
- out_state: out STD_LOGIC_VECTOR (3 downto 0));
- end FSM;
- ARCHITECTURE Behavioral OF FSM IS
- SIGNAL y_present, y_next : STD_LOGIC_VECTOR(4 DOWNTO 0);
- CONSTANT S0 : STD_LOGIC_VECTOR(4 DOWNTO 0) := "10000";
- CONSTANT S1 : STD_LOGIC_VECTOR(4 DOWNTO 0) := "01000";
- CONSTANT S2 : STD_LOGIC_VECTOR(4 DOWNTO 0) := "00100";
- CONSTANT S3 : STD_LOGIC_VECTOR(4 DOWNTO 0) := "00010";
- CONSTANT S4 : STD_LOGIC_VECTOR(4 DOWNTO 0) := "00001";
- BEGIN
- PROCESS (RUN, y_present)
- BEGIN
- if RUN='0' then
- y_next<=S0;
- elsif RUN='1' then
- CASE y_present IS
- WHEN S0 =>
- y_next <= S1;
- WHEN S1 =>
- y_next <= S2;
- WHEN S2 =>
- y_next <= S3;
- WHEN S3 =>
- y_next <= S4;
- WHEN S4 =>
- y_next <= S4;
- WHEN OTHERS =>
- y_next <= S0;
- END CASE;
- END IF;
- END PROCESS;
- process (Clk)
- begin
- if(Clk'EVENT and Clk = '1') then
- y_present <= y_next;
- end if;
- end PROCESS;
- process (y_present, MOP)
- begin
- if MOP = "0000" then -- nop
- if y_present = S0 then
- out_state <= "0000";
- Input_Select <= "000";
- elsif y_present = S1 then
- out_state <= "0001";
- Input_Select <= "100";
- elsif y_present = S2 then
- out_state <= "0010";
- Input_Select <= "000";
- elsif y_present = S3 then
- out_state <= "0100";
- Input_Select <= "000";
- else
- out_state <= "1000";
- Input_Select <= "000";
- end if;
- Load_A <= '0';
- Load_B <= '0';
- Cin <= '0';
- ALUop <= "000";
- Reset <= '0';
- elsif MOP = "0001" then -- clear
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Input_Select <= "000";
- Load_A <= '0';
- Load_B <= '0';
- Cin <= '0';
- ALUop <= "000";
- Reset <= '1';
- elsif MOP = "0010" then -- load A
- if y_present = S1 then
- Input_Select <= "110";
- Load_A <= '1';
- else
- Input_Select <= "000";
- Load_A <= '0';
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Load_B <= '0';
- Cin <= '0';
- ALUop <= "000";
- Reset <= '0';
- elsif MOP = "0011" then -- load B
- if y_present = S1 then
- Input_Select <= "110";
- Load_B <= '1';
- else
- Input_Select <= "000";
- Load_B <= '0';
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Load_A <= '0';
- Cin <= '0';
- ALUop <= "000";
- Reset <= '0';
- elsif MOP = "0100" then -- BcopyA
- if y_present = S1 then
- Load_B <= '1';
- else
- Load_B <= '0';
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Input_Select <= "000";
- Load_A <= '0';
- Cin <= '0';
- ALUop <= "000";
- Reset <= '0';
- elsif MOP = "0101" then -- Add2
- if y_present = S3 then
- Load_B <= '1';
- ALUop <= "001";
- Input_Select <= "100";
- else
- Load_B <= '0';
- ALUop <= "000";
- Input_Select <= "000";
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Load_A <= '0';
- Cin <= '0';
- Reset <= '0';
- elsif MOP = "0110" then -- Add21
- if y_present = S3 then
- Load_B <= '1';
- ALUop <= "001";
- Input_Select <= "100";
- Cin <= '1';
- else
- Load_B <= '0';
- ALUop <= "000";
- Input_Select <= "000";
- Cin <= '0';
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Load_A <= '0';
- Reset <= '0';
- elsif MOP = "0111" then -- Add3
- if y_present = S1 then
- Input_Select <= "100";
- Load_A <= '0';
- Load_B <= '1';
- ALUop <= "001";
- elsif y_present = S2 then
- Input_Select <= "100";
- Load_A <= '1';
- Load_B <= '0';
- ALUop <= "000";
- elsif y_present = S3 then
- Input_Select <= "110";
- Load_A <= '0';
- Load_B <= '1';
- ALUop <= "001";
- else
- Input_Select <= "000";
- Load_A <= '0';
- Load_B <= '0';
- ALUop <= "000";
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Cin <= '0';
- Reset <= '0';
- elsif MOP = "1000" then -- SUB
- if y_present = S1 then
- Input_Select <= "101";
- Load_B <= '1'; -- Select BitFlip B, add 1 => 2's complement -B
- Cin <= '1';
- ALUop <= "001";
- else
- Input_Select <= "000";
- Load_B <= '0';
- Cin <= '0';
- ALUop <= "000";
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Load_A <= '0';
- Reset <= '0';
- elsif MOP = "1001" then -- BINVB
- if y_present = S1 then
- Input_Select <= "101";
- Load_B <= '1';
- else
- Input_Select <= "000";
- Load_B <= '0';
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Load_A <= '0';
- Cin <= '0';
- ALUop <= "000";
- Reset <= '0';
- elsif MOP = "1010" then -- BAND
- if y_present = S1 then
- Input_Select <= "100";
- Load_B <= '1';
- ALUop <= "101";
- else
- Input_Select <= "000";
- Load_B <= '0';
- ALUop <= "000";
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Load_A <= '0';
- Cin <= '1';
- Reset <= '0';
- elsif MOP = "1011" then -- BOR
- if y_present = S1 then
- Input_Select <= "100";
- Load_B <= '1';
- ALUop <= "100";
- else
- Input_Select <= "000";
- Load_B <= '0';
- ALUop <= "000";
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Load_A <= '0';
- Cin <= '0';
- Reset <= '0';
- elsif MOP = "1100" then -- BXOR
- if y_present = S1 then
- Input_Select <= "100";
- Load_B <= '1';
- ALUop <= "110";
- else
- Input_Select <= "000";
- Load_B <= '0';
- ALUop <= "000";
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Load_A <= '0';
- Cin <= '1';
- Reset <= '0';
- elsif MOP = "1101" then -- BLSRA
- if y_present = S1 then
- Input_Select <= "010";
- Load_B <= '1';
- else
- Input_Select <= "000";
- Load_B <= '0';
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Load_A <= '0';
- Cin <= '0';
- ALUop <= "000";
- Reset <= '0';
- elsif MOP = "1110" then -- BLSLA
- if y_present = S1 then
- Input_Select <= "001";
- Load_B <= '1';
- else
- Input_Select <= "000";
- Load_B <= '0';
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Load_A <= '0';
- Cin <= '0';
- ALUop <= "000";
- Reset <= '0';
- elsif MOP= "1111" then -- BASRA
- if y_present = S1 then
- Input_Select <= "011";
- Load_B <= '1';
- else
- Input_Select <= "000";
- Load_B <= '0';
- end if;
- if y_present = S0 then
- out_state <= "0000";
- elsif y_present = S1 then
- out_state <= "0001";
- elsif y_present = S2 then
- out_state <= "0010";
- elsif y_present = S3 then
- out_state <= "0100";
- else
- out_state <= "1000";
- end if;
- Load_A <= '0';
- Cin <= '0';
- ALUop <= "000";
- Reset <= '0';
- end if;
- end process;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement