about summary refs log tree commit diff stats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/add2.tf441
-rw-r--r--examples/hello-world.tf271
-rw-r--r--examples/rot13.tf56
3 files changed, 83 insertions, 685 deletions
diff --git a/examples/add2.tf b/examples/add2.tf index 3c1529b..bdb0ddf 100644 --- a/examples/add2.tf +++ b/examples/add2.tf
@@ -5,7 +5,7 @@ from https://en.wikipedia.org/wiki/Brainfuck#Adding_two_values
5 5
6 6
7ALL ABOARD 7ALL ABOARD
8chug chug 8chug chug
9END OF THE LINE 9END OF THE LINE
10 Cell c0 = 2 10 Cell c0 = 2
11 11
@@ -13,15 +13,15 @@ ALL ABOARD
13choo 13choo
14 14
15END OF THE LINE 15END OF THE LINE
16 16
17ALL ABOARD 17ALL ABOARD
18chug chug chug chug chug 18chug chug chug chug chug
19END OF THE LINE 19END OF THE LINE
20 Cell c1 = 5 20 Cell c1 = 5
21 21
22 22
23ALL ABOARD 23ALL ABOARD
24tickets please 24tickets please
25END OF THE LINE 25END OF THE LINE
26 Start your loops with your cell pointer on the loop counter (c1 in our case) 26 Start your loops with your cell pointer on the loop counter (c1 in our case)
27 27
@@ -29,9 +29,9 @@ ALL ABOARD
29choo choo 29choo choo
30 30
31END OF THE LINE 31END OF THE LINE
32 32
33ALL ABOARD 33ALL ABOARD
34chug 34chug
35END OF THE LINE 35END OF THE LINE
36 Add 1 to c0 36 Add 1 to c0
37 37
@@ -39,14 +39,14 @@ ALL ABOARD
39choo 39choo
40 40
41END OF THE LINE 41END OF THE LINE
42 42
43ALL ABOARD 43ALL ABOARD
44chugga 44chugga
45END OF THE LINE 45END OF THE LINE
46 Subtract 1 from c1 46 Subtract 1 from c1
47 47
48ALL ABOARD 48ALL ABOARD
49your ticket please 49your ticket please
50END OF THE LINE 50END OF THE LINE
51 End your loops with the cell pointer on the loop counter 51 End your loops with the cell pointer on the loop counter
52 52
@@ -58,26 +58,26 @@ We use a loop to compute 48 = 6 * 8
58 58
59 59
60ALL ABOARD 60ALL ABOARD
61chug chug chug chug 61chug chug chug chug
62END OF THE LINE 62END OF THE LINE
63 63
64ALL ABOARD 64ALL ABOARD
65chug chug chug chug 65chug chug chug chug
66END OF THE LINE 66END OF THE LINE
67 c1 = 8 and this will be our loop counter again 67 c1 = 8 and this will be our loop counter again
68 68
69ALL ABOARD 69ALL ABOARD
70tickets please 70tickets please
71choo choo 71choo choo
72 72
73END OF THE LINE 73END OF THE LINE
74 74
75ALL ABOARD 75ALL ABOARD
76chug chug chug 76chug chug chug
77END OF THE LINE 77END OF THE LINE
78 78
79ALL ABOARD 79ALL ABOARD
80chug chug chug 80chug chug chug
81END OF THE LINE 81END OF THE LINE
82 Add 6 to c0 82 Add 6 to c0
83 83
@@ -85,416 +85,29 @@ ALL ABOARD
85choo 85choo
86 86
87END OF THE LINE 87END OF THE LINE
88 88
89ALL ABOARD 89ALL ABOARD
90chugga 90chugga
91END OF THE LINE 91END OF THE LINE
92 Subtract 1 from c1 92 Subtract 1 from c1
93 93
94ALL ABOARD 94ALL ABOARD
95your ticket please 95your ticket please
96choo choo 96choo choo
97 97
98END OF THE LINE 98END OF THE LINE
99 99
100ALL ABOARD 100ALL ABOARD
101click 101click
102END OF THE LINE 102END OF THE LINE
103 Print out c0 which has the value 55 which translates to "7"! 103 Print out c0 which has the value 55 which translates to "7"!
104 104
105Finally print a newline: 105Finally print a newline:
106 106
107ALL ABOARD 107ALL ABOARD
108chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga 108chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga
109chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga 109chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga
110chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga 110chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga
111chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga 111chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga
112chugga click 112chugga click
113 This program prints "Hello World!" and a newline to the screen, its
114length is 106 active command characters. [It is not the shortest.]
115
116This loop is an "initial comment loop", a simple way of adding a comment
117to a BF program such that you don't have to worry about any command
118characters. Any ".", ",", "+", "-", "<" and ">" characters are simply
119ignored, the "[" and "]" characters just have to be balanced. This
120loop and the commands it contains are ignored because the current cell
121defaults to a value of 0; the 0 value causes this loop to be skipped.
122
123from https://en.wikipedia.org/wiki/Brainfuck#Hello_World!
124
125
126ALL ABOARD
127chug chug chug chug chug chug chug chug
128END OF THE LINE
129 Set Cell #0 to 8
130
131ALL ABOARD
132tickets please
133choo
134chug chug chug chug
135END OF THE LINE
136 Add 4 to Cell #1; this will always set Cell #1 to 4
137
138ALL ABOARD
139tickets please
140END OF THE LINE
141 as the cell will be cleared by the loop
142
143ALL ABOARD
144choo
145chug chug
146END OF THE LINE
147 Add 2 to Cell #2
148
149ALL ABOARD
150choo
151chug chug chug
152END OF THE LINE
153 Add 3 to Cell #3
154
155ALL ABOARD
156choo
157chug chug chug
158END OF THE LINE
159 Add 3 to Cell #4
160
161ALL ABOARD
162choo
163chug
164END OF THE LINE
165 Add 1 to Cell #5
166
167ALL ABOARD
168choo choo
169choo choo
170choo choo
171choo choo
172chugga
173END OF THE LINE
174 Decrement the loop counter in Cell #1
175
176ALL ABOARD
177your ticket please
178END OF THE LINE
179 Loop until Cell #1 is zero; number of iterations is 4
180
181ALL ABOARD
182choo
183chug
184END OF THE LINE
185 Add 1 to Cell #2
186
187ALL ABOARD
188choo
189chug
190END OF THE LINE
191 Add 1 to Cell #3
192
193ALL ABOARD
194choo
195chugga
196END OF THE LINE
197 Subtract 1 from Cell #4
198
199ALL ABOARD
200choo
201choo
202chug
203END OF THE LINE
204 Add 1 to Cell #6
205
206ALL ABOARD
207tickets please choo choo
208your ticket please
209END OF THE LINE
210 Move back to the first zero cell you find; this will
211 be Cell #1 which was cleared by the previous loop
212
213ALL ABOARD
214choo choo
215chugga
216END OF THE LINE
217 Decrement the loop Counter in Cell #0
218
219ALL ABOARD
220your ticket please
221END OF THE LINE
222 Loop until Cell #0 is zero; number of iterations is 8
223
224The result of this is:
225Cell no : 0 1 2 3 4 5 6
226Contents: 0 0 72 104 88 32 8
227Pointer : ^
228
229
230ALL ABOARD
231choo
232choo
233click
234END OF THE LINE
235 Cell #2 has value 72 which is 'H'
236
237ALL ABOARD
238choo
239chugga chugga chugga click
240END OF THE LINE
241 Subtract 3 from Cell #3 to get 101 which is 'e'
242
243ALL ABOARD
244chug chug chug chug chug chug chug clickety click chug chug chug click
245
246END OF THE LINE
247 Likewise for 'llo' from Cell #3
248
249ALL ABOARD
250choo
251choo
252click
253END OF THE LINE
254 Cell #5 is 32 for the space
255
256ALL ABOARD
257choo choo
258chugga clickety
259END OF THE LINE
260 Subtract 1 from Cell #4 for 87 to give a 'W'
261
262ALL ABOARD
263choo choo
264clickety
265END OF THE LINE
266 Cell #3 was set to 'o' from the end of 'Hello'
267
268ALL ABOARD
269chug chug chug click chugga chugga chugga chugga chugga chugga clickety
270chugga chugga chugga chugga chugga chugga chugga chugga click
271END OF THE LINE
272 Cell #3 for 'rl' and 'd'
273
274ALL ABOARD
275choo
276choo
277chug click
278END OF THE LINE
279 Add 1 to Cell #5 gives us an exclamation point
280
281ALL ABOARD
282choo
283chug chug click
284END OF THE LINE
285 And finally a newline from Cell #6
286 ROT13 in Brainfuck
287from https://en.wikipedia.org/wiki/Brainfuck#ROT13
288
289
290
291
292ALL ABOARD
293chugga clack chug tickets please
294END OF THE LINE
295 Read first character and start outer character reading loop
296
297ALL ABOARD
298chugga tickets please
299END OF THE LINE
300 Skip forward if character is 0
301
302ALL ABOARD
303choo
304choo
305chug chug chug chug tickets please choo
306chug chug chug chug chug chug chug chug
307choo choo
308chugga your ticket please
309END OF THE LINE
310 Set up divisor (32) for division loop
311(MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero)
312
313ALL ABOARD
314choo choo
315chug choo choo
316chugga tickets please
317END OF THE LINE
318 Set up dividend (x minus 1) and enter division loop
319
320ALL ABOARD
321choo
322chug choo
323chug choo
324chugga tickets please choo
325choo
326choo
327your ticket please
328END OF THE LINE
329 Increase copy and remainder / reduce divisor / Normal case: skip forward
330
331ALL ABOARD
332choo choo
333tickets please tickets please choo
334chug choo choo
335chugga your ticket please choo
336choo
337chug choo
338your ticket please
339
340END OF THE LINE
341 Special case: move remainder back to divisor and increase quotient
342
343ALL ABOARD
344choo choo
345choo choo
346choo choo
347choo choo
348choo choo
349chugga
350END OF THE LINE
351 Decrement dividend
352
353ALL ABOARD
354your ticket please
355END OF THE LINE
356 End division loop
357
358ALL ABOARD
359your ticket please choo
360choo
361choo
362tickets please chugga your ticket please chug
363END OF THE LINE
364 End skip loop; zero former divisor and reuse space for a flag
365
366ALL ABOARD
367choo
368chugga chugga tickets please chugga tickets please choo choo
369chugga choo
370chug chug chug
371tickets please chugga your ticket please your ticket please your ticket please
372choo choo
373tickets please
374END OF THE LINE
375 Zero that flag unless quotient was 2 or 3; zero quotient; check flag
376
377ALL ABOARD
378chug chug chug chug chug chug chug chug chug chug chug chug choo choo
379tickets please
380
381END OF THE LINE
382 If flag then set up divisor (13) for second division loop
383(MEMORY LAYOUT: zero copy dividend divisor remainder quotient zero zero)
384
385ALL ABOARD
386choo
387chugga tickets please choo
388chug choo
389choo
390your ticket please
391END OF THE LINE
392 Reduce divisor; Normal case: increase remainder
393
394ALL ABOARD
395choo
396tickets please chug tickets please choo choo
397chug choo
398chugga your ticket please choo
399chug
400choo
401choo
402your ticket please
403END OF THE LINE
404 Special case: increase remainder / move it back to divisor / increase quotient
405
406ALL ABOARD
407choo choo
408choo choo
409choo choo
410choo choo
411choo choo
412chugga
413END OF THE LINE
414 Decrease dividend
415
416ALL ABOARD
417your ticket please
418END OF THE LINE
419 End division loop
420
421ALL ABOARD
422choo
423choo
424tickets please choo choo
425chug choo
426chugga your ticket please
427END OF THE LINE
428 Add remainder back to divisor to get a useful 13
429
430ALL ABOARD
431choo
432tickets please
433END OF THE LINE
434 Skip forward if quotient was 0
435
436ALL ABOARD
437chugga tickets please
438END OF THE LINE
439 Decrement quotient and skip forward if quotient was 1
440
441ALL ABOARD
442chugga choo choo
443choo choo
444tickets please chugga your ticket please choo
445choo
446
447END OF THE LINE
448 Zero quotient and divisor if quotient was 2
449
450ALL ABOARD
451your ticket please choo choo
452choo choo
453tickets please choo choo
454choo choo
455chugga choo
456choo
457chugga your ticket please choo
458choo
459
460END OF THE LINE
461 Zero divisor and subtract 13 from copy if quotient was 1
462
463ALL ABOARD
464your ticket please choo choo
465choo choo
466tickets please choo choo
467choo choo
468chug choo
469choo
470chugga your ticket please
471END OF THE LINE
472 Zero divisor and add 13 to copy if quotient was 0
473
474ALL ABOARD
475your ticket please
476END OF THE LINE
477 End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3)
478
479ALL ABOARD
480choo choo
481tickets please chugga your ticket please
482END OF THE LINE
483 Clear remainder from first division if second division was skipped
484
485ALL ABOARD
486choo choo
487click tickets please chugga your ticket please
488END OF THE LINE
489 Output ROT13ed character from copy and clear it
490
491ALL ABOARD
492choo choo
493chugga clack chug
494END OF THE LINE
495 Read next character
496
497ALL ABOARD
498your ticket please
499END OF THE LINE 113END OF THE LINE
500 End character reading loop
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
diff --git a/examples/rot13.tf b/examples/rot13.tf index f7c24df..31a6829 100644 --- a/examples/rot13.tf +++ b/examples/rot13.tf
@@ -5,12 +5,12 @@ from https://en.wikipedia.org/wiki/Brainfuck#ROT13
5 5
6 6
7ALL ABOARD 7ALL ABOARD
8chugga clack chug tickets please 8chugga clack chug tickets please
9END OF THE LINE 9END OF THE LINE
10 Read first character and start outer character reading loop 10 Read first character and start outer character reading loop
11 11
12ALL ABOARD 12ALL ABOARD
13chugga tickets please 13chugga tickets please
14END OF THE LINE 14END OF THE LINE
15 Skip forward if character is 0 15 Skip forward if character is 0
16 16
@@ -18,9 +18,9 @@ ALL ABOARD
18choo 18choo
19choo 19choo
20chug chug chug chug tickets please choo 20chug chug chug chug tickets please choo
21chug chug chug chug chug chug chug chug 21chug chug chug chug chug chug chug chug
22choo choo 22choo choo
23chugga your ticket please 23chugga your ticket please
24END OF THE LINE 24END OF THE LINE
25 Set up divisor (32) for division loop 25 Set up divisor (32) for division loop
26(MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero) 26(MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero)
@@ -28,7 +28,7 @@ END OF THE LINE
28ALL ABOARD 28ALL ABOARD
29choo choo 29choo choo
30chug choo choo 30chug choo choo
31chugga tickets please 31chugga tickets please
32END OF THE LINE 32END OF THE LINE
33 Set up dividend (x minus 1) and enter division loop 33 Set up dividend (x minus 1) and enter division loop
34 34
@@ -39,7 +39,7 @@ chug choo
39chugga tickets please choo 39chugga tickets please choo
40choo 40choo
41choo 41choo
42your ticket please 42your ticket please
43END OF THE LINE 43END OF THE LINE
44 Increase copy and remainder / reduce divisor / Normal case: skip forward 44 Increase copy and remainder / reduce divisor / Normal case: skip forward
45 45
@@ -50,7 +50,7 @@ chug choo choo
50chugga your ticket please choo 50chugga your ticket please choo
51choo 51choo
52chug choo 52chug choo
53your ticket please 53your ticket please
54 54
55END OF THE LINE 55END OF THE LINE
56 Special case: move remainder back to divisor and increase quotient 56 Special case: move remainder back to divisor and increase quotient
@@ -61,12 +61,12 @@ choo choo
61choo choo 61choo choo
62choo choo 62choo choo
63choo choo 63choo choo
64chugga 64chugga
65END OF THE LINE 65END OF THE LINE
66 Decrement dividend 66 Decrement dividend
67 67
68ALL ABOARD 68ALL ABOARD
69your ticket please 69your ticket please
70END OF THE LINE 70END OF THE LINE
71 End division loop 71 End division loop
72 72
@@ -74,7 +74,7 @@ ALL ABOARD
74your ticket please choo 74your ticket please choo
75choo 75choo
76choo 76choo
77tickets please chugga your ticket please chug 77tickets please chugga your ticket please chug
78END OF THE LINE 78END OF THE LINE
79 End skip loop; zero former divisor and reuse space for a flag 79 End skip loop; zero former divisor and reuse space for a flag
80 80
@@ -82,16 +82,16 @@ ALL ABOARD
82choo 82choo
83chugga chugga tickets please chugga tickets please choo choo 83chugga chugga tickets please chugga tickets please choo choo
84chugga choo 84chugga choo
85chug chug chug 85chug chug chug
86tickets please chugga your ticket please your ticket please your ticket please 86tickets please chugga your ticket please your ticket please your ticket please
87choo choo 87choo choo
88tickets please 88tickets please
89END OF THE LINE 89END OF THE LINE
90 Zero that flag unless quotient was 2 or 3; zero quotient; check flag 90 Zero that flag unless quotient was 2 or 3; zero quotient; check flag
91 91
92ALL ABOARD 92ALL ABOARD
93chug chug chug chug chug chug chug chug chug chug chug chug choo choo 93chug chug chug chug chug chug chug chug chug chug chug chug choo choo
94tickets please 94tickets please
95 95
96END OF THE LINE 96END OF THE LINE
97 If flag then set up divisor (13) for second division loop 97 If flag then set up divisor (13) for second division loop
@@ -102,7 +102,7 @@ choo
102chugga tickets please choo 102chugga tickets please choo
103chug choo 103chug choo
104choo 104choo
105your ticket please 105your ticket please
106END OF THE LINE 106END OF THE LINE
107 Reduce divisor; Normal case: increase remainder 107 Reduce divisor; Normal case: increase remainder
108 108
@@ -111,10 +111,10 @@ choo
111tickets please chug tickets please choo choo 111tickets please chug tickets please choo choo
112chug choo 112chug choo
113chugga your ticket please choo 113chugga your ticket please choo
114chug 114chug
115choo 115choo
116choo 116choo
117your ticket please 117your ticket please
118END OF THE LINE 118END OF THE LINE
119 Special case: increase remainder / move it back to divisor / increase quotient 119 Special case: increase remainder / move it back to divisor / increase quotient
120 120
@@ -124,12 +124,12 @@ choo choo
124choo choo 124choo choo
125choo choo 125choo choo
126choo choo 126choo choo
127chugga 127chugga
128END OF THE LINE 128END OF THE LINE
129 Decrease dividend 129 Decrease dividend
130 130
131ALL ABOARD 131ALL ABOARD
132your ticket please 132your ticket please
133END OF THE LINE 133END OF THE LINE
134 End division loop 134 End division loop
135 135
@@ -138,18 +138,18 @@ choo
138choo 138choo
139tickets please choo choo 139tickets please choo choo
140chug choo 140chug choo
141chugga your ticket please 141chugga your ticket please
142END OF THE LINE 142END OF THE LINE
143 Add remainder back to divisor to get a useful 13 143 Add remainder back to divisor to get a useful 13
144 144
145ALL ABOARD 145ALL ABOARD
146choo 146choo
147tickets please 147tickets please
148END OF THE LINE 148END OF THE LINE
149 Skip forward if quotient was 0 149 Skip forward if quotient was 0
150 150
151ALL ABOARD 151ALL ABOARD
152chugga tickets please 152chugga tickets please
153END OF THE LINE 153END OF THE LINE
154 Decrement quotient and skip forward if quotient was 1 154 Decrement quotient and skip forward if quotient was 1
155 155
@@ -182,34 +182,34 @@ tickets please choo choo
182choo choo 182choo choo
183chug choo 183chug choo
184choo 184choo
185chugga your ticket please 185chugga your ticket please
186END OF THE LINE 186END OF THE LINE
187 Zero divisor and add 13 to copy if quotient was 0 187 Zero divisor and add 13 to copy if quotient was 0
188 188
189ALL ABOARD 189ALL ABOARD
190your ticket please 190your ticket please
191END OF THE LINE 191END OF THE LINE
192 End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3) 192 End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3)
193 193
194ALL ABOARD 194ALL ABOARD
195choo choo 195choo choo
196tickets please chugga your ticket please 196tickets please chugga your ticket please
197END OF THE LINE 197END OF THE LINE
198 Clear remainder from first division if second division was skipped 198 Clear remainder from first division if second division was skipped
199 199
200ALL ABOARD 200ALL ABOARD
201choo choo 201choo choo
202click tickets please chugga your ticket please 202click tickets please chugga your ticket please
203END OF THE LINE 203END OF THE LINE
204 Output ROT13ed character from copy and clear it 204 Output ROT13ed character from copy and clear it
205 205
206ALL ABOARD 206ALL ABOARD
207choo choo 207choo choo
208chugga clack chug 208chugga clack chug
209END OF THE LINE 209END OF THE LINE
210 Read next character 210 Read next character
211 211
212ALL ABOARD 212ALL ABOARD
213your ticket please 213your ticket please
214END OF THE LINE 214END OF THE LINE
215 End character reading loop 215 End character reading loop