about summary refs log tree commit diff stats
path: root/examples/hello-world.tf
diff options
context:
space:
mode:
Diffstat (limited to 'examples/hello-world.tf')
-rw-r--r--examples/hello-world.tf271
1 files changed, 28 insertions, 243 deletions
diff --git a/examples/hello-world.tf b/examples/hello-world.tf index 397bc43..227faf6 100644 --- a/examples/hello-world.tf +++ b/examples/hello-world.tf
@@ -8,47 +8,47 @@ ignored, the "[" and "]" characters just have to be balanced. This
8loop and the commands it contains are ignored because the current cell 8loop and the commands it contains are ignored because the current cell
9defaults to a value of 0; the 0 value causes this loop to be skipped. 9defaults to a value of 0; the 0 value causes this loop to be skipped.
10 10
11from https://en.wikipedia.org/wiki/Brainfuck#Hello_World! 11from https://en.wikipedia.org/wiki/Brainfuck#Hello_World!
12 12
13 13
14ALL ABOARD 14ALL ABOARD
15chug chug chug chug chug chug chug chug 15chug chug chug chug chug chug chug chug
16END OF THE LINE 16END OF THE LINE
17 Set Cell #0 to 8 17 Set Cell #0 to 8
18 18
19ALL ABOARD 19ALL ABOARD
20tickets please 20tickets please
21choo 21choo
22chug chug chug chug 22chug chug chug chug
23END OF THE LINE 23END OF THE LINE
24 Add 4 to Cell #1; this will always set Cell #1 to 4 24 Add 4 to Cell #1; this will always set Cell #1 to 4
25 25
26ALL ABOARD 26ALL ABOARD
27tickets please 27tickets please
28END OF THE LINE 28END OF THE LINE
29 as the cell will be cleared by the loop 29 as the cell will be cleared by the loop
30 30
31ALL ABOARD 31ALL ABOARD
32choo 32choo
33chug chug 33chug chug
34END OF THE LINE 34END OF THE LINE
35 Add 2 to Cell #2 35 Add 2 to Cell #2
36 36
37ALL ABOARD 37ALL ABOARD
38choo 38choo
39chug chug chug 39chug chug chug
40END OF THE LINE 40END OF THE LINE
41 Add 3 to Cell #3 41 Add 3 to Cell #3
42 42
43ALL ABOARD 43ALL ABOARD
44choo 44choo
45chug chug chug 45chug chug chug
46END OF THE LINE 46END OF THE LINE
47 Add 3 to Cell #4 47 Add 3 to Cell #4
48 48
49ALL ABOARD 49ALL ABOARD
50choo 50choo
51chug 51chug
52END OF THE LINE 52END OF THE LINE
53 Add 1 to Cell #5 53 Add 1 to Cell #5
54 54
@@ -57,55 +57,55 @@ choo choo
57choo choo 57choo choo
58choo choo 58choo choo
59choo choo 59choo choo
60chugga 60chugga
61END OF THE LINE 61END OF THE LINE
62 Decrement the loop counter in Cell #1 62 Decrement the loop counter in Cell #1
63 63
64ALL ABOARD 64ALL ABOARD
65your ticket please 65your ticket please
66END OF THE LINE 66END OF THE LINE
67 Loop until Cell #1 is zero; number of iterations is 4 67 Loop until Cell #1 is zero; number of iterations is 4
68 68
69ALL ABOARD 69ALL ABOARD
70choo 70choo
71chug 71chug
72END OF THE LINE 72END OF THE LINE
73 Add 1 to Cell #2 73 Add 1 to Cell #2
74 74
75ALL ABOARD 75ALL ABOARD
76choo 76choo
77chug 77chug
78END OF THE LINE 78END OF THE LINE
79 Add 1 to Cell #3 79 Add 1 to Cell #3
80 80
81ALL ABOARD 81ALL ABOARD
82choo 82choo
83chugga 83chugga
84END OF THE LINE 84END OF THE LINE
85 Subtract 1 from Cell #4 85 Subtract 1 from Cell #4
86 86
87ALL ABOARD 87ALL ABOARD
88choo 88choo
89choo 89choo
90chug 90chug
91END OF THE LINE 91END OF THE LINE
92 Add 1 to Cell #6 92 Add 1 to Cell #6
93 93
94ALL ABOARD 94ALL ABOARD
95tickets please choo choo 95tickets please choo choo
96your ticket please 96your ticket please
97END OF THE LINE 97END OF THE LINE
98 Move back to the first zero cell you find; this will 98 Move back to the first zero cell you find; this will
99 be Cell #1 which was cleared by the previous loop 99 be Cell #1 which was cleared by the previous loop
100 100
101ALL ABOARD 101ALL ABOARD
102choo choo 102choo choo
103chugga 103chugga
104END OF THE LINE 104END OF THE LINE
105 Decrement the loop Counter in Cell #0 105 Decrement the loop Counter in Cell #0
106 106
107ALL ABOARD 107ALL ABOARD
108your ticket please 108your ticket please
109END OF THE LINE 109END OF THE LINE
110 Loop until Cell #0 is zero; number of iterations is 8 110 Loop until Cell #0 is zero; number of iterations is 8
111 111
@@ -118,18 +118,18 @@ Pointer : ^
118ALL ABOARD 118ALL ABOARD
119choo 119choo
120choo 120choo
121click 121click
122END OF THE LINE 122END OF THE LINE
123 Cell #2 has value 72 which is 'H' 123 Cell #2 has value 72 which is 'H'
124 124
125ALL ABOARD 125ALL ABOARD
126choo 126choo
127chugga chugga chugga click 127chugga chugga chugga click
128END OF THE LINE 128END OF THE LINE
129 Subtract 3 from Cell #3 to get 101 which is 'e' 129 Subtract 3 from Cell #3 to get 101 which is 'e'
130 130
131ALL ABOARD 131ALL ABOARD
132chug chug chug chug chug chug chug clickety click chug chug chug click 132chug chug chug chug chug chug chug clickety click chug chug chug click
133 133
134END OF THE LINE 134END OF THE LINE
135 Likewise for 'llo' from Cell #3 135 Likewise for 'llo' from Cell #3
@@ -137,252 +137,37 @@ END OF THE LINE
137ALL ABOARD 137ALL ABOARD
138choo 138choo
139choo 139choo
140click 140click
141END OF THE LINE 141END OF THE LINE
142 Cell #5 is 32 for the space 142 Cell #5 is 32 for the space
143 143
144ALL ABOARD 144ALL ABOARD
145choo choo 145choo choo
146chugga clickety 146chugga clickety
147END OF THE LINE 147END OF THE LINE
148 Subtract 1 from Cell #4 for 87 to give a 'W' 148 Subtract 1 from Cell #4 for 87 to give a 'W'
149 149
150ALL ABOARD 150ALL ABOARD
151choo choo 151choo choo
152clickety 152clickety
153END OF THE LINE 153END OF THE LINE
154 Cell #3 was set to 'o' from the end of 'Hello' 154 Cell #3 was set to 'o' from the end of 'Hello'
155 155
156ALL ABOARD 156ALL ABOARD
157chug chug chug click chugga chugga chugga chugga chugga chugga clickety 157chug chug chug click chugga chugga chugga chugga chugga chugga clickety
158chugga chugga chugga chugga chugga chugga chugga chugga click 158chugga chugga chugga chugga chugga chugga chugga chugga click
159END OF THE LINE 159END OF THE LINE
160 Cell #3 for 'rl' and 'd' 160 Cell #3 for 'rl' and 'd'
161 161
162ALL ABOARD 162ALL ABOARD
163choo 163choo
164choo 164choo
165chug click 165chug click
166END OF THE LINE 166END OF THE LINE
167 Add 1 to Cell #5 gives us an exclamation point 167 Add 1 to Cell #5 gives us an exclamation point
168 168
169ALL ABOARD 169ALL ABOARD
170choo 170choo
171chug chug click 171chug chug click
172END OF THE LINE 172END OF THE LINE
173 And finally a newline from Cell #6 173 And finally a newline from Cell #6
174 ROT13 in Brainfuck
175from https://en.wikipedia.org/wiki/Brainfuck#ROT13
176
177
178
179
180ALL ABOARD
181chugga clack chug tickets please
182END OF THE LINE
183 Read first character and start outer character reading loop
184
185ALL ABOARD
186chugga tickets please
187END OF THE LINE
188 Skip forward if character is 0
189
190ALL ABOARD
191choo
192choo
193chug chug chug chug tickets please choo
194chug chug chug chug chug chug chug chug
195choo choo
196chugga your ticket please
197END OF THE LINE
198 Set up divisor (32) for division loop
199(MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero)
200
201ALL ABOARD
202choo choo
203chug choo choo
204chugga tickets please
205END OF THE LINE
206 Set up dividend (x minus 1) and enter division loop
207
208ALL ABOARD
209choo
210chug choo
211chug choo
212chugga tickets please choo
213choo
214choo
215your ticket please
216END OF THE LINE
217 Increase copy and remainder / reduce divisor / Normal case: skip forward
218
219ALL ABOARD
220choo choo
221tickets please tickets please choo
222chug choo choo
223chugga your ticket please choo
224choo
225chug choo
226your ticket please
227
228END OF THE LINE
229 Special case: move remainder back to divisor and increase quotient
230
231ALL ABOARD
232choo choo
233choo choo
234choo choo
235choo choo
236choo choo
237chugga
238END OF THE LINE
239 Decrement dividend
240
241ALL ABOARD
242your ticket please
243END OF THE LINE
244 End division loop
245
246ALL ABOARD
247your ticket please choo
248choo
249choo
250tickets please chugga your ticket please chug
251END OF THE LINE
252 End skip loop; zero former divisor and reuse space for a flag
253
254ALL ABOARD
255choo
256chugga chugga tickets please chugga tickets please choo choo
257chugga choo
258chug chug chug
259tickets please chugga your ticket please your ticket please your ticket please
260choo choo
261tickets please
262END OF THE LINE
263 Zero that flag unless quotient was 2 or 3; zero quotient; check flag
264
265ALL ABOARD
266chug chug chug chug chug chug chug chug chug chug chug chug choo choo
267tickets please
268
269END OF THE LINE
270 If flag then set up divisor (13) for second division loop
271(MEMORY LAYOUT: zero copy dividend divisor remainder quotient zero zero)
272
273ALL ABOARD
274choo
275chugga tickets please choo
276chug choo
277choo
278your ticket please
279END OF THE LINE
280 Reduce divisor; Normal case: increase remainder
281
282ALL ABOARD
283choo
284tickets please chug tickets please choo choo
285chug choo
286chugga your ticket please choo
287chug
288choo
289choo
290your ticket please
291END OF THE LINE
292 Special case: increase remainder / move it back to divisor / increase quotient
293
294ALL ABOARD
295choo choo
296choo choo
297choo choo
298choo choo
299choo choo
300chugga
301END OF THE LINE
302 Decrease dividend
303
304ALL ABOARD
305your ticket please
306END OF THE LINE
307 End division loop
308
309ALL ABOARD
310choo
311choo
312tickets please choo choo
313chug choo
314chugga your ticket please
315END OF THE LINE
316 Add remainder back to divisor to get a useful 13
317
318ALL ABOARD
319choo
320tickets please
321END OF THE LINE
322 Skip forward if quotient was 0
323
324ALL ABOARD
325chugga tickets please
326END OF THE LINE
327 Decrement quotient and skip forward if quotient was 1
328
329ALL ABOARD
330chugga choo choo
331choo choo
332tickets please chugga your ticket please choo
333choo
334
335END OF THE LINE
336 Zero quotient and divisor if quotient was 2
337
338ALL ABOARD
339your ticket please choo choo
340choo choo
341tickets please choo choo
342choo choo
343chugga choo
344choo
345chugga your ticket please choo
346choo
347
348END OF THE LINE
349 Zero divisor and subtract 13 from copy if quotient was 1
350
351ALL ABOARD
352your ticket please choo choo
353choo choo
354tickets please choo choo
355choo choo
356chug choo
357choo
358chugga your ticket please
359END OF THE LINE
360 Zero divisor and add 13 to copy if quotient was 0
361
362ALL ABOARD
363your ticket please
364END OF THE LINE
365 End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3)
366
367ALL ABOARD
368choo choo
369tickets please chugga your ticket please
370END OF THE LINE
371 Clear remainder from first division if second division was skipped
372
373ALL ABOARD
374choo choo
375click tickets please chugga your ticket please
376END OF THE LINE
377 Output ROT13ed character from copy and clear it
378
379ALL ABOARD
380choo choo
381chugga clack chug
382END OF THE LINE
383 Read next character
384
385ALL ABOARD
386your ticket please
387END OF THE LINE
388 End character reading loop