Befunge for Android

User manual

This app provides an integrated development environment (editor and interpretter) for the esoteric computer language Befunge (invented by Chris Pressey). It implements Befunge-93, with the sole extension of an adjustable memory size.


Befunge programs consist of one-byte opcodes spread over a two-dimensional memory, which is typically 80 columns wide and 25 rows high. The program counter (PC) consists of the tuple (x,y,direction). It starts with the value (0,0,right). When the PC reaches the edge of the memory, it wraps around onto the other side. For example, in a typical 80x25 memory space, if the PC holds the value (10,24,down) then when it is incremented it will hold (10,0,down).

There is a single stack of signed 32-bit integers, and most operands operate primarily on the stack. Here is a brief summary of the opcodes:
1( -- 1)push 1 onto the stack
2( -- 2)push 2 onto the stack
3( -- 3)push 3 onto the stack
4( -- 4)push 4 onto the stack
5( -- 5)push 5 onto the stack
6( -- 6)push 6 onto the stack
7( -- 7)push 7 onto the stack
8( -- 8)push 8 onto the stack
9( -- 9)push 9 onto the stack
0( -- 0)push 0 onto the stack
+(x y -- x+y)adds top two elements of stack
-(x y -- x-y)subtracts top two elements of stack
*(x y -- x*y)multiplies top two elements of stack
/(x y -- x/y)divides top two elements of stack
%(x y -- x%y)modulos (division remainder) top two elements of stack
!(x -- !x)adds top two elements of stack
`(x y -- x>y)compares (greater than) top two elements of stack
g(x y -- mem[x,y])gets a byte from memory onto the top of the stack
p(val x y -- )puts a byte to memory
<( -- )PC direction left
>( -- )PC direction right
^( -- )PC direction up
v( -- )PC direction down
|(x -- )vertical if: true=up, false=down
_(x -- )horizontal if: true=left, false=right
?( -- )random PC direction
#( -- )don't execute next instruction (skip)
@( -- )end program execution
:(x -- x x)duplicate top of stack
\(x y -- y x)swap top two elements of stack
$(x -- )drop top of stack
.(x -- )output top of stack as integer
,(x -- )output top of stack as ASCII character
&( -- x)input integer to top of stack
~( -- x)input ASCII character to top of stack
"( -- )toggle string mode, which pushes each memory cell's ASCII value onto top of stack
( -- )space is no-operation


The top portion of the screen is a source display. Use your finger to scroll around in it. tap to set the cursor position (which is also the PC), and long tap to set the PC direction. Pinch to zoom in or out, for convenience when editing.

The bottom portion of the screen provides buttons representing the 37 opcodes in Befunge. Tap on one of the opcodes and its value will be placed at the current cursor position. Long tap on one of the opcodes and a brief description of its function will be displayed.

In the middle is a few command buttons:

Single-step the execution, and provide a brief pop-up displaying the top few elements of the stack and the recent I/O history. Hold it down for repeated stepping.
Run the befunge program and display its I/O terminal.
New - create a new memory area. Load - load a saved program. Save - save the current program. Reset environment - move the PC back to (0,0,right) and clear the stack and I/O history. Reload source - reset the memory as well as the PC, stack, and I/O.
Browse - look at programs that people have shared. Share - share your program with the world.
Bring up the Android soft keyboard for inputting special characters in the Befunge memory (i.e., for use in string mode).
Access this webpage.


If you want to edit the Befunge source, it is generally accessible through the underlying Linux filesystem in

Once you share source, it is out of your hands forever. And there is no verification of the "author" field or anything. So if you need to maintain your shared programs (such as to remove an older version or correct meta-data), you should email me:

If your Befunge program is infinite-looping, or is taking a long time to execute, then the interpretter will enforce a 500ms timeout every 750ms to ensure the UI remains responsive.

All errors are simply ignored (the value 0 is generated if needed), for the time being. That includes unknown opcode, stack underflow, out-of-bounds memory accesses, and divide-by-zero.


2013/12/30 Version 0.2. Hold down "step" for repeat. Scrollable history in "run" mode. File->reload. A few important bug fixes.

2013/12/29 Version 0.1. Initial release.