From 0a78720644e45bd27c4a57cbddf2d32aacb555c3 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 29 Jun 2022 00:59:59 -0500 Subject: Probably version ... whatever the next higher one is --- examples/add2.bf | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 examples/add2.bf (limited to 'examples/add2.bf') 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 @@ +[ Add two values +from https://en.wikipedia.org/wiki/Brainfuck#Adding_two_values +] + +++ Cell c0 = 2 +> +++++ Cell c1 = 5 + +[ Start your loops with your cell pointer on the loop counter (c1 in our case) +< + Add 1 to c0 +> - Subtract 1 from c1 +] 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 + +++++ ++++ c1 = 8 and this will be our loop counter again +[ +< +++ +++ Add 6 to c0 +> - Subtract 1 from c1 +] +< . Print out c0 which has the value 55 which translates to "7"! + +Finally print a newline: +---------------------------------------------. -- cgit 1.4.1-21-gabe81