BFasm

From Esolang
Jump to navigation Jump to search
For Palaiologos's language that compiles to brainfuck, also known as bfasm or asmbf, see asm2bf.

BFasm is a programming language that compiles to brainfuck. It is created by User:Evylah.

This is still a work in progress. It may be changed in the future.

Overview

Memory locations

A BFasm program contains 255 memory locations you can use. Each memory location is an actual cell in the brainfuck tape, so it can hold a value of 00-FF. Each location is labeled with a address, and the addresses are written in hexadecimal.

When compiled, this is the structure of the brainfuck tape.
BFasmTape.png

00 to 08 are the memory locations for use in BFasm. The memory locations continue in that pattern until location FF.

Anchor cells

The two anchor cells are always 255 or -1 so the memory pointer knows where to go. Once it moves to a memory location, the memory pointer will move to the left anchor cell so it can go to another cell. (Although if you access address 255 the code will result in > about 515 times.)

There are also two anchor cells: one at the beginning and one after all the variables. The pointer can move to either one using the brainfuck code +[-<+]- (left) or +[->+]- (right).

But there's one issue: If any other cell is 255, then the anchor is pretty much moved over and will break the program.

There's a solution. You may have noticed the 255 was in the tape twice. That is used for checking if it's the real anchor cell. Each memory location is separated with a 0 in between, and that 0 is never modified. If the cell to the right of the anchor cell (the pointer will move to the left anchor cell and check the right one) is not 0, it must be the anchor cell. Text is not an issue, since it will always be 0 in the end.

Action Go to left anchor cell? Go to right anchor cell?
Copy one memory location's value to another Yes No
Output text Yes (to get to the text cell) No

Right anchor cell

The cells after the right anchor cell are used for number outputting. A memory location can be copied over to the cells after the right anchor cell, and run an algorithm below to print the value.

>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-
<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++
<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<

From Brainfuck algorithms