; definition of state machine: this_state: if(condition1) then { actions; Fstate = next_state1 } if(condition2) then { actions; Fstate = next_state2 } ... goto machine_yield ; go do something else next_state1: if(condition1.1) then { actions; Fstate = next_state1.1 } ... goto machine_yield When you translate into assembler: machine_init: movlw 0 ; initial state movwf Fstate machine_again: movf Fstate,w ; get state addlw Ctable_base ; you want to set the page bits here! movwf PC ; jump there Ctable_base: goto Sstate0 goto Sstate1 goto Sstate2 ... Sstate0: btfss PB,0 ; condition 1 goto state0_c1 ; not met, try next movf NEXT_STATE1 ; met, advance to next state movwf Fstate ;; state0:condition1 actions here goto machine_yield ; ran through state0_c1: btfss PB,1 ; condition 2 goto machine_yield ; not met, stay in same state, exit machine Sstate1: ... as above There are other ways to do this, such as direct threading (state transition physically jumps into the code of the next state instead of using Fstate. Direct threaded state machines are very hard to edit by hand (most programs written in assembly are direct threaded state machines ;-) ;-)). good luck, Peter -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.