Executable Emoji: an x86 Program Made Entirely of Smileys
Translated by a model; the original is in Russian.
It all started with a chance observation. The author was tinkering with his own online x86 disassembler and noticed that the goat emoji 🐐 pasted into the address bar is encoded in UTF-8 as the sequence %F0%9F%90%90. To anyone familiar with x86 assembly, the byte 90h says a lot: it's the NOP opcode, the “no operation.” On the 8088, the byte F0h is the LOCK prefix, which for most instructions is simply ignored, and 9Fh is LAHF. In other words, the goat as a whole is perfectly valid code: lock lahf; nop; nop.
What followed was the natural question. The overwhelming majority of emoji in UTF-8 begin with the bytes F0 9F, so why not write a program for the 8088 using nothing but displayable smileys?
Precedents
The idea isn't new: it has long been known that executable files can be assembled from nothing but printable ASCII characters. The most famous example is the EICAR test file, which is simultaneously a string and a valid DOS executable that prints an antivirus warning. Tiny ASCII utilities such as the TCOM terminal have also been published, ones you could, in a pinch, type in from the keyboard. But emoji as machine code, the author says, is something nobody had seriously tried before.
“HELLO” in Smileys
First up — Hello World, or rather a truncated version of it that prints only HELLO (arithmetic in emoji is sheer torture). The final 141-byte program is saved as a .COM file in UTF-8 without a BOM and runs in DOSBox-X. The letters are synthesized by hand, one at a time; for instance, subtracting FFB8h is equivalent to adding 48h — and 48h is precisely the ASCII code for the letter H. One of the L's comes out green in the process: the LAHF instruction clobbers the flags register, whose contents happen to end up visible as a color attribute. The author left this glitch in on purpose — as “a tiny hint at the nightmare going on behind the scenes.”
The article includes a whole reference — an “emoji assembler”: tables of individual emoji (the goat as a four-byte alignment, the cow 🐮 as a tidy pointer increment), emoji with an “open tail” whose unfinished bytes are picked up by the following character, and ready-made “gadgets” with telling names like BunnySad, PlateGoat, and FrogStrap.
The Loader and a VGA Demo
Writing this way directly is, the author honestly admits, a torturous exercise without proper numbers, arithmetic, and jumps. So he built a loader: a short decoder extracts arbitrary bytes from the “tails” of emoji using an undocumented feature of the AAD instruction that lets you specify a non-decimal base. The packing efficiency is only 25%, but the result is a full-fledged VGA demo weighing in at 1092 bytes that runs in any DOSBox.
The author didn't stop at emoji: the same trick was pulled off with Japanese kana and Korean hangul, which also print “Hello World.” In closing, he dreamily wonders: couldn't you assemble an entire BIOS out of emoji, an operating system, or — why the hell not — EmojiDOOM? He promises to collect examples of “executable Unicode” in a separate GitHub repository.
Source: Lobsters
Comments
Sign in, to comment.