Brainfuck Interpreter

Ben Ryves 2004

Installation

Send the file brainfck.8xp to you TI-83 Plus. This program will run inside any Ion compatible shell. It's also recommended that you send at least one of the demo programs from the "samples" folder.

Creating programs

You can use the usual program editor to create your programs.

Press PRGM then the right arrow key twice to select NEW. Press the Enter key and enter a new file name.

Now, in your program type the text BFPROG on the top line, followed by the Enter key.

Start entering code on the second line. You must have the BFPROG line for the Brainfuck program to appear in the Brainfuck interpreter. If you get stuck with any of this, look at one of the sample programs to see how to structure a program.

Running programs

Run the Brainfuck interpreter from the shell you installed it to. If it exits before the main screen displays; check

- that you have at least one Brainfuck program in RAM

- that you have at least 10000 bytes of free RAM.

You cannot run archived Brainfuck programs. Press the Alpha key to cycle through available files. When you have found the file you wish to run, press the 2nd key. Your program will start to execute.

Brainfuck syntax

Brainfuck is a nice simple language to learn - there are only 8 instructions.

They are:

> Increment the pointer.
< Decrement the pointer.
+ Increment the byte at the pointer.
- Decrement the byte at the pointer.
. Output the byte at the pointer.
, Input a byte and store it in the byte at the pointer.
[ Jump forward past the matching ] if the byte at the pointer is zero.
] Jump backward to the matching [ unless the byte at the pointer is zero.

You can liken them to their C equivalents:

> becomes ++p;
< becomes --p;
+ becomes ++*p;
- becomes --*p;
. becomes putchar(*p);
, becomes *p = getchar();
[ becomes while (*p) {
] becomes }

The interpreter will ignore any non-Brainfuck characters inside the program. So you can include comments without having to escape them - just make sure you don't use a Brainfuck instruction inside a comment (for example don't put an email address with a dot in it).

My implementation is "nice" Brainfuck compliant. These specifications list that:

 

One thing to note is that "classic" Brainfuck calls for a 30000 cell array. Due to the limitations of the TI-83 Plus, this is impossible, so I've opted for a 9999 byte solution. This explains why you need 10000 bytes of free RAM to run the interpreter!

The cell size is 0 to 255 inclusive, and cells will loop around if you try to increment or decrement them out of their range.

Program prompts and Errors

Sometimes a program will prompt for input or cause an error. If a square block appears on the screen, either filled or marked with an "A" or "a" then you need to enter a key. To do this, press a key on the keypad. You can cycle through text input modes by pressing Alpha. If the block is filled in, you'll enter the "standard" values - that is, the values printed on the keys. This includes the number keys, the mathematical operator keys, the parentheses and other keys such as the comma and the decimal point. If the block for text input is marked with an "A", you'll enter the text value (the green letter next to each key). If it's marked with an "a", you'll input the lowercase equivalent of the key when it's in "A" mode. Some keys do special things - the + key inputs a + in standard mode, a " in uppercase mode and a ' in lowercase mode.

If you want to try the key combinations yourself, try this little Brainfuck program:

:BFPROG
:+[>,.<]

Run that, and you can enter text onto the screen.

Now, at any point during program execution you can press Clear to halt the running. This prevents infinite loops from locking the calculator (the above code is an infinite loop). Some error messages include:


ASCII Table

For those who lack one; here is a quick reference. 32 is the space character. 10 is the carriage return (the Enter key emulates this). You can output this to go to a new line. Non standard ASCII codes are shown in red. For example, on most systems 36 is the $, but on the TI it's a to-the-power-of-four sign. 91 is usually the [, but on the TI it's θ. The [ gets assigned to 193, for some reason. It makes creating ASM programs a lot more interesting, I can tell you that...

032   | 048 0 | 064 @ | 080 P | 096 ` | 112 p
033 ! | 049 1 | 065 A | 081 Q | 097 a | 113 q
034 " | 050 2 | 066 B | 082 R | 098 b | 114 r
035 # | 051 3 | 067 C | 083 S | 099 c | 115 s
036 4 | 052 4 | 068 D | 084 T | 100 d | 116 t
037 % | 053 5 | 069 E | 085 U | 101 e | 117 u
038 & | 054 6 | 070 F | 086 V | 102 f | 118 v
039 ' | 055 7 | 071 G | 087 W | 103 g | 119 w
040 ( | 056 8 | 072 H | 088 X | 104 h | 120 x
041 ) | 057 9 | 073 I | 089 Y | 105 i | 121 y
042 * | 058 : | 074 J | 090 Z | 106 j | 122 z
043 + | 059 ; | 075 K | 091 θ | 107 k | 123 {
044 , | 060 < | 076 L | 092 \ | 108 l | 124 |
045 - | 061 = | 077 M | 093 ] | 109 m | 125 }
046 . | 062 > | 078 N | 094 ^ | 110 n | 126 ~
047 / | 063 ? | 079 O | 095 _ | 111 o | 193 [

Contact

Bugs, comments, death threats? benryves@benryves.com is the place to go.

Have fun with this crazy language!