Hello, I seem to be having a problem doing a computed goto with a 18f258. I'm basically trying to make a state machine, but only the first two states are working, and I use that term loosely. I'm using the following code to generate the state-machine run loop. The "curr_state" variable holds the current state number. I've made this a macro so that the GOTOs can be generated automatically. In my test code, the "states" is set to 3 (so, labels state0, state1, and state2.) run_state_machine macro states movlw UPPER(state0) ; make sure the upper bytes of the PC movwf PCLATU ; register are defined to the beginning movlw HIGH(state0) ; of the state machine goto list movwf PCLATH banksel curr_state rlncf curr_state, W ; double because gotos are two words long addwf PCL, F local index = 0 while index < states goto state#v(index) index = index + 1 endw endm Does anyone see what I'm doing wrong with this code? When I set "curr_state" to 2, it should vector to the third GOTO, but that does not happen. I'm not sure if this is enough information, but if more is required, please let me know. I can post as much as required. Thank you for any help you can provide. -- Robert -- Robert James Kaes --- Flarenet Inc. --- (519) 426-3782 http://www.flarenet.com/consulting/ * Putting the Service Back in Internet Service Provider * -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads