\$\begingroup\$

Story time: A week ago I found a question about optimizing Assembly code, then I remembered how awesome Brainfuck was, and the match was made very quickly. I decided to write a Brainfuck Interpreter in Assembly!

For this I have used the NASM assembler with x86 Assembly and is intended to run on an Intel CPU and on the Windows OS. I'm sure you can make it run on other combinations if you really want to. I'm also using the Borland 5.5 C Compiler, which is quite old, but the Assembly Book used it and I decided not to deviate from it.

You can compile the code with the following:

nasm -f obj bf-interpreter.asm bcc32 bf-interpreter.obj

I wrote the interpreter with performance as main focus, yet I have not read a lot about optimization yet, so I'm not surprised if it turns out to be quite horrible code. As the code is linking with the C stdlib I'm able to call methods from the C stdlib, and essentially only the EBX , EDI and ESI registers are considered "safe", that means they won't be overwritten by calls to the C stdlib, my implementation uses that convention a lot.

This version of the BF Interpreter reads from a file that is passed as argument to the program.