This projects contains a number of examples written in ARM unified assembly including Brainfuck JIT compiler. All examples are tested on Cubieboard2 (ARM Cortex-A7 board) running Cubian r4 (Debian Wheezy) with GCC 4.7.
bfjit(sources) is a limited
JIT compiler for a subset of Brainfuck programming language.
It supports 5 of 8 Brainfuck commands (,, [ and ] are not supported). It currently implements just-in-time
compilation only for > command, the same technique can be used for other commands.
ARM machine code instructions for > command are stored in .data section of ELF binary. When this
instruction is found in Brainfuck input source code bfjit uses posix_memalign
to allocate page-aligned memory and mprotect
to allow to write machine code instructions to that chunk of memory and then branch there to execute
written instructions.
hello.bf contains a sample
Brainfuck program that prints HELLO ASM.
Build and run the sample program:
as bfjit.s -o bfjit.o
gcc bfjit.o
a.out < hello.bf