library IEEE;
use IEEE.std_logic_1164.all;

entity jk_ff is
	 port(
		 clock 	: in 	std_logic;
		 reset 	: in 	std_logic; 
		 enable	: in	std_logic;
		 j 		: in 	std_logic;
		 k 		: in 	std_logic;
		 q_out 	: out 	std_logic
	 );
end jk_ff;

architecture synthesis of jk_ff is	   
	signal q	: std_logic;
	signal qns	: std_logic;
begin		 
	ff : process (clock)
	begin
		if rising_edge(clock) then 
			if reset = '1' then
				q <= '0';
			elsif enable = '1' then
				q <= qns;
			end if;
		end if;
	end process ff;
	
    jk_next_state : process (j, k, q)
    	variable jk : std_logic_vector (1 downto 0);
    begin
    	jk := (j & k);
	    case jk is
		    when "01"	=> qns <= '0';
		    when "10"	=> qns <= '1';
		    when "11"	=> qns <= not (q);
		    when "00"	=> qns <= q;   
			when others => null;
		end case;
	end process jk_next_state;
	
    q_out <= q;

end synthesis;
