We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.
addfuck
| Paradigm(s) | imperative |
|---|---|
| Designed by | Fgaoxing |
| Appeared in | 2026 |
| Memory system | Cell-based |
| Dimensions | one-dimensional |
| Computational class | Turing complete |
| Major implementations | Reference implementation |
| File extension(s) | .af, .addfuck |
AddFuck is an esoteric programming language and virtual machine centered around addition operations. It uses explicit memory addressing with a compact set of arithmetic opcodes. Its name reflects its core mechanic — all operations revolve around various forms of addition.
Language overview
AddFuck operates on a linear array of memory cells, each initially set to zero. The first two cells are reserved for special purposes.
| Address | Purpose |
|---|---|
mem[0]
|
Program counter (PC) — automatically incremented after each instruction |
mem[1]
|
Carry flag (CF) — set on arithmetic overflow, consumed by conditional instructions |
mem[2..]
|
User-available memory |
Programs are written as text, one instruction per line. Lines beginning with # are comments. Each instruction consists of an opcode character followed by numeric parameters separated by spaces.
Instructions
| Opcode | Name | Parameters | Description |
|---|---|---|---|
A
|
Add immediate | dest value
|
Adds value to mem[dest]. If the result overflows a signed 32-bit integer (231−1), the value wraps around and CF is set to 1; otherwise CF is cleared to 0.
|
CA
|
Conditional add | dest src
|
If CF == 1, adds mem[src] to mem[dest]. CF is always cleared after execution.
|
IA
|
Indirect add | dest src
|
Reads an address from mem[src], then adds the value at that address to mem[dest]. Enables pointer-like indirection.
|
I
|
Input | addr len
|
Reads a line from stdin into memory starting at mem[addr], up to len bytes. Stores the actual byte count at mem[addr + len].
|
O
|
Output | addr len
|
Writes len bytes from mem[addr] to stdout. Supports UTF-8 encoded output.
|
Execution model
The VM reads the program file line by line. For each line, the opcode is parsed from the first character and the remaining tokens are converted to numeric parameters. The instruction is executed, then mem[0] (the program counter) increments automatically. Execution continues until end of file.
Overflow semantics
The A instruction operates on signed 32-bit integers. If the result exceeds INT_MAX (2,147,483,647), the value wraps around (modulo 232) and the carry flag at mem[1] is set to 1. This flag can then be tested by the CA instruction, allowing branching based on arithmetic overflow.
Indirect addressing
The IA instruction provides a level of indirection: it reads a target address from mem[src], dereferences that address to obtain the operand value, and adds it to mem[dest]. This allows for pointer-like behavior and dynamic memory access patterns impossible with direct addressing alone.
Input/Output
Input via I reads a line from standard input. The raw bytes are placed into memory starting at mem[addr], and the count of bytes actually read is written to mem[addr + len], allowing programs to determine how much data was provided.
Output via O writes len bytes from mem[addr] to standard output. The VM treats the data as UTF-8, enabling proper handling of multi-byte characters.
Examples
Basic addition
This program stores 5 in mem[2], then adds 3 to it, resulting in 8:
A 2 5 # mem[2] = 5 A 2 3 # mem[2] = 5 + 3 = 8
Conditional addition (overflow branch)
This program demonstrates overflow detection. Adding 1 to INT_MAX triggers the carry flag, which is then consumed by a conditional add:
A 2 2147483647 # mem[2] = INT_MAX A 2 1 # overflow! mem[2] wraps, CF = 1 CA 3 2 # CF is 1, so mem[3] += mem[2]; CF cleared
Indirect addition
This example stores a value at address 5, stores the address 5 in cell 6, then uses indirect addressing to add through the pointer:
A 5 10 # mem[5] = 10 (the value) A 6 5 # mem[6] = 5 (the address of the value) IA 2 6 # reads address from mem[6] (= 5), adds mem[5] (= 10) to mem[2]
Echo program
A simple cat program that reads input and writes it back out:
I 2 256 # read up to 256 bytes into mem[2..] O 2 256 # output 256 bytes from mem[2..]
A more precise version using the stored byte count:
I 2 256 # read up to 256 bytes into mem[2..] A 258 2 # mem[258] = 2 + 256 = 258 (address where byte count is stored) IA 259 258 # mem[259] = byte count (loaded indirectly from mem[258]) A 261 2 # mem[261] = 2 (output source address) O 261 259 # output byte count bytes from address 2
Computational class
AddFuck is believed to be Turing-complete. Addition with overflow detection provides a form of conditional branching (through the carry flag and CA instruction), while indirect addressing (IA) enables pointer arithmetic and dynamic memory access. Together with unbounded memory, these primitives are sufficient to simulate arbitrary computation.
Related languages
- Subleq — another minimal arithmetic-based language (subtract and branch if less-than-or-equal-to zero)
- Addleq — a variant of Subleq using addition instead of subtraction
External resources
- GitHub repository — reference C++ implementation with CMake build system
- Test programs — example programs demonstrating each instruction