an 8-bit microarch that uses brainf*ck as the core of the instruction set
The top level module is tb_bfX
opcode | instruction | description |
---|---|---|
nnnn0000 | > | increment data pointer n times |
nnnn0001 | < | decrement data pointer n times |
nnnn0010 | + | increment byte at data pointer n times |
nnnn0011 | - | decrement byte at data pointer n times |
xxxx0100 | . | output byte to bus |
xxxx0101 | , | input byte from bus |
xxxx1000 | [ | if byte = 0, branch forward to matching ] |
xxxx1001 | ] | if byte != 0, branch backward to matching [ |
11111111 | end of code (HALT) |
the
[
and]
instructions force the ISA to become CISC since it must loop for the first 4 instructions, an operand of 0 is effectively a nop instruction
512B memory, which is shared by both instructions and data
The PC starts at address 0, and the BF data pointer is initialized to byte 256
The code can modify itself by subtracting the data pointer far enough
The assembly can be assembled with the assembler at ./assembler/assembler.py
it is used like so:
python assembler.py [INPUTFILE] [OUTPUTFILE]
the output file is optional, if not output is specified it will be saved to
./bin/[INPUTFILE]
The assembly converts bf into machine code
To run this code, copy the binary into code.txt
in the root folder
//
prefixes comments all illegal characters including whitespace are ignored
While any valid bf is valid and can be run, there are extra shortcut opcodes
for the >
,<
, +
, -
instructions
The first 4 bits of these instructions specify the number of times to repeat an instruction:
In bf, this is usually written as the same operation multiple times. The assembler also allows a similar shortcutting by prefixing a hex number in front of the operation.
opcode | operation | assembly |
---|---|---|
00010000 | > |
> |
00100000 | >> |
2> |
00110000 | >>> |
3> |
00000000 | nop | n/a |