"Hello, world!" in Piet
Program

Original code Visualization
(codel size 11)
Design Goals
For decorativeness the image should appear symmetrical. Preferably
no color block other than the black ones should be greater than one
codel. Nevertheless the image should be as small as possible.
Implementation
Program flow follows a spiral ending in the black cage in the center.
Some needless additional code was added to stretch the spiral path,
which was necessary to prevent adjacent codels from having the same
color. Fortunately that also caused the code terminating exactly in
the black center.
In the visualization above non-coding codels are colored black.
Program flow is shown as a black line. The position of additional
code is marked by black squares.
Commands
Since the color blocks are not greater than one codel some stack
tricks are needed to put large numbers on the stack and to avoid
defining the same character more than once.
out: character output ("SP" = space, "\n" = newline)
cmd: command (abbr.), "out" = "out(char)"
stack: stack after execution of the adjoining command
blue: additional commands, acting as NOP
red: sequence "pus, poi" to rotate the DP at the edges of the spiral
comment
--- --- ---------------------------------------------------------------
out cmd stack ==>
--- --- ---------------------------------------------------------------
swi
pus 1
pus 1 1
add 2
dup 2 2
dup 2 2 2
add 2 4
mul 8
dup 8 8
dup 8 8 8
pus 8 8 8 1
poi 8 8 8
dup 8 8 8 8
mul 8 8 64
add 8 72
H out 8
pus 8 1
pus 8 1 1
add 8 2
add 10
dup 10 10
dup 10 10 10
pus 10 10 10 1
poi 10 10 10
mul 10 100
dup 10 100 100
pus 10 100 100 1
add 10 100 101
e out 10 100
dup 10 100 100
pus 10 100 100 1
pus 10 100 100 1 1
add 10 100 100 2
pus 10 100 100 2 1
poi 10 100 100 2
dup 10 100 100 2 2
dup 10 100 100 2 2 2
add 10 100 100 2 4
mul 10 100 100 8
add 10 100 108
dup 10 100 108 108
dup 10 100 108 108 108
dup 10 100 108 108 108 108
l out 10 100 108 108 108
pus 10 100 108 108 108 1
poi 10 100 108 108 108
l out 10 100 108 108
pus 10 100 108 108 1
pus 10 100 108 108 1 1
add 10 100 108 108 2
pus 10 100 108 108 2 1
add 10 100 108 108 3
pus 10 100 108 108 3 1
pop 10 100 108 108 3
pus 10 100 108 108 3 1
poi 10 100 108 108 3
dup 10 100 108 108 3 3
dup 10 100 108 108 3 3 3
pus 10 100 108 108 3 3 3 1
pus 10 100 108 108 3 3 3 1 1
add 10 100 108 108 3 3 3 2
rol 10 100 108 3 3 108
add 10 100 108 3 111
dup 10 100 108 3 111 111
pus 10 100 108 3 111 111 1
poi 10 100 108 3 111 111
dup 10 100 108 3 111 111 111
o out 10 100 108 3 111 111
dup 10 100 108 3 111 111 111
pus 10 100 108 3 111 111 111 1
pus 10 100 108 3 111 111 111 1 1
pus 10 100 108 3 111 111 111 1 1 1
pop 10 100 108 3 111 111 111 1 1
pus 10 100 108 3 111 111 111 1 1 1
poi 10 100 108 3 111 111 111 1 1
pus 10 100 108 3 111 111 111 1 1 1
pop 10 100 108 3 111 111 111 1 1
add 10 100 108 3 111 111 111 2
dup 10 100 108 3 111 111 111 2 2
dup 10 100 108 3 111 111 111 2 2 2
add 10 100 108 3 111 111 111 2 4
dup 10 100 108 3 111 111 111 2 4 4
pus 10 100 108 3 111 111 111 2 4 4 1
poi 10 100 108 3 111 111 111 2 4 4
dup 10 100 108 3 111 111 111 2 4 4 4
mul 10 100 108 3 111 111 111 2 4 16
dup 10 100 108 3 111 111 111 2 4 16 16
add 10 100 108 3 111 111 111 2 4 32
dup 10 100 108 3 111 111 111 2 4 32 32
pus 10 100 108 3 111 111 111 2 4 32 32 1
pus 10 100 108 3 111 111 111 2 4 32 32 1 1
poi 10 100 108 3 111 111 111 2 4 32 32 1
pus 10 100 108 3 111 111 111 2 4 32 32 1 1
add 10 100 108 3 111 111 111 2 4 32 32 2
dup 10 100 108 3 111 111 111 2 4 32 32 2 2
add 10 100 108 3 111 111 111 2 4 32 32 4
dup 10 100 108 3 111 111 111 2 4 32 32 4 4
dup 10 100 108 3 111 111 111 2 4 32 32 4 4 4
pus 10 100 108 3 111 111 111 2 4 32 32 4 4 4 1
poi 10 100 108 3 111 111 111 2 4 32 32 4 4 4
add 10 100 108 3 111 111 111 2 4 32 32 4 8
add 10 100 108 3 111 111 111 2 4 32 32 12
add 10 100 108 3 111 111 111 2 4 32 44
, out 10 100 108 3 111 111 111 2 4 32
SP out 10 100 108 3 111 111 111 2 4
pus 10 100 108 3 111 111 111 2 4 1
poi 10 100 108 3 111 111 111 2 4
mul 10 100 108 3 111 111 111 8
add 10 100 108 3 111 111 119
w out 10 100 108 3 111 111
o out 10 100 108 3 111
add 10 100 108 114
pus 10 100 108 114 1
poi 10 100 108 114
r out 10 100 108
l out 10 100
dup 10 100 100
d out 10 100
pus 10 100 1
poi 10 100
pus 10 100 1
pus 10 100 1 1
add 10 100 2
pus 10 100 2 1
pus 10 100 2 1 1
poi 10 100 2 1
add 10 100 3
pus 10 100 3 1
poi 10 100 3
div 10 33
! out 10
\n out
Copyright © Thomas Schoch 2006 www.retas.de
Image License: Creative Commons Attribution-ShareAlike 2.5
