diff options
author | Case Duckworth | 2022-06-29 00:59:59 -0500 |
---|---|---|
committer | Case Duckworth | 2022-06-29 00:59:59 -0500 |
commit | 0a78720644e45bd27c4a57cbddf2d32aacb555c3 (patch) | |
tree | 29783dc9a534dbbfe172d5c84e66f5efcd9c43dc /examples/add2.bf | |
parent | Recognize bf comments (diff) | |
download | trainfuck-0a78720644e45bd27c4a57cbddf2d32aacb555c3.tar.gz trainfuck-0a78720644e45bd27c4a57cbddf2d32aacb555c3.zip |
Probably version ... whatever the next higher one is
Diffstat (limited to 'examples/add2.bf')
-rw-r--r-- | examples/add2.bf | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/add2.bf b/examples/add2.bf new file mode 100644 index 0000000..42361db --- /dev/null +++ b/examples/add2.bf | |||
@@ -0,0 +1,27 @@ | |||
1 | [ Add two values | ||
2 | from https://en.wikipedia.org/wiki/Brainfuck#Adding_two_values | ||
3 | ] | ||
4 | |||
5 | ++ Cell c0 = 2 | ||
6 | > +++++ Cell c1 = 5 | ||
7 | |||
8 | [ Start your loops with your cell pointer on the loop counter (c1 in our case) | ||
9 | < + Add 1 to c0 | ||
10 | > - Subtract 1 from c1 | ||
11 | ] End your loops with the cell pointer on the loop counter | ||
12 | |||
13 | At this point our program has added 5 to 2 leaving 7 in c0 and 0 in c1 | ||
14 | but we cannot output this value to the terminal since it is not ASCII encoded | ||
15 | |||
16 | To display the ASCII character "7" we must add 48 to the value 7 | ||
17 | We use a loop to compute 48 = 6 * 8 | ||
18 | |||
19 | ++++ ++++ c1 = 8 and this will be our loop counter again | ||
20 | [ | ||
21 | < +++ +++ Add 6 to c0 | ||
22 | > - Subtract 1 from c1 | ||
23 | ] | ||
24 | < . Print out c0 which has the value 55 which translates to "7"! | ||
25 | |||
26 | Finally print a newline: | ||
27 | ---------------------------------------------. | ||