Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- entity control is
- Port ( CLR : in std_logic;
- CLK : in std_logic;
- MX : out std_logic_vector(2 downto 0);
- CTRL : out std_logic;
- LDA, LDB, LDACC : out std_logic);
- end control;
- architecture Behavioral of control is
- type state_type is (LDRA,LDRB,ADDA,SUBB,ADDB,INC,CLEAR);
- attribute ENUM_ENCODING: STRING;
- -- attribute ENUM_ENCODING of state_type: type is "100000 010000 001000 000100 000010 000001";
- signal PS,NS : state_type;
- begin
- sync_proc: process (CLK,CLR,NS)
- begin
- if (CLR = '1') then PS <= CLEAR; --the program is reset/stopped
- elsif (rising_edge(CLK)) then PS <= NS;
- end if;
- end process sync_proc;
- comb_proc: process (PS)
- begin
- case (PS) is
- when LDRA => --register a is loaded
- LDA <= '1';
- LDB <= '0';
- LDACC <= '0';
- MX <= "000";
- CTRL <= '0';
- NS <= LDRB;
- when LDRB => --register b is loaded
- LDA <= '0';
- LDB <= '1';
- LDACC <= '0';
- MX <= "000";
- CTRL <= '0';
- NS <= ADDA;
- when ADDA => --mux chosen to add A to the value in acc
- LDA <= '0';
- LDB <= '0';
- LDACC <= '1';
- MX <= "000";
- CTRL <= '0';
- NS <= SUBB;
- when SUBB => --mux chosen to subtract B to the value in acc
- LDA <= '0';
- LDB <= '0';
- LDACC <= '1';
- MX <= "011"; --not B
- CTRL <= '1';
- NS <= INC;
- when INC => --the value mux has chosen is zeros. incrementing by 1
- LDA <= '0';
- LDB <= '0';
- LDACC <= '1';
- MX <= "100";
- CTRL <= '1';
- NS <= ADDB;
- when ADDB => --mux chosen to add B to the value in acc
- LDA <= '0';
- LDB <= '0';
- LDACC <= '1';
- MX <= "001";
- CTRL <= '0';
- NS <= LDRA;
- when CLEAR =>
- LDA <= '0';
- LDB <= '0';
- LDACC <= '0';
- MX <= "000";
- NS <= LDRA;
- when others => -- the just in case case...
- LDA <= '0';
- LDB <= '0';
- LDACC <= '0';
- MX <= "000";
- CTRL <= '0';
- NS <= LDRA;
- end case;
- end process comb_proc;
- end Behavioral;
Add Comment
Please, Sign In to add comment