// Etykiety current_state=0 finish_state=1 program_end=2 program=3 tape=4 left_shift=5 right_shift=6 current_pos=7 current_symbol=8 pc=9 n=10 p=11 q=12 put_symbol_to=13 C0=14 C1=15 C2=16 C3=17 C4=18 C5=19 absolute_pos=20 absolute_pos_mod=21 // C0...5=0...5 Z(C0) Z(C1) S(C1) Z(C2) S(C2) S(C2) T(C2,C3) S(C3) T(C3,C4) S(C4) T(C4,C5) S(C5) // left_shift=1; right_shift=2; T(C1,left_shift) T(C2,right_shift) // program=$PROGRAM Z(program) // for(i=0;i<$PROGRAM;i+=1) // { S(program) // } // tape=$TAPE Z(tape) // for(i=0;i<$TAPE;i+=1) // { S(tape) // } T(tape,current_pos) S(current_pos) S(current_pos) while: I(current_state,finish_state,end) T(program,pc) I(0,0,get_symbol) for: // for(i=$PROGRAM;i<$MAX_PROGRAM_END;i+=5) // { I(pc,program_end,undefined_state) I($i,current_state,state_ok_$i) I(0,0,continue_$i) state_ok_$i: I($i+1,current_symbol,found_instruction_$i) I(0,0,continue_$i) found_instruction_$i: // Zapamietaj pozycje glowicy T(current_pos,put_symbol_to) // absolute_pos = current_pos - tape // absolute_pos_mod = absolute_pos % 2 Z(p) Z(absolute_pos) Z(absolute_pos_mod) T(tape,p) subtract_pos_loop_$i: I(p,current_pos,subtract_pos_end_$i) S(p) S(absolute_pos) S(absolute_pos_mod) // if(absolute_pos_mod==2) absolute_pos_mod=0; I(absolute_pos_mod,C2,zero_mod_$i) I(0,0,subtract_pos_loop_$i) zero_mod_$i: Z(absolute_pos_mod) I(0,0,subtract_pos_loop_$i) subtract_pos_end_$i: // Czy ruch w lewo? I($i+3,left_shift,move_left_$i) I(0,0,check_right_$i) // Ruch w lewo move_left_$i: I(absolute_pos,C0,add_one_$i) I(absolute_pos_mod,C0,subtract_two_$i) I(absolute_pos_mod,C1,add_two_$i) check_right_$i: I($i+3,right_shift,move_right_$i) I(0,0,change_state_$i) move_right_$i: I(absolute_pos,C1,subtract_two_$i) I(absolute_pos_mod,C0,add_two_$i) T(tape,current_pos) I(0,0,change_state_$i) // Odejmij 2 od current_pos subtract_two_$i: Z(p) T(C2,q) subtract_two_loop_$i: I(q,current_pos,subtract_two_end_$i) S(p) S(q) I(0,0,subtract_two_loop_$i) subtract_two_end_$i: T(p,current_pos) I(0,0,change_state_$i) // Dodaj 1 do current_pos add_one_$i: S(current_pos) I(0,0,change_state_$i) // Dodaj 2 do current_pos add_two_$i: S(current_pos) S(current_pos) I(0,0,change_state_$i) // Ustaw nowy stan maszyny change_state_$i: T($i+4,current_state) // Drukuj symbol i wroc do glownej petli T($i+2,current_symbol) I(0,0,put_symbol) continue_$i: S(pc) S(pc) S(pc) S(pc) S(pc) // } I(0,0,undefined_state) get_symbol: T(tape,n) // for(i=$TAPE;i<=$TAPE_END;i+=1) // { I(n,current_pos,get_symbol_ok_$i) I(0,0,get_symbol_next_$i) get_symbol_ok_$i: T($i,current_symbol) I(0,0,for) get_symbol_next_$i: S(n) // } I(0,0,undefined_state) put_symbol: T(tape,n) // for(i=$TAPE;i<=$TAPE_END;i+=1) // { I(n,put_symbol_to,put_symbol_ok_$i) I(0,0,put_symbol_next_$i) put_symbol_ok_$i: T(current_symbol,$i) I(0,0,while) put_symbol_next_$i: S(n) // } I(0,0,undefined_state) // Koniec end: undefined_state: T(0,0)