Brainfuck interpreter for Linux, written in IA-32/i386/x86 assembly language using the NASM syntax.
Execution of the mandelbrot program by Erik Bosman.
Current version: 2019.04.1
Format: <year>.<zero padded month>.<revision number>
Brainfuck is a very simple programming language created by Urban Müller in 1993. It has 8 different instructions which are used to operate a pointer and an array of memory cells. Despite being turing complete, the minimalistic aspect of the language means that it is very complex to create anything useful with it.
Instruction | Description | C equivalent |
---|---|---|
> | increase cell pointer | ++cellPointer; |
> | decrease cell pointer | --cellPointer; |
+ | increase cell value | ++*cellPointer; |
- | decrease cell value | --*cellPointer; |
. | print cell value | putchar(*cellPointer); |
, | store one byte of input into cell | *cellPointer = getchar(); |
[ | if the cell value is 0, jump to the instruction next to the matching ']' | while (*cellPointer == 0) { |
] | if the cell value is not 0, jump to the instruction next to the matching '[' | } |
Description | Value |
---|---|
Cell size | 1 byte |
Tape size | 30000 cells (configurable) |
Out of bounds behaviour | wraparound |
New line value | 10 |
EOF behaviour | no change |
Input stream | standard input |
Output stream | standard output |
Error stream | standard error |
This program needs to be assembled using the NASM assembler.
nasm -f elf main.asm
ld -m elf_i386 -s -o bfasm main.o
./bfasm <file name> [tape size]
A dockerfile is included which takes the same amount of arguments as bfasm, but the bf code must be passed directly as an argument.
docker build -t bfasm .
docker run --rm -it bfasm <bf program surrounded by quotes> [tape size]
Docker run example:
docker run --rm -it bfasm ">++++++++++++++[<+++++++>-]<.++++."
- Fixed size cells
- ASCII only input files
- Slow implementation (slow bracket jumps)