2013-08-08

webfind: The smallest compiler (it compiles Brainfuck)

I've found the smallest compiler so far. It's a Brainfuck compiler written in x86 assembly, and it compiles to an i386 Linux binary. Downloaded it from here and play with it on Linux (i386 or amd64):

$ sudo apt-get install nasm
$ wget -O bf.asm http://www.muppetlabs.com/~breadbox/software/tiny/bf.asm.txt
$ nasm -f bin -o bf bf.asm && chmod +x bf
$ cat >hello_world.bf <<'END'
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]
>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++
.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.
END
$ ./bf hello_world && chmod +x hello_world
$ ./hello_world
Hello world!

A 16-bit DOS version, which is even shorter (135 bytes) can be found here. There is a challange here for implementing Brainfuck interpreters, and the best so far is 106 bytes in Perl, but unfortunately the source code is not available. There is also a 98-byte interpreter for 16-bit DOS here.

See a 160-byte (source code) interpreter in C here.

Here is a similar page listing short interpreters for a small, Turing-complete language.

No comments:

Post a Comment