This is a JavaScript interpreter for COW.
Paste the source code in the program text area and click on execute. An example from the author of the JavaScript program:
OOOMoOMoOMoOMoOMoOMoOMoOMoOMMMmoOMMMMMMmoOMMMMOOMOomOoMoOmoOmoomOo MMMmoOMMMMMMmoOMMMMOOMOomOoMoOmoOmoomOoMMMmoOMMMMMMmoOMMMMOOMOomOo MoOmoOmooOOOMoOMoOMoOMoOMoOMoOmOoMMMmoOmoOMMMMOOMOomOoMoOmoOmoomOo MoomOoMMMmoOMMMmOomOoMMMmoOmoOmoOMMMMOOMOomOoMoOmoOmoomOoMMMmoOMMM MoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoomOoMMMmoO MMMMoOMoomOoMMMmoOMMMMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoo MOoMOoMOoMoo
Program:
Click this button to execute the program:
Click this button to generate a COW program from the text in the result area below:
Result:
The "generate" algorithm uses the prolog of my program for creating 16, 32 and 64 in three successive memory locations, then sums the values for each 1-bit of the character and finally increments for the rest. If the ASCII code of successive characters is not far apart, it could be optimized, like you can see in the commented version of my hand optimized code:
; store 8 to next location OOO MoO MoO MoO MoO MoO MoO MoO MoO ; copy 8 to next location and load register with it MMM moO MMM MMM ; copy 8 to next location moO MMM ; loop: use the number in current memory location as a counter ; for incrementing the previous memory location, which will be 16 after the loop MOO MOo mOo MoO moO moo ; back to the previous location and copy 16 to next location mOo MMM moO MMM MMM ; copy 16 to the next location moO MMM ; same loop, but now resulting in 32 MOO MOo mOo MoO moO moo ; back to the previous location and copy 32 to next location mOo MMM moO MMM MMM ; copy 32 to the next location moO MMM ; same loop, but now resulting in 64 MOO MOo mOo MoO moO moo ; at this point there are 8, 16, 32 and 64 in memory positions 1, 2, 3 and 4 ; and the current memory position is 5 ; to make it easier to describe the rest of the program, ; memory block 5 will be named A and block 6 is B ; A=6 OOO MoO MoO MoO MoO MoO MoO ; B=64 mOo MMM moO moO MMM ; A=A+B (70, ASCII for 'F') MOO MOo mOo MoO moO moo ; print the 'F' mOo Moo ; next letter 'r', ASCII code 114 ; A=64 mOo MMM moO MMM ; B=32 mOo mOo MMM moO moO moO MMM ; A=A+B (96) MOO MOo mOo MoO moO moo ; B=A (96) mOo MMM moO MMM ; B=B+18 (114) MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO ; print Moo ; next character is 'a', ASCII code 97 ; B=A (96) mOo MMM moO MMM ; increment and print ; B=B+1 MoO Moo ; next character is 'n', ASCII code 110 ; B=A (96) mOo MMM moO MMM ; B=B+14 (110) MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO ; print Moo ; next character is 'k', ASCII code 107 ; B=B-3 MOo MOo MOo Moo