-
Notifications
You must be signed in to change notification settings - Fork 0
/
rule110.mx
229 lines (197 loc) · 2.33 KB
/
rule110.mx
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
; Rule 110 reference implementation in Masfix, without macros
; input prompt
:start
outc 73
outc 110
outc 112
outc 117
outc 116
outc 32
outc 98
outc 111
outc 97
outc 114
outc 100
outc 32
outc 115
outc 105
outc 122
outc 101
outc 32
outc 40
outc 50
outc 32
outc 45
outc 32
outc 49
outc 48
outc 48
outc 41
outc 58
outc 32
inu
inl
outc 10
:run_rule110 ; size @r
; clamp to bounds
strr
lds 2
bge over2
str 2
:over2
ldm
lds 100
blt below100
str 100
:below100
ldm
; memory ; size @r
mov 0 ; size of board
strr
mov 1 ; line idx
str 0
mov 2 ; cell idx
str 0
mov 3 ; new value for the left cell
str 0
mov 4 ; addr of curr cell
str 0
; 10 - 20 temp
; 1024 - 1024+size - line of board
:init_line
mov 2 ; board[curr] = 0
movm
mova 1023
str 0
mov 0 ; while (curr != size)
ldm
lda 2 ; before first and after last
mov 2
stra 1 ; curr ++
ldsm
bne init_line
mov 2 ; curr = 0
str 0
mov 0 ; board[-1] = true
movm
mova 1023
str 1
:line_loop
mov 0
ldm
mov 1 ; while (line idx < board size)
ldsm
beq end_rule110
ldm
; var init - cell idx = 0, new val = 0
mov 2
str 0
mov 3
str 0
:cell_loop
mov 0 ; while (cell idx < board size)
ldm
mov 2
ldsm
beq end_line_loop
ldm ; r = &board[curr]
lda 1024
mov 4 ; curr addr = &board[curr]
strr
; update_cell ; cell addr in temp[1]
mov 4
movm
; get cells around ; at central cell
movs 1
ldm
mova 1
ld< 1
ldam
mova 1
ld< 1
ldam
; print original cell ; cell values @r
mov 10
strr
ld. 1
ld^ 1
ldt 11
lda 35
outcr
; get evolved value ; cell values @m
ldm
ld& 3
lne 0
swap
lne 7
ld&m
; update left node, store curr ; evolved state @r
mov 3
swap
mov 2
movm
mova 1023
strr
mov 2 ; cell idx ++
stra 1
jmp cell_loop
:end_line_loop
; update last entry
mov 3
ldm
mov 0
movm
mova 1023
strr
outc 10
mov 1 ; line idx ++
stra 1
jmp line_loop
:end_rule110
; repeat prompt
outc 10
outc 82
outc 101
outc 112
outc 101
outc 97
outc 116
outc 63
outc 32
outc 40
outc 121
outc 47
outc 110
outc 47
outc 110
outc 117
outc 109
outc 98
outc 101
outc 114
outc 41
outc 58
outc 32
ipc
strr
lds 89 ; 'Y'
beq repeat
ldm
lds 121 ; 'y'
beq repeat
ldm
lds 48 ; '0'
blt end
lds 9
bgt end
inu
inl
beq end
jmp repeat_with_num
:repeat
inl
outc 10
jmp start
:repeat_with_num
outc 10
jmp run_rule110