forked from aaronbloomfield/pdr
-
Notifications
You must be signed in to change notification settings - Fork 228
/
turing.ibcm
126 lines (126 loc) · 5.52 KB
/
turing.ibcm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
c010 000 jmp init // skip around variables
0000 001 state 0000 // current state
0100 002 head 3000 // current head position
0000 003 input 0000 // current input symbol
0000 004 initial 0000 // value of initial state (0)
0003 005 final 0001 // value of final state (1)
3000 006 load 3000 // value of load instruction
4000 007 store 4000 // value of store instruction
0060 008 trans 3000 // start of transitions
0000 009 xpos 0000 // transition memory position
0000 00a zero 0000 // the constant 0
0001 00b one 0001 // the constant 1
0002 00c two 0002 // the constant 2
0003 00d three 0003 // the constant 3
0004 00e four 0004 // the constant 4
0005 00f five 0005 // the constant 5
3004 010 init load initial // load initial state
4001 011 store state // store as current state
3001 012 start load state // load current state variable
6005 013 sub final // subtract the final state
d016 014 jmpe exit // if zero, then we are in the final state
c017 015 jmp cont // if not, then keep going
0000 016 exit halt // we are in the final state, so halt
3002 017 cont load head // load head position
5006 018 add load // add load instruction value
401a 019 store pos1 // store the load instruction into pos1
b000 01a pos1 nop // will hold the load instruction; input symbol is now in acc
4003 01b store input // store input symbol
3008 01c load trans // load start of transitions
4009 01d store xpos // store in xpos, the transition position
c022 01e jmp midloop // skip past increment step the first time
3009 01f loop load xpos // otherwise, we will iterate again
500f 020 add five // add 5 to xpos
4009 021 store xpos // store the updated value
3009 022 midloop load xpos // load current transition position
5006 023 add load // create a load instruction
4025 024 store pos2 // store in next instruction
b000 025 pos2 nop // will hold the load transition function state command
6001 026 sub state // subtract the current state
d029 027 jmpe found // if zero, we've found a transition for the current state
c01f 028 jmp loop // otherwise, continue the loop
3009 029 found load xpos // load start of transitions
5006 02a add load // create a load instruction
500b 02b add one // move forward one for the input symbol
402d 02c store pos3 // store in next instruction
b000 02d pos3 nop // will hold the load transition function input symbol command
6003 02e sub input // subtract the current input symbol
d031 02f jmpe bingo // we've found the right transition
c01f 030 jmp loop // otherwise, continue the loop
3009 031 bingo load xpos // load position of transition function
5006 032 add load // create a load instruction
500c 033 add two // move forward two for the destination state
4035 034 store pos4 // store in next instruction
b000 035 pos4 nop // will hold the load destination state command
4001 036 store state // store that in the state variable
3009 037 load xpos // load position of transition function
5006 038 add load // create a load instruction
500d 039 add three // move forward three for the output symbol to write
403b 03a store pos5 // store in next instruction
b000 03b pos5 nop // will hold the load output symbol command
4003 03c store input // store that in the input variable
3002 03d load head // load position of tape head
5007 03e add store // create a store instruction
4041 03f store pos6 // store in next instruction
3003 040 load input // load the output symbol to write
b000 041 pos6 nop // will hold the store output symbol command
3009 042 load xpos // load position of transition function
5006 043 add load // create a load instruction
500e 044 add four // move forward four for the
4046 045 store pos7 // store in next instruction
b000 046 pos7 nop // will hold the load tape direction command
d04b 047 jmpe moveL // if zero, that means move the tape left
600b 048 sub one // subtract one
d04f 049 jmpe moveR // if it *was* one, that means move the tape right
c012 04a jmp start // otherwise, there is no movement; done with this iteration!
3002 04b moveL load head // load the head position
500b 04c add one // add one, effectively moving the tape to the left
4002 04d store head // store the updated head position
c012 04e jmp start // done with this iteration!
3002 04f moveR load head // load the head position
600b 050 sub one // subtract one, effectively moving the tape to the right
4002 051 store head // store the updated head position
c012 052 jmp start // done with this iteration!
0000 053
0000 054
0000 055
0000 056
0000 057
0000 058
0000 059
0000 05a
0000 05b
0000 05c
0000 05d
0000 05e
0000 05f
0000 060 // transition: from state 0
0000 061 // on input 0
0001 062 // goes to state 1
0001 063 // and writes a 1
0001 064 // and moves the tape right
0000 065 // transition: from state 0
0001 066 // on input 1
0002 067 // goes to state 2
0001 068 // and writes a 1
0000 069 // and moves the tape left
0001 06a // transition: from state 1
0000 06b // on input 0
0000 06c // goes to state 0
0001 06d // and writes a 1
0000 06e // and moves the tape left
0001 06f // transition: from state 1
0001 070 // on input 1
0001 071 // goes to state 1
0001 072 // and writes a 1
0001 073 // and moves the tape right
0002 074 // transition: from state 2
0000 075 // on input 0
0001 076 // goes to state 1
0001 077 // and writes a 1
0000 078 // and moves the tape left
0002 079 // transition: from state 2
0001 07a // on input 1
0003 07b // goes to state 3
0001 07c // and writes a 1
0002 07d // and doesn't move the tape