Introduction to Programming in COW
Overview
The COW Programming Language is an esoteric programming language designed for cows. Commands are rooted in the moo sound cows make. Esoteric programming languages, also known as esolangs, are not designed for practical use. They might be designed to make a joke, prove a scientific point, or just for fun. They are esoteric because only a small group understands how to use these languages. They are not designed for practical programming tasks. Many esolangs are Turing Complete, including COW. They can be used to write any program a computer can run, but doing so would be difficult enough that it is impractical.
The COW Language was designed by Sean Heber in 2003. You can find it on the esolang wiki. This wiki is dedicated to collecting all the fun and weird esolangs of the world.
This article will cover the machine model of COW, its commands, and how to write a simple program.
Computer Model
Every programming language has a model of how the computer looks. This does not always match up with how the physical hardware works. It gives the human programmer a way to imagine the hardware. The programming language is translated into commands that run on the hardware.
COW has a fairly simple model for what the computer hardware looks like. The entire working memory of the computer is a single large array. When the program starts, the memory is located in the first position in this array. The array grows as needed. If the program moves off the left or right side of the array, more empty spaces will appear.
The computer also has a single register that can be used to store a value. This is separate from the memory array. It is especially useful for copying values. It gives you an extra location to store values before moving or copying them.
The program itself is also loaded into a section of memory. The program is like a second array. The program starts with the command at index 0 and moves left or right through the commands.
The computer has two counters. A program counter tracking the location in the program instructions and a memory counter for the current position in memory.
A summary of the model computer’s features are:
- A counter with the program instruction to be executed.
- A counter with the memory location currently accessible.
- An array of memory values.
- An array of program instructions.
- A single extra register for storing a value.
Instructions
The COW programming languages is designed to be used by cows. It has 12 commands. Each command is case sensative. All characters entered into a program that do not exactly match one of these commands get treated as comments. Whitespace doesn’t matter, which will cause moon to be treated as moo followed by the comment n.
Each instruction has something called an opcode. This is the numeric value of the command. It is what is actually stored in the computer’s memory. When the code is being executed, the opcode’s as what appears in the computer’s instructions array. It is not an array of strings with human readable commands.
The instructions are described in the table below.
| Opcode | Instruction | Meaning |
|---|---|---|
| 0 | moo | Search program instructions in reverse after skipping the instruction immediately before it. Begin normal execution starting at the first MOO command found. |
| 1 | mOo | Move back one memory position. New positions appear if needed when moving. |
| 2 | moO | Move forward one memory position. New positions appear if needed when moving. |
| 3 | mOO | Execute the current memory location’s value as if it was an opcode. The value three and any value over eleven are invalid. Invalid opcodes cause the program to exit. |
| 4 | Moo | This command prints and reads ASCII characters. When called at a memory location with a 0, it reads one character from the standard input and stores in into that memory location. If the memory location has a non-zero value, it is printed as an ASCII character. |
| 5 | MOo | Subtract one from the current memory location’s value. |
| 6 | MoO | Add one to the current memory location’s value. |
| 7 | MOO | If current memory location is not equal to 0, continue program normally. When current memory location is equal to 0, skip over next instruction. Then search forward in the program instructions until a moo command is found. Begin normal execution after the matching moo command. |
| 8 | OOO | Set the current memory location to zero. |
| 9 | MMM | This command is used to manipulate the register. If the register is empty, copy the current memory location’s value into the register. Otherwise, overwrite the current memory location with the register’s value and reset the register to empty. |
| 10 | OOM | Print the value of the current memory location, but as an integer. |
| 11 | oom | Read a single integer from standard in and store it in the current memory location. |
It is important to note both moo and MOO skip a command before starting a linear search for the matching instruction. This can cause confusion with closely nested loops. The easiest way to avoid it is to make sure no two loops are directly next to each other. You can always do a command that has no effect, like add one then subtract one to leave space between loops.
Example Program
There are a number of COW interpreters and computers on the official site. I also developed a Javascript interpreter with some debugging features you can use COW Interactive Debugger.
The following puzzle is trivial in common programming languages. This is the kind of thing students are asked to do the first time they learn about loops. It will be much harder in cow.
Problem: Write a program that reads in two integers. The first is n, the number of values to print. The second is s, the starting value. Starting at s print n values. Print a newline after each value.
In Python, this can be done easily.
n = int(input())
s = int(input())
for i in range(0,n):
print(s)
s += 1
If we ask the program to print 10 values starting at 5, we will get the following output.
5
6
7
8
9
10
11
12
13
14
How can we do this same thing in COW?
We only have one big array of memory. Lets call it mem for easy reference. We also have position we are currently on in memory. We can treat this as a variable pos. The memory position always starts at pos = 0.
We need to decide how we are going to use our memory. We need three positions.
mem[0]will be the counter storing the number of things to print.mem[1]will be store the value to print.mem[2]will store the newline character. There is no way to enter characters into the source directly. We need to put them into memory.
The first thing our program needs to do is read in the integer for the number of iterations. This uses the oom command. This is like having a mem[pos] = read_integer() command.
Next, we move over to the second space using moO and then read another integer with oom. The moO command is similar to doing pos = pos + 1. The code so far is shown below.
oom moO oom
We move to the third space. The ASCII code for a newline in 10. To get a 10, we can set the space to 0 using OOO. The OOO command is similar to mem[pos] = 0. We next use MoO to add one. This command act like mem[pos] = mem[pos] + 1. We need to do this 10 times to get to 10.
Here is the code so far with pseudocode commands added in. Remember that any text that is not a valid command is treated as a comment. Since most programmers are used to comments having a syntax, the below example uses C style //. The COW languages doesn’t treat this symbol as special, it just makes the comments more obvious to humans.
// mem[pos] = read_integer()
oom
// pos = pos + 1
moO
// mem[pos] = read_integer()
oom
//pos = pos + 1
moO
// mem[pos] = 0
OOO
// mem[pos] = mem[pos] + 10
MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO
We want create our while loop next. We can only loop on while(mem[pos] != 0). That means we need to move pos back to the counter position before the while. We also need to denote the end of the while loop with the moo command.
// pos = pos - 2
mOo mOo
// while(mem[pos]!=0){
MOO
// } end while
moo
What do we need to accomplish in the body of the loop? We have four tasks.
- Print the correct value.
- Update the value to print for next iteration.
- Print the newline.
- Update the loop counter.
Remember that after each operation, we need to move to the correct memory location. We also need to make sure we end in the same place we started. The loop just checks the current location, it doesn’t care where we are. We need to make sure it is in the right place.
The loop body with pseudocode is shown next.
// 1. Print the correct value.
// pos = pos + 1
moO
// print_integer(mem[pos])
OOM
// 2. Update the value to print for next iteration.
// mem[pos] = mem[pos] + 1
MoO
// 3. Print the newline.
// pos = pos + 1
moO
// print_char(mem[pos])
Moo
// 4. Update the loop counter.
// pos = pos - 2
mOo mOo
// mem[pos] = mem[pos] -1
MOo
Putting everything together and removing all the extra comments, we get a bunch cow noises.
oom moO oom moO OOO MoO MoO MoO MoO MoO MoO MoO MoO MoO
MoO mOo mOo MOO moO OOM MoO moO Moo mOo mOo MOo moo
Spaces are not required and can all be removed. This makes it even harder to read!
oommoOoommoOOOOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOmOomOoMOOmoOOOMMoOmoOMoomOomOoMOomoo
Here is the final program with lots of comments.
// Author: Mark Boady
// Date: September 2026
// A COW Program to print n integers starting at s
// Note: I am using C style comments for visuals,
// but cow treats any non-keyword as comments.
// That means you cannot write commands in these or they would execute.
// Read in the first integer.
oom
// Move over one space in memory to store second integer.
moO
// Read in second integer.
oom
// We will need a newline character.
// We use the third memory location.
moO
// Set it to zero.
OOO
// Newline is ascii character ten. Add one to current location ten times.
MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO
// The first integer was the loop counter.
// Move back to it.
mOo mOo
// Test if it is zero or not. If zero jump down to matching command.
MOO // While memory[0] != 0 is true execute loop body.
// Print out current value and increment.
moO // Move to the second memory location.
OOM // Print the value.
MoO // Add one to the value.
// Move memory pointer to the location of the newline.
moO
// Print memory as an ASCII value.
Moo
// Move back to the loop index counter.
// We have moved two positions away from it.
mOo mOo
MOo // Subtract one from the loop counter.
moo // Go back up to the start of the while and check the condition again.
// We will end up here and exit the program here when memory[0] == 0.
This covers the basics of COW. We can do some more interesting programs now that we know how it works. This language is not practical for every day use. It is a fun challenge to practice your algorithm design skills.