control_fsm_rtl.vhd
上传用户:sztwq510
上传日期:2007-04-20
资源大小:209k
文件大小:97k
源码类别:

VHDL/FPGA/Verilog

开发平台:

Matlab

  1. -------------------------------------------------------------------------------
  2. --                                                                           --
  3. --          X       X   XXXXXX    XXXXXX    XXXXXX    XXXXXX      X          --
  4. --          XX     XX  X      X  X      X  X      X  X           XX          --
  5. --          X X   X X  X         X      X  X      X  X          X X          --
  6. --          X  X X  X  X         X      X  X      X  X         X  X          --
  7. --          X   X   X  X          XXXXXX   X      X   XXXXXX      X          --
  8. --          X       X  X         X      X  X      X         X     X          --
  9. --          X       X  X         X      X  X      X         X     X          --
  10. --          X       X  X      X  X      X  X      X         X     X          --
  11. --          X       X   XXXXXX    XXXXXX    XXXXXX    XXXXXX      X          --
  12. --                                                                           --
  13. --                                                                           --
  14. --                       O R E G A N O   S Y S T E M S                       --
  15. --                                                                           --
  16. --                            Design & Consulting                            --
  17. --                                                                           --
  18. -------------------------------------------------------------------------------
  19. --                                                                           --
  20. --         Web:           http://www.oregano.at/                             --
  21. --                                                                           --
  22. --         Contact:       mc8051@oregano.at                                  --
  23. --                                                                           --
  24. -------------------------------------------------------------------------------
  25. --                                                                           --
  26. --  MC8051 - VHDL 8051 Microcontroller IP Core                               --
  27. --  Copyright (C) 2001 OREGANO SYSTEMS                                       --
  28. --                                                                           --
  29. --  This library is free software; you can redistribute it and/or            --
  30. --  modify it under the terms of the GNU Lesser General Public               --
  31. --  License as published by the Free Software Foundation; either             --
  32. --  version 2.1 of the License, or (at your option) any later version.       --
  33. --                                                                           --
  34. --  This library is distributed in the hope that it will be useful,          --
  35. --  but WITHOUT ANY WARRANTY; without even the implied warranty of           --
  36. --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        --
  37. --  Lesser General Public License for more details.                          --
  38. --                                                                           --
  39. --  Full details of the license can be found in the file LGPL.TXT.           --
  40. --                                                                           --
  41. --  You should have received a copy of the GNU Lesser General Public         --
  42. --  License along with this library; if not, write to the Free Software      --
  43. --  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  --
  44. --                                                                           --
  45. -------------------------------------------------------------------------------
  46. --
  47. --
  48. --         Author:                 Helmut Mayrhofer
  49. --
  50. --         Filename:               control_fsm_rtl.vhd
  51. --
  52. --         Date of Creation:       Mon Aug  9 12:14:48 1999
  53. --
  54. --         Version:                $Revision: 1.6 $
  55. --
  56. --         Date of Latest Version: $Date: 2002/01/07 12:17:44 $
  57. --
  58. --
  59. --         Description: Decode instruction and execute it. Pure combinational
  60. --                      descripton of the finite state machine.
  61. --
  62. --
  63. --
  64. --
  65. -------------------------------------------------------------------------------
  66. architecture rtl of control_fsm is
  67.   alias CY : std_logic is psw(7);              -- carry
  68.   alias AC : std_logic is psw(6);              -- auxilary carry
  69.   alias OV : std_logic is psw(2);              -- overflow flag
  70.   alias EA:  std_logic is ie(7);               -- enable interupts
  71.   alias ES:  std_logic is ie(4);               -- enable serial interupt
  72.   alias ET1: std_logic is ie(3);               -- enable timer 1 interupt
  73.   alias EX1: std_logic is ie(2);               -- enable external 1 interupt
  74.   alias ET0: std_logic is ie(1);               -- enable timer 0 interupt
  75.   alias EX0: std_logic is ie(0);               -- enable external 0 interupt
  76.   alias PS0: std_logic is ip(4);               -- priority of serial interupt
  77.   alias PT1: std_logic is ip(3);               -- priority of timer1 interupt
  78.   alias PX1: std_logic is ip(2);               -- priority of ext1 interupt
  79.   alias PT0: std_logic is ip(1);               -- priority of timer0 interupt
  80.   alias PX0: std_logic is ip(0);               -- priority of ext0 interupt
  81.   signal state:         t_state;               -- actual state
  82.   signal s_nextstate:   t_state;               -- enable signal for state
  83.   signal s_instr_category : t_instr_category;  -- predecoded insturction
  84.   
  85.   signal s_help:        unsigned (7 downto 0); -- general help-register
  86.   signal s_bit_data :   std_logic;             -- bitdata from MUX
  87.   signal s_intpre:      std_logic;             -- an interrupt must start
  88.   signal s_intpre2:     std_logic;             -- prepare for interrupt
  89.   signal s_inthigh:     std_logic;             -- high priority int is running
  90.   signal s_intlow:      std_logic;             -- low priority int is running
  91.   signal s_tf1 :        std_logic;               -- Timer1-Overflowflag
  92.   signal s_tf0 :        std_logic;               -- Timer0-Overflowflag
  93.   signal s_ie1 :        std_logic;               -- ExtINT1-Flag
  94.   signal s_it1 :        std_logic;               -- edge-sensitive-Bit EXT1
  95.   signal s_ie0 :        std_logic;               -- ExtINT0-Flag
  96.   signal s_it0 :        std_logic;               -- edge-sensitive-Bit EXT0
  97.   signal s_ri : std_logic;                       -- serial receive-ready
  98.   signal s_ti : std_logic;                       -- serial transmit-ready
  99.   signal s_command:     std_logic_vector (7 downto 0); -- actual command
  100.   signal s_pc_inc_en  : std_logic_vector (3 downto 0);  -- pc control
  101.   signal s_regs_wr_en : std_logic_vector (2 downto 0);  -- write control
  102.   signal s_data_mux   : std_logic_vector (3 downto 0);  -- data control
  103.   signal s_bdata_mux  : std_logic_vector (3 downto 0);  -- bitdata control
  104.   signal s_adr_mux    : std_logic_vector (3 downto 0);  -- adress control
  105.   signal s_adrx_mux   : std_logic_vector (1 downto 0);  -- ext. adress control
  106.   signal s_wrx_mux    : std_logic;                      -- ext. write control
  107.   signal s_help_en    : std_logic_vector (3 downto 0);  -- helpreg control
  108.   signal s_help16_en  : std_logic_vector (1 downto 0);  -- help16 control
  109.   signal s_helpb_en   : std_logic;                      -- helpbit control
  110.   signal s_intpre2_d  : std_logic;                      -- intput of intpre2
  111.   signal s_intpre2_en : std_logic;                      -- control
  112.   signal s_intlow_d   : std_logic;                      -- input of intlow
  113.   signal s_intlow_en  : std_logic;                      -- control
  114.   signal s_inthigh_d  : std_logic;                      -- input of inthigh
  115.   signal s_inthigh_en : std_logic;                      -- control
  116. begin
  117.   -- some simple signal-assignments for outputs
  118.   pc_inc_en_o  <= s_pc_inc_en;
  119.   nextstate_o  <= s_nextstate;
  120.   adr_mux_o    <= s_adr_mux;
  121.   adrx_mux_o   <= s_adrx_mux;
  122.   wrx_mux_o    <= s_wrx_mux;
  123.   data_mux_o   <= s_data_mux;
  124.   bdata_mux_o  <= s_bdata_mux;
  125.   regs_wr_en_o <= s_regs_wr_en;
  126.   help_en_o    <= s_help_en;
  127.   help16_en_o  <= s_help16_en;
  128.   helpb_en_o   <= s_helpb_en;
  129.   inthigh_en_o <= s_inthigh_en;
  130.   intlow_en_o  <= s_intlow_en;
  131.   intpre2_en_o <= s_intpre2_en;
  132.   inthigh_d_o  <= s_inthigh_d;
  133.   intlow_d_o   <= s_intlow_d;
  134.   intpre2_d_o  <= s_intpre2_d;
  135.   -- some simple signal assignments from intputs
  136.   state      <= state_i;
  137.   s_help     <= unsigned(help_i);
  138.   s_bit_data <= bit_data_i;
  139.   s_command  <= command_i;
  140.   s_inthigh  <= inthigh_i;
  141.   s_intlow   <= intlow_i;
  142.   s_intpre   <= intpre_i;
  143.   s_intpre2  <= intpre2_i;
  144.   s_ti       <= ti_i;
  145.   s_ri       <= ri_i;
  146.   s_it0      <= it0_i;
  147.   s_ie0      <= ie0_i;
  148.   s_it1      <= it1_i;
  149.   s_ie1      <= ie1_i;
  150.   s_tf0      <= tf0_i;
  151.   s_tf1      <= tf1_i;
  152.   -- predecode instruction
  153.   s_instr_category <=
  154.     IC_ACALL          when s_command(4 downto 0) = ACALL          else
  155.     IC_ADD_A_RR       when s_command(7 downto 3) = ADD_A_RR       else
  156.     IC_ADD_A_D        when s_command             = ADD_A_D        else
  157.     IC_ADD_A_ATRI     when s_command(7 downto 1) = ADD_A_ATRI     else
  158.     IC_ADD_A_DATA     when s_command             = ADD_A_DATA     else
  159.     IC_ADDC_A_RR      when s_command(7 downto 3) = ADDC_A_RR      else
  160.     IC_ADDC_A_D       when s_command             = ADDC_A_D       else
  161.     IC_ADDC_A_ATRI    when s_command(7 downto 1) = ADDC_A_ATRI    else
  162.     IC_ADDC_A_DATA    when s_command             = ADDC_A_DATA    else
  163.     IC_AJMP           when s_command(4 downto 0) = AJMP           else
  164.     IC_ANL_A_RR       when s_command(7 downto 3) = ANL_A_RR       else
  165.     IC_ANL_A_D        when s_command             = ANL_A_D        else
  166.     IC_ANL_A_ATRI     when s_command(7 downto 1) = ANL_A_ATRI     else
  167.     IC_ANL_A_DATA     when s_command             = ANL_A_DATA     else
  168.     IC_ANL_D_A        when s_command             = ANL_D_A        else
  169.     IC_ANL_D_DATA     when s_command             = ANL_D_DATA     else
  170.     IC_ANL_C_BIT      when s_command             = ANL_C_BIT      else
  171.     IC_ANL_C_NBIT     when s_command             = ANL_C_NBIT     else
  172.     IC_CJNE_A_D       when s_command             = CJNE_A_D       else
  173.     IC_CJNE_A_DATA    when s_command             = CJNE_A_DATA    else
  174.     IC_CJNE_RR_DATA   when s_command(7 downto 3) = CJNE_RR_DATA   else
  175.     IC_CJNE_ATRI_DATA when s_command(7 downto 1) = CJNE_ATRI_DATA else
  176.     IC_CLR_A          when s_command             = CLR_A          else
  177.     IC_CLR_C          when s_command             = CLR_C          else
  178.     IC_CLR_BIT        when s_command             = CLR_BIT        else
  179.     IC_CPL_A          when s_command             = CPL_A          else
  180.     IC_CPL_C          when s_command             = CPL_C          else
  181.     IC_CPL_BIT        when s_command             = CPL_BIT        else
  182.     IC_DA_A           when s_command             = DA_A           else
  183.     IC_DEC_A          when s_command             = DEC_A          else
  184.     IC_DEC_RR         when s_command(7 downto 3) = DEC_RR         else
  185.     IC_DEC_D          when s_command             = DEC_D          else
  186.     IC_DEC_ATRI       when s_command(7 downto 1) = DEC_ATRI       else
  187.     IC_DIV_AB         when s_command             = DIV_AB         else
  188.     IC_DJNZ_RR        when s_command(7 downto 3) = DJNZ_RR        else
  189.     IC_DJNZ_D         when s_command             = DJNZ_D         else
  190.     IC_INC_A          when s_command             = INC_A          else
  191.     IC_INC_RR         when s_command(7 downto 3) = INC_RR         else
  192.     IC_INC_D          when s_command             = INC_D          else
  193.     IC_INC_ATRI       when s_command(7 downto 1) = INC_ATRI       else
  194.     IC_INC_DPTR       when s_command             = INC_DPTR       else
  195.     IC_JB             when s_command             = JB             else
  196.     IC_JBC            when s_command             = JBC            else
  197.     IC_JC             when s_command             = JC             else
  198.     IC_JMP_A_DPTR     when s_command             = JMP_A_DPTR     else
  199.     IC_JNB            when s_command             = JNB            else
  200.     IC_JNC            when s_command             = JNC            else
  201.     IC_JNZ            when s_command             = JNZ            else
  202.     IC_JZ             when s_command             = JZ             else
  203.     IC_LCALL          when s_command             = LCALL          else
  204.     IC_LJMP           when s_command             = LJMP           else
  205.     IC_MOV_A_RR       when s_command(7 downto 3) = MOV_A_RR       else
  206.     IC_MOV_A_D        when s_command             = MOV_A_D        else
  207.     IC_MOV_A_ATRI     when s_command(7 downto 1) = MOV_A_ATRI     else
  208.     IC_MOV_A_DATA     when s_command             = MOV_A_DATA     else
  209.     IC_MOV_RR_A       when s_command(7 downto 3) = MOV_RR_A       else
  210.     IC_MOV_RR_D       when s_command(7 downto 3) = MOV_RR_D       else
  211.     IC_MOV_RR_DATA    when s_command(7 downto 3) = MOV_RR_DATA    else
  212.     IC_MOV_D_A        when s_command             = MOV_D_A        else
  213.     IC_MOV_D_RR       when s_command(7 downto 3) = MOV_D_RR       else
  214.     IC_MOV_D_D        when s_command             = MOV_D_D        else
  215.     IC_MOV_D_ATRI     when s_command(7 downto 1) = MOV_D_ATRI     else
  216.     IC_MOV_D_DATA     when s_command             = MOV_D_DATA     else
  217.     IC_MOV_ATRI_A     when s_command(7 downto 1) = MOV_ATRI_A     else
  218.     IC_MOV_ATRI_D     when s_command(7 downto 1) = MOV_ATRI_D     else
  219.     IC_MOV_ATRI_DATA  when s_command(7 downto 1) = MOV_ATRI_DATA  else
  220.     IC_MOVC_A_ATDPTR  when s_command             = MOVC_A_ATDPTR  else
  221.     IC_MOVC_A_ATPC    when s_command             = MOVC_A_ATPC    else
  222.     IC_MOVX_A_ATRI    when s_command(7 downto 1) = MOVX_A_ATRI    else
  223.     IC_MOVX_A_ATDPTR  when s_command             = MOVX_A_ATDPTR  else
  224.     IC_MOVX_ATRI_A    when s_command(7 downto 1) = MOVX_ATRI_A    else
  225.     IC_MOVX_ATDPTR_A  when s_command             = MOVX_ATDPTR_A  else
  226.     IC_MOV_C_BIT      when s_command             = MOV_C_BIT      else
  227.     IC_MOV_BIT_C      when s_command             = MOV_BIT_C      else
  228.     IC_MOV_DPTR_DATA  when s_command             = MOV_DPTR_DATA  else
  229.     IC_MUL_AB         when s_command             = MUL_AB         else
  230.     IC_NOP            when s_command             = NOP            else
  231.     IC_ORL_A_RR       when s_command(7 downto 3) = ORL_A_RR       else
  232.     IC_ORL_A_D        when s_command             = ORL_A_D        else
  233.     IC_ORL_A_ATRI     when s_command(7 downto 1) = ORL_A_ATRI     else
  234.     IC_ORL_A_DATA     when s_command             = ORL_A_DATA     else
  235.     IC_ORL_D_A        when s_command             = ORL_D_A        else
  236.     IC_ORL_D_DATA     when s_command             = ORL_D_DATA     else
  237.     IC_ORL_C_BIT      when s_command             = ORL_C_BIT      else
  238.     IC_ORL_C_NBIT     when s_command             = ORL_C_NBIT     else
  239.     IC_POP            when s_command             = POP            else
  240.     IC_PUSH           when s_command             = PUSH           else
  241.     IC_RET            when s_command             = RET            else
  242.     IC_RETI           when s_command             = RETI           else
  243.     IC_RL_A           when s_command             = RL_A           else
  244.     IC_RLC_A          when s_command             = RLC_A          else
  245.     IC_RR_A           when s_command             = RR_A           else
  246.     IC_RRC_A          when s_command             = RRC_A          else
  247.     IC_SETB_C         when s_command             = SETB_C         else
  248.     IC_SETB_BIT       when s_command             = SETB_BIT       else
  249.     IC_SJMP           when s_command             = SJMP           else
  250.     IC_SUBB_A_RR      when s_command(7 downto 3) = SUBB_A_RR      else
  251.     IC_SUBB_A_D       when s_command             = SUBB_A_D       else
  252.     IC_SUBB_A_ATRI    when s_command(7 downto 1) = SUBB_A_ATRI    else
  253.     IC_SUBB_A_DATA    when s_command             = SUBB_A_DATA    else
  254.     IC_SWAP_A         when s_command             = SWAP_A         else
  255.     IC_XCH_A_RR       when s_command(7 downto 3) = XCH_A_RR       else
  256.     IC_XCH_A_D        when s_command             = XCH_A_D        else
  257.     IC_XCH_A_ATRI     when s_command(7 downto 1) = XCH_A_ATRI     else
  258.     IC_XCHD_A_ATRI    when s_command(7 downto 1) = XCHD_A_ATRI    else
  259.     IC_XRL_A_RR       when s_command(7 downto 3) = XRL_A_RR       else
  260.     IC_XRL_A_D        when s_command             = XRL_A_D        else
  261.     IC_XRL_A_ATRI     when s_command(7 downto 1) = XRL_A_ATRI     else
  262.     IC_XRL_A_DATA     when s_command             = XRL_A_DATA     else
  263.     IC_XRL_D_A        when s_command             = XRL_D_A        else
  264.     IC_XRL_D_DATA     when s_command             = XRL_D_DATA     else
  265.     IC_NOP;
  266.   
  267. ------------------------------------------------------------------------------
  268. -- purpose: main-process to control the mcu
  269. --          includes the interupt-handling and the state machine
  270. -- inputs:  state,s_help,s_ti,s_ri,s_it0,s_ie0,s_it1,s_ie1,s_tf0,s_tf1,
  271. --          s_bit_data,aludata_i,s_command,s_inthigh,
  272. --          s_intlow,acc,psw,s_intpre,s_intpre2,ie,ip
  273. -- outputs: pc_inc_en_o,s_nextstate_o,adr_mux_o,data_mux_o,bdata_mux_o
  274. --          regs_wr_en_o,help_en_o,help16_en_o,helpb_en_o,inthigh_en_o
  275. --          intlow_en_o,intpre2_en_o,inthigh_d_o,intlow_d_o,intpre2_d_o
  276. ------------------------------------------------------------------------------
  277.  p_state: process (state,s_help,s_ti,s_ri,s_it0,s_ie0,s_it1,s_ie1,s_tf0,s_tf1,
  278.                    s_bit_data,aludata_i,s_instr_category,s_inthigh,
  279.                    s_intlow,acc,psw,s_intpre,s_intpre2,ie,ip)
  280.   begin
  281.     s_data_mux   <= "0000";             -- default values
  282.     s_adr_mux    <= "0000";
  283.     s_bdata_mux  <= "0000";
  284.     alu_cmd_o    <= OFF;
  285.     s_regs_wr_en <= "000";
  286.     s_help_en    <= "0000";
  287.     s_help16_en  <= "00";
  288.     s_helpb_en   <= '0';
  289.     s_pc_inc_en  <= "0000";
  290.     s_inthigh_en <= '0';
  291.     s_intlow_en  <= '0';
  292.     s_intpre2_en <= '0';
  293.     s_inthigh_d  <= '0';
  294.     s_intlow_d   <= '0';
  295.     s_intpre2_d  <= '0';
  296.     s_adrx_mux   <= "00";
  297.     s_wrx_mux    <= '0';
  298.     s_nextstate  <= FETCH;
  299.     if state=STARTUP then
  300.       -- Power up wait cycle
  301.       NULL;
  302.     else
  303.       -- begin of starting the interrupt procedure
  304.                                                       -- saving the old adress
  305.       if (s_intpre='1' and state=FETCH) or s_intpre2='1' then
  306.         if state=FETCH then
  307.           s_intpre2_en <= '1';
  308.           s_intpre2_d <= '1';
  309.           s_regs_wr_en <= "001";            -- increment stackpointer
  310.           s_nextstate <= EXEC1;
  311.         elsif state=EXEC1 then
  312.           if (PX0 and EX0 and s_ie0)='1' then   -- external interrupt 0
  313.             s_help_en <= "0101";                -- interruptvector 0003h
  314.             s_inthigh_d <= '1';
  315.             s_inthigh_en <= '1';
  316.             if s_it0='1' then         -- interrupt is edge-sensitive
  317.               s_adr_mux <= "0001";
  318.               s_regs_wr_en <= "110";  -- reset IE0
  319.             else
  320.               NULL;
  321.             end if;
  322.           elsif (PT0 and ET0 and s_tf0)='1' then  -- timer interrupt 0
  323.             s_help_en <= "0110";                  -- interruptvector 000Bh
  324.             s_inthigh_d <= '1';
  325.             s_inthigh_en <= '1';
  326.             s_adr_mux <= "0010";
  327.             s_regs_wr_en <= "110";                -- reset TF0
  328.           elsif (PX1 and EX1 and s_ie1)='1' then  -- external interrupt 1
  329.             s_help_en <= "0111";                  -- interruptvector 0013h
  330.             s_inthigh_d <= '1';
  331.             s_inthigh_en <= '1';
  332.             if s_it1='1' then         -- interrupt is edge-sensitive
  333.               s_adr_mux <= "0011";
  334.               s_regs_wr_en <= "110";  -- reset IE1
  335.             else
  336.               NULL;
  337.             end if;
  338.           elsif (PT1 and ET1 and s_tf1)='1' then  -- timer interrupt 1
  339.             s_help_en <= "1000";                  -- interruptvector 001Bh
  340.             s_inthigh_d <= '1';
  341.             s_inthigh_en <= '1';
  342.             s_adr_mux <= "0100";
  343.             s_regs_wr_en <= "110";          -- reset TF1
  344.           elsif (PS0 and ES and (s_ri or s_ti))='1' then -- serial interrupt 0
  345.             s_help_en <= "1001";            -- interruptvector 0023h
  346.             s_inthigh_d <= '1';
  347.             s_inthigh_en <= '1';
  348.          elsif (EX0 and s_ie0)='1' then   -- external interrupt 0 low priority
  349.             s_help_en <= "0101";          -- interruptvector 0003h
  350.             s_intlow_d <= '1';
  351.             s_intlow_en <= '1';
  352.             if s_it0='1' then         -- interrupt is edge-sensitive
  353.               s_adr_mux <= "0001";
  354.               s_regs_wr_en <= "110";  -- reset IE0
  355.             else
  356.               NULL;
  357.             end if;
  358.           elsif (ET0 and s_tf0)='1' then   -- timer interrupt 0 low priority
  359.             s_help_en <= "0110";           -- interruptvector 000Bh
  360.             s_intlow_d <= '1';
  361.             s_intlow_en <= '1';
  362.             s_adr_mux <= "0010";
  363.             s_regs_wr_en <= "110";         -- reset TF0
  364.           elsif (EX1 and s_ie1)='1' then   -- external interrupt 1 low priority
  365.             s_help_en <= "0111";           -- interruptvector 0013h
  366.             s_intlow_d <= '1';
  367.             s_intlow_en <= '1';
  368.             if s_it0='1' then         -- interrupt is edge-sensitive
  369.               s_adr_mux <= "0011";
  370.               s_regs_wr_en <= "110";  -- reset IE1
  371.             else
  372.               NULL;
  373.             end if;
  374.           elsif (ET1 and s_tf1)='1' then   -- timer interrupt 1 low priority
  375.             s_help_en <= "1000";           -- interruptvector 001Bh
  376.             s_intlow_d <= '1';
  377.             s_intlow_en <= '1';
  378.             s_adr_mux <= "0100";
  379.             s_regs_wr_en <= "110";               -- reset TF1
  380.           elsif (ES and (s_ri or s_ti))='1' then -- serial int 0 low priority
  381.             s_help_en <= "1001";                 -- interruptvector 0023h
  382.             s_intlow_d <= '1';
  383.             s_intlow_en <= '1';
  384.           else
  385.             NULL;
  386.           end if;
  387.           s_nextstate <= EXEC2;
  388.         elsif state=EXEC2 then
  389.           s_adr_mux <= "0101";
  390.           s_data_mux <= "0001";         -- data = pc(7 downto 0)
  391.           s_regs_wr_en <= "101";        -- write one byte and increment SP
  392.           s_nextstate <= EXEC3;
  393.         elsif state=EXEC3 then
  394.           s_intpre2_d <= '0';
  395.           s_intpre2_en <= '1';
  396.           s_adr_mux <= "0101";
  397.           s_data_mux <= "0010";         -- data = pc(15 downto 8)
  398.           s_regs_wr_en <= "100";        -- write one byte
  399.           s_pc_inc_en <= "0011";        -- load program counter
  400.           s_nextstate <= FETCH;
  401.         else
  402.           s_nextstate <= FETCH;
  403.         end if;
  404.        -- end of starting interrupt procedure
  405.        else
  406.         case s_instr_category is
  407.           ---------------------------------------------------------------------
  408.           when IC_ACALL =>              -- ACALL addr11
  409.             if state=FETCH then
  410.               s_adr_mux <= "1111";      -- adress = sp + 1
  411.               s_data_mux <= "1110";     -- data = (pc+2)(7 downto 0)
  412.               s_regs_wr_en <= "101";    -- write one byte and increment SP
  413.               s_help16_en <= "10";      -- s_help16 = pc+2
  414.               s_pc_inc_en <= "0001";    -- increment program-counter
  415.               s_nextstate <= EXEC1;
  416.             elsif state=EXEC1 then
  417.               s_adr_mux <= "1111";       -- adress = sp + 1
  418.               s_data_mux <= "1101";      -- data = s_help16(15 downto 8)
  419.               s_regs_wr_en <= "101";     -- write one byte and increment SP
  420.               s_pc_inc_en <= "0100";     -- load PC with 11 bits (2k block)
  421.               s_nextstate <= FETCH;
  422.             end if;
  423.           ---------------------------------------------------------------------
  424.           when IC_ADD_A_RR =>           -- ADD A,Rr
  425.             if state=FETCH then
  426.               s_adr_mux <= "0110";      -- adress = RR-adress
  427.               s_nextstate <= EXEC1;
  428.             elsif state=EXEC1 then
  429.               alu_cmd_o <= ADD_ACC_RAM; -- addition command (ACC + RAM_DATA)
  430.               s_data_mux <= "0011";     -- data = aludata_i
  431.               s_regs_wr_en <= "011";    -- write ACC and CY,OV,AC
  432.               s_pc_inc_en <= "0001";    -- increment program-counter
  433.               s_nextstate <= FETCH;
  434.             end if;
  435.           ---------------------------------------------------------------------
  436.           when IC_ADD_A_D =>            -- ADD A, direct
  437.             if state=FETCH then
  438.               s_pc_inc_en <= "0001";    -- increment program-counter
  439.               s_nextstate <= EXEC1;
  440.             elsif state=EXEC1 then
  441.               s_adr_mux <= "1000";      -- adress = rom_data_i
  442.               s_nextstate <= EXEC2;
  443.             elsif state=EXEC2 then
  444.               alu_cmd_o <= ADD_ACC_RAM; -- addition command (ACC + RAM_DATA)
  445.               s_data_mux <= "0011";     -- data = aludata_i
  446.               s_regs_wr_en <= "011";    -- write ACC and CY,OV,AC
  447.               s_pc_inc_en <= "0001";    -- increment program-counter
  448.               s_nextstate <= FETCH;
  449.             end if;
  450.           ---------------------------------------------------------------------
  451.           when IC_ADD_A_ATRI =>         -- ADD A,@Ri
  452.             if state=FETCH then
  453.               s_adr_mux <= "0111";      -- address = Ri-register
  454.               s_nextstate <= EXEC1;
  455.             elsif state=EXEC1 then
  456.               alu_cmd_o <= ADD_ACC_RAM; -- addition command (ACC + RAM_DATA)
  457.               s_data_mux <= "0011";     -- data = aludata_i
  458.               s_regs_wr_en <= "011";    -- write ACC and CY,OV,AC
  459.               s_pc_inc_en <= "0001";    -- increment program-counter
  460.               s_nextstate <= FETCH;
  461.             end if;
  462.           ---------------------------------------------------------------------
  463.           when IC_ADD_A_DATA =>         -- ADD A, DATA
  464.             if state=FETCH then
  465.               s_pc_inc_en <= "0001";    -- increment program-counter
  466.               s_nextstate <= EXEC1;
  467.             elsif state=EXEC1 then
  468.               alu_cmd_o <= ADD_ACC_ROM; -- addition command (ACC + ROM_DATA_I)
  469.               s_data_mux <= "0011";     -- data = aludata_i
  470.               s_regs_wr_en <= "011";    -- write ACC and CY,OV,AC
  471.               s_pc_inc_en <= "0001";    -- increment program-counter
  472.               s_nextstate <= FETCH;
  473.             end if;
  474.           ---------------------------------------------------------------------
  475.           when IC_ADDC_A_RR =>          -- ADDC A,Rr
  476.             if state=FETCH then
  477.               s_adr_mux <= "0110";      -- adress = RR-adress
  478.               s_nextstate <= EXEC1;
  479.             elsif state=EXEC1 then
  480.               alu_cmd_o <= ADDC_ACC_RAM;  -- addition command (ACC+RAM_DATA+CY)
  481.               s_data_mux <= "0011";       -- data = aludata_i
  482.               s_regs_wr_en <= "011";      -- write ACC and CY,OV,AC
  483.               s_pc_inc_en <= "0001";      -- increment program-counter
  484.               s_nextstate <= FETCH;
  485.             end if;
  486.           ---------------------------------------------------------------------
  487.           when IC_ADDC_A_D =>           -- ADDC A, direct
  488.             if state=FETCH then
  489.               s_pc_inc_en <= "0001";    -- increment program-counter
  490.               s_nextstate <= EXEC1;
  491.             elsif state=EXEC1 then
  492.               s_adr_mux <= "1000";      -- adress = rom_data_i
  493.               s_nextstate <= EXEC2;
  494.             elsif state=EXEC2 then
  495.               alu_cmd_o <= ADDC_ACC_RAM;  -- addition command (ACC+RAM_DATA+CY)
  496.               s_data_mux <= "0011";       -- data = aludata_i
  497.               s_regs_wr_en <= "011";      -- write ACC and CY,OV,AC
  498.               s_pc_inc_en <= "0001";      -- increment program-counter
  499.               s_nextstate <= FETCH;
  500.             end if;
  501.           ---------------------------------------------------------------------
  502.           when IC_ADDC_A_ATRI =>        -- ADDC A,@Ri
  503.             if state=FETCH then
  504.               s_adr_mux <= "0111";      -- address = Ri-register
  505.               s_nextstate <= EXEC1;
  506.             elsif state=EXEC1 then
  507.               alu_cmd_o <= ADDC_ACC_RAM;  -- addition command (ACC+RAM_DATA+CY)
  508.               s_data_mux <= "0011";       -- data = aludata_i
  509.               s_regs_wr_en <= "011";      -- write ACC and CY,OV,AC
  510.               s_pc_inc_en <= "0001";      -- increment program-counter
  511.               s_nextstate <= FETCH;
  512.             end if;
  513.           ---------------------------------------------------------------------
  514.           when IC_ADDC_A_DATA =>        -- ADDC A, data
  515.             if state=FETCH then
  516.               s_pc_inc_en <= "0001";    -- increment program-counter
  517.               s_nextstate <= EXEC1;
  518.             elsif state=EXEC1 then
  519.               alu_cmd_o <= ADDC_ACC_ROM;-- addition command (ACC+ROM_DATA_I+CY)
  520.               s_data_mux <= "0011";     -- data = aludata_i
  521.               s_regs_wr_en <= "011";    -- write ACC and CY,OV,AC
  522.               s_pc_inc_en <= "0001";    -- increment program-counter
  523.               s_nextstate <= FETCH;
  524.             end if;
  525.           ---------------------------------------------------------------------
  526.           when IC_AJMP =>               -- AJMP addr11
  527.             if state=FETCH then
  528.               s_help16_en <= "10";      -- s_help16 = pc+2
  529.               s_pc_inc_en <= "0001";    -- increment program-counter
  530.               s_nextstate <= EXEC1;
  531.             elsif state=EXEC1 then
  532.               s_pc_inc_en <= "0100";    -- load PC with 11 bits (2k block)
  533.               s_nextstate <= FETCH;
  534.             end if;
  535.           ---------------------------------------------------------------------
  536.           when IC_ANL_A_RR =>           -- ANL A,Rr
  537.             if state=FETCH then
  538.               s_adr_mux <= "0110";      -- adress = RR-adress
  539.               s_nextstate <= EXEC1;
  540.             elsif state=EXEC1 then
  541.               alu_cmd_o <= AND_ACC_RAM; -- AND command (ACC ^ RAM_DATA)
  542.               s_data_mux <= "0011";     -- data = aludata_i
  543.               s_regs_wr_en <= "010";    -- write ACC
  544.               s_pc_inc_en <= "0001";    -- increment program-counter
  545.               s_nextstate <= FETCH;
  546.             end if;
  547.           ---------------------------------------------------------------------
  548.           when IC_ANL_A_D =>            -- ANL A, direct
  549.             if state=FETCH then
  550.               s_pc_inc_en <= "0001";    -- increment program-counter
  551.               s_nextstate <= EXEC1;
  552.             elsif state=EXEC1 then
  553.               s_adr_mux <= "1000";      -- address = rom_data_i
  554.               s_nextstate <= EXEC2;
  555.             elsif state=EXEC2 then
  556.               alu_cmd_o <= AND_ACC_RAM; -- AND command (ACC ^ RAM_DATA)
  557.               s_data_mux <= "0011";     -- data = aludata_i
  558.               s_regs_wr_en <= "010";    -- write ACC
  559.               s_pc_inc_en <= "0001";    -- increment program-counter
  560.               s_nextstate <= FETCH;
  561.             end if;
  562.           ---------------------------------------------------------------------
  563.           when IC_ANL_A_ATRI =>          -- ANL A,ATRi
  564.             if state=FETCH then
  565.               s_adr_mux <= "0111";       -- address = Ri-register
  566.               s_nextstate <= EXEC1;
  567.             elsif state=EXEC1 then
  568.               alu_cmd_o <= AND_ACC_RAM;  -- AND command (ACC ^ RAM_DATA)
  569.               s_data_mux <= "0011";      -- data = aludata_i
  570.               s_regs_wr_en <= "010";     -- write ACC
  571.               s_pc_inc_en <= "0001";     -- increment program-counter
  572.               s_nextstate <= FETCH;
  573.             end if;
  574.           ---------------------------------------------------------------------
  575.           when IC_ANL_A_DATA =>          -- ANL A, data
  576.             if state=FETCH then
  577.               s_pc_inc_en <= "0001";     -- increment program-counter
  578.               s_nextstate <= EXEC1;
  579.             elsif state=EXEC1 then
  580.               alu_cmd_o <= AND_ACC_ROM;   -- AND command (ACC ^ ROM_DATA_I)
  581.               s_data_mux <= "0011";       -- data = aludata_i
  582.               s_regs_wr_en <= "010";      -- write ACC
  583.               s_pc_inc_en <= "0001";      -- increment program-counter
  584.               s_nextstate <= FETCH;
  585.             end if;
  586.           ---------------------------------------------------------------------
  587.           when IC_ANL_D_A =>            -- ANL direct, A
  588.             if state=FETCH then
  589.               s_pc_inc_en <= "0001";    -- increment program-counter
  590.               s_nextstate <= EXEC1;
  591.             elsif state=EXEC1 then
  592.               s_adr_mux <= "1000";      -- adress = rom_data_i
  593.               s_nextstate <= EXEC2;
  594.             elsif state=EXEC2 then
  595.               alu_cmd_o <= AND_ACC_RAM;  -- AND command (ACC ^ RAM_DATA)
  596.               s_adr_mux <= "1000";       -- adress = rom_data_i
  597.               s_data_mux <= "0011";      -- data = aludata_i
  598.               s_regs_wr_en <= "100";     -- write one byte
  599.               s_pc_inc_en <= "0001";     -- increment program-counter
  600.               s_nextstate <= FETCH;
  601.             end if;
  602.           ---------------------------------------------------------------------
  603.           when IC_ANL_D_DATA =>         -- ANL direct, DATA
  604.             if state=FETCH then
  605.               s_pc_inc_en <= "0001";    -- increment program-counter
  606.               s_nextstate <= EXEC1;
  607.             elsif state=EXEC1 then
  608.               s_help_en <= "0001";      -- help = rom_data_i
  609.               s_adr_mux <= "1000";      -- adress = rom_data_i
  610.               s_pc_inc_en <= "0001";    -- increment program-counter
  611.               s_nextstate <= EXEC2;
  612.             elsif state=EXEC2 then
  613.               alu_cmd_o <= AND_RAM_ROM;  -- AND command (ROM_DATA_I ^ RAM_DATA)
  614.               s_adr_mux <= "1010";       -- adress = help
  615.               s_data_mux <= "0011";      -- data = aludata_i
  616.               s_regs_wr_en <= "100";     -- write one byte
  617.               s_pc_inc_en <= "0001";     -- increment program-counter
  618.               s_nextstate <= FETCH;
  619.             end if;
  620.           ---------------------------------------------------------------------
  621.           when IC_ANL_C_BIT =>          -- ANL C, bit
  622.             if state=FETCH then
  623.               s_pc_inc_en <= "0001";    -- increment program-counter
  624.               s_nextstate <= EXEC1;
  625.             elsif state=EXEC1 then
  626.               s_adr_mux <= "1000";      -- adress = rom_data_i
  627.               s_nextstate <= EXEC2;
  628.             elsif state=EXEC2 then
  629.               s_bdata_mux <= "0001";    -- bdata = s_bit_data and cy
  630.               s_regs_wr_en <= "110";    -- write one bit (automatic CY-address)
  631.               s_pc_inc_en <= "0001";    -- increment program-counter
  632.               s_nextstate <= FETCH;
  633.             end if;
  634.           ---------------------------------------------------------------------
  635.           when IC_ANL_C_NBIT =>         -- ANL C, /bit
  636.             if state=FETCH then
  637.               s_pc_inc_en <= "0001";    -- increment program-counter
  638.               s_nextstate <= EXEC1;
  639.             elsif state=EXEC1 then
  640.               s_adr_mux <= "1000";      -- adress = rom_data_i
  641.               s_nextstate <= EXEC2;
  642.             elsif state=EXEC2 then
  643.               s_bdata_mux <= "0010";    -- bdata = not (s_bit_data and cy)
  644.               s_regs_wr_en <= "110";    -- write one bit (automatic CY-address)
  645.               s_pc_inc_en <= "0001";    -- increment program-counter
  646.               s_nextstate <= FETCH;
  647.             end if;
  648.           ---------------------------------------------------------------------
  649.           when IC_CJNE_A_D =>           -- CJNE A, direct, rel
  650.             if state=FETCH then
  651.               s_pc_inc_en <= "0001";    -- increment program-counter
  652.               s_nextstate <= EXEC1;
  653.             elsif state=EXEC1 then
  654.               s_adr_mux <= "1000";      -- address = rom_data_i
  655.               s_pc_inc_en <= "0001";    -- increment program-counter
  656.               s_nextstate <= EXEC2;
  657.             elsif state=EXEC2 then
  658.               alu_cmd_o <= COMP_RAM_ACC;  -- Compare RAM_DATA/ACC operation
  659.               if unsigned(aludata_i) /= 0 then
  660.                 s_adr_mux <= "1011";      -- adress of CY
  661.                 s_bdata_mux <= "0011";    -- bdata = cby_i
  662.                 s_regs_wr_en <= "110";    -- write one bit
  663.                 s_pc_inc_en <= "0010";    -- add relativ adress to PC
  664.               else
  665.                 s_pc_inc_en <= "0001";    -- increment program-counter
  666.               end if;
  667.               s_nextstate <= FETCH;
  668.             end if;
  669.           ---------------------------------------------------------------------
  670.           when IC_CJNE_A_DATA =>        -- CJNE A, #data, rel
  671.             if state=FETCH then
  672.               s_pc_inc_en <= "0001";    -- increment program-counter
  673.               s_nextstate <= EXEC1;
  674.             elsif state=EXEC1 then
  675.               alu_cmd_o <= COMP_ROM_ACC; -- Compare ROM_DATA_I/ACC operation
  676.               s_help_en <= "0010";
  677.               s_helpb_en <= '1';         -- save new_cy_i
  678.               s_pc_inc_en <= "0001";     -- increment program-counter
  679.               s_nextstate <= EXEC2;
  680.             elsif state=EXEC2 then
  681.               if s_help /= 0 then
  682.                 s_adr_mux <= "1011";     -- adress of CY
  683.                 s_bdata_mux <= "0100";   -- bdata = s_helpb
  684.                 s_regs_wr_en <= "110";   -- write one bit
  685.                 s_pc_inc_en <= "0010";   -- add relativ adress to PC
  686.               else
  687.                 s_pc_inc_en <= "0001";   -- increment program-counter
  688.               end if;
  689.               s_nextstate <= FETCH;
  690.             end if;
  691.           ---------------------------------------------------------------------
  692.           when IC_CJNE_RR_DATA =>        -- CJNE RR, #data, rel
  693.             if state=FETCH then
  694.               s_adr_mux <= "0110";       -- address = rr-address
  695.               s_pc_inc_en <= "0001";     -- increment program-counter
  696.               s_nextstate <= EXEC1;
  697.             elsif state=EXEC1 then
  698.               alu_cmd_o <= COMP_ROM_RAM;-- Compare ROM_DATA_I/RAM_DATA operat.
  699.               s_help_en <= "0010";      -- save aludata_i
  700.               s_helpb_en <= '1';        -- save new_cy_i
  701.               s_pc_inc_en <= "0001";    -- increment program-counter
  702.               s_nextstate <= EXEC2;
  703.             elsif state=EXEC2 then
  704.               if s_help /= 0 then
  705.                 s_adr_mux <= "1011";     -- adress of CY
  706.                 s_bdata_mux <= "0100";   -- bdata = s_helpb
  707.                 s_regs_wr_en <= "110";   -- write one bit
  708.                 s_pc_inc_en <= "0010";   -- add relativ adress to PC
  709.               else
  710.                 s_pc_inc_en <= "0001";   -- increment program-counter
  711.               end if;
  712.               s_nextstate <= FETCH;
  713.             end if;
  714.           ---------------------------------------------------------------------
  715.           when IC_CJNE_ATRI_DATA =>       -- CJNE @Ri, #data, rel
  716.             if state=FETCH then
  717.               s_adr_mux <= "0111";        -- address = Ri-register
  718.               s_pc_inc_en <= "0001";      -- increment program-counter
  719.               s_nextstate <= EXEC1;
  720.             elsif state=EXEC1 then
  721.               alu_cmd_o <= COMP_ROM_RAM;  -- Compare ROM_/RAM_DATA operation
  722.               s_help_en <= "0010";        -- save aludata_i
  723.               s_helpb_en <= '1';          -- save new_cy_i
  724.               s_pc_inc_en <= "0001";      -- increment program-counter
  725.               s_nextstate <= EXEC2;
  726.             elsif state=EXEC2 then
  727.               if s_help /= 0 then
  728.                 s_adr_mux <= "1011";     -- adress of CY
  729.                 s_bdata_mux <= "0100";   -- bdata = s_helpb
  730.                 s_regs_wr_en <= "110";   -- write one bit
  731.                 s_pc_inc_en <= "0010";   -- add relativ adress to PC
  732.               else
  733.                 s_pc_inc_en <= "0001";   -- increment program-counter
  734.               end if;
  735.               s_nextstate <= FETCH;
  736.             end if;
  737.           ---------------------------------------------------------------------
  738.           when IC_CLR_A =>              -- CLR A
  739.             s_data_mux <= "0000";       -- data = 0
  740.             s_regs_wr_en <= "010";      -- write ACC
  741.             s_pc_inc_en <= "0001";      -- increment program-counter
  742.             s_nextstate <= FETCH;
  743.           ---------------------------------------------------------------------
  744.           when IC_CLR_C =>              -- CLR C
  745.             s_adr_mux <= "1011";        -- adress of CY
  746.             s_bdata_mux <= "0000";      -- bdata = 0
  747.             s_regs_wr_en <= "110";      -- write one bit
  748.             s_pc_inc_en <= "0001";      -- increment program-counter
  749.             s_nextstate <= FETCH;
  750.           ---------------------------------------------------------------------
  751.           when IC_CLR_BIT =>            -- CLR bit
  752.             if state=FETCH then
  753.               s_pc_inc_en <= "0001";    -- increment program-counter
  754.               s_nextstate <= EXEC1;
  755.             elsif state=EXEC1 then
  756.               s_adr_mux <= "1000";      -- address = rom_data_i
  757.               s_bdata_mux <= "0000";    -- bdata = 0
  758.               s_regs_wr_en <= "110";    -- write one bit
  759.               s_pc_inc_en <= "0001";    -- increment program-counter
  760.               s_nextstate <= FETCH;
  761.             end if;
  762.           ---------------------------------------------------------------------
  763.           when IC_CPL_A =>              -- CPL A
  764.             alu_cmd_o <= INV_ACC;       -- complement operation
  765.             s_data_mux <= "0011";       -- data = aludata_i
  766.             s_regs_wr_en <= "010";      -- write ACC
  767.             s_pc_inc_en <= "0001";      -- increment program-counter
  768.             s_nextstate <= FETCH;
  769.           ---------------------------------------------------------------------
  770.           when IC_CPL_C =>              -- CPL C
  771.             s_adr_mux <= "1011";        -- adress of CY
  772.             s_bdata_mux <= "0101";      -- bdata = not cy
  773.             s_regs_wr_en <= "110";      -- write one bit
  774.             s_pc_inc_en <= "0001";      -- increment program-counter
  775.             s_nextstate <= FETCH;
  776.           ---------------------------------------------------------------------
  777.           when IC_CPL_BIT =>            -- CPL bit
  778.             if state=FETCH then
  779.               s_pc_inc_en <= "0001";    -- increment program-counter
  780.               s_nextstate <= EXEC1;
  781.             elsif state=EXEC1 then
  782.               s_adr_mux <= "1000";      -- bit adress
  783.               s_nextstate <= EXEC2;
  784.             elsif state=EXEC2 then
  785.               s_adr_mux <= "1000";      -- bit adress
  786.               s_bdata_mux <= "0110";    -- bdata = not s_bit_data
  787.               s_regs_wr_en <= "110";    -- write one bit
  788.               s_pc_inc_en <= "0001";    -- increment program-counter
  789.               s_nextstate <= FETCH;
  790.            else
  791.               s_nextstate <= FETCH;
  792.             end if;
  793.           ---------------------------------------------------------------------
  794.           when IC_DA_A =>             -- DA A
  795.             alu_cmd_o <= DA;          -- DA operation
  796.             s_data_mux <= "0011";     -- data = aludata_i
  797.             s_regs_wr_en <= "111";    -- write ACC and CY (special operation)
  798.             s_pc_inc_en <= "0001";    -- increment program-counter
  799.             s_nextstate <= FETCH;
  800.           ---------------------------------------------------------------------
  801.           when IC_DEC_A =>              -- DEC A
  802.             alu_cmd_o <= DEC_ACC;       -- decrement operation
  803.             s_data_mux <= "0011";       -- data = aludata_i
  804.             s_regs_wr_en <= "010";      -- write ACC
  805.             s_pc_inc_en <= "0001";      -- increment program-counter
  806.             s_nextstate <= FETCH;
  807.           ---------------------------------------------------------------------
  808.           when IC_DEC_RR =>             -- DEC Rr
  809.             if state=FETCH then
  810.               s_adr_mux <= "0110";      -- address = rr-address
  811.               s_nextstate <= EXEC1;
  812.             elsif state=EXEC1 then
  813.               alu_cmd_o <= DEC_RAM;     -- decrement operation
  814.               s_adr_mux <= "0110";      -- address = rr-address
  815.               s_data_mux <= "0011";     -- data = aludata_i
  816.               s_regs_wr_en <= "100";    -- write one byte
  817.               s_pc_inc_en <= "0001";    -- increment program-counter
  818.               s_nextstate <= FETCH;
  819.             end if;
  820.           ---------------------------------------------------------------------
  821.           when IC_DEC_D =>              -- DEC direct
  822.             if state=FETCH then
  823.               s_pc_inc_en <= "0001";    -- increment program-counter
  824.               s_nextstate <= EXEC1;
  825.             elsif state=EXEC1 then
  826.               s_adr_mux <= "1000";      -- address = rom_data_i
  827.               s_nextstate <= EXEC2;
  828.             elsif state=EXEC2 then
  829.               s_adr_mux <= "1000";      -- address = rom_data_i
  830.               s_data_mux <= "0011";     -- data = aludata_i
  831.               s_regs_wr_en <= "100";    -- write one byte
  832.               alu_cmd_o <= DEC_RAM;     -- decrement operation
  833.               s_pc_inc_en <= "0001";    -- increment program-counter
  834.               s_nextstate <= FETCH;
  835.             end if;
  836.           ---------------------------------------------------------------------
  837.           when IC_DEC_ATRI =>           -- DEC @Ri
  838.             if state=FETCH then
  839.               s_adr_mux <= "0111";      -- address = Ri-register
  840.               s_nextstate <= EXEC1;
  841.             elsif state=EXEC1 then
  842.               alu_cmd_o <= DEC_RAM;     -- decrement operation
  843.               s_adr_mux <= "0111";      -- address = ri-address
  844.               s_data_mux <= "0011";     -- data = aludata_i
  845.               s_regs_wr_en <= "100";    -- write one byte
  846.               s_pc_inc_en <= "0001";    -- increment program-counter
  847.               s_nextstate <= FETCH;
  848.             end if;
  849.           ---------------------------------------------------------------------
  850.           when IC_DIV_AB =>             -- DIV AB
  851.             if state=FETCH then
  852.               s_adr_mux <= "1100";      -- adress of B register
  853.               alu_cmd_o <= DIV_ACC_RAM; -- divison operation
  854.               s_nextstate <= EXEC1;
  855.             elsif state=EXEC1 then
  856.               s_data_mux <= "0011";     -- data = aludata_i
  857.               s_adr_mux <= "1100";      -- adress of B register
  858.               alu_cmd_o <= DIV_ACC_RAM; -- divison operation
  859.               s_nextstate <= EXEC2;
  860.             elsif state=EXEC2 then
  861.               s_data_mux <= "0011";     -- data = aludata_i
  862.               s_adr_mux <= "1100";      -- adress of B register
  863.               s_regs_wr_en <= "111";    -- write ACC,B,OV,CY(special operation)
  864.               alu_cmd_o <= DIV_ACC_RAM; -- divison operation
  865.               s_pc_inc_en <= "0001";    -- increment program-counter
  866.               s_nextstate <= FETCH;
  867.             end if;
  868.           ---------------------------------------------------------------------
  869.           when IC_DJNZ_RR =>            -- DJNZ Rr, rel
  870.             if state=FETCH then
  871.               s_adr_mux <= "0110";      -- address = rr-address
  872.               s_help_en <= "0100";      -- save Rr-adress
  873.               s_pc_inc_en <= "0001";    -- increment program-counter
  874.               s_nextstate <= EXEC1;
  875.             elsif state=EXEC1 then
  876.               alu_cmd_o <= DEC_RAM;     -- decrement operation
  877.               if unsigned(aludata_i) /= 0 then
  878.                 s_adr_mux <= "1010";    -- address = rr-address
  879.                 s_data_mux <= "0011";   -- data = aludata_i
  880.                 s_regs_wr_en <= "100";  -- write one byte
  881.                 s_pc_inc_en <= "0010";  -- add relativ adress to PC
  882.               else
  883.                 s_adr_mux <= "1010";    -- address = rr-address
  884.                 s_data_mux <= "0011";   -- data = aludata_i
  885.                 s_regs_wr_en <= "100";  -- write one byte
  886.                 s_pc_inc_en <= "0001";  -- increment program-counter
  887.               end if;
  888.               s_nextstate <= FETCH;
  889.             end if;
  890.           ---------------------------------------------------------------------
  891.           when IC_DJNZ_D =>             -- DJNZ direct, rel
  892.             if state=FETCH then
  893.               s_pc_inc_en <= "0001";    -- increment program-counter
  894.               s_nextstate <= EXEC1;
  895.             elsif state=EXEC1 then
  896.               s_help_en <= "0001";      -- save address
  897.               s_adr_mux <= "1000";      -- address = rom_data
  898.               s_pc_inc_en <= "0001";    -- increment program-counter
  899.               s_nextstate <= EXEC2;
  900.             elsif state=EXEC2 then
  901.               alu_cmd_o <= DEC_RAM;            -- decrement operation
  902.               if unsigned(aludata_i) /= 0 then
  903.                 s_adr_mux <= "1010";           -- address = help
  904.                 s_data_mux <= "0011";          -- data = aludata_i
  905.                 s_regs_wr_en <= "100";         -- write one byte
  906.                 s_pc_inc_en <= "0010";         -- add relativ adress to PC
  907.               else
  908.                 s_adr_mux <= "1010";           -- address = help
  909.                 s_data_mux <= "0011";          -- data = aludata_i
  910.                 s_regs_wr_en <= "100";         -- write one byte
  911.                 s_pc_inc_en <= "0001";         -- increment program-counter
  912.               end if;
  913.               s_nextstate <= FETCH;
  914.             end if;
  915.           ---------------------------------------------------------------------
  916.           when IC_INC_A =>              -- INC A
  917.             alu_cmd_o <= INC_ACC;       -- increment operation
  918.             s_data_mux <= "0011";       -- data = aludata_i
  919.             s_regs_wr_en <= "010";      -- write ACC
  920.             s_pc_inc_en <= "0001";      -- increment program-counter
  921.             s_nextstate <= FETCH;
  922.           ---------------------------------------------------------------------
  923.           when IC_INC_RR =>             -- INC Rr
  924.             if state=FETCH then
  925.               s_adr_mux <= "0110";      -- address = rr-address
  926.               s_nextstate <= EXEC1;
  927.             elsif state=EXEC1 then
  928.               alu_cmd_o <= INC_RAM;     -- increment operation
  929.               s_adr_mux <= "0110";      -- address = rr-address
  930.               s_data_mux <= "0011";     -- data = aludata_i
  931.               s_regs_wr_en <= "100";    -- write one byte
  932.               s_pc_inc_en <= "0001";    -- increment program-counter
  933.               s_nextstate <= FETCH;
  934.             end if;
  935.           ---------------------------------------------------------------------
  936.           when IC_INC_D =>              -- INC direct
  937.             if state=FETCH then
  938.               s_pc_inc_en <= "0001";    -- increment program-counter
  939.               s_nextstate <= EXEC1;
  940.             elsif state=EXEC1 then
  941.               s_adr_mux <= "1000";      -- address = rom_data_i
  942.               s_nextstate <= EXEC2;
  943.             elsif state=EXEC2 then
  944.               alu_cmd_o <= INC_RAM;     -- increment operation
  945.               s_adr_mux <= "1000";      -- address = rom_data_i
  946.               s_data_mux <= "0011";     -- data = aludata_i
  947.               s_regs_wr_en <= "100";    -- write one byte
  948.               s_pc_inc_en <= "0001";    -- increment program-counter
  949.               s_nextstate <= FETCH;
  950.             end if;
  951.           ---------------------------------------------------------------------
  952.           when IC_INC_ATRI =>           -- INC @Ri
  953.             if state=FETCH then
  954.               s_adr_mux <= "0111";      -- address = Ri-register
  955.               s_nextstate <= EXEC1;
  956.             elsif state=EXEC1 then
  957.               alu_cmd_o <= INC_RAM;     -- increment operation
  958.               s_adr_mux <= "0111";      -- address = Ri-register
  959.               s_data_mux <= "0011";     -- data = aludata_i
  960.               s_regs_wr_en <= "100";    -- write one byte
  961.               s_pc_inc_en <= "0001";    -- increment program-counter
  962.               s_nextstate <= FETCH;
  963.             end if;
  964.           ---------------------------------------------------------------------
  965.           when IC_INC_DPTR =>           -- INC DPTR
  966.             if state=FETCH then
  967.               s_adr_mux <= "1101";      -- adress of DPL
  968.               s_nextstate <= EXEC1;
  969.             elsif state=EXEC1 then
  970.               alu_cmd_o <= INC_RAM;     -- increment operation
  971.               s_help_en <= "0010";      -- help = aludata_i
  972.               s_adr_mux <= "1101";      -- adress of DPL
  973.               s_data_mux <= "0011";     -- data = aludata_i
  974.               s_regs_wr_en <= "100";    -- write one byte
  975.               s_nextstate <= EXEC2;
  976.             elsif state=EXEC2 then
  977.               s_adr_mux <= "1110";      -- adress of DPH
  978.               s_nextstate <= EXEC3;
  979.             elsif state=EXEC3 then
  980.               if s_help=conv_unsigned(0,8) then
  981.                 alu_cmd_o <= INC_RAM;    -- increment operation
  982.                 s_adr_mux <= "1110";     -- adress of DPH
  983.                 s_data_mux <= "0011";    -- data = aludata_i
  984.                 s_regs_wr_en <= "100";   -- write one byte
  985.               else
  986.               end if;
  987.               s_pc_inc_en <= "0001";     -- increment program-counter
  988.               s_nextstate <= FETCH;
  989.             end if;
  990.           ---------------------------------------------------------------------
  991.           when IC_JB =>                 -- JB bit, rel
  992.             if state=FETCH then
  993.               s_pc_inc_en <= "0001";    -- increment program-counter
  994.               s_nextstate <= EXEC1;
  995.             elsif state=EXEC1 then
  996.               s_adr_mux <= "1000";       -- bit adress = rom_data_i
  997.               s_pc_inc_en <= "0001";    -- increment program-counter
  998.               s_nextstate <= EXEC2;
  999.             elsif state=EXEC2 then
  1000.               if s_bit_data = '1' then
  1001.                 s_pc_inc_en <= "0010";  -- add relativ adress to PC
  1002.               else
  1003.                 s_pc_inc_en <= "0001";  -- increment program-counter
  1004.               end if;
  1005.               s_nextstate <= FETCH;
  1006.             end if;
  1007.           ---------------------------------------------------------------------
  1008.           when IC_JBC =>                -- JBC bit, rel
  1009.             if state=FETCH then
  1010.               s_pc_inc_en <= "0001";    -- increment program-counter
  1011.               s_nextstate <= EXEC1;
  1012.             elsif state=EXEC1 then
  1013.               s_adr_mux <= "1000";      -- bit adress = rom_data_i
  1014.               s_help_en <= "0001";      -- s_help = rom_data_i
  1015.               s_pc_inc_en <= "0001";    -- increment program-counter
  1016.               s_nextstate <= EXEC2;
  1017.             elsif state=EXEC2 then
  1018.               s_adr_mux <= "1010";       -- s_adr = s_help
  1019.               s_bdata_mux <= "0000";     -- s_bdata = 0
  1020.               s_regs_wr_en <= "110";     -- write one bit
  1021.               if s_bit_data = '1' then
  1022.                 s_pc_inc_en <= "0010";   -- add relativ adress to PC
  1023.               else
  1024.                 s_pc_inc_en <= "0001";   -- increment program-counter
  1025.               end if;
  1026.               s_nextstate <= FETCH;
  1027.             end if;
  1028.           ---------------------------------------------------------------------
  1029.           when IC_JC =>                 -- JC rel
  1030.             if state=FETCH then
  1031.               s_pc_inc_en <= "0001";    -- increment program-counter
  1032.               s_nextstate <= EXEC1;
  1033.             elsif state=EXEC1 then
  1034.               if cy = '1' then
  1035.                 s_pc_inc_en <= "0010";  -- add relativ adress to PC
  1036.               else
  1037.                 s_pc_inc_en <= "0001";  -- increment program-counter
  1038.               end if;
  1039.               s_nextstate <= FETCH;
  1040.             end if;
  1041.           ---------------------------------------------------------------------
  1042.           when IC_JMP_A_DPTR =>         -- JMP @A+DPTR
  1043.             s_pc_inc_en <= "0101";      -- PC = ACC + DPTR
  1044.             s_nextstate <= FETCH;
  1045.           ---------------------------------------------------------------------
  1046.           when IC_JNB =>                -- JNB bit, rel
  1047.             if state=FETCH then
  1048.               s_pc_inc_en <= "0001";    -- increment program-counter
  1049.               s_nextstate <= EXEC1;
  1050.             elsif state=EXEC1 then
  1051.               s_adr_mux <= "1000";       -- bit adress = rom_data_i
  1052.               s_pc_inc_en <= "0001";    -- increment program-counter
  1053.               s_nextstate <= EXEC2;
  1054.             elsif state=EXEC2 then
  1055.               if s_bit_data = '0' then
  1056.                 s_pc_inc_en <= "0010";   -- add relativ adress to PC
  1057.               else
  1058.                 s_pc_inc_en <= "0001";   -- increment program-counter
  1059.               end if;
  1060.               s_nextstate <= FETCH;
  1061.             end if;
  1062.           ---------------------------------------------------------------------
  1063.           when IC_JNC =>                -- JNC rel
  1064.             if state=FETCH then
  1065.               s_pc_inc_en <= "0001";    -- increment program-counter
  1066.               s_nextstate <= EXEC1;
  1067.             elsif state=EXEC1 then
  1068.               if cy = '0' then
  1069.                 s_pc_inc_en <= "0010";  -- add relativ adress to PC
  1070.               else
  1071.                 s_pc_inc_en <= "0001";  -- increment program-counter
  1072.               end if;
  1073.               s_nextstate <= FETCH;
  1074.             end if;
  1075.           ---------------------------------------------------------------------
  1076.           when IC_JNZ =>                -- JNZ rel
  1077.             if state=FETCH then
  1078.               s_pc_inc_en <= "0001";    -- increment program-counter
  1079.               s_nextstate <= EXEC1;
  1080.             elsif state=EXEC1 then
  1081.               if unsigned(acc) /= conv_unsigned(0,8) then
  1082.                 s_pc_inc_en <= "0010";  -- add relativ adress to PC
  1083.               else
  1084.                 s_pc_inc_en <= "0001";  -- increment program-counter
  1085.               end if;
  1086.               s_nextstate <= FETCH;
  1087.             end if;
  1088.           ---------------------------------------------------------------------
  1089.           when IC_JZ =>                 -- JZ rel
  1090.             if state=FETCH then
  1091.               s_pc_inc_en <= "0001";    -- increment program-counter
  1092.               s_nextstate <= EXEC1;
  1093.             elsif state=EXEC1 then
  1094.               if unsigned(acc) = conv_unsigned(0,8) then
  1095.                 s_pc_inc_en <= "0010";         -- add relativ adress to PC
  1096.               else
  1097.                 s_pc_inc_en <= "0001";         -- increment program-counter
  1098.               end if;
  1099.               s_nextstate <= FETCH;
  1100.             end if;
  1101.           ---------------------------------------------------------------------
  1102.           when IC_LCALL =>              -- LCALL addr16
  1103.             if state=FETCH then
  1104.               s_regs_wr_en <= "001";    -- increment stackpointer
  1105.               s_help16_en <= "01";      -- s_help16 <= pc + 3
  1106.               s_pc_inc_en <= "0001";    -- increment program-counter
  1107.               s_nextstate <= EXEC1;
  1108.             elsif state=EXEC1 then
  1109.               s_help_en <= "0001";      -- help <= rom_data_i
  1110.               s_data_mux <= "1100";     -- data <= help16(7 downto 0)
  1111.               s_adr_mux <= "0101";      -- s_adr <= sp
  1112.               s_regs_wr_en <= "101";    -- write one byte and increment SP
  1113.               s_pc_inc_en <= "0001";    -- increment program-counter
  1114.               s_nextstate <= EXEC2;
  1115.             elsif state=EXEC2 then
  1116.               s_data_mux <= "1101";     -- data = help16(15 downto 8)
  1117.               s_adr_mux <= "0101";      -- s_adr <= sp
  1118.               s_regs_wr_en <= "100";    -- write one byte
  1119.               s_pc_inc_en <= "0111";    -- load program counter
  1120.               s_nextstate <= FETCH;
  1121.             end if;
  1122.           ---------------------------------------------------------------------
  1123.           when IC_LJMP =>               -- LJMP addr16
  1124.             if state=FETCH then
  1125.               s_pc_inc_en <= "0001";    -- increment program-counter
  1126.               s_nextstate <= EXEC1;
  1127.             elsif state=EXEC1 then
  1128.               s_help_en <= "0001";      -- help = rom_data_i
  1129.               s_pc_inc_en <= "0001";    -- increment program-counter
  1130.               s_nextstate <= EXEC2;
  1131.             elsif state=EXEC2 then
  1132.               s_pc_inc_en <= "0111";    -- load program-counter
  1133.               s_nextstate <= FETCH;
  1134.             end if;
  1135.           ---------------------------------------------------------------------
  1136.           when IC_MOV_A_RR =>           -- MOV A,Rr
  1137.             if state=FETCH then
  1138.               s_adr_mux <= "0110";      -- address = rr-address
  1139.               s_nextstate <= EXEC1;
  1140.             elsif state=EXEC1 then
  1141.               s_data_mux <= "0100";     -- data = s_reg_data
  1142.               s_regs_wr_en <= "010";    -- write ACC
  1143.               s_pc_inc_en <= "0001";    -- increment program-counter
  1144.               s_nextstate <= FETCH;
  1145.             end if;
  1146.           ---------------------------------------------------------------------
  1147.           when IC_MOV_A_D =>            -- MOV A, direct
  1148.             if state=FETCH then
  1149.               s_pc_inc_en <= "0001";    -- increment program-counter
  1150.               s_nextstate <= EXEC1;
  1151.             elsif state=EXEC1 then
  1152.               s_adr_mux <= "1000";      -- address = rom_data_i
  1153.               s_nextstate <= EXEC2;
  1154.             elsif state=EXEC2 then
  1155.               s_data_mux <= "0100";     -- data = s_reg_data
  1156.               s_regs_wr_en <= "010";    -- write ACC
  1157.               s_pc_inc_en <= "0001";    -- increment program-counter
  1158.               s_nextstate <= FETCH;
  1159.             end if;
  1160.           ---------------------------------------------------------------------
  1161.           when IC_MOV_A_ATRI =>         -- MOV A,@Ri
  1162.             if state=FETCH then
  1163.               s_adr_mux <= "0111";      -- address = Ri-register
  1164.               s_nextstate <= EXEC1;
  1165.             elsif state=EXEC1 then
  1166.               s_data_mux <= "0100";     -- data = s_reg_data
  1167.               s_regs_wr_en <= "010";    -- write ACC
  1168.               s_pc_inc_en <= "0001";    -- increment program-counter
  1169.               s_nextstate <= FETCH;
  1170.             end if;
  1171.           ---------------------------------------------------------------------
  1172.           when IC_MOV_A_DATA =>         -- MOV A, #DATA
  1173.             if state=FETCH then
  1174.               s_pc_inc_en <= "0001";    -- increment program-counter
  1175.               s_nextstate <= EXEC1;
  1176.             elsif state=EXEC1 then
  1177.               s_data_mux <= "0101";     -- data = rom_data_i
  1178.               s_regs_wr_en <= "010";    -- write ACC
  1179.               s_pc_inc_en <= "0001";    -- increment program-counter
  1180.               s_nextstate <= FETCH;
  1181.             end if;
  1182.           ---------------------------------------------------------------------
  1183.           when IC_MOV_RR_A =>           -- MOV Rr,A
  1184.             s_adr_mux <= "0110";        -- address = rr-address
  1185.             s_data_mux <= "0110";       -- data = ACC
  1186.             s_regs_wr_en <= "100";      -- write one byte
  1187.             s_pc_inc_en <= "0001";      -- increment program-counter
  1188.             s_nextstate <= FETCH;
  1189.           ---------------------------------------------------------------------
  1190.           when IC_MOV_RR_D =>           -- MOV Rr, direct
  1191.             if state=FETCH then
  1192.               s_help_en <= "0100";      -- save Rr-adress in help
  1193.               s_pc_inc_en <= "0001";    -- increment program-counter
  1194.               s_nextstate <= EXEC1;
  1195.             elsif state=EXEC1 then
  1196.               s_adr_mux <= "1000";      -- address = rom_data_i
  1197.               s_nextstate <= EXEC2;
  1198.             elsif state=EXEC2 then
  1199.               s_adr_mux <= "1010";      -- address = help
  1200.               s_data_mux <= "0100";     -- data = s_reg_data
  1201.               s_regs_wr_en <= "100";    -- write one byte
  1202.               s_pc_inc_en <= "0001";    -- do nothing with program counter
  1203.               s_nextstate <= FETCH;
  1204.             end if;
  1205.           ---------------------------------------------------------------------
  1206.           when IC_MOV_RR_DATA =>        -- MOV Rr,#data
  1207.             if state=FETCH then
  1208.               s_help_en <= "0100";      -- save Rr-adress in help
  1209.               s_pc_inc_en <= "0001";    -- increment program-counter
  1210.               s_nextstate <= EXEC1;
  1211.             elsif state=EXEC1 then
  1212.               s_adr_mux <= "1010";      -- address = help
  1213.               s_data_mux <= "0101";     -- data = rom_data_i
  1214.               s_regs_wr_en <= "100";    -- write one byte
  1215.               s_pc_inc_en <= "0001";    -- do nothing with program counter
  1216.               s_nextstate <= FETCH;
  1217.             end if;
  1218.           ---------------------------------------------------------------------
  1219.           when IC_MOV_D_A =>            -- MOV direct, A
  1220.             if state=FETCH then
  1221.               s_pc_inc_en <= "0001";    -- increment program-counter
  1222.               s_nextstate <= EXEC1;
  1223.             elsif state=EXEC1 then
  1224.               s_adr_mux <= "1000";      -- address = rom_data_i
  1225.               s_data_mux <= "0110";     -- data = ACC
  1226.               s_regs_wr_en <= "100";    -- write one byte
  1227.               s_pc_inc_en <= "0001";    -- increment program-counter
  1228.               s_nextstate <= FETCH;
  1229.             end if;
  1230.             -------------------------------------------------------------------
  1231.           when IC_MOV_D_RR =>           -- MOV direct, Rr
  1232.             if state=FETCH then
  1233.               s_adr_mux <= "0110";      -- address = rr-address
  1234.               s_pc_inc_en <= "0001";    -- increment program-counter
  1235.               s_nextstate <= EXEC1;
  1236.             elsif state=EXEC1 then
  1237.               s_adr_mux <= "1000";      -- address = rom_data_i
  1238.               s_data_mux <= "0100";     -- data = s_reg_data
  1239.               s_regs_wr_en <= "100";    -- write one byte
  1240.               s_pc_inc_en <= "0001";    -- do nothing with program counter
  1241.               s_nextstate <= FETCH;
  1242.             end if;
  1243.           ---------------------------------------------------------------------
  1244.           when IC_MOV_D_D =>            -- MOV direct, direct
  1245.             if state=FETCH then
  1246.               s_pc_inc_en <= "0001";    -- increment program-counter
  1247.               s_nextstate <= EXEC1;
  1248.             elsif state=EXEC1 then
  1249.               s_adr_mux <= "1000";      -- address = rom_data_i
  1250.               s_pc_inc_en <= "0001";    -- increment program-counter
  1251.               s_nextstate <= EXEC2;
  1252.             elsif state=EXEC2 then
  1253.               s_adr_mux <= "1000";      -- address = rom_data_i
  1254.               s_data_mux <= "0100";     -- data = s_reg_data
  1255.               s_regs_wr_en <= "100";    -- write one byte
  1256.               s_pc_inc_en <= "0001";    -- increment program-counter
  1257.               s_nextstate <= FETCH;
  1258.             end if;
  1259.           ---------------------------------------------------------------------
  1260.           when IC_MOV_D_ATRI =>         -- MOV direct ,@Ri
  1261.             if state=FETCH then
  1262.               s_adr_mux <= "0111";      -- address = Ri-register
  1263.               s_pc_inc_en <= "0001";    -- increment program-counter
  1264.               s_nextstate <= EXEC1;
  1265.             elsif state=EXEC1 then
  1266.               s_adr_mux <= "1000";      -- address = rom_data_i
  1267.               s_data_mux <= "0100";     -- data = s_reg_data
  1268.               s_regs_wr_en <= "100";    -- write one byte
  1269.               s_pc_inc_en <= "0001";    -- increment program-counter
  1270.               s_nextstate <= FETCH;
  1271.             end if;
  1272.           ---------------------------------------------------------------------
  1273.           when IC_MOV_D_DATA =>         -- MOV direct, #data
  1274.             if state=FETCH then
  1275.               s_pc_inc_en <= "0001";    -- increment program-counter
  1276.               s_nextstate <= EXEC1;
  1277.             elsif state=EXEC1 then
  1278.               s_help_en <= "0001";      -- save direct adress
  1279.               s_pc_inc_en <= "0001";    -- increment program-counter
  1280.               s_nextstate <= EXEC2;
  1281.             elsif state=EXEC2 then
  1282.               s_adr_mux <= "1010";      -- address = help
  1283.               s_data_mux <= "0101";     -- data = rom_data_i
  1284.               s_regs_wr_en <= "100";    -- write one byte
  1285.               s_pc_inc_en <= "0001";    -- increment program-counter
  1286.               s_nextstate <= FETCH;
  1287.             end if;
  1288.           ---------------------------------------------------------------------
  1289.           when IC_MOV_ATRI_A =>        -- MOV @Ri,A
  1290.             s_adr_mux <= "0111";       -- address = Ri-register
  1291.             s_data_mux <= "0110";      -- data = ACC
  1292.             s_regs_wr_en <= "100";     -- write one byte
  1293.             s_pc_inc_en <= "0001";     -- increment program-counter
  1294.             s_nextstate <= FETCH;
  1295.           ---------------------------------------------------------------------
  1296.           when IC_MOV_ATRI_D =>         -- MOV @Ri, direct
  1297.             if state=FETCH then
  1298.               s_pc_inc_en <= "0001";    -- increment program-counter
  1299.               s_nextstate <= EXEC1;
  1300.             elsif state=EXEC1 then
  1301.               s_adr_mux <= "1000";      -- address = rom_data_i
  1302.               s_nextstate <= EXEC2;
  1303.             elsif state=EXEC2 then
  1304.               s_adr_mux <= "0111";      -- address = Ri-register
  1305.               s_data_mux <= "0100";     -- data = s_reg_data
  1306.               s_regs_wr_en <= "100";    -- write one byte
  1307.               s_pc_inc_en <= "0001";    -- increment program-counter
  1308.               s_nextstate <= FETCH;
  1309.             end if;
  1310.           ---------------------------------------------------------------------
  1311.           when IC_MOV_ATRI_DATA =>      -- MOV @Ri,#data
  1312.             if state=FETCH then
  1313.               s_pc_inc_en <= "0001";    -- increment program-counter
  1314.               s_nextstate <= EXEC1;
  1315.             elsif state=EXEC1 then
  1316.               s_adr_mux <= "0111";      -- address = Ri-register
  1317.               s_data_mux <= "0101";     -- data = rom_data_i
  1318.               s_regs_wr_en <= "100";    -- write one byte
  1319.               s_pc_inc_en <= "0001";    -- increment program-counter
  1320.               s_nextstate <= FETCH;
  1321.             end if;
  1322.           ---------------------------------------------------------------------
  1323.           when IC_MOVC_A_ATDPTR =>       -- MOVC A, @A+DPTR
  1324.             if state=FETCH then
  1325.               s_help16_en <= "11";       -- save PC+1 in help16
  1326.               s_pc_inc_en <= "0101";     -- PC = A+DPTR
  1327.               s_nextstate <= EXEC1;
  1328.             elsif state=EXEC1 then
  1329.               s_data_mux <= "0101";      -- data = rom_data_i
  1330.               s_regs_wr_en <= "010";     -- write ACC
  1331.               s_pc_inc_en <= "0110";     -- PC = help16
  1332.               s_nextstate <= FETCH;
  1333.             end if;
  1334.           ---------------------------------------------------------------------
  1335.           when IC_MOVC_A_ATPC =>         -- MOVC A, @A+PC
  1336.             if state=FETCH then
  1337.               s_help16_en <= "11";       -- save PC+1 in help16
  1338.               s_pc_inc_en <= "1001";     -- PC = A+PC+1
  1339.               s_nextstate <= EXEC1;
  1340.             elsif state=EXEC1 then
  1341.               s_data_mux <= "0101";      -- data = rom_data_i
  1342.               s_regs_wr_en <= "010";     -- write ACC
  1343.               s_pc_inc_en <= "0110";     -- PC = help16
  1344.               s_nextstate <= FETCH;
  1345.             end if;
  1346.           ---------------------------------------------------------------------
  1347.           when IC_MOVX_A_ATRI =>         -- MOVX A, @RI
  1348.             if state=FETCH then
  1349.               s_adrx_mux <= "10";        -- external adress = Ri
  1350.               s_nextstate <= EXEC1;
  1351.             elsif state=EXEC1 then
  1352.               s_data_mux <= "1111";      -- data = datax_i
  1353.               s_regs_wr_en <= "010";     -- write ACC
  1354.               s_pc_inc_en <= "0001";     -- increment program-counter
  1355.               s_nextstate <= FETCH;
  1356.             end if;
  1357.           ---------------------------------------------------------------------
  1358.           when IC_MOVX_A_ATDPTR =>       -- MOVX A, @DPTR
  1359.             if state=FETCH then
  1360.               s_adrx_mux <= "01";        -- external adress = DPTR
  1361.               s_nextstate <= EXEC1;
  1362.             elsif state=EXEC1 then
  1363.               s_data_mux <= "1111";      -- data = datax_i
  1364.               s_regs_wr_en <= "010";     -- write ACC
  1365.               s_pc_inc_en <= "0001";     -- increment program-counter
  1366.               s_nextstate <= FETCH;
  1367.             end if;
  1368.           ---------------------------------------------------------------------
  1369.           when IC_MOVX_ATRI_A =>       -- MOVX @RI, A
  1370.             s_adrx_mux <= "10";        -- external adress = Ri
  1371.             s_wrx_mux <= '1';
  1372.             s_pc_inc_en <= "0001";     -- increment program-counter
  1373.             s_nextstate <= FETCH;
  1374.           ---------------------------------------------------------------------
  1375.           when IC_MOVX_ATDPTR_A =>     -- MOVX @DPTR, A
  1376.             s_adrx_mux <= "01";        -- external adress = DPTR
  1377.             s_wrx_mux <= '1';
  1378.             s_pc_inc_en <= "0001";     -- increment program-counter
  1379.             s_nextstate <= FETCH;
  1380.           ---------------------------------------------------------------------
  1381.           when IC_MOV_C_BIT =>          -- MOV C, bit
  1382.             if state=FETCH then
  1383.               s_pc_inc_en <= "0001";    -- increment program-counter
  1384.               s_nextstate <= EXEC1;
  1385.             elsif state=EXEC1 then
  1386.               s_adr_mux <= "1000";      -- address = rom_data_i
  1387.               s_nextstate <= EXEC2;
  1388.             elsif state=EXEC2 then
  1389.               s_bdata_mux <= "0111";    -- bdata = s_bit_data
  1390.               s_regs_wr_en <= "110";    -- write one bit (automatic CY-address)
  1391.               s_pc_inc_en <= "0001";    -- increment program-counter
  1392.               s_nextstate <= FETCH;
  1393.             end if;
  1394.           ---------------------------------------------------------------------
  1395.           when IC_MOV_BIT_C =>          -- MOV bit,C
  1396.             if state=FETCH then
  1397.               s_pc_inc_en <= "0001";    -- increment program-counter
  1398.               s_nextstate <= EXEC1;
  1399.             elsif state=EXEC1 then
  1400.               s_adr_mux <= "1000";      -- address = rom_data_i
  1401.               s_bdata_mux <= "1000";    -- bdata = cy
  1402.               s_regs_wr_en <= "110";    -- write one bit
  1403.               s_pc_inc_en <= "0001";    -- increment program-counter
  1404.               s_nextstate <= FETCH;
  1405.             end if;
  1406.           ---------------------------------------------------------------------
  1407.           when IC_MOV_DPTR_DATA =>      -- MOV DPTR, #data16
  1408.             if state=FETCH then
  1409.               s_pc_inc_en <= "0001";    -- increment program-counter
  1410.               s_nextstate <= EXEC1;
  1411.             elsif state=EXEC1 then
  1412.               s_adr_mux <= "1110";      -- adress of DPH
  1413.               s_data_mux <= "0101";     -- data = rom_data_i
  1414.               s_regs_wr_en <= "100";    -- write one byte
  1415.               s_pc_inc_en <= "0001";    -- increment program-counter
  1416.               s_nextstate <= EXEC2;
  1417.             elsif state=EXEC2 then
  1418.               s_adr_mux <= "1101";      -- adress of DPL
  1419.               s_data_mux <= "0101";     -- data = rom_data_i
  1420.               s_regs_wr_en <= "100";    -- write one byte
  1421.               s_pc_inc_en <= "0001";    -- increment program-counter
  1422.               s_nextstate <= FETCH;
  1423.             end if;
  1424.           ---------------------------------------------------------------------
  1425.           when IC_MUL_AB =>             -- MUL AB
  1426.             if state=FETCH then
  1427.               s_adr_mux <= "1100";      -- adress of B register
  1428.               alu_cmd_o <= MUL_ACC_RAM; -- divison operation
  1429.               s_nextstate <= EXEC1;
  1430.             elsif state=EXEC1 then
  1431.               s_data_mux <= "0011";     -- data = aludata_i
  1432.               s_adr_mux <= "1100";      -- adress of B register
  1433.               alu_cmd_o <= MUL_ACC_RAM; -- divison operation
  1434.               s_nextstate <= EXEC2;
  1435.             elsif state=EXEC2 then
  1436.               s_data_mux <= "0011";    -- data = aludata_i
  1437.               s_adr_mux <= "1100";     -- adress of B register
  1438.               s_regs_wr_en <= "111";   -- write ACC,B,OV,CY (special operation)
  1439.               alu_cmd_o <= MUL_ACC_RAM; -- divison operation
  1440.               s_pc_inc_en <= "0001";    -- increment program-counter
  1441.               s_nextstate <= FETCH;
  1442.             end if;
  1443.           ---------------------------------------------------------------------
  1444.           when IC_NOP =>              -- NOP
  1445.             s_pc_inc_en <= "0001";    -- increment program-counter
  1446.             s_nextstate <= FETCH;
  1447.           ---------------------------------------------------------------------
  1448.           when IC_ORL_A_RR =>           -- ORL A,Rr
  1449.             if state=FETCH then
  1450.               s_adr_mux <= "0110";      -- address = rr-address
  1451.               s_nextstate <= EXEC1;
  1452.             elsif state=EXEC1 then
  1453.               alu_cmd_o <= OR_RAM_ACC;  -- OR command (ACC v RAM_DATA)
  1454.               s_data_mux <= "0011";     -- data = aludata_i
  1455.               s_regs_wr_en <= "010";    -- write ACC
  1456.               s_pc_inc_en <= "0001";    -- increment program-counter
  1457.               s_nextstate <= FETCH;
  1458.             end if;
  1459.           ---------------------------------------------------------------------
  1460.           when IC_ORL_A_D =>            -- ORL A, direct
  1461.             if state=FETCH then
  1462.               s_pc_inc_en <= "0001";    -- increment program-counter
  1463.               s_nextstate <= EXEC1;
  1464.             elsif state=EXEC1 then
  1465.               s_adr_mux <= "1000";      -- address = rom_data_i
  1466.               s_nextstate <= EXEC2;
  1467.             elsif state=EXEC2 then
  1468.               alu_cmd_o <= OR_RAM_ACC;  -- OR command (ACC v RAM_DATA)
  1469.               s_data_mux <= "0011";     -- data = aludata_i
  1470.               s_regs_wr_en <= "010";    -- write ACC
  1471.               s_pc_inc_en <= "0001";    -- increment program-counter
  1472.               s_nextstate <= FETCH;
  1473.             end if;
  1474.           ---------------------------------------------------------------------
  1475.           when IC_ORL_A_ATRI =>         -- ORL A,@Ri
  1476.             if state=FETCH then
  1477.               s_adr_mux <= "0111";      -- address = Ri-register
  1478.               s_nextstate <= EXEC1;
  1479.             elsif state=EXEC1 then
  1480.               alu_cmd_o <= OR_RAM_ACC;  -- OR command (ACC v RAM_DATA)
  1481.               s_data_mux <= "0011";     -- data = aludata_i
  1482.               s_regs_wr_en <= "010";    -- write ACC
  1483.               s_pc_inc_en <= "0001";    -- increment program-counter
  1484.               s_nextstate <= FETCH;
  1485.             end if;
  1486.           ---------------------------------------------------------------------
  1487.           when IC_ORL_A_DATA =>         -- ORL A, data
  1488.             if state=FETCH then
  1489.               s_pc_inc_en <= "0001";    -- increment program-counter
  1490.               s_nextstate <= EXEC1;
  1491.             elsif state=EXEC1 then
  1492.               alu_cmd_o <= OR_ROM_ACC;  -- OR command (ACC v ROM_DATA_I)
  1493.               s_data_mux <= "0011";     -- data = aludata_i
  1494.               s_regs_wr_en <= "010";    -- write ACC
  1495.               s_pc_inc_en <= "0001";    -- increment program-counter
  1496.               s_nextstate <= FETCH;
  1497.             end if;
  1498.           ---------------------------------------------------------------------
  1499.           when IC_ORL_D_A =>            -- ORL direct, A
  1500.             if state=FETCH then
  1501.               s_pc_inc_en <= "0001";    -- increment program-counter
  1502.               s_nextstate <= EXEC1;
  1503.             elsif state=EXEC1 then
  1504.               s_adr_mux <= "1000";      -- address = rom_data_i
  1505.               s_nextstate <= EXEC2;
  1506.             elsif state=EXEC2 then
  1507.               alu_cmd_o <= OR_RAM_ACC;  -- OR command (ACC v RAM_DATA)
  1508.               s_adr_mux <= "1000";      -- address = rom_data_i
  1509.               s_data_mux <= "0011";     -- data = aludata_i
  1510.               s_regs_wr_en <= "100";    -- write one byte
  1511.               s_pc_inc_en <= "0001";    -- increment program-counter
  1512.               s_nextstate <= FETCH;
  1513.             end if;
  1514.           ---------------------------------------------------------------------
  1515.           when IC_ORL_D_DATA =>         -- ORL direct, DATA
  1516.             if state=FETCH then
  1517.               s_pc_inc_en <= "0001";    -- increment program-counter
  1518.               s_nextstate <= EXEC1;
  1519.             elsif state=EXEC1 then
  1520.               s_help_en <= "0001";      -- save rom_data_i
  1521.               s_adr_mux <= "1000";
  1522.               s_pc_inc_en <= "0001";    -- increment program-counter
  1523.               s_nextstate <= EXEC2;
  1524.             elsif state=EXEC2 then
  1525.               alu_cmd_o <= OR_ROM_RAM;  -- OR command (ROM_DATA_I v RAM_DATA)
  1526.               s_adr_mux <= "1010";      -- address = help
  1527.               s_data_mux <= "0011";     -- data = aludata_i
  1528.               s_regs_wr_en <= "100";    -- write one byte
  1529.               s_pc_inc_en <= "0001";    -- increment program-counter
  1530.               s_nextstate <= FETCH;
  1531.             end if;
  1532.           ---------------------------------------------------------------------
  1533.           when IC_ORL_C_BIT =>          -- ORL C, bit
  1534.             if state=FETCH then
  1535.               s_pc_inc_en <= "0001";    -- increment program-counter
  1536.               s_nextstate <= EXEC1;
  1537.             elsif state=EXEC1 then
  1538.               s_adr_mux <= "1000";      -- address = rom_data_i
  1539.               s_nextstate <= EXEC2;
  1540.             elsif state=EXEC2 then
  1541.               s_bdata_mux <= "1001";    -- bdata = s_bit_data or cy
  1542.               s_regs_wr_en <= "110";    -- write one bit (autmatically CY)
  1543.               s_pc_inc_en <= "0001";    -- increment program-counter
  1544.               s_nextstate <= FETCH;
  1545.             end if;
  1546.           ---------------------------------------------------------------------
  1547.           when IC_ORL_C_NBIT =>         -- ORL C, /bit
  1548.             if state=FETCH then
  1549.               s_pc_inc_en <= "0001";    -- increment program-counter
  1550.               s_nextstate <= EXEC1;
  1551.             elsif state=EXEC1 then
  1552.               s_adr_mux <= "1000";      -- address = rom_data_i
  1553.               s_nextstate <= EXEC2;
  1554.             elsif state=EXEC2 then
  1555.               s_bdata_mux <= "1010";    -- bdata = not (s_bit_data or cy)
  1556.               s_regs_wr_en <= "110";    -- write one bit (autmatically CY)
  1557.               s_pc_inc_en <= "0001";    -- increment program-counter
  1558.               s_nextstate <= FETCH;
  1559.             end if;
  1560.           ---------------------------------------------------------------------
  1561.           when IC_POP =>                -- POP direct
  1562.             if state=FETCH then
  1563.               s_adr_mux <= "0101";      -- address = SP
  1564.               s_pc_inc_en <= "0001";    -- increment program-counter
  1565.               s_nextstate <= EXEC1;
  1566.             elsif state=EXEC1 then
  1567.               s_adr_mux <= "1000";      -- address = rom_data_i
  1568.               s_data_mux <= "0100";     -- data = s_reg_data
  1569.               s_regs_wr_en <= "101";    -- write one byte and decrement SP
  1570.               s_pc_inc_en <= "0001";    -- increment program-counter
  1571.               s_nextstate <= FETCH;
  1572.             end if;
  1573.           ---------------------------------------------------------------------
  1574.           when IC_PUSH =>               -- PUSH direct
  1575.             if state=FETCH then
  1576.               s_regs_wr_en <= "001";    -- increment SP
  1577.               s_pc_inc_en <= "0001";    -- increment program-counter
  1578.               s_nextstate <= EXEC1;
  1579.             elsif state=EXEC1 then
  1580.               s_adr_mux <= "1000";      -- address = rom_data_i
  1581.               s_nextstate <= EXEC2;
  1582.             elsif state=EXEC2 then
  1583.               s_adr_mux <= "0101";      -- address = SP
  1584.               s_data_mux <= "0100";     -- data = s_reg_data
  1585.               s_regs_wr_en <= "100";    -- write one byte
  1586.               s_pc_inc_en <= "0001";    -- increment program-counter
  1587.               s_nextstate <= FETCH;
  1588.             end if;
  1589.           ---------------------------------------------------------------------
  1590.           when IC_RET =>                -- RET
  1591.             if state=FETCH then
  1592.               s_adr_mux <= "0101";      -- adress = SP
  1593.               s_regs_wr_en <= "001";    -- decrement stackpointer
  1594.               s_nextstate <= EXEC1;
  1595.             elsif state=EXEC1 then
  1596.               s_help_en <= "0011";      -- save data for PC-high
  1597.               s_adr_mux <= "0101";      -- adress = SP
  1598.               s_nextstate <= EXEC2;
  1599.             elsif state=EXEC2 then
  1600.               s_regs_wr_en <= "001";    -- decrement stackpointer
  1601.               s_pc_inc_en <= "1000";    -- reload program-counter
  1602.               s_nextstate <= FETCH;
  1603.             end if;
  1604.           ---------------------------------------------------------------------
  1605.           when IC_RETI =>               -- RETI
  1606.             if state=FETCH then
  1607.               s_adr_mux <= "0101";      -- adress = SP
  1608.               s_regs_wr_en <= "001";    -- decrement stackpointer
  1609.               s_nextstate <= EXEC1;
  1610.             elsif state=EXEC1 then
  1611.               s_help_en <= "0011";      -- save data for PC-high
  1612.               s_adr_mux <= "0101";
  1613.               s_nextstate <= EXEC2;
  1614.             elsif state=EXEC2 then
  1615.               if s_inthigh='1' then     -- an high priority interrupt is ending
  1616.                 s_inthigh_en <= '1';
  1617.                 s_inthigh_d <= '0';
  1618.               elsif s_intlow='1' then   -- an low priority interrupt is ending
  1619.                 s_intlow_en <= '1';
  1620.                 s_intlow_d <= '0';
  1621.               else                      -- no interrupt was started
  1622.                 NULL;                   -- => normal RET command
  1623.               end if;
  1624.               s_regs_wr_en <= "001";    -- decrement stackpointer
  1625.               s_pc_inc_en <= "1000";    -- reload program-counter
  1626.               s_nextstate <= FETCH;
  1627.             end if;
  1628.           ---------------------------------------------------------------------
  1629.           when IC_RL_A =>               -- RL A
  1630.             alu_cmd_o <= RL_ACC;        -- rotate ACC left
  1631.             s_data_mux <= "0011";       -- data = aludata_i
  1632.             s_regs_wr_en <= "010";      -- write ACC
  1633.             s_pc_inc_en <= "0001";      -- increment program-counter
  1634.             s_nextstate <= FETCH;
  1635.           ---------------------------------------------------------------------
  1636.           when IC_RLC_A =>              -- RLC A
  1637.             alu_cmd_o <= RLC_ACC;       -- rotate ACC with CY left
  1638.             s_data_mux <= "0011";       -- data = aludata_i
  1639.             s_regs_wr_en <= "111";      -- write ACC and CY (special operation)
  1640.             s_pc_inc_en <= "0001";      -- increment program-counter
  1641.             s_nextstate <= FETCH;
  1642.           ---------------------------------------------------------------------
  1643.           when IC_RR_A =>               -- RR A
  1644.             alu_cmd_o <= RR_ACC;        -- rotate ACC right
  1645.             s_data_mux <= "0011";       -- data = aludata_i
  1646.             s_regs_wr_en <= "010";      -- write ACC
  1647.             s_pc_inc_en <= "0001";      -- increment program-counter
  1648.             s_nextstate <= FETCH;
  1649.           ---------------------------------------------------------------------
  1650.           when IC_RRC_A =>              -- RRC A
  1651.             alu_cmd_o <= RRC_ACC;       -- rotate ACC with CY right
  1652.             s_data_mux <= "0011";       -- data = aludata_i
  1653.             s_regs_wr_en <= "111";      -- write ACC and CY (special operation)
  1654.             s_pc_inc_en <= "0001";      -- increment program-counter
  1655.             s_nextstate <= FETCH;
  1656.           ---------------------------------------------------------------------
  1657.           when IC_SETB_C =>             -- SETB C
  1658.             s_adr_mux <= "1011";        -- adress of CY
  1659.             s_bdata_mux <= "1011";      -- bdata = 1
  1660.             s_regs_wr_en <= "110";      -- write one bit
  1661.             s_pc_inc_en <= "0001";      -- increment program-counter
  1662.             s_nextstate <= FETCH;
  1663.           ---------------------------------------------------------------------
  1664.           when IC_SETB_BIT =>           -- SETB bit
  1665.             if state=FETCH then
  1666.               s_pc_inc_en <= "0001";    -- increment program-counter
  1667.               s_nextstate <= EXEC1;
  1668.             elsif state=EXEC1 then
  1669.               s_adr_mux <= "1000";      -- byte adress
  1670.               s_bdata_mux <= "1011";    -- bdata = 1
  1671.               s_regs_wr_en <= "110";    -- write one bit
  1672.               s_pc_inc_en <= "0001";    -- increment program-counter
  1673.               s_nextstate <= FETCH;
  1674.             end if;
  1675.           ---------------------------------------------------------------------
  1676.           when IC_SJMP =>               -- SJMP rel
  1677.             if state=FETCH then
  1678.               s_pc_inc_en <= "0001";    -- increment program-counter
  1679.               s_nextstate <= EXEC1;
  1680.             elsif state=EXEC1 then
  1681.               s_pc_inc_en <= "0010";    -- load program-counter
  1682.               s_nextstate <= FETCH;
  1683.             end if;
  1684.           ---------------------------------------------------------------------
  1685.           when IC_SUBB_A_RR =>          -- SUBB A,Rr
  1686.             if state=FETCH then
  1687.               s_adr_mux <= "0110";      -- address = rr-address
  1688.               s_nextstate <= EXEC1;
  1689.             elsif state=EXEC1 then
  1690.               alu_cmd_o <= SUB_ACC_RAM; -- subtraction command (ACC - RAM_DATA)
  1691.               s_data_mux <= "0011";     -- data = aludata_i
  1692.               s_regs_wr_en <= "011";    -- write ACC and CY,OV,AC
  1693.               s_pc_inc_en <= "0001";    -- increment program-counter
  1694.               s_nextstate <= FETCH;
  1695.             end if;
  1696.           ---------------------------------------------------------------------
  1697.           when IC_SUBB_A_D =>           -- SUBB A, direct
  1698.             if state=FETCH then
  1699.               s_pc_inc_en <= "0001";    -- increment program-counter
  1700.               s_nextstate <= EXEC1;
  1701.             elsif state=EXEC1 then
  1702.               s_adr_mux <= "1000";      -- address = rom_data_i
  1703.               s_nextstate <= EXEC2;
  1704.             elsif state=EXEC2 then
  1705.               alu_cmd_o <= SUB_ACC_RAM; -- subtraction command (ACC - RAM_DATA)
  1706.               s_data_mux <= "0011";     -- data = aludata_i
  1707.               s_regs_wr_en <= "011";    -- write ACC and CY,OV,AC
  1708.               s_pc_inc_en <= "0001";    -- increment program-counter
  1709.               s_nextstate <= FETCH;
  1710.             end if;
  1711.           ---------------------------------------------------------------------
  1712.           when IC_SUBB_A_ATRI =>        -- SUBB A,@Ri
  1713.             if state=FETCH then
  1714.               s_adr_mux <= "0111";      -- address = Ri-register
  1715.               s_nextstate <= EXEC1;
  1716.             elsif state=EXEC1 then
  1717.               alu_cmd_o <= SUB_ACC_RAM; -- subtraction command (ACC - RAM_DATA)
  1718.               s_data_mux <= "0011";     -- data = aludata_i
  1719.               s_regs_wr_en <= "011";    -- write ACC and CY,OV,AC
  1720.               s_pc_inc_en <= "0001";    -- increment program-counter
  1721.               s_nextstate <= FETCH;
  1722.             end if;
  1723.           ---------------------------------------------------------------------
  1724.           when IC_SUBB_A_DATA =>        -- SUBB A, DATA
  1725.             if state=FETCH then
  1726.               s_pc_inc_en <= "0001";    -- increment program-counter
  1727.               s_nextstate <= EXEC1;
  1728.             elsif state=EXEC1 then
  1729.               s_data_mux <= "0011";     -- data = aludata_i
  1730.               s_regs_wr_en <= "011";    -- write ACC and CY,OV,AC
  1731.               alu_cmd_o <= SUB_ACC_ROM; -- subtraction command (ACC-ROM_DATA_I)
  1732.               s_pc_inc_en <= "0001";    -- increment program-counter
  1733.               s_nextstate <= FETCH;
  1734.             end if;
  1735.           ---------------------------------------------------------------------
  1736.           when IC_SWAP_A =>         -- SWAP A
  1737.             s_data_mux <= "0111";   -- data = acc(3 downto 0) acc(7 downto 4)
  1738.             s_regs_wr_en <= "010";  -- write ACC
  1739.             s_pc_inc_en <= "0001";  -- increment program-counter
  1740.             s_nextstate <= FETCH;
  1741.           ---------------------------------------------------------------------
  1742.           when IC_XCH_A_RR =>           -- XCH A,Rr
  1743.             if state=FETCH then
  1744.               s_adr_mux <= "0110";      -- address = rr-address
  1745.               s_data_mux <= "0110";     -- data = ACC
  1746.               s_regs_wr_en <= "100";    -- write one byte
  1747.               s_nextstate <= EXEC1;
  1748.             elsif state=EXEC1 then
  1749.               s_data_mux <= "0100";     -- data = s_reg_data;
  1750.               s_regs_wr_en <= "010";    -- write ACC
  1751.               s_pc_inc_en <= "0001";    -- increment program-counter
  1752.               s_nextstate <= FETCH;
  1753.             end if;
  1754.           ---------------------------------------------------------------------
  1755.           when IC_XCH_A_D =>            -- XCH A, direct
  1756.             if state=FETCH then
  1757.               s_pc_inc_en <= "0001";    -- increment program-counter
  1758.               s_nextstate <= EXEC1;
  1759.             elsif state=EXEC1 then
  1760.               s_adr_mux <= "1000";      -- address = rom_data_i
  1761.               s_data_mux <= "0110";     -- data = ACC
  1762.               s_regs_wr_en <= "100";    -- write one byte
  1763.               s_nextstate <= EXEC2;
  1764.             elsif state=EXEC2 then
  1765.               s_data_mux <= "0100";     -- data = s_reg_data;
  1766.               s_regs_wr_en <= "010";    -- write ACC
  1767.               s_pc_inc_en <= "0001";    -- increment program-counter
  1768.               s_nextstate <= FETCH;
  1769.             end if;
  1770.           ---------------------------------------------------------------------
  1771.           when IC_XCH_A_ATRI =>         -- XCH A,@Ri
  1772.             if state=FETCH then
  1773.               s_adr_mux <= "0111";      -- address = Ri-register
  1774.               s_data_mux <= "0110";     -- data = ACC
  1775.               s_regs_wr_en <= "100";    -- write one byte
  1776.               s_nextstate <= EXEC1;
  1777.             elsif state=EXEC1 then
  1778.               s_data_mux <= "0100";     -- data = s_reg_data;
  1779.               s_regs_wr_en <= "010";    -- write ACC
  1780.               s_pc_inc_en <= "0001";    -- increment program-counter
  1781.               s_nextstate <= FETCH;
  1782.             end if;
  1783.           ---------------------------------------------------------------------
  1784.           when IC_XCHD_A_ATRI =>        -- XCHD A,@Ri
  1785.             if state=FETCH then
  1786.               s_adr_mux <= "0111";      -- address = Ri-register
  1787.               s_help_en <= "1010";      -- s_help = acc
  1788.               s_nextstate <= EXEC1;
  1789.             elsif state=EXEC1 then
  1790.               s_adr_mux <= "0111";      -- address = Ri-register
  1791.               s_data_mux <= "1010";     -- data = acc(7..4) & s_reg_data(3..0)
  1792.               s_regs_wr_en <= "010";    -- write ACC
  1793.               s_nextstate <= EXEC2;
  1794.             elsif state=EXEC2 then
  1795.               s_adr_mux <= "0111";    -- address = Ri-register
  1796.               s_data_mux <= "1001";   -- data = s_reg_data(7..4) & s_help(3..0)
  1797.               s_regs_wr_en <= "100";  -- write one byte
  1798.               s_pc_inc_en <= "0001";  -- increment program-counter
  1799.               s_nextstate <= FETCH;
  1800.             end if;
  1801.           ---------------------------------------------------------------------
  1802.           when IC_XRL_A_RR =>           -- XRL A,Rr
  1803.             if state=FETCH then
  1804.               s_adr_mux <= "0110";      -- address = rr-address
  1805.               s_nextstate <= EXEC1;
  1806.             elsif state=EXEC1 then
  1807.               alu_cmd_o <= XOR_RAM_ACC; -- XOR command (ACC v RAM_DATA)
  1808.               s_data_mux <= "0011";     -- data = aludata_i
  1809.               s_regs_wr_en <= "010";    -- write ACC
  1810.               s_pc_inc_en <= "0001";    -- increment program-counter
  1811.               s_nextstate <= FETCH;
  1812.             end if;
  1813.           ---------------------------------------------------------------------
  1814.           when IC_XRL_A_D =>            -- XRL A, direct
  1815.             if state=FETCH then
  1816.               s_pc_inc_en <= "0001";    -- increment program-counter
  1817.               s_nextstate <= EXEC1;
  1818.             elsif state=EXEC1 then
  1819.               s_adr_mux <= "1000";
  1820.               s_nextstate <= EXEC2;
  1821.             elsif state=EXEC2 then
  1822.               alu_cmd_o <= XOR_RAM_ACC;   -- XOR command (ACC v RAM_DATA)
  1823.               s_data_mux <= "0011";       -- data = aludata_i
  1824.               s_regs_wr_en <= "010";      -- write ACC
  1825.               s_pc_inc_en <= "0001";      -- increment program-counter
  1826.               s_nextstate <= FETCH;
  1827.             end if;
  1828.           ---------------------------------------------------------------------
  1829.           when IC_XRL_A_ATRI =>         -- XRL A,@Ri
  1830.             if state=FETCH then
  1831.               s_adr_mux <= "0111";      -- address = Ri-register
  1832.               s_nextstate <= EXEC1;
  1833.             elsif state=EXEC1 then
  1834.               alu_cmd_o <= XOR_RAM_ACC; -- XOR command (ACC v RAM_DATA)
  1835.               s_data_mux <= "0011";     -- data = aludata_i
  1836.               s_regs_wr_en <= "010";    -- write ACC
  1837.               s_pc_inc_en <= "0001";    -- increment program-counter
  1838.               s_nextstate <= FETCH;
  1839.             end if;
  1840.           ---------------------------------------------------------------------
  1841.           when IC_XRL_A_DATA =>         -- XRL A, data
  1842.             if state=FETCH then
  1843.               s_pc_inc_en <= "0001";    -- increment program-counter
  1844.               s_nextstate <= EXEC1;
  1845.             elsif state=EXEC1 then
  1846.               s_data_mux <= "0011";     -- data = aludata_i
  1847.               s_regs_wr_en <= "010";    -- write ACC
  1848.               alu_cmd_o <= XOR_ROM_ACC; -- XOR command (ACC v ROM_DATA_I)
  1849.               s_pc_inc_en <= "0001";    -- increment program-counter
  1850.               s_nextstate <= FETCH;
  1851.             end if;
  1852.           ---------------------------------------------------------------------
  1853.           when IC_XRL_D_A =>            -- XRL direct, A
  1854.             if state=FETCH then
  1855.               s_pc_inc_en <= "0001";    -- increment program-counter
  1856.               s_nextstate <= EXEC1;
  1857.             elsif state=EXEC1 then
  1858.               s_adr_mux <= "1000";
  1859.               s_nextstate <= EXEC2;
  1860.             elsif state=EXEC2 then
  1861.               s_adr_mux <= "1000";
  1862.               s_data_mux <= "0011";     -- data = aludata_i
  1863.               s_regs_wr_en <= "100";    -- write one byte
  1864.               alu_cmd_o <= XOR_RAM_ACC; -- XOR command (ACC v RAM_DATA)
  1865.               s_pc_inc_en <= "0001";    -- increment program-counter
  1866.               s_nextstate <= FETCH;
  1867.             end if;
  1868.           ---------------------------------------------------------------------
  1869.           when IC_XRL_D_DATA =>         -- XRL direct, DATA
  1870.             if state=FETCH then
  1871.               s_pc_inc_en <= "0001";    -- increment program-counter
  1872.               s_nextstate <= EXEC1;
  1873.             elsif state=EXEC1 then
  1874.               s_help_en <= "0001";
  1875.               s_adr_mux <= "1000";
  1876.               s_pc_inc_en <= "0001";    -- increment program-counter
  1877.               s_nextstate <= EXEC2;
  1878.             elsif state=EXEC2 then
  1879.               s_adr_mux <= "1010";
  1880.               s_data_mux <= "0011";     -- data = aludata_i
  1881.               alu_cmd_o <= XOR_ROM_RAM; -- XOR command (ROM_DATA_I v RAM_DATA)
  1882.               s_regs_wr_en <= "100";    -- write one byte
  1883.               s_pc_inc_en <= "0001";    -- increment program-counter
  1884.               s_nextstate <= FETCH;
  1885.             end if;
  1886.           ---------------------------------------------------------------------
  1887.           when others =>
  1888.             s_nextstate <= FETCH;
  1889.         end case;
  1890.        end if;
  1891.      end if;
  1892.   end process p_state;
  1893. end rtl;