Writing a program in BF requires some planning, just as it used to be with machine language programming, but with the help of some macros it is not that hard. We will see that values will be copied arround between memory locations a lot, so some bookkeeping of which values are stored where and which memory locations are free, is needed.
For the description of the eight elementary BF commands, read the introduction page.
You can think yourself of a smart way of copying a value from one location to two other locations. In all the above examples we have silently assumed that the destination location contained the value zero. What if it did not? Exactly, then we would not have been moving and copying, but adding to the value already present.
This program assumes that the destination location d contains zero at the start of the program, and causes the source location s to become zero. Many of the following programs will follow this convention that the output locations are considered to be zero, and that the input locations are zeroed.
As multiplying can be seen as repeated adding, it is also very simply to see, how two numbers can be multiplied.
Dividing however, is a whole different story, far beyond an introductionary course.
The zero(s2) is needed to clear s2 in case s1 is zero.
To add a constant to a certain memory location, one can simply use the required number of '+' symbols. However for large constants this results in very long programs. To avoid this one can make use of multiplication or powers. To read more about how to make big constants efficiently, read the page Big numbers in BF.
b: Specifies the starting point (base) of the arrays.
n: Specifies the number of arrays.
v: For getting it is the memory location in which the value from the array should be stored into, while for setting it is the memory location from which the value is copied into the array.
In which the expression right(n) represent n times the '>' symbol, and in which the expression left(n) represent n times the '<' symbol.
Dr. Alva Couch has made an implementation for a macro language for producing BF code, which is based on the ideas presented on this page. The details can be found on this page. I also thank him for correcting some errors on this page, which he found while implementing the macro language.