На MPASM сделал так:
Код
ReadUserInput:
movlw high ReadUserInput_gotos
movwf PCLATH
movf a1_state, W ; W <- a1_state
andlw b'00000011' ; clip to [0..3]
addwf PCL, F ; jump
ReadUserInput_gotos:
goto read_user_input_0
goto read_user_input_1
goto read_user_input_2
goto read_user_input_3
; ^^^ 8 Tcy
read_user_input_0:
jbc b_tst, rui_00
bsf a1_state, 0
goto read_user_input_end
rui_00:
jbc b_dwn, rui_01
bsf a1_state, 1
goto read_user_input_end
rui_01:
clb b_ui_mc
jbs b_mc, read_user_input_end
seb b_ui_mc
bsf a1_state, 0
bsf a1_state, 1
goto read_user_input_end
read_user_input_1:
jbs b_tst, read_user_input_end
bcf a1_state, 0
seb b_ui_tst
goto read_user_input_end
read_user_input_2:
jbs b_dwn, read_user_input_end
bcf a1_state, 1
seb b_ui_dwn
goto read_user_input_end
read_user_input_3:
jbs b_mc, read_user_input_end
bcf a1_state, 0
bsf a1_state, 1
;seb b_ui_mc
;goto read_user_input_end
read_user_input_end:
return
movlw high ReadUserInput_gotos
movwf PCLATH
movf a1_state, W ; W <- a1_state
andlw b'00000011' ; clip to [0..3]
addwf PCL, F ; jump
ReadUserInput_gotos:
goto read_user_input_0
goto read_user_input_1
goto read_user_input_2
goto read_user_input_3
; ^^^ 8 Tcy
read_user_input_0:
jbc b_tst, rui_00
bsf a1_state, 0
goto read_user_input_end
rui_00:
jbc b_dwn, rui_01
bsf a1_state, 1
goto read_user_input_end
rui_01:
clb b_ui_mc
jbs b_mc, read_user_input_end
seb b_ui_mc
bsf a1_state, 0
bsf a1_state, 1
goto read_user_input_end
read_user_input_1:
jbs b_tst, read_user_input_end
bcf a1_state, 0
seb b_ui_tst
goto read_user_input_end
read_user_input_2:
jbs b_dwn, read_user_input_end
bcf a1_state, 1
seb b_ui_dwn
goto read_user_input_end
read_user_input_3:
jbs b_mc, read_user_input_end
bcf a1_state, 0
bsf a1_state, 1
;seb b_ui_mc
;goto read_user_input_end
read_user_input_end:
return
А теперь вопрос: как на C осуществить табличный переход? А то при использовании switch (a1_state) {case0: break; case 1: break; ...} или при использовании if (a1_state == 0) ... компилятор генерит код, который осуществляет проверку значения переменной a1_state на равенство сначала 0, потом 1, потом ... долго в общем. Пробовал еще так:
Код
typedef void (* StatePtr ) ( void );
void state0( void ) {}
void state1( void ) {}
...
const StatePtr states[] = {state0, state1, state2, state3};
char a1_state = 0;
void main()
{
while (1)
{
// some stuff
states[a1_state] ();
}
}
void state0( void ) {}
void state1( void ) {}
...
const StatePtr states[] = {state0, state1, state2, state3};
char a1_state = 0;
void main()
{
while (1)
{
// some stuff
states[a1_state] ();
}
}
Но перед вызовом функции states[a1_state]() компилятор загружает полный адрес функции, после чего вызывает

Как лечить, что читать?
Извиняюсь за возможные ошибки, но с пиками знаком лишь один месяц

