library ieee;
use ieee.std_logic_1164.all;

-- FSM for testing Student Version Bug
entity fsmbad is
  port (  clk:  in std_logic;
	  reset: in std_logic;
	  in_a: in std_logic;
	  in_b: in std_logic;
	  in_c: in std_logic;
	-- outputs
	  state: out std_logic_vector(2 downto 0)
       );
 end fsmbad;

architecture a of fsmbad is

  signal nstate,pstate: std_logic_vector(2 downto 0);
  
  CONSTANT S0 : std_logic_vector(2 downto 0) := "000";
  CONSTANT S1 : std_logic_vector(2 downto 0) := "001";
  CONSTANT S2 : std_logic_vector(2 downto 0) := "010";
  CONSTANT S3 : std_logic_vector(2 downto 0) := "011";
  CONSTANT S4 : std_logic_vector(2 downto 0) := "100";

 begin

   state <= pstate;

   stateff:process(clk)
     begin
      if (reset = '1') then
	     pstate <= S0;
      elsif (clk'event and clk='1') then  
	  -- rising edge of clock
	    pstate <= nstate;
      end if;
     end process stateff;

   comb: process (pstate, in_a, in_b, in_c) 
     begin
       nstate <= pstate;  -- this default assignment causes
	                      -- incorrect logic to be synthesized in student
	                      -- version.  Works fine in latest professional version.
       CASE pstate IS
       	WHEN S0 =>
	    if (in_a = '1') then nstate <= S1; end if;
       	WHEN S1 =>
            nstate <= S2;
        WHEN S2 =>
	      if (in_b = '1') then nstate <= S3; end if;
        when S3 =>
	       if (in_c = '1') then nstate <= S4;	end if;
	    when S4 =>
	       if (in_b = '1') then nstate <= S3; end if;
       	WHEN OTHERS =>
	       nstate <= S0;
       END CASE;
     end process comb;
   
 end a;


<div align="center"><br /><script type="text/javascript"><!--
google_ad_client = "pub-7293844627074885";
//468x60, Created at 07. 11. 25
google_ad_slot = "8619794253";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />&nbsp;</div>