BFASM
- Not to be confused with asm2bf.
Paradigm(s) | Imperative |
---|---|
Designed by | User:Waffelz |
Appeared in | 2025 |
Memory system | Variable-based |
Dimensions | One-dimensional |
Computational class | Unknown |
Major implementations | See [1] |
File extension(s) | *.bfasm |
About
BFASM is an imperative, assembly-like language designed by User:Waffelz that compiles directly to brainfuck. Its name comes from the words "brainfuck" and "assembly". It currently has 12 statements. Although the preferred file extension for BFASM programs is *.bfasm
, the current implementation can accept any file type.
Statements
Statement | Function |
---|---|
set %x v | Set the variable %x to the value provided. Variable names must start with %. This is currently the only command that takes a number literal as an argument. |
add %x %y %z | Compute %x + %y and store it in %z. |
sub %x %y %z | Compute %x - %y and store it in %z. |
mul %x %y %z | Compute %x * %y and store it in %z. |
div %x %y %z | Compute %x / %y and store it in %z. |
out %x | Output the ASCII character stored in %x. |
inp %x | Input an ASCII character and store it in %x. |
cmp %x %y %z %w %v | Compare %x to %y. If %x = %y, set %z to 1. If %x > %y, set %w to 1. If %x < %y, set %v to 1. All other arguments are set to zero. |
begin_if %x | If %x is nonzero, execute the code until the matching end_if (see next row) once, else skip it. |
end_if | Close the matching begin_if. |
begin_while %x | If %x is nonzero, execute the code until the matching end_while (see next row) while %x is nonzero, else skip it. |
end_while %x | Close the matching begin_while. The variable given must match the variable given to matching begin_while. |
Memory Structure
A BFASM program removes all of brainfuck's pointer arithmetic and handles it all internally. Variables are reserved at the beginning of the tape in the order that they are defined. To perform operations, all operands are cloned to the next available free spaces, the result is computed, and is them moved into the target variable.
- A visual diagram of the tape structure after compiling a BFASM program.
Syntax/Semantics
Programming in BFASM is relatively simple. Every line in BFASM contains one statement, and every argument is separated by a space. Each line is trimmed, so whitespace at the beginning or end of a line is ignored. The current implementation (see [1]) has next to no error checking, but here are the few that exists:
Error | Cause |
---|---|
Too many or too little tokens on line {n} | The number of arguments given on line {n} does not match the expected amount. |
Variables must start with '%' (found '{v}' on line {n}) | Variable {v} was initialized without a percent sign on line {n}. |
Expected number, got '{v}' on line {n} | Found {v} when expecting a number on line {n}. Currently only the set statement can cause this. |
Too many or too little arguments | The number of arguments given to the executable does not match the expected amount. |
All other errors silently continue with compilation.
Computational Class
While waffelz, the creator of BFASM, strongly believes it has equivalent power to a linear bounded automaton, he has been unable to prove it.
Example Programs
Brainfuck code given is split by every 100 commands.
Print "Hello, World!"
BFASM Code
set %c 72 out %c set %c 101 out %c set %c 108 out %c out %c set %c 111 out %c set %c 44 out %c set %c 32 out %c set %c 87 out %c set %c 111 out %c set %c 114 out %c set %c 108 out %c set %c 100 out %c set %c 33 out %c
Generated Brainfuck
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]+++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++..[-]++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++.[-]++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]+++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]+ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++.[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++.[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++.[-]+++++++++++++++++++++++++++++++++.
Example Output
Hello, World!
Cat
BFASM Code
set %t 1 set %i 0 begin_while %t inp %i out %i end_while %t
Generated Brainfuck
+[>,.<]
Example Output
>>> h h >>> i i >>> 1 1 >>> 2 2 >>> $ $
Decimal Output
BFASM Code
set %i 0 inp %i set %v 0 add %v %i %v set %h 0 set %t 0 set %o 0 set %d 100 div %v %d %h mul %d %h %d sub %v %d %v set %d 10 div %v %d %t mul %d %t %d sub %v %d %v add %v %o %o set %d 48 add %h %d %h add %t %d %t add %o %d %o out %h out %t out %o
Generated Brainfuck
,>[->+>+<<]>>[-<<+>>]<<<[->>>+>+<<<<]>>>>[-<<<<+>>>>]<[-<+>]<<[-]>[-<+>]>>>+++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<<<<[->>>>>+>+<<<<<<]>>>> >>[-<<<<<<+>>>>>>]<<[->>+>+<<<]>>[-<<+>>]<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>[-]>[-]>[-]<<<<<<<[-]>>> >>>>>[-<<<<<<<<+>>>>>>>>]<<<<<[->+>+<<]>>[-<<+>>]<<<<<[->>>>>+>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>]<<[>[-> +>+<<]>>[<<+>>-]<<<-]>[-]<<[-]>>>[-<<<+>>>]<<<<<<<[->>>>>+>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>]<<[->>+>+<< <]>>>[-<<<+>>>]<[-<->]<<<<<<[-]>>>>>[-<<<<<+>>>>>]<[-]++++++++++<<<<[->>>>>+>+<<<<<<]>>>>>>[-<<<<<<+ >>>>>>]<<[->>+>+<<<]>>[-<<+>>]<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>[-]>[-]>[-]<<<<<<[-]>>>>>>>[-<<<<<< <+>>>>>>>]<<<<<[->+>+<<]>>[-<<+>>]<<<<[->>>>+>+<<<<<]>>>>>[-<<<<<+>>>>>]<<[>[->+>+<<]>>[<<+>>-]<<<-] >[-]<<[-]>>>[-<<<+>>>]<<<<<<<[->>>>>+>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>]<<[->>+>+<<<]>>>[-<<<+>>>]<[-<-> ]<<<<<<[-]>>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>]<<<[->>>+>+<<<<]>>>>[-<<<<+ >>>>]<[-<+>]<<<[-]>>[-<<+>>]<[-]++++++++++++++++++++++++++++++++++++++++++++++++<<<[->>>>+>+<<<<<]>> >>>[-<<<<<+>>>>>]<<[->>+>+<<<]>>>[-<<<+>>>]<[-<+>]<<<<<[-]>>>>[-<<<<+>>>>]<<<[->>>+>+<<<<]>>>>[-<<<< +>>>>]<<[->>+>+<<<]>>>[-<<<+>>>]<[-<+>]<<<<[-]>>>[-<<<+>>>]<<[->>+>+<<<]>>>[-<<<+>>>]<<[->>+>+<<<]>> >[-<<<+>>>]<[-<+>]<<<[-]>>[-<<+>>]<<<<.>.>.
Example Output
>>> a 097
External Links
- Note: This currently has next to no error checking.