THREAD

331 words ~ 2-3 mins

The "10 print" maze generator in 15 bytes of x86 assembler.

Fifteen bytes

thread:
mov dl,'/'
in al,41h
aaa
jp print
mov dl,'\'
print:
mov ah,02h
int 21h
jmp thread

It ain't much yet this reproduces the famous 10 print program from the Commodore 64 Basic manual featured in a brilliant book 10 print by Nick Montfort et al.

The original

10 PRINT CHR$(205.5+RND(1)); : GOTO 10

The original Commodore 64 BASIC program consists in an infinite loop that randomly prints out the character 205 or 206, i.e. the slash or back-slash characters, which as they fill the screen form some intricate pattern akin to a maze or a weaving thread.

How does it work

There is not much science in this piece of code.

The register dl is first set to output the character /, then we check the system clock, do a little BCD ( binary coded decimal ) dance around the current tick count, and either jump to output the character stored in dl, or switch dl to the character \ and output it, and finaly we repeat the procedure until the user breaks the program by pressing Ctrl+C.

Kicking the ball

My x86 fu was rusty, so my only hope with this production was to get the ball rolling and see other takes on this seemingly simple problem.

About one hour after I published Thread JS on Pouet, a comment in Thread over, the 12 bytes record on C64 linked to 10 and 11 bytes versions of 10 PRINT program for DOS turning the memory into a woven maze!

Ten bytes

init:
  scasb
  salc
  and al,'\'-'/'
  add al,'/'
  int 29h
  jmp init

Mission accomplished

The feedback to Thread on Pouet.net was positive. This took off some of the dust out of my x86 assembler fu, got some cool tricks and pointers from the best size optimizers and shed some light on even smaller renditions of the 10 PRINT program.


Other recent experiments

There are many experiments and projects like THREAD to discover other here.


Let's talk

Don't be shy; get in touch by mail, twitter, github, linkedin or pouet if you have any questions, feedback, speaking, workshop or performance opportunity.