library IEEE; use IEEE.std_logic_1164.all; entity smexamp is port ( CLOCK, A, B: in STD_LOGIC; Z: out STD_LOGIC ); end; architecture smexampm_arch of smexamp is type Sreg_type is (INIT, A0, A1, OK0, OK1); signal Sreg: Sreg_type; begin process (CLOCK, Sreg) -- state-machine states and transitions begin if CLOCK'event and CLOCK = '1' then case Sreg is when INIT => if A='0' then Sreg <= A0; elsif A='1' then Sreg <= A1; end if; when A0 => if A='0' then Sreg <= OK0; elsif A='1' then Sreg <= A1; end if; when A1 => if A='0' then Sreg <= A0; elsif A='1' then Sreg <= OK1; end if; when OK0 => if A='0' then Sreg <= OK0; elsif A='1' and B='0' then Sreg <= A1; elsif A='1' and B='1' then Sreg <= OK1; end if; when OK1 => if A='0' and B='0' then Sreg <= A0; elsif A='0' and B='1' then Sreg <= OK0; elsif A='1' then Sreg <= OK1; end if; when others => Sreg <= INIT; end case; case Sreg is -- output values based on state when INIT | A0 | A1 => Z <= '0'; when OK0 | OK1 => Z <= '1'; when others => Z <= '0'; end case; end if; end process; end smexampm_arch;