2025/cable – Best imaginary emulator

kristianpaul1 pts0 comments

2025/cable - Best imaginary emulator

Please Enable JavaScript

Entries

Winning entries

Winning authors

Location of authors

Bugs and (mis)features

Fixing entries

Updating author info

Thanks for the help

Status

News

Contest status

IOCCC rules

IOCCC guidelines

Markdown guidelines

Security policy

FAQ

Frequently asked questions

Enter the IOCCC

Compiling entries

Running entries

How to help

About

Home page

IOCCC social media

About the IOCCC

The judges

Contact us

The International Obfuscated C Code Contest

2025/cable - Best imaginary emulator

Subleq computer

&larr; 2025/ayu<br>&uarr; 2025 &uarr;<br>2025/cesmoak &rarr;<br>C code<br>Makefile<br>Inventory<br>Original C

Author:

Name: Adrian Cable

Location: US - United States of America (United States)

Award: Best imaginary emulator

To build:

make all<br>To use:

./prog<br>Try:

./prog<br>Download a special vmlinux image and try it:

wget https://raw.githubusercontent.com/adriancable/eternal/main/ioccc/vmlinux.bootimage.xz<br>xz -d vmlinux.bootimage.xz<br>./prog<br>When the vmlinux.bootimage is running try:

export TZ=PST8PDT # or whatever is your timezome<br>~/fbclock -s -d

# ^C to exit

./pi

cd ~/doom<br>./doom<br>Judges’ remarks:

At 366 bytes, 2025/cable/prog.c also qualifies for the “Best Small<br>Program” award!

When looking at the entry, our thoughts were not “what does this program do?”, but “what good could this little piece of code do?”

As it turns out, quite a lot, including running some of the previous<br>IOCCC winners! Moreover, you can do a lot with just one instruction !

BTW : If you try running this entry under WSL, and it does not respond<br>to key presses, you may need to restart the WSL, or reboot your computer.

On purposes

Keep in mind that two of the purposes of this entry are to create a<br>sense of surprise and wonder: This wonderful winning entry is<br>NOT intended for production use. Adding bounds<br>checks to 2025/cable/prog.c would make<br>it larger and slower, and diminish both of these attributes.

See also the Eternal Software Initiative.

A fun challenge

Fun challenge 0

Use the toolchain to compile your own<br>software to run on this VM.

UPDATE : We are in the process of changing how we present fun challenges,<br>and present potential solutions to those challenges. Please stay tuned for an update.

Fun challenge 1

Produce variant of the vmlinux bootimage that contains a C compiler for this VM.

UPDATE : We are in the process of changing how we present fun challenges,<br>and present potential solutions to those challenges. Please stay tuned for an update.

Author’s remarks:

VM - eternal virtual machine

About

Virtual machines are notoriously large pieces of software (QEMU is around 2 million lines of code). Previous<br>IOCCC winners have pushed the boundaries on how small you can make a virtual machine: see for example<br>2024/macke (OpenRISC Linux, 4588 bytes). Or, there’s<br>2024/kurdyukov3 which runs DOOM and weighs in at an impressive<br>2495 bytes of C.

But with some creativity you can go much smaller, and thus, the author presents this year, for the delectation of<br>the judges, a virtual machine in 366 bytes of C, implementing:

32-bit CPU, 1.5GB RAM

800x512 resolution graphics card

real time clock, keyboard driver, pre-emptive multitasking, etc.

And yes, it runs DOOM (and Linux).

How to use

Only dependency is the SDL3 graphics library, to provide a portable way to write pixels to a screen. Install SDL3<br>with: apt install libsdl3-dev on Linux, brew install sdl3 on macOS.

Build:

make<br>Try (press q to quit):

./prog<br>Enjoy a classic game (player 1: a = up, z = down, player 2: k = up, m = down, press q to quit):

./prog<br>Then:

wget https://raw.githubusercontent.com/adriancable/eternal/main/ioccc/vmlinux.bootimage.xz<br>xz -d vmlinux.bootimage.xz<br>./prog<br>Once Linux is running, there’s lots to explore (just type exit when you’re done). You can try some of the<br>author’s favourite IOCCC winners from the past (have a look in ~/ioccc). Then try DOOM:

cd ~/doom<br>./doom<br>Or, enjoy a nice clock (remember to set your time zone):

export TZ=PST8PDT<br>~/fbclock -s -d<br>Or, try running a web server and browser:

ping 127.0.0.1<br>httpd -h /usr/share/www<br>htop<br>lynx http://127.0.0.1<br>Hint 1: build this entry with gcc rather than clang to get the best performance, at least on ARM.

Hint 2: the 8e5 number in the source controls the priority of CPU vs keyboard/display updates. Decrease it if<br>the keyboard/display feels laggy, increase it to improve CPU performance.

How it works

This VM implements an OISC - a One Instruction Set Computer. That instruction takes three signed 32-bit operands,<br>a, b and c, and runs a program from memory m[] as follows:

PC (program counter) starts at 0

Fetch the next instruction (32-bit signed operands a, b and c)

If the low bit on any operand is set, remove it, and replace that operand with m[operand] i.e., a dereference of that address

Set m[b] = m[b] - m[a]

If m[b] is 0 or negative, set the PC to c, otherwise increment PC by 3 words

Go to step 2

(This is a...

ioccc prog vmlinux doom cable best

Related Articles