Here we take a look at some building blocks for Brainfuck programs. I'm not going into painful detail about these. They're all pretty easy to understand (after all, it's an easy language) and there's no better way to get a feel for a language then to play with it.
Examples:
Move a value from a[p]
to a[p+1]
.
[>+<-]Move a value from
a[p]
to a[p+2]
and a[p+4]
.
[>>+>>+<<<<-]
Examples:
Simple copy from a[p]
to a[p+1]
(using a[p+2]
as a work area).
[>+>+<<-]>>[<<+>>-]Copy from
a[p]
to a[p+1]
and a[p+2]
(using [p+3]
as a work area).
[>+>+>+<<<-]>>>[<<<+>>>-]
Example:
Multiply three (a[p]
) times five.
+++[>+++++<-]
Example:
Multiply three (a[p]
) times five (a[p+1]
) and place the result in a[p+2]
.
+++>+++++< [>>>+>+<<<<-]>>>>[<<<<+>>>>-]< [<< [>>>+>+<<<<-]>>>>[<<<<+>>>>-]< [<<+>>-] <-]
Traditionally, since Brainfuck dealt only with byte values using unsigned arithmetic, there were no issues vis-a-vis negative numbers. Many implimentations (my own amongst them), however, allow for values which exceed one byte, supporting signed arithmetic. Should you wish to use any of these 'expanded' Brainfuck implementations, all the above can be adapted for use with negative numbers, etc...
Aw, your smart... You'll figure it out!
"OK. I'm ready play around with this. Do I have to roll my own interpreter or do you have something I can use?"
Geez... Nobody ever wants to do any extra work :).
Have a look here for some Brainfuck resources.
Home | Introduction | First Program | Input Processing | Building Blocks | Resources | bf2pl