|Memory system||Cell based|
|Major implementations||py-four, ruby|
The memory-area is made up of a 100 integer cells found on a
10×10 grid, with initial value of
0. Each is described by its coordinates:
00 01 02 .. 09 10 11 12 .. .. .. .. .. .. .. 90 91 92 .. 99
All codes in 4 must start with
3. and end with
4. If they don't, it is considered a syntax error.
The body of the code contains a few operations, each made up of a single-digit operation name and [0 to 3] 2-digits operands (variables).
For example, a code that sets the cell
05's value to
1 would look like this (the spacing is simply for aesthetics - it is poor form to have any non-number characters in one's code):
3. 6 05 01 4 prefix opcode operand operand suffix
The table below summarizes the operations:
|Opcode||Operation||First operand||Second operand||Third operand||Description|
||Addition||Target cell||First cell||Second cell||The target cell is set to the value of the first cell added to the second cell.|
||Subtraction||Target cell||First cell||Second cell||The target cell is set to the value of the first cell minus the second cell.|
||Multiplication||Target cell||First cell||Second cell||The target cell is set to the value of the first cell multiplied by the second cell.|
||Division||Target cell||First cell||Second cell||The target cell is set to the value of the first cell divided by the second cell (rounded down).|
||Exit||Exits the code.|
||Output||Target cell||Prints the Unicode character of the target grid cell.|
||Set||Target cell||Two-digits number (
||The value of the target grid cell will be set to the number.|
||Input||Target cell||Takes a single character input and sets the value of the target cell to its Unicode value.|
||Begin loop||Target cell||If the value of the target grid cell is |
||End loop||Jumps back to the beginning of the loop.|
- A ruby interpreter which, for the sake of novelty, accepts the program source as a direct call on the number
- A short python interpreter.
- py-four - A python 4 interpreter.
- A APLBAONWSJAS interpeter: