about summary refs log tree commit diff stats
path: root/examples/add2.tf
blob: bdb0ddf9862402fed472c8364c8a0d2d890ee8b1 (plain)
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
  Add two values
from https://en.wikipedia.org/wiki/Brainfuck#Adding_two_values




ALL ABOARD
chug chug 
END OF THE LINE
       Cell c0 = 2

ALL ABOARD
choo

END OF THE LINE
 
ALL ABOARD
chug chug chug chug chug 
END OF THE LINE
  Cell c1 = 5


ALL ABOARD
tickets please 
END OF THE LINE
        Start your loops with your cell pointer on the loop counter (c1 in our case)

ALL ABOARD
choo choo

END OF THE LINE
 
ALL ABOARD
chug 
END OF THE LINE
      Add 1 to c0

ALL ABOARD
choo

END OF THE LINE
 
ALL ABOARD
chugga 
END OF THE LINE
      Subtract 1 from c1

ALL ABOARD
your ticket please 
END OF THE LINE
        End your loops with the cell pointer on the loop counter

At this point our program has added 5 to 2 leaving 7 in c0 and 0 in c1
but we cannot output this value to the terminal since it is not ASCII encoded

To display the ASCII character "7" we must add 48 to the value 7
We use a loop to compute 48 = 6 * 8


ALL ABOARD
chug chug chug chug 
END OF THE LINE
 
ALL ABOARD
chug chug chug chug 
END OF THE LINE
  c1 = 8 and this will be our loop counter again

ALL ABOARD
tickets please 
choo choo

END OF THE LINE
 
ALL ABOARD
chug chug chug 
END OF THE LINE
 
ALL ABOARD
chug chug chug 
END OF THE LINE
  Add 6 to c0

ALL ABOARD
choo

END OF THE LINE
 
ALL ABOARD
chugga 
END OF THE LINE
        Subtract 1 from c1

ALL ABOARD
your ticket please 
choo choo

END OF THE LINE
 
ALL ABOARD
click 
END OF THE LINE
        Print out c0 which has the value 55 which translates to "7"!

Finally print a newline:

ALL ABOARD
chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga 
chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga 
chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga 
chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga 
chugga click 
END OF THE LINE