Brainfuck Assembly (BFASM) is a human-readable assembly language designed to simplify the process of writing Brainfuck programs. Brainfuck, a minimalist esoteric language, uses only eight commands and is notoriously difficult to write and maintain due to its cryptic syntax. Brainfuck Assembly serves as an intermediate language, allowing developers to write more understandable code, which can then be translated into Brainfuck.
Features
This example implements a simple echo program that reads input from the user and outputs it, effectively functioning as a basic "cat" command in Unix, which outputs its input to the standard output.
in ; Get an initial input
jmp begin ; Begin the loop
out ; Output the previous value
in ; Get another input
jmp end ; End of loop
Simply transpile the cat.bfasm example program if the Brainfuck Assembly is already installed on the current system with the following command:
bfasm examples/cat.bfasm dist/cat.bf
Instructions
- in — This command reads one character from standard input and stores its ASCII value in the current memory cell. The in instruction has an equivalent Brainfuck instruction of ,.
- out — This command prints the ASCII character stored in the current memory cell to standard output also has an equivalent Brainfuck instruction ..
- mov ptr,
— Moves the memory pointer to the specified relative address. This instruction takes a parameter addr which is the relative address to move the pointer to. Positive values move the pointer to the right, and negative values move it to the left. - mov dat,
— Sets the value of the current memory cell to the specified value. Also takes a parameter named val for value to set in the current memory cell. If the value is positive, it corresponds to a series of + commands; if negative, to a series of - commands. - inc dat — Increments the value of the current memory cell by 1, which has an equivalent Brainfuck instruction of +.
- dec dat — Decrements the value of the current memory cell by 1, which has an equivalent Brainfuck instruction of -.
- inc ptr — Moves the memory pointer one cell to the right, similar to Brainfuck's >.
- dec ptr — Moves the memory pointer one cell to the left, similar to Brainfuck's <.
- ld
— Loads a value into the current memory cell by repeatedly incrementing it to reach the specified value. The parameter val is the value to load into the current memory cell. - jmp begin — This command begins a loop. The loop will continue to execute until the current memory cell's value is zero.
- jmp end — Ends the loop that started with jmp begin.

