Add preview of 1984-2019

The 2020 winners are hinted it, but the source code is not there,
nor are the hints. Someone could look into the HTML and
see what was commented out, but that is not a problem because
WHO won is known and the name of their AWARD is known already.
Moreover a number of the winners have talked about what their
entirs do, so the commented out spoiler text is not a bit problem.

One will find HTML commented out with:

    <!-- XXX remove when 2020 is ready
    2020 links here
    XXX remove when 2020 is ready -->

The "XXX remove when 2020 is ready" string is found at the
start and end comment blocks.  Again, soneone could read
what was commented out, but that is OK since most of that
information is known or can be known.  The following files
have such HTML comment blocks in them.

    ./winners.html
    ./years-spoiler.html
    ./years.html

In addition, ./all/summary.txt was modified to not
include the 2020 entries for the momemt.

The 2020 winner code AND write-ups are NOT part of this set.

p.s. The all/all.tar.bz2 does not contain the 2020 source code (yet?).
This commit is contained in:
Landon Curt Noll committed 2020-12-30 16:57:03 -08:00
1 parent 28efc67f5d
commit c0663537cb
1683 files changed
+220064

No files matched your search

BIN
View File
Binary file not shown.
+118
View File
@@ -0,0 +1,118 @@
#
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# tool locations
#
SHELL= /bin/sh
CP= cp
CPP= cpp
GUNZIP= gunzip
LD= ld
MAKE= make
RM= rm
SED= sed
TAR= tar
TRUE= true
# Set X11_LIBDIR to the directory where the X11 library resides
#
X11_LIBDIR= /usr/X11R6/lib
# Set X11_INCLUDEDIR to the directory where the X11 include files reside
#
X11_INCDIR= /usr/X11R6/include
# optimization
#
# Most compiles will safely use -O3. Some can use only -O2 or -O1 or -O.
# A few compilers have broken optimizers and thus you may
# not want anything.
#
#OPT=
#OPT= -O
#OPT= -O1
#OPT= -O2
OPT= -O3
# default flags for ANSI C compilation
#
#CFLAGS=
#CFLAGS= -Wall -W -ansi
#CFLAGS= -Wall -W -ansi -pedantic
#CFLAGS= -Wall -W -ansi ${OPT}
CFLAGS= -Wall -W -ansi -pedantic ${OPT}
# ANSI compiler
#
# Set CC to the name of your ANSI compiler.
#
# Some entries seem to need gcc. If you have gcc, set
# both CC and MAY_NEED_GCC to gcc.
#
# If you do not have gcc, set CC to the name of your ANSI compiler, and
# set MAY_NEED_GCC to either ${CC} (and hope for the best) or to just :
# to disable such programs.
#
CC= cc
MAY_NEED_GCC= gcc
# 2006 winners
#
WINNERS= birken borsanyi grothe hamre meyer monge night sloane stewart sykes1 \
sykes2 toledo1 toledo2 toledo3
# default build
#
build:
for i in ${WINNERS} ; do (cd $$i && ${MAKE} "ENTRY=$$i" "CC=${CC}" "X11_LIBDIR=${X11_LIBDIR}" "X11_INCDIR=${X11_INCDIR}" build) done
# alternative executable
#
alt:
for i in ${WINNERS} ; do (cd $$i && ${MAKE} "ENTRY=$$i" "CC=${CC}" "CFLAGS=${CFLAGS}" "X11_LIBDIR=${X11_LIBDIR}" "X11_INCDIR=${X11_INCDIR}" alt) done
# data files
#
data:
for i in ${WINNERS} ; do (cd $$i && ${MAKE} "ENTRY=$$i" data) done
# utility rules
#
everything: build alt data
love:
@echo 'not war?'
haste:
$(MAKE) waste
waste:
@echo 'waste'
clean:
for i in ${WINNERS} ; do (cd $$i && ${MAKE} "ENTRY=$$i" clean) done
clobber:
for i in ${WINNERS} ; do (cd $$i && ${MAKE} "ENTRY=$$i" clobber) done
nuke: clobber
@${TRUE}
install: all
@${TRUE}
+81
View File
@@ -0,0 +1,81 @@
2006 marked the "The Nineteenth International Obfuscated C Code Contest"
========================================================================
Copyright (C) 2006, Landon Curt Noll, Simon Cooper, and Leonid A.
Broukhis. All Rights Reserved. Permission for personal, educational
or non-profit use is granted provided this copyright and notice are
included in its entirety and remains unaltered. All other uses
must receive prior permission from the contest judges.
Standard IOCCC stuff
--------------------
The IOCCC has a web site and now has a number of international mirrors.
The primary site can be found at,
> <http://www.ioccc.org/>
Use make to compile entries. It is possible that on non-Un*x / non-Linux
systems the makefile needs to be changed. See the Makefile for details.
Look at the source and try to figure out what the programs do, and run
them with various inputs. If you want to, look at the hints files for
spoilers - this year we included most of the information included
by the submitters.
Read over the makefile for compile/build issues. Your system may require
certain changes (add or remove a library, add or remove a #define).
Some ANSI C compilers are not quite as good as they should be. If
yours is lacking, you may need to compile using gcc instead of your
local compiler.
Remarks on some of the entries
------------------------------
There were some outstanding entries that did not win. Unfortunately
some very good entries lost because they:
+ depended too much on non-portable side effects in expressions;
+ depended too much on a particular byte order;
+ required the use of a special script, data file or pseudo-machine
language that was not supplied with the entry.
We hope the authors of some of those entries will fix and re-submit
them for the next IOCCC.
We believe you will be impressed with this year's winners. The Best
of Show is a fine example of (retro) obfuscation. But don't ignore the other
winners! There are games, puzzles, puzzle solvers, simulators, emulators,
calculators and graphical and audio tools.
This year a single person won three awards and another two awards! Many
winners won for the first time. (Please note that judging is done completely
anonymously. Be warned that we may disqualify entries that reveal the identity
of the submitter).
Final Comments
--------------
Please feel free to send us comments and suggestions about the
competition, this README or anything else that you would like to see in
future contests.
If you use, distribute or publish these entries in some way, please drop
us a line. We enjoy seeing who, where and how the contest is used.
If you have problems with any of the entries, AND YOU HAVE A FIX, please
send us the fix (patch file or the entire changed file).
For the latest information on how to contact the IOCCC Judges please visit
> <http://www.ioccc.org/contact.html>
For news of the next contest watch:
> <http://www.ioccc.org/>
+31
View File
@@ -0,0 +1,31 @@
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# data files for this entry
#
DATA= adder.tofu buffer.tofu computer.tofu counter.tofu divider.tofu \
lfsr.tofu memory.tofu multiplier.tofu multiplier2.tofu oneline.tofu \
shift.tofu zuse.tofu zuse2.tofu
build: ${ENTRY}
clean:
-${RM} ${ENTRY}
clobber: clean
alt:
data:
${ENTRY}: ${ENTRY}.c ${DATA}
${CC} ${CFLAGS} ${ENTRY}.c -o ${ENTRY}
+72
View File
@@ -0,0 +1,72 @@
# Buffer
def buf input output :
r input output 1 0
# Inverter
def inv input output :
r input output 0 1
# AND Gate
def and i1 i0 o :
r i0 z 1 0
r i1 o z 0
# NAND Gate
def nand i0 i1 o :
r i0 1 0 o
r i1 1 0 o
# OR Gate
def or i0 i1 o :
r i0 1 o 0
r i1 1 o 0
# NOR Gate
def nor i0 i1 o :
r i0 1 0 z
r i1 z 0 o
# XOR Gate
def xor i0 i1 o :
r i0 1 b a
r i1 o a b
# XNOR Gate
def xnor i0 i1 o :
r i0 1 a b
r i1 o a b
# Half Adder
def halfAdder a b s1 s0 :
and a b s1
xor a b s0
# Full Adder
def fullAdder carryIn a b carryOut sum :
halfAdder a b s1 s0
halfAdder s0 carryIn carry sum
or s1 carry carryOut
# 2-bit Adder
def adder2 carryIn a1 a0 b1 b0 carryOut s1 s0 :
fullAdder carryIn a0 b0 carry s0
fullAdder carry a1 b1 carryOut s1
# 4-bit Adder
def adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carryOut s3 s2 s1 s0 :
adder2 carryIn a1 a0 b1 b0 carry s1 s0
adder2 carry a3 a2 b3 b2 carryOut s3 s2
# 8-bit Adder
def adder8 carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carry s3 s2 s1 s0
adder4 carry a7 a6 a5 a4 b7 b6 b5 b4 carryOut s7 s6 s5 s4
# 57 + 142 = ?
run 100 1 adder8 0
0 0 1 1 1 0 0 1
1 0 0 0 1 1 1 0
? ? ? ? ? ? ? ? ?
+133
View File
@@ -0,0 +1,133 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PI 314
#define Z if
#define P a->b
#define Q else
#define W =f();
#define X char
#define J while
#define N return
#define V struct e
#define g(_,a)((_&&a)?!strcmp(_,a):0)
typedef V*d; V{ d o,_; X*b; int c; };
d f() { d _=(d)malloc(sizeof(V)); _
->b=0; _->o=_->_=0; _->c=1>>1>1;
N _; } d k,l,m,n,o,p,q,r; d j
() { d _=l; d a W a->o W
l->o=a; l W l-> _=_;
N a; } d u(d _,
X*a){ J(_){
Z(g(a,_
->b)
){
N
_;
} _=
_->_; }
N 0; } d s
(X*q){ d _=n; Z
(g("q", q)){ N o; }
J(PI){ _=u(_,"cde"); _=_
-> _ ; Z ( g (q, _->b) ){ N _
->_ ; } } } void t(d a, d _) { d
S,I,M,U,L,A,T,O,R ; Z(a==o){ S W
S->o W m->o=S; I=m; m W m->_=I; _=_->
_; J(_) { S->o->o=_->o; I=S->o; S->o W
S->o->_=I; _->o->o->o=S; I=_->o->o; _
->o->o W _->o->o->_=I; _=_->_; } }
Q { M W _=_->_; J(57-*P){ U=M; U
->b=P; U->o=_->o; M W M->_=U;
_=_->_; a=a->_; } a=a->_
; J(a&&!g("qtm",P)&&
!g("cde",P)){ L
=s (P); a=a
->_; A=
L; T
W
O=
T;
J(*L
->b-57){ R
=g("/",P)?j():g
(P,"0")?p:g("b",P)?
q:g(P,"j")?r:0; Z(!!!R){
R=u(M,P); Z(!R) { R=j(); U=M;
U->b=P; U->o=R; M W M->_=U; } Q{
R=R->o; } } O=O->_ W O->o=R; O->b=L
->b; L=L->_; a=a->_; } t(A, T); } } }
void h(d e){ d _,a,c, z=e->o->_; J(z){
_=z->o; c=_->o->_; a= c->_->_->o; c=_
->c?c->_->o :c->o; Z(c->c<a->c) { c
->c++; h(c); } Q Z(a->c<c->c){ a
->c++; h(a); } z=z->_; } } X*
v(X*_,int O){ X*s=(X*)m\
alloc(strlen(_)*siz\
eof(X)); X*l=s;
J((*l++=*_?
*_-O:0)
)_++
;N
s;
}
/**/
int ma\
in(){d a,_
,b;d T,O,F,U
, R, E, L, A, Y
; X c[PI],x[PI],w[PI],*y
,*B,*d,*K=v("Cvjme!dpnqmfuf;\
!&e!dpnqpofout-!&e!opeft/\x0b",1
),*e=v("&e;!&t\x0b\0nbjo)*|jou!j>1\
<gps)<j=51<j,,*qsjoug)#&e!#-j+j,j,52\
*<~",1); int i,z,C,G,H,D,I ; k W l W m
W n W o W p W q W r W b=o; for(*x=D=I
=i=0; 5-i; i++){ b->b=i&4?v(";",2):
v("s",2); b=b->_ W } H=p->c=1; p
->o W r->o W q->o W a=n; J(g\
ets(c)){ d=c; J(*d){ *d=
*d<65||*d>90 ?*d:*d+
32; d++; } y=s\
trchr(c,35)
; Z(y){
*y=0
;
}
B
=st\
rtok(c,
" "); J(B)
{ a=a->_ W P=v(
B,1); Z(g("qtm",P))
{ _=a; } B=strtok(0," ")
; } } _=_->_; z=atoi(v(_->b,-
1)); _=_->_; C=atoi(v(_->b,-1));
G=C; _=_->_; T=s(_->b); _=_->_; O W
F=O; U=k; J(_&&!g( "cde",_->b)){ i=*_
->b; R=i-47?48-i?i-98?106-i?0:r:q:p:j(
); Z(!R){ R=j(); U=U->_ W U->o=R; } F
= F->_ W F->o=R; _=_->_; } t(T, O);
E=m->_; J(E){ D++; E=E->_; } L=l
->_; J(L){ I++; L =L->_; } p\
rintf(K,D,I); for(i='\''
/'\''; z>i; i++){ J(
!--G){ G=C; H=1
-H ; break;
} r->c=
! (q
->
c=
H)
; L=
l->_; J
(L) { L->o
->c=!1; L=L->_;
} h(p); Z(q->c){ h(
q); } Q{ h(r); } E=m->_;
J(E){ A=E->o; A->c=A->o->_->_
->_->_->o->c; E= E->_; } Y=k->_;
d=w; J(Y){ *d++=48+Y->o->c; Y=Y->_;
} *d=0; Z(!g(w,x)){ strcpy(x,w); pri\
ntf (e, i, w ) ; } } N 0 ; }
+5
View File
@@ -0,0 +1,5 @@
# Buffer
def buf input output :
r input output 1 0
run 100 10 buf c ?
+799
View File
@@ -0,0 +1,799 @@
# Harry Porter's Relay Computer
# Buffer
def buf i o :
r i o 1 0
# Inverter
def inv i o :
r i o 0 1
# AND Gate
def and i0 i1 o :
r i0 1 z 0
r i1 z o 0
# NAND Gate
def nand i0 i1 o :
r i0 1 0 o
r i1 1 0 o
# OR Gate
def or i0 i1 o :
r i0 1 o 0
r i1 1 o 0
# NOR Gate
def nor i0 i1 o :
r i0 1 0 z
r i1 z 0 o
# XOR Gate
def xor i0 i1 o :
r i0 1 b a
r i1 o a b
# XNOR Gate
def xnor i0 i1 o :
r i0 1 a b
r i1 o a b
# Dual-rail-carry Full Adder (Konrad Zuse design)
def fullAdder carryIn carryInNeg a b carryOutNeg carryOut sum :
r a carryIn 2 3
r a 1 3 4
r a sum 5 7
r a carryInNeg 4 6
r b carryOut 3 2
r b carryIn 5 7
r b carryInNeg 7 5
r b carryOutNeg 6 4
# 2-bit Full Adder
def fullAdder2 carryIn carryInNeg a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
fullAdder carryIn carryInNeg a0 b0 carryOutNeg0 carryOut0 s0
fullAdder carryOut0 carryOutNeg0 a1 b1 carryOutNeg carryOut s1
# 4-bit Full Adder
def fullAdder4 carryIn carryInNeg a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
fullAdder2 carryIn carryInNeg a1 a0 b1 b0 carryOutNeg0 carryOut0 s1 s0
fullAdder2 carryOut0 carryOutNeg0 a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# 8-bit Full Adder
def fullAdder8
carryIn carryInNeg a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
fullAdder4 carryIn carryInNeg a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg0 carryOut0 s3 s2 s1 s0
fullAdder4 carryOut0 carryOutNeg0 a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# Zero-Detect Circuit
def zeroDetector b7 b6 b5 b4 b3 b2 b1 b0 zero :
r b7 1 0 i6
r b6 i6 0 i5
r b5 i5 0 i4
r b4 i4 0 i3
r b3 i3 0 i2
r b2 i2 0 i1
r b1 i1 0 i0
r b0 i0 0 zero
# Enable Circuit
def enable enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0 :
r enabled a7 b7 0
r enabled a6 b6 0
r enabled a5 b5 0
r enabled a4 b4 0
r enabled a3 b3 0
r enabled a2 b2 0
r enabled a1 b1 0
r enabled a0 b0 0
# Byte MUX
def muxByte
address
h7 h6 h5 h4 h3 h2 h1 h0
l7 l6 l5 l4 l3 l2 l1 l0
o7 o6 o5 o4 o3 o2 o1 o0 :
r address o7 h7 l7
r address o6 h6 l6
r address o5 h5 l5
r address o4 h4 l4
r address o3 h3 l3
r address o2 h2 l2
r address o1 h1 l1
r address o0 h0 l0
# Byte AND
def andByte
enabled
b7 b6 b5 b4 b3 b2 b1 b0
c7 c6 c5 c4 c3 c2 c1 c0
o7 o6 o5 o4 o3 o2 o1 o0 :
and b7 c7 z7
and b6 c6 z6
and b5 c5 z5
and b4 c4 z4
and b3 c3 z3
and b2 c2 z2
and b1 c1 z1
and b0 c0 z0
enable enabled z7 z6 z5 z4 z3 z2 z1 z0 o7 o6 o5 o4 o3 o2 o1 o0
# Byte OR
def orByte
enabled
b7 b6 b5 b4 b3 b2 b1 b0
c7 c6 c5 c4 c3 c2 c1 c0
o7 o6 o5 o4 o3 o2 o1 o0 :
or b7 c7 z7
or b6 c6 z6
or b5 c5 z5
or b4 c4 z4
or b3 c3 z3
or b2 c2 z2
or b1 c1 z1
or b0 c0 z0
enable enabled z7 z6 z5 z4 z3 z2 z1 z0 o7 o6 o5 o4 o3 o2 o1 o0
# Byte XOR
def xorByte
enabled
b7 b6 b5 b4 b3 b2 b1 b0
c7 c6 c5 c4 c3 c2 c1 c0
o7 o6 o5 o4 o3 o2 o1 o0 :
xor b7 c7 z7
xor b6 c6 z6
xor b5 c5 z5
xor b4 c4 z4
xor b3 c3 z3
xor b2 c2 z2
xor b1 c1 z1
xor b0 c0 z0
enable enabled z7 z6 z5 z4 z3 z2 z1 z0 o7 o6 o5 o4 o3 o2 o1 o0
# Byte NOT
def notByte enabled b7 b6 b5 b4 b3 b2 b1 b0 o7 o6 o5 o4 o3 o2 o1 o0 :
inv b7 z7
inv b6 z6
inv b5 z5
inv b4 z4
inv b3 z3
inv b2 z2
inv b1 z1
inv b0 z0
enable enabled z7 z6 z5 z4 z3 z2 z1 z0 o7 o6 o5 o4 o3 o2 o1 o0
# Shift Left Circular Circuit
def shlByte enabled b7 b6 b5 b4 b3 b2 b1 b0 o7 o6 o5 o4 o3 o2 o1 o0 :
enable enabled b7 b6 b5 b4 b3 b2 b1 b0 o0 o7 o6 o5 o4 o3 o2 o1
# 2-to-4 Decoder
def decoder2to4 f1 f0 o3 o2 o1 o0 :
r f1 1 t1 n1
r f0 t1 o3 o2
r f0 n1 o1 o0
# 2-to-4 Decoder With Output Enable
def eDecoder2to4 enabled f1 f0 o3 o2 o1 o0 :
decoder2to4 f1 f0 z3 z2 z1 z0
r enabled o3 z3 0
r enabled o2 z2 0
r enabled o1 z1 0
r enabled o0 z0 0
# 3-to-8 Decoder
def decoder3to8 f2 f1 f0 o7 o6 o5 o4 o3 o2 o1 o0 :
r f2 1 t2 n2
r f1 t2 t11 n11
r f1 n2 t10 n10
r f0 t11 o7 o6
r f0 n11 o5 o4
r f0 t10 o3 o2
r f0 n10 o1 o0
# 3-to-8 Decoder With Output Enable
def eDecoder3to8 enabled f2 f1 f0 o7 o6 o5 o4 o3 o2 o1 o0 :
decoder3to8 f2 f1 f0 z7 z6 z5 z4 z3 z2 z1 z0
enable enabled z7 z6 z5 z4 z3 z2 z1 z0 o7 o6 o5 o4 o3 o2 o1 o0
# 3-bit Flag Register
# B is bus, A for bulbs
def flagRegister
load select Bzero Bcarry Bsign
Azero Acarry Asign :
inv load loadNeg0
inv load loadNeg1
inv load loadNeg2
buf load load2
buf load2 select
r select Azero Bzero 0
r select Acarry Bcarry 0
r select Asign Bsign 0
r Azero Azero loadNeg0 0
r Acarry Acarry loadNeg1 0
r Asign Asign loadNeg2 0
# 8-bit Register
# B is bus, A can feeds ALU and for bulbs
def register8
load select b7 b6 b5 b4 b3 b2 b1 b0
a7 a6 a5 a4 a3 a2 a1 a0 :
inv load loadNeg
buf load load2
buf load2 select
enable select a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
r a7 a7 loadNeg 0
r a6 a6 loadNeg 0
r a5 a5 loadNeg 0
r a4 a4 loadNeg 0
r a3 a3 loadNeg 0
r a2 a2 loadNeg 0
r a1 a1 loadNeg 0
r a0 a0 loadNeg 0
# 16-bit Register
# B is bus, A for bulbs
def register16
load select b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0 :
inv load loadNeg
buf load load2
buf load2 select
enable select a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
enable select a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
r a15 a15 loadNeg 0
r a14 a14 loadNeg 0
r a13 a13 loadNeg 0
r a12 a12 loadNeg 0
r a11 a11 loadNeg 0
r a10 a10 loadNeg 0
r a9 a9 loadNeg 0
r a8 a8 loadNeg 0
r a7 a7 loadNeg 0
r a6 a6 loadNeg 0
r a5 a5 loadNeg 0
r a4 a4 loadNeg 0
r a3 a3 loadNeg 0
r a2 a2 loadNeg 0
r a1 a1 loadNeg 0
r a0 a0 loadNeg 0
# High-low Register
# H/L/B buses, A for bulbs
def registerHighLow
loadHigh selectHigh
loadLow selectLow
load16 select16
h7 h6 h5 h4 h3 h2 h1 h0 l7 l6 l5 l4 l3 l2 l1 l0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0 :
nor load16 loadHigh loadHighNeg
nor load16 loadLow loadLowNeg
buf loadHigh loadHigh2
buf loadHigh2 selectHigh
buf loadLow loadLow2
buf loadLow2 selectLow
buf load16 load162
buf load162 select16
enable selectLow a7 a6 a5 a4 a3 a2 a1 a0 l7 l6 l5 l4 l3 l2 l1 l0
enable selectHigh a15 a14 a13 a12 a11 a10 a9 a8 h7 h6 h5 h4 h3 h2 h1 h0
enable select16 a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
enable select16 a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
r a15 a15 loadHighNeg 0
r a14 a14 loadHighNeg 0
r a13 a13 loadHighNeg 0
r a12 a12 loadHighNeg 0
r a11 a11 loadHighNeg 0
r a10 a10 loadHighNeg 0
r a9 a9 loadHighNeg 0
r a8 a8 loadHighNeg 0
r a7 a7 loadLowNeg 0
r a6 a6 loadLowNeg 0
r a5 a5 loadLowNeg 0
r a4 a4 loadLowNeg 0
r a3 a3 loadLowNeg 0
r a2 a2 loadLowNeg 0
r a1 a1 loadLowNeg 0
r a0 a0 loadLowNeg 0
# Arithmetic Logic Unit
def ALU selectB loadB selectC loadC selectFlag loadFlag f2 f1 f0
d7 d6 d5 d4 d3 d2 d1 d0 zero carry sign
b7 b6 b5 b4 b3 b2 b1 b0
c7 c6 c5 c4 c3 c2 c1 c0 :
flagRegister loadFlag selectFlag zero carry sign Azero Acarry Asign
register8 loadB selectB d7 d6 d5 d4 d3 d2 d1 d0 b7 b6 b5 b4 b3 b2 b1 b0
register8 loadC selectC d7 d6 d5 d4 d3 d2 d1 d0 c7 c6 c5 c4 c3 c2 c1 c0
muxByte incSig 0 0 0 0 0 0 0 1 c7 c6 c5 c4 c3 c2 c1 c0 i7 i6 i5 i4 i3 i2 i1 i0
decoder3to8 f2 f1 f0 0 shlSig notSig xorSig orSig andSig incSig addSig
fullAdder8 0 1 b7 b6 b5 b4 b3 b2 b1 b0 i7 i6 i5 i4 i3 i2 i1 i0
0 carryOut s7 s6 s5 s4 s3 s2 s1 s0
or incSig addSig adderSig
enable adderSig s7 s6 s5 s4 s3 s2 s1 s0 d7 d6 d5 d4 d3 d2 d1 d0
andByte andSig
b7 b6 b5 b4 b3 b2 b1 b0 c7 c6 c5 c4 c3 c2 c1 c0 d7 d6 d5 d4 d3 d2 d1 d0
orByte orSig
b7 b6 b5 b4 b3 b2 b1 b0 c7 c6 c5 c4 c3 c2 c1 c0 d7 d6 d5 d4 d3 d2 d1 d0
xorByte xorSig
b7 b6 b5 b4 b3 b2 b1 b0 c7 c6 c5 c4 c3 c2 c1 c0 d7 d6 d5 d4 d3 d2 d1 d0
notByte notSig b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0
shlByte shlSig b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0
zeroDetector d7 d6 d5 d4 d3 d2 d1 d0 zeroOut
r loadFlag zero zeroOut 0
r loadFlag carry carryOut 0
r loadFlag sign d7 0
# 16-bit Incrementer
def incrementer
i15 i14 i13 i12 i11 i10 i9 i8 i7 i6 i5 i4 i3 i2 i1 i0
o15 o14 o13 o12 o11 o10 o9 o8 o7 o6 o5 o4 o3 o2 o1 o0 :
fullAdder8 1 0 i7 i6 i5 i4 i3 i2 i1 i0 0 0 0 0 0 0 0 0
carryOutNeg carryOut o7 o6 o5 o4 o3 o2 o1 o0
fullAdder8 carryOut carryOutNeg i15 i14 i13 i12 i11 i10 i9 i8 0 0 0 0 0 0 0 0
0 0 o15 o14 o13 o12 o11 o10 o9 o8
# Latch, stores when w = 1
def latch w d q :
r w c2 d q
r c2 q 1 0
# Latch, stores when w = 0
def latchNeg w d q :
r w c2 q d
r c2 q 1 0
# Flip flop, stores when w rises to 1, expresses new value when w drops to 0
def flipFlop w d q :
latch w d q2
latchNeg w q2 q
def trans enabled a b :
r enabled a b 0
# 2-bit transmission gate
def trans2 enabled a1 a0 b1 b0 :
trans enabled a1 b1
trans enabled a0 b0
# 4-bit transmission gate
def trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0 :
trans2 enabled a3 a2 b3 b2
trans2 enabled a1 a0 b1 b0
# 8-bit transmission gate
def trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0 :
trans4 enabled a7 a6 a5 a4 b7 b6 b5 b4
trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0
# 2-to-1 Mux
def mux a i1 i0 o :
r a o i1 i0
# Multiplication program in ROM
def rom select d7 d6 d5 d4 d3 d2 d1 d0 a6 a5 a4 a3 a2 a1 a0 :
mux a0 ad0000001 ad0000000 ad000000
mux a0 ad0000011 ad0000010 ad000001
mux a0 ad0000101 ad0000100 ad000010
mux a0 ad0000111 ad0000110 ad000011
mux a0 ad0001001 ad0001000 ad000100
mux a0 ad0001011 ad0001010 ad000101
mux a0 ad0001101 ad0001100 ad000110
mux a0 ad0001111 ad0001110 ad000111
mux a0 ad0010001 ad0010000 ad001000
mux a0 ad0010011 ad0010010 ad001001
mux a0 ad0010101 ad0010100 ad001010
mux a0 ad0010111 ad0010110 ad001011
mux a0 ad0011001 ad0011000 ad001100
mux a0 ad0011011 ad0011010 ad001101
mux a0 ad0011101 ad0011100 ad001110
mux a0 ad0011111 ad0011110 ad001111
mux a0 ad0100001 ad0100000 ad010000
mux a0 ad0100011 ad0100010 ad010001
mux a0 ad0100101 ad0100100 ad010010
mux a0 ad0100111 ad0100110 ad010011
mux a0 ad0101001 ad0101000 ad010100
mux a0 ad0101011 ad0101010 ad010101
mux a0 ad0101101 ad0101100 ad010110
mux a0 ad0101111 ad0101110 ad010111
mux a0 ad0110001 ad0110000 ad011000
mux a0 ad0110011 ad0110010 ad011001
mux a0 ad0110101 ad0110100 ad011010
mux a0 ad0110111 ad0110110 ad011011
mux a0 ad0111001 ad0111000 ad011100
mux a0 ad0111011 ad0111010 ad011101
mux a0 ad0111101 ad0111100 ad011110
mux a0 ad0111111 ad0111110 ad011111
mux a0 ad1000001 ad1000000 ad100000
mux a0 ad1000011 ad1000010 ad100001
mux a1 ad000001 ad000000 ad00000
mux a1 ad000011 ad000010 ad00001
mux a1 ad000101 ad000100 ad00010
mux a1 ad000111 ad000110 ad00011
mux a1 ad001001 ad001000 ad00100
mux a1 ad001011 ad001010 ad00101
mux a1 ad001101 ad001100 ad00110
mux a1 ad001111 ad001110 ad00111
mux a1 ad010001 ad010000 ad01000
mux a1 ad010011 ad010010 ad01001
mux a1 ad010101 ad010100 ad01010
mux a1 ad010111 ad010110 ad01011
mux a1 ad011001 ad011000 ad01100
mux a1 ad011011 ad011010 ad01101
mux a1 ad011101 ad011100 ad01110
mux a1 ad011111 ad011110 ad01111
mux a1 ad100001 ad100000 ad10000
mux a2 ad00001 ad00000 ad0000
mux a2 ad00011 ad00010 ad0001
mux a2 ad00101 ad00100 ad0010
mux a2 ad00111 ad00110 ad0011
mux a2 ad01001 ad01000 ad0100
mux a2 ad01011 ad01010 ad0101
mux a2 ad01101 ad01100 ad0110
mux a2 ad01111 ad01110 ad0111
mux a2 ad10001 ad10000 ad1000
mux a3 ad0001 ad0000 ad000
mux a3 ad0011 ad0010 ad001
mux a3 ad0101 ad0100 ad010
mux a3 ad0111 ad0110 ad011
mux a3 ad1001 ad1000 ad100
mux a4 ad001 ad000 ad00
mux a4 ad011 ad010 ad01
mux a4 ad101 ad100 ad10
mux a5 ad01 ad00 ad0
mux a5 ad11 ad10 ad1
mux a6 ad1 ad0 select
trans8 ad0000000 d7 d6 d5 d4 d3 d2 d1 d0 1 1 0 0 0 0 0 0
trans8 ad0000001 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 0 0 0 0
trans8 ad0000010 d7 d6 d5 d4 d3 d2 d1 d0 0 1 0 0 0 0 0 1
trans8 ad0000011 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 1 0 0 0 0
trans8 ad0000100 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 1 0 0 0 0
trans8 ad0000101 d7 d6 d5 d4 d3 d2 d1 d0 1 1 0 0 0 0 0 0
trans8 ad0000110 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 0 0 0 0
trans8 ad0000111 d7 d6 d5 d4 d3 d2 d1 d0 0 1 0 0 0 0 1 0
trans8 ad0001000 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 1 0 0 0 0
trans8 ad0001001 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 1 1 0 0 0
trans8 ad0001010 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 0 0 1 0 0
trans8 ad0001011 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 0 1 1 1 0
trans8 ad0001100 d7 d6 d5 d4 d3 d2 d1 d0 0 1 0 1 1 0 0 1
trans8 ad0001101 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 1 1 0 0 0
trans8 ad0001110 d7 d6 d5 d4 d3 d2 d1 d0 0 1 1 0 0 0 0 0
trans8 ad0001111 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 1 0 1 1 1
trans8 ad0010000 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 0 0 0 1 1
trans8 ad0010001 d7 d6 d5 d4 d3 d2 d1 d0 1 1 1 1 0 0 0 0
trans8 ad0010010 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 0 0 0 0
trans8 ad0010011 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 1 0 1 0 1
trans8 ad0010100 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 0 1 0 0 1
trans8 ad0010101 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 1 1 0 0
trans8 ad0010110 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 0 0 1 1 0
trans8 ad0010111 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 1 0 0 0 0
trans8 ad0011000 d7 d6 d5 d4 d3 d2 d1 d0 0 1 1 1 1 1 1 0
trans8 ad0011001 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 0 0 0 1 0
trans8 ad0011010 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 0 0 0 0 0
trans8 ad0011011 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 1 1 0 1
trans8 ad0011100 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 0 0 1 0 1
trans8 ad0011101 d7 d6 d5 d4 d3 d2 d1 d0 1 1 1 1 0 0 0 0
trans8 ad0011110 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 0 0 0 0
trans8 ad0011111 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 0 0 0 1 1
trans8 ad0100000 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 1 1 0 0
trans8 ad0100001 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 0 0 0 0 1
trans8 ad0100010 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 0 0 0 0 0
trans8 ad0100011 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 1 1 0 1
trans8 ad0100100 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 0 0 1 1 0
trans8 ad0100101 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 1 0 0 0 0
trans8 ad0100110 d7 d6 d5 d4 d3 d2 d1 d0 0 1 1 1 1 1 1 0
trans8 ad0100111 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 0 0 0 1 0
trans8 ad0101000 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 0 1 0 0 0
trans8 ad0101001 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 1 1 1 1
trans8 ad0101010 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 0 0 1 1 0
trans8 ad0101011 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 1 1 0 0 0
trans8 ad0101100 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 1 1 1 1
trans8 ad0101101 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 0 0 1 0 1
trans8 ad0101110 d7 d6 d5 d4 d3 d2 d1 d0 1 1 1 1 0 0 0 0
trans8 ad0101111 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 0 0 0 0
trans8 ad0110000 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 1 1 0 1 1
trans8 ad0110001 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 1 1 0 1
trans8 ad0110010 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 1 0 1 1 0
trans8 ad0110011 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 0 0 0 0 0
trans8 ad0110100 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 0 1 0 0 0
trans8 ad0110101 d7 d6 d5 d4 d3 d2 d1 d0 1 1 1 0 1 0 0 0
trans8 ad0110110 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 0 0 0 0
trans8 ad0110111 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 1 1 0 1 1
trans8 ad0111000 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 1 1 0 0
trans8 ad0111001 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 0 0 0 0 1
trans8 ad0111010 d7 d6 d5 d4 d3 d2 d1 d0 0 0 1 0 0 0 0 0
trans8 ad0111011 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 1 0 1 1
trans8 ad0111100 d7 d6 d5 d4 d3 d2 d1 d0 1 0 0 0 1 0 0 1
trans8 ad0111101 d7 d6 d5 d4 d3 d2 d1 d0 1 1 1 0 0 0 1 0
trans8 ad0111110 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 0 0 0 0 0
trans8 ad0111111 d7 d6 d5 d4 d3 d2 d1 d0 0 0 0 1 0 1 0 1
trans8 ad1000000 d7 d6 d5 d4 d3 d2 d1 d0 1 0 1 0 1 1 1 0
trans8 ad1000001 d7 d6 d5 d4 d3 d2 d1 d0 1 1 0 1 1 1 0 1
trans8 ad1000010 d7 d6 d5 d4 d3 d2 d1 d0 1 0 1 1 0 0 1 1
# Putting it all together
def computer
ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0
rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0
rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0
rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0
m15 m14 m13 m12 m11 m10 m9 m8 m7 m6 m5 m4 m3 m2 m1 m0
xy15 xy14 xy13 xy12 xy11 xy10 xy9 xy8 xy7 xy6 xy5 xy4 xy3 xy2 xy1 xy0 :
rom selectMemory d7 d6 d5 d4 d3 d2 d1 d0 a6 a5 a4 a3 a2 a1 a0
register16 loadPC selectPC
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
pc15 pc14 pc13 pc12 pc11 pc10 pc9 pc8 pc7 pc6 pc5 pc4 pc3 pc2 pc1 pc0
registerHighLow loadIN 0 loadIN 0 0 selectIN
ic15 ic14 ic13 ic12 ic11 ic10 ic9 ic8 ic7 ic6 ic5 ic4 ic3 ic2 ic1 ic0
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
in15 in14 in13 in12 in11 in10 in9 in8 in7 in6 in5 in4 in3 in2 in1 in0
incrementer
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
ic15 ic14 ic13 ic12 ic11 ic10 ic9 ic8 ic7 ic6 ic5 ic4 ic3 ic2 ic1 ic0
ALU selectB loadB selectC loadC selectFlag loadFlag
alu2 alu1 alu0
d7 d6 d5 d4 d3 d2 d1 d0 zero carry sign
rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0
rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0
register8 loadA selectA
d7 d6 d5 d4 d3 d2 d1 d0 ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0
register8 loadD selectD
d7 d6 d5 d4 d3 d2 d1 d0 rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0
register8 loadInst selectInst
d7 d6 d5 d4 d3 d2 d1 d0 ns7 ns6 ns5 ns4 ns3 ns2 ns1 ns0
registerHighLow loadM1 selectM1 loadM2 selectM2 loadM selectM
d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
m15 m14 m13 m12 m11 m10 m9 m8 m7 m6 m5 m4 m3 m2 m1 m0
registerHighLow loadJ1 selectJ1 loadJ2 selectJ2 loadJ selectJ
d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
j15 j14 j13 j12 j11 j10 j9 j8 j7 j6 j5 j4 j3 j2 j1 j0
registerHighLow loadX selectX loadY selectY loadXY selectXY
d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
xy15 xy14 xy13 xy12 xy11 xy10 xy9 xy8 xy7 xy6 xy5 xy4 xy3 xy2 xy1 xy0
# BOOT (starts as 0, locks into 1 forever)
flipFlop C 1 boot
inv boot bootNeg
# PC = 0
flipFlop C bootNeg state4
buf state4 loadPC
buf state4 mainLoop
# -- COPY INSTRUCTION IN MEMORY TO INSTRUCTION REGISTER BEGIN ----------------
flipFlop C mainLoop stateMainLoop
flipFlop C stateMainLoop state5
buf state5 selectPC
flipFlop C state5 state6
buf state6 selectPC
buf state6 selectMemory
buf state6 loadInst
buf state6 loadIN # IN = PC + 1
flipFlop C state6 state7
buf state7 selectPC
buf state7 selectMemory
flipFlop C state7 state8
buf state8 loadPC # PC = IN
buf state8 selectIN
flipFlop C state8 state9
buf state9 selectIN
buf state9 processInst
# -- COPY INSTRUCTION IN MEMORY TO INSTRUCTION REGISTER END ------------------
# -- RETURN (1010 dss0) BEGIN ------------------------------------------------
r ns7 rt7 processInst 0
r ns6 rt6 0 rt7
r ns5 rt5 rt6 0
r ns4 rt4 0 rt5
flipFlop C rt4 state38
buf state38 state38b
buf state38 state38c
r ns3 state38c loadPC loadXY
eDecoder2to4 state38b ns2 ns1 halt selectJ selectXY selectM
flipFlop C state38 state39
buf state39 state38b
inv halt haltNeg
and haltNeg state39 mainLoop
# -- RETURN (1010 dss0) END --------------------------------------------------
# -- 16-BIT INSTRUCTION (11rs cznx) BEGIN ------------------------------------
r ns7 nx7 processInst 0
r ns6 nx6 nx7 0
flipFlop C nx6 state24b
buf state24b selectPC
flipFlop C state24b state25
buf state25 selectPC
buf state25 selectMemory
buf state25 state25b
r ns5 state25b loadJ1 loadM1 # M1/J1 <- MEM
buf state25 loadIN # IN = PC + 1
flipFlop C state25 state26
buf state26 selectPC
buf state26 selectMemory
flipFlop C state26 state27
buf state27 loadPC # PC = IN
buf state27 selectIN
flipFlop C state27 state28
buf state28 selectIN
flipFlop C state28 state29
buf state29 selectPC
buf state29 selectMemory
buf state29 state29b
r ns5 state29b loadJ2 loadM2 # M2/J2 <- MEM
buf state29 loadIN # IN = PC + 1
flipFlop C state29 state30
buf state30 selectPC
buf state30 selectMemory
flipFlop C state30 state31
buf state31 loadPC # PC = IN
buf state31 selectIN
flipFlop C state31 state35
buf state35 selectFlag
inv carry carryNeg
inv zero zeroNeg
and ns4 sign jmp0
and ns3 carryNeg jmp1
and ns2 zero jmp2
and ns1 zeroNeg jmp3
buf jmp0 jmp
buf jmp1 jmp
buf jmp2 jmp
buf jmp3 jmp
inv jmp jmpNeg
and state35 jmp doJump
and state35 jmpNeg mainLoop
flipFlop C doJump state32
inv ns0 ns0neg
and state32 ns0 savePC
and state32 ns0neg dontSavePC
flipFlop C savePC state33
buf state33 selectPC
buf state33 loadXY # XY = PC
flipFlop C state33 state34
buf state34 selectPC
buf state34 dontSavePC
flipFlop C dontSavePC state36
buf state36 state36b
r ns5 state36b selectJ selectM
buf state36 loadPC # PC = M/J
flipFlop C state36 state37
buf state37 state36b
buf state37 mainLoop
# -- 16-BIT INSTRUCTION (11rs cznx) END --------------------------------------
# -- INC XY (1011 0000) BEGIN ------------------------------------------------
r ns7 ix7 processInst 0
r ns6 ix6 0 ix7
r ns5 ix5 ix6 0
r ns4 ix4 ix5 0
r ns3 ix3 0 ix4
r ns2 ix2 0 ix3
r ns1 ix1 0 ix2
r ns0 ix0 0 ix1
flipFlop C ix0 state21
buf state21 selectXY
buf state21 loadIN
flipFlop C state21 state22
buf state22 selectXY
flipFlop C state22 state23
buf state23 loadXY
buf state23 selectIN
flipFlop C state23 state24
buf state24 selectIN
buf state24 mainLoop
# -- INC XY (1011 0000) END --------------------------------------------------
# -- ALU (1000 rfff) BEGIN ---------------------------------------------------
r ns7 al7 processInst 0
r ns6 al6 0 al7
r ns5 al5 0 al6
r ns4 al4 0 al5
flipFlop C al4 state19
buf state19 aluing
r aluing alu2 ns2 1
r aluing alu1 ns1 1
r aluing alu0 ns0 1
buf state19 loadFlag
buf state19 state19b
r ns3 state19b loadD loadA
flipFlop C state19 state20
buf state20 aluing
buf state20 mainLoop
# -- ALU (1000 rfff) END -----------------------------------------------------
# -- LD (1001 0xrr) BEGIN ----------------------------------------------------
r ns3 ld3 0 sto4
flipFlop C ld3 state17
buf state17 selectM
buf state17 selectMemory
eDecoder2to4 state17 ns1 ns0 loadD loadC loadB loadA
flipFlop C state17 state18
buf state18 selectM
buf state18 selectMemory
buf state18 mainLoop
# -- LD (1001 0xrr) END ------------------------------------------------------
# -- STO (1001 1xrr) BEGIN ---------------------------------------------------
r ns7 sto7 processInst 0
r ns6 sto6 0 sto7
r ns5 sto5 0 sto6
r ns4 sto4 sto5 0
r ns3 sto3 sto4 0
flipFlop C sto3 state14
buf state14 storing
buf storing selectM
eDecoder2to4 storing ns1 ns0 selectD selectC selectB selectA
flipFlop C state14 state15
buf state15 storing
buf state15 loadMemory
flipFlop C state15 state16
buf state16 storing
buf state16 mainLoop
# -- STO (1001 1xrr) END -----------------------------------------------------
# -- MOV (00dd dsss) BEGIN ---------------------------------------------------
r ns7 mo7 0 processInst
r ns6 mo6 0 mo7
flipFlop C mo6 state12
or state12 state13 movSrc
eDecoder3to8 state12 ns5 ns4 ns3
loadY loadX loadM2 loadM1 loadD loadC loadB loadA
eDecoder3to8 movSrc ns2 ns1 ns0
selectY selectX selectM2 selectM1 selectD selectC selectB selectA
flipFlop C state12 state13
buf state13 mainLoop
# -- MOV (00dd dsss) END -----------------------------------------------------
# -- SET-8 (01rv vvvv) BEGIN -------------------------------------------------
r ns7 se7 0 processInst
r ns6 se6 se7 0
flipFlop C se6 state10
buf state10 state10load
r ns5 state10load loadB loadA
or state10 state11 enable1011
enable enable1011 ns4 ns4 ns4 ns4 ns3 ns2 ns1 ns0 d7 d6 d5 d4 d3 d2 d1 d0
flipFlop C state10 state11
buf state11 mainLoop
# -- SET-8 (01rv vvvv) END ---------------------------------------------------
run 41000 10 computer
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
+311
View File
@@ -0,0 +1,311 @@
# Four double-pole relay
def r4 coil l3 nd3 nc3 l2 nd2 nc2 l1 nd1 nc1 l0 nd0 nc0 :
r coil l3 nd3 nc3
r coil l2 nd2 nc2
r coil l1 nd1 nc1
r coil l0 nd0 nc0
# Buffer
def buf input output :
r input output 1 0
# Inverter
def inv input output :
r input output 0 1
# AND Gate
def and i1 i0 o :
r i0 z 1 0
r i1 o z 0
# NAND Gate
def nand i0 i1 o :
r i0 1 0 o
r i1 1 0 o
# OR Gate
def or i0 i1 o :
r i0 1 o 0
r i1 1 o 0
# NOR Gate
def nor i0 i1 o :
r i0 1 0 z
r i1 z 0 o
# XOR Gate
def xor i0 i1 o :
r i0 1 b a
r i1 o a b
# XNOR Gate
def xnor i0 i1 o :
r i0 1 a b
r i1 o a b
# Half Adder
def halfAdder a b s1 s0 :
and a b s1
xor a b s0
# Full Adder
def fullAdder carryIn a b carryOut sum :
halfAdder a b s1 s0
halfAdder s0 carryIn carry sum
or s1 carry carryOut
# 2-bit Adder
def adder2 carryIn a1 a0 b1 b0 carryOut s1 s0 :
fullAdder carryIn a0 b0 carry s0
fullAdder carry a1 b1 carryOut s1
# 4-bit Adder
def adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carryOut s3 s2 s1 s0 :
adder2 carryIn a1 a0 b1 b0 carry s1 s0
adder2 carry a3 a2 b3 b2 carryOut s3 s2
# 8-bit Adder
def adder8 carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carry s3 s2 s1 s0
adder4 carry a7 a6 a5 a4 b7 b6 b5 b4 carryOut s7 s6 s5 s4
# Konrad Zuse Dual-Rail-Carry Full Adder
def zuseFullAdder carryInNeg carryIn a b carryOutNeg carryOut sum :
r4 a carryInNeg y z sum w x 1 v y carryIn u v
r4 b carryOutNeg z y carryInNeg x w carryIn w x carryOut v u
# Konrad Zuse Dual-Rail-Carry 2-bit Adder
def zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
zuseFullAdder carryInNeg carryIn a0 b0 cOutNeg cOut s0
zuseFullAdder cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# Konrad Zuse Dual-Rail-Carry 4-bit Adder
def zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
zuseAdder2 cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# Konrad Zuse Dual-Rail-Carry 8-bit Adder
def zuseAdder8 carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0 cOutNeg cOut s3 s2 s1 s0
zuseAdder4 cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 1-bit Partial Adder/Subtractor
def xFullAdder subtract carryInNeg carryIn a b carryOutNeg carryOut sum :
xor subtract b bNeg
zuseFullAdder carryInNeg carryIn a bNeg carryOutNeg carryOut sum
# 2-bit Partial Adder/Subtractor
def xFullAdder2 subtract carryInNeg carryIn
a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
xFullAdder subtract carryInNeg carryIn a0 b0 cOutNeg cOut s0
xFullAdder subtract cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# 4-bit Partial Adder/Subtractor
def xFullAdder4 subtract carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
xFullAdder2 subtract carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
xFullAdder2 subtract cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# 8-bit Partial Adder/Subtractor
def xFullAdder8 subtract carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
xFullAdder4 subtract carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
cOutNeg cOut s3 s2 s1 s0
xFullAdder4 subtract cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 8-bit Adder/Subtractor
def adderSubtractor subtract
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
inv subtract carryInNeg
xFullAdder8 subtract carryInNeg subtract
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg cOut s7 s6 s5 s4 s3 s2 s1 s0
xor cOut subtract carryOut
# 2-to-1 Mux
def mux a i1 i0 o :
r a o i1 i0
# 4-to-1 Mux
def mux4to1 a1 a0 i3 i2 i1 i0 o :
mux a0 i1 i0 x
mux a0 i3 i2 y
mux a1 y x o
# 8-to-1 Mux
def mux8to1 a2 a1 a0 i7 i6 i5 i4 i3 i2 i1 i0 o :
mux4to1 a1 a0 i3 i2 i1 i0 x
mux4to1 a1 a0 i7 i6 i5 i4 y
mux a2 y x o
# 3-to-8 Decoder
def decoder3to8 a2 a1 a0 o7 o6 o5 o4 o3 o2 o1 o0 :
mux8to1 a2 a1 a0 o7 o6 o5 o4 o3 o2 o1 o0 1
def trans enabled a b :
r enabled a b 0
# 2-bit transmission gate
def trans2 enabled a1 a0 b1 b0 :
trans enabled a1 b1
trans enabled a0 b0
# 4-bit transmission gate
def trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0 :
trans2 enabled a3 a2 b3 b2
trans2 enabled a1 a0 b1 b0
# 8-bit transmission gate
def trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0 :
trans4 enabled a7 a6 a5 a4 b7 b6 b5 b4
trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0
# 16-bit transmission gate
def trans16 enabled
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 :
trans8 enabled a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
# Latch, stores when w = 1
def latch w d q :
mux w d q z
buf z q
# Latch, stores when w = 0
def latchNeg w d q :
mux w q d z
buf z q
# Flip flop, stores when w rises to 1, expresses new value when w drops to 0
def flipFlop w d q :
latch w d q2
latchNeg w q2 q
def flipFlopRegister w d7 d6 d5 d4 d3 d2 d1 d0 q7 q6 q5 q4 q3 q2 q1 q0:
flipFlop w d7 q7
flipFlop w d6 q6
flipFlop w d5 q5
flipFlop w d4 q4
flipFlop w d3 q3
flipFlop w d2 q2
flipFlop w d1 q1
flipFlop w d0 q0
def latchRegister w d7 d6 d5 d4 d3 d2 d1 d0 q7 q6 q5 q4 q3 q2 q1 q0:
latch w d7 q7
latch w d6 q6
latch w d5 q5
latch w d4 q4
latch w d3 q3
latch w d2 q2
latch w d1 q1
latch w d0 q0
def tinyLatchRegister writeNeg d7 d6 d5 d4 d3 d2 d1 d0 :
r d7 d7 writeNeg 0
r d6 d6 writeNeg 0
r d5 d5 writeNeg 0
r d4 d4 writeNeg 0
r d3 d3 writeNeg 0
r d2 d2 writeNeg 0
r d1 d1 writeNeg 0
r d0 d0 writeNeg 0
def memoryRegister select load d7 d6 d5 d4 d3 d2 d1 d0 :
inv load writeNeg
inv writeNeg select
trans8 select d7 d6 d5 d4 d3 d2 d1 d0 z7 z6 z5 z4 z3 z2 z1 z0
tinyLatchRegister writeNeg z7 z6 z5 z4 z3 z2 z1 z0
# 2 Bytes of memory
def memory2 address select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux address select1 select0 select
mux address load1 load0 load
memoryRegister select0 load0 d7 d6 d5 d4 d3 d2 d1 d0
memoryRegister select1 load1 d7 d6 d5 d4 d3 d2 d1 d0
# 4 Bytes of memory
def memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a1 select1 select0 select
mux a1 load1 load0 load
memory2 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory2 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 8 Bytes of memory
def memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a2 select1 select0 select
mux a2 load1 load0 load
memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 16 Bytes of memory
def memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a3 select1 select0 select
mux a3 load1 load0 load
memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 32 Bytes of memory
def memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a4 select1 select0 select
mux a4 load1 load0 load
memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 64 Bytes of memory
def memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a5 select1 select0 select
mux a5 load1 load0 load
memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 128 Bytes of memory
def memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a6 select1 select0 select
mux a6 load1 load0 load
memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 256 Bytes of memory
def memory256 a7 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a7 select1 select0 select
mux a7 load1 load0 load
memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
def counterElement andIn andOut value :
xor andIn value data
flipFlop c data value
and andIn value andOut
def counter2 andIn andOut v1 v0 :
counterElement andIn x v0
counterElement x andOut v1
def counter4 andIn andOut v3 v2 v1 v0 :
counter2 andIn x v1 v0
counter2 x andOut v3 v2
def counter8 andIn andOut v7 v6 v5 v4 v3 v2 v1 v0 :
counter4 andIn x v3 v2 v1 v0
counter4 x andOut v7 v6 v5 v4
run 160 5 counter8 1 0 ? ? ? ? ? ? ? ?
+598
View File
@@ -0,0 +1,598 @@
# Four double-pole relay
def r4 coil l3 nd3 nc3 l2 nd2 nc2 l1 nd1 nc1 l0 nd0 nc0 :
r coil l3 nd3 nc3
r coil l2 nd2 nc2
r coil l1 nd1 nc1
r coil l0 nd0 nc0
# Buffer
def buf input output :
r input output 1 0
# Inverter
def inv input output :
r input output 0 1
# AND Gate
def and i1 i0 o :
r i0 z 1 0
r i1 o z 0
# NAND Gate
def nand i0 i1 o :
r i0 1 0 o
r i1 1 0 o
# OR Gate
def or i0 i1 o :
r i0 1 o 0
r i1 1 o 0
# NOR Gate
def nor i0 i1 o :
r i0 1 0 z
r i1 z 0 o
# XOR Gate
def xor i0 i1 o :
r i0 1 b a
r i1 o a b
# XNOR Gate
def xnor i0 i1 o :
r i0 1 a b
r i1 o a b
# Half Adder
def halfAdder a b s1 s0 :
and a b s1
xor a b s0
# Full Adder
def fullAdder carryIn a b carryOut sum :
halfAdder a b s1 s0
halfAdder s0 carryIn carry sum
or s1 carry carryOut
# 2-bit Adder
def adder2 carryIn a1 a0 b1 b0 carryOut s1 s0 :
fullAdder carryIn a0 b0 carry s0
fullAdder carry a1 b1 carryOut s1
# 4-bit Adder
def adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carryOut s3 s2 s1 s0 :
adder2 carryIn a1 a0 b1 b0 carry s1 s0
adder2 carry a3 a2 b3 b2 carryOut s3 s2
# 8-bit Adder
def adder8 carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carry s3 s2 s1 s0
adder4 carry a7 a6 a5 a4 b7 b6 b5 b4 carryOut s7 s6 s5 s4
# Konrad Zuse Dual-Rail-Carry Full Adder
def zuseFullAdder carryInNeg carryIn a b carryOutNeg carryOut sum :
r4 a carryInNeg y z sum w x 1 v y carryIn u v
r4 b carryOutNeg z y carryInNeg x w carryIn w x carryOut v u
# Konrad Zuse Dual-Rail-Carry 2-bit Adder
def zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
zuseFullAdder carryInNeg carryIn a0 b0 cOutNeg cOut s0
zuseFullAdder cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# Konrad Zuse Dual-Rail-Carry 4-bit Adder
def zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
zuseAdder2 cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# Konrad Zuse Dual-Rail-Carry 8-bit Adder
def zuseAdder8 carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0 cOutNeg cOut s3 s2 s1 s0
zuseAdder4 cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 1-bit Partial Adder/Subtractor
def xFullAdder subtract carryInNeg carryIn a b carryOutNeg carryOut sum :
xor subtract b bNeg
zuseFullAdder carryInNeg carryIn a bNeg carryOutNeg carryOut sum
# 2-bit Partial Adder/Subtractor
def xFullAdder2 subtract carryInNeg carryIn
a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
xFullAdder subtract carryInNeg carryIn a0 b0 cOutNeg cOut s0
xFullAdder subtract cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# 4-bit Partial Adder/Subtractor
def xFullAdder4 subtract carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
xFullAdder2 subtract carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
xFullAdder2 subtract cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# 8-bit Partial Adder/Subtractor
def xFullAdder8 subtract carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
xFullAdder4 subtract carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
cOutNeg cOut s3 s2 s1 s0
xFullAdder4 subtract cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 8-bit Adder/Subtractor
def adderSubtractor subtract
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
inv subtract carryInNeg
xFullAdder8 subtract carryInNeg subtract
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg cOut s7 s6 s5 s4 s3 s2 s1 s0
xor cOut subtract carryOut
# 2-to-1 Mux
def mux a i1 i0 o :
r a o i1 i0
# 4-to-1 Mux
def mux4to1 a1 a0 i3 i2 i1 i0 o :
mux a0 i1 i0 x
mux a0 i3 i2 y
mux a1 y x o
# 8-to-1 Mux
def mux8to1 a2 a1 a0 i7 i6 i5 i4 i3 i2 i1 i0 o :
mux4to1 a1 a0 i3 i2 i1 i0 x
mux4to1 a1 a0 i7 i6 i5 i4 y
mux a2 y x o
# 3-to-8 Decoder
def decoder3to8 a2 a1 a0 o7 o6 o5 o4 o3 o2 o1 o0 :
mux8to1 a2 a1 a0 o7 o6 o5 o4 o3 o2 o1 o0 1
def trans enabled a b :
r enabled a b 0
# 2-bit transmission gate
def trans2 enabled a1 a0 b1 b0 :
trans enabled a1 b1
trans enabled a0 b0
# 4-bit transmission gate
def trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0 :
trans2 enabled a3 a2 b3 b2
trans2 enabled a1 a0 b1 b0
# 8-bit transmission gate
def trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0 :
trans4 enabled a7 a6 a5 a4 b7 b6 b5 b4
trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0
# 16-bit transmission gate
def trans16 enabled
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 :
trans8 enabled a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
# Latch, stores when w = 1
def latch w d q :
mux w d q z
buf z q
# Latch, stores when w = 0
def latchNeg w d q :
mux w q d z
buf z q
# Flip flop, stores when w rises to 1, expresses new value when w drops to 0
def flipFlop w d q :
latch w d q2
latchNeg w q2 q
def flipFlopRegister w d7 d6 d5 d4 d3 d2 d1 d0 q7 q6 q5 q4 q3 q2 q1 q0:
flipFlop w d7 q7
flipFlop w d6 q6
flipFlop w d5 q5
flipFlop w d4 q4
flipFlop w d3 q3
flipFlop w d2 q2
flipFlop w d1 q1
flipFlop w d0 q0
def latchRegister w d7 d6 d5 d4 d3 d2 d1 d0 q7 q6 q5 q4 q3 q2 q1 q0:
latch w d7 q7
latch w d6 q6
latch w d5 q5
latch w d4 q4
latch w d3 q3
latch w d2 q2
latch w d1 q1
latch w d0 q0
def tinyLatchRegister writeNeg d7 d6 d5 d4 d3 d2 d1 d0 :
r d7 d7 writeNeg 0
r d6 d6 writeNeg 0
r d5 d5 writeNeg 0
r d4 d4 writeNeg 0
r d3 d3 writeNeg 0
r d2 d2 writeNeg 0
r d1 d1 writeNeg 0
r d0 d0 writeNeg 0
def memoryRegister select load d7 d6 d5 d4 d3 d2 d1 d0 :
inv load writeNeg
inv writeNeg select
trans8 select d7 d6 d5 d4 d3 d2 d1 d0 z7 z6 z5 z4 z3 z2 z1 z0
tinyLatchRegister writeNeg z7 z6 z5 z4 z3 z2 z1 z0
# 2 Bytes of memory
def memory2 address select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux address select1 select0 select
mux address load1 load0 load
memoryRegister select0 load0 d7 d6 d5 d4 d3 d2 d1 d0
memoryRegister select1 load1 d7 d6 d5 d4 d3 d2 d1 d0
# 4 Bytes of memory
def memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a1 select1 select0 select
mux a1 load1 load0 load
memory2 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory2 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 8 Bytes of memory
def memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a2 select1 select0 select
mux a2 load1 load0 load
memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 16 Bytes of memory
def memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a3 select1 select0 select
mux a3 load1 load0 load
memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 32 Bytes of memory
def memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a4 select1 select0 select
mux a4 load1 load0 load
memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 64 Bytes of memory
def memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a5 select1 select0 select
mux a5 load1 load0 load
memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 128 Bytes of memory
def memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a6 select1 select0 select
mux a6 load1 load0 load
memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 256 Bytes of memory
def memory256 a7 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a7 select1 select0 select
mux a7 load1 load0 load
memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
def counterElement andIn andOut value :
xor andIn value data
flipFlop c data value
and andIn value andOut
def counter2 andIn andOut v1 v0 :
counterElement andIn x v0
counterElement x andOut v1
def counter4 andIn andOut v3 v2 v1 v0 :
counter2 andIn x v1 v0
counter2 x andOut v3 v2
def counter8 andIn andOut v7 v6 v5 v4 v3 v2 v1 v0 :
counter4 andIn x v3 v2 v1 v0
counter4 x andOut v7 v6 v5 v4
def shift2 shiftIn q1 q0 :
flipFlop c shiftIn q1
flipFlop c q1 q0
def shift4 shiftIn q3 q2 q1 q0 :
shift2 shiftIn q3 q2
shift2 q2 q1 q0
def shift8 shiftIn q7 q6 q5 q4 q3 q2 q1 q0 :
shift4 shiftIn q7 q6 q5 q4
shift4 q4 q3 q2 q1 q0
def shiftOne q7 q6 q5 q4 q3 q2 q1 q0 :
flipFlop c 1 q
inv q shiftIn
shift8 shiftIn q7 q6 q5 q4 q3 q2 q1 q0
def loop q7 q6 q5 q4 q3 q2 q1 q0 :
flipFlop c 1 q
inv q shiftIn
shift8 shiftIn q7 q6 q5 q4 q3 q2 q1 q0
buf q0 shiftIn
# 1-bit adder
def mAdder add carryInNeg carryIn a b carryOutNeg carryOut sum :
trans add b s
zuseFullAdder carryInNeg carryIn a s carryOutNeg carryOut sum
# 2-bit adder
def mAdder2 add carryInNeg carryIn a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
mAdder add carryInNeg carryIn a0 b0 cOutNeg cOut s0
mAdder add cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# 4-bit adder
def mAdder4 add carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
mAdder2 add carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
mAdder2 add cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# 8-bit adder
def mAdder8 add
carryInNeg carryIn a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
mAdder4 add carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
cOutNeg cOut s3 s2 s1 s0
mAdder4 add cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 16-bit adder
def mAdder16 add
carryInNeg carryIn a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s15 s14 s13 s12 s11 s10 s9 s8 s7 s6 s5 s4 s3 s2 s1 s0 :
mAdder8 add carryInNeg carryIn a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
cOutNeg cOut s7 s6 s5 s4 s3 s2 s1 s0
mAdder8 add cOutNeg cOut
a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
carryOutNeg carryOut s15 s14 s13 s12 s11 s10 s9 s8
def multiplier
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0 :
mAdder16 b0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0
0 0 d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
mAdder16 b1 1 0
d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
0 0 0 0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0
0 0 e15 e14 e13 e12 e11 e10 e9 e8 e7 e6 e5 e4 e3 e2 e1 e0
mAdder16 b2 1 0
e15 e14 e13 e12 e11 e10 e9 e8 e7 e6 e5 e4 e3 e2 e1 e0
0 0 0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0
0 0 f15 f14 f13 f12 f11 f10 f9 f8 f7 f6 f5 f4 f3 f2 f1 f0
mAdder16 b3 1 0
f15 f14 f13 f12 f11 f10 f9 f8 f7 f6 f5 f4 f3 f2 f1 f0
0 0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0
0 0 g15 g14 g13 g12 g11 g10 g9 g8 g7 g6 g5 g4 g3 g2 g1 g0
mAdder16 b4 1 0
g15 g14 g13 g12 g11 g10 g9 g8 g7 g6 g5 g4 g3 g2 g1 g0
0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0 0
0 0 h15 h14 h13 h12 h11 h10 h9 h8 h7 h6 h5 h4 h3 h2 h1 h0
mAdder16 b5 1 0
h15 h14 h13 h12 h11 h10 h9 h8 h7 h6 h5 h4 h3 h2 h1 h0
0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0 0 0
0 0 i15 i14 i13 i12 i11 i10 i9 i8 i7 i6 i5 i4 i3 i2 i1 i0
mAdder16 b6 1 0
i15 i14 i13 i12 i11 i10 i9 i8 i7 i6 i5 i4 i3 i2 i1 i0
0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0 0 0 0
0 0 j15 j14 j13 j12 j11 j10 j9 j8 j7 j6 j5 j4 j3 j2 j1 j0
mAdder16 b7 1 0
j15 j14 j13 j12 j11 j10 j9 j8 j7 j6 j5 j4 j3 j2 j1 j0
0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0 0 0 0 0
0 0 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0
# 16-bit Partial Adder/Subtractor
def xFullAdder16 subtract carryInNeg carryIn
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s15 s14 s13 s12 s11 s10 s9 s8 s7 s6 s5 s4 s3 s2 s1 s0 :
xFullAdder8 subtract carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
cOutNeg cOut s7 s6 s5 s4 s3 s2 s1 s0
xFullAdder8 subtract cOutNeg cOut
a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
carryOutNeg carryOut s15 s14 s13 s12 s11 s10 s9 s8
# 16-bit Adder/Subtractor
def adderSubtractor16 subtract
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
carryOut s15 s14 s13 s12 s11 s10 s9 s8 s7 s6 s5 s4 s3 s2 s1 s0 :
inv subtract carryInNeg
xFullAdder16 subtract carryInNeg subtract
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg cOut s15 s14 s13 s12 s11 s10 s9 s8 s7 s6 s5 s4 s3 s2 s1 s0
xor cOut subtract carryOut
def signedMultiplier signed
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0 :
and signed a7 negateA
and signed b7 negateB
adderSubtractor negateA 0 0 0 0 0 0 0 0
a7 a6 a5 a4 a3 a2 a1 a0 0 c7 c6 c5 c4 c3 c2 c1 c0
adderSubtractor negateB 0 0 0 0 0 0 0 0
b7 b6 b5 b4 b3 b2 b1 b0 0 d7 d6 d5 d4 d3 d2 d1 d0
multiplier
c7 c6 c5 c4 c3 c2 c1 c0
d7 d6 d5 d4 d3 d2 d1 d0
q15 q14 q13 q12 q11 q10 q9 q8 q7 q6 q5 q4 q3 q2 q1 q0
xor a7 b7 negateProduct
and signed negateProduct negateQ
adderSubtractor16 negateQ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
q15 q14 q13 q12 q11 q10 q9 q8 q7 q6 q5 q4 q3 q2 q1 q0
0 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0
# 4-input OR gate
def or4 i3 i2 i1 i0 o :
or i3 i2 o
or i1 i0 o
# 8-input OR gate
def or8 i7 i6 i5 i4 i3 i2 i1 i0 o :
or4 i7 i6 i5 i4 o
or4 i3 i2 i1 i0 o
def multiplier2
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0 :
# 16-bit register made of flip flops
flipFlop c d15 p15
flipFlop c d14 p14
flipFlop c d13 p13
flipFlop c d12 p12
flipFlop c d11 p11
flipFlop c d10 p10
flipFlop c d9 p9
flipFlop c d8 p8
flipFlop c d7 p7
flipFlop c d6 p6
flipFlop c d5 p5
flipFlop c d4 p4
flipFlop c d3 p3
flipFlop c d2 p2
flipFlop c d1 p1
flipFlop c d0 p0
# Transmission gates and 8-bit adder
trans8 loadB d7 d6 d5 d4 d3 d2 d1 d0 b7 b6 b5 b4 b3 b2 b1 b0
trans8 p0 a7 a6 a5 a4 a3 a2 a1 a0 z7 z6 z5 z4 z3 z2 z1 z0
zuseAdder8 1 0 p15 p14 p13 p12 p11 p10 p9 p8 z7 z6 z5 z4 z3 z2 z1 z0
0 s8 s7 s6 s5 s4 s3 s2 s1 s0
trans16 tallyShift d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
s8 s7 s6 s5 s4 s3 s2 s1 s0 p7 p6 p5 p4 p3 p2 p1
trans16 keepValue d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0
# State machine
flipFlop c 1 boot
inv boot loadB
flipFlop c loadB state1
flipFlop c state1 state2
flipFlop c state2 state3
flipFlop c state3 state4
flipFlop c state4 state5
flipFlop c state5 state6
flipFlop c state6 state7
flipFlop c state7 state8
flipFlop c state8 keepValue
or8 state1 state2 state3 state4 state5 state6 state7 state8 tallyShift
buf keepValue keepValue
def signedMultiplier2 signed
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0 :
and signed a7 negateA
and signed b7 negateB
adderSubtractor negateA 0 0 0 0 0 0 0 0
a7 a6 a5 a4 a3 a2 a1 a0 0 c7 c6 c5 c4 c3 c2 c1 c0
adderSubtractor negateB 0 0 0 0 0 0 0 0
b7 b6 b5 b4 b3 b2 b1 b0 0 d7 d6 d5 d4 d3 d2 d1 d0
multiplier2
c7 c6 c5 c4 c3 c2 c1 c0
d7 d6 d5 d4 d3 d2 d1 d0
q15 q14 q13 q12 q11 q10 q9 q8 q7 q6 q5 q4 q3 q2 q1 q0
xor a7 b7 negateProduct
and signed negateProduct negateQ
adderSubtractor16 negateQ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
q15 q14 q13 q12 q11 q10 q9 q8 q7 q6 q5 q4 q3 q2 q1 q0
0 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0
# Divider (A = Dividend, B = Divisor, P = Quotient, Q = Remainder)
def divider
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
divideByZeroError
p7 p6 p5 p4 p3 p2 p1 p0
q7 q6 q5 q4 q3 q2 q1 q0 :
# 16-bit register made of flip flops
flipFlop c d15 q7
flipFlop c d14 q6
flipFlop c d13 q5
flipFlop c d12 q4
flipFlop c d11 q3
flipFlop c d10 q2
flipFlop c d9 q1
flipFlop c d8 q0
flipFlop c d7 p7
flipFlop c d6 p6
flipFlop c d5 p5
flipFlop c d4 p4
flipFlop c d3 p3
flipFlop c d2 p2
flipFlop c d1 p1
flipFlop c d0 p0
# Transmission gates and 8-bit subtractor
trans8 loadA d7 d6 d5 d4 d3 d2 d1 d0 a7 a6 a5 a4 a3 a2 a1 a0
trans16 positive d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
s7 s6 s5 s4 s3 s2 s1 s0 p6 p5 p4 p3 p2 p1 p0 1
trans16 negative d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
q6 q5 q4 q3 q2 q1 q0 p7 p6 p5 p4 p3 p2 p1 p0 0
trans16 keepValue d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
q7 q6 q5 q4 q3 q2 q1 q0 p7 p6 p5 p4 p3 p2 p1 p0
adderSubtractor 1 q6 q5 q4 q3 q2 q1 q0 p7 b7 b6 b5 b4 b3 b2 b1 b0
0 s7 s6 s5 s4 s3 s2 s1 s0
inv s7 s7Neg
and shift s7 negative
and shift s7Neg positive
# Divide-by-zero check
or8 b7 b6 b5 b4 b3 b2 b1 b0 divideByZeroErrorNeg
inv divideByZeroErrorNeg divideByZeroError
# State machine
flipFlop c 1 boot
inv boot bootNeg
trans divideByZeroErrorNeg bootNeg loadA
flipFlop c loadA state1
flipFlop c state1 state2
flipFlop c state2 state3
flipFlop c state3 state4
flipFlop c state4 state5
flipFlop c state5 state6
flipFlop c state6 state7
flipFlop c state7 state8
flipFlop c state8 keepValue
or8 state1 state2 state3 state4 state5 state6 state7 state8 shift
buf keepValue keepValue
run 1000 5 divider
0 0 0 0 1 1 1 0
0 0 0 0 0 0 1 1
?
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
+52
View File
@@ -0,0 +1,52 @@
# EDAMAME Award
# (Electronic Design Automation - Mechanical Abstract Machine Emulator)
Michael Birken
US
o__1 at hotmail dot com
## Judges' comments:
### To build
make birken
Try:
./birken < counter.tofu
What is TUFO? It's not a veggy friendly food, nor it is Verilog or
VHDL. It is not even Pascal!
NOTE: On some systems, file(1) claims one of the .tofu files is Pascal
source. :-)
It may not be the most readable hardware description language, but it is
one of the easiest 55 page long manual to learn. :-)
For a small but non-trivial design, try implementing a
[Linear Feedback Shift Register](http://en.wikipedia.org/wiki/LFSR)
And for those who are still confused:
> <http://en.wikipedia.org/wiki/Edamame>
> <http://en.wikipedia.org/wiki/Tofu>
## Author's comments:
If man is capable of creating tofu hotdogs (simulated meat), then why
not tofu circuitry (simulated circuits)? This program is my tribute to
the early computer pioneers like Konrad Zuse. It's an educational tool
designed to introduce students to digital circuit theory using
technology that was considered state of the art in the 1940's! To
enable you to fully understand the capabilities of this circuit
simulator, I have included a 55 page manual (info.pdf) in the info
portion of the entry submission.
The primary obfuscation is the data structure chosen for parsing the
input file and for executing the simulation. Oh man... coding that
data structure gave me such a bad headache. But, I figure, who needs
more than a pair anyway? Subtle obfuscations abound. Bonus points go
out the one who discovers the hidden program within the source.
Note that the shape of the source is a wave, not a waveform.
Binary file not shown.
+72
View File
@@ -0,0 +1,72 @@
# Buffer
def buf input output :
r input output 1 0
# Inverter
def inv input output :
r input output 0 1
# AND Gate
def and i1 i0 o :
r i0 z 1 0
r i1 o z 0
# NAND Gate
def nand i0 i1 o :
r i0 1 0 o
r i1 1 0 o
# OR Gate
def or i0 i1 o :
r i0 1 o 0
r i1 1 o 0
# NOR Gate
def nor i0 i1 o :
r i0 1 0 z
r i1 z 0 o
# XOR Gate
def xor i0 i1 o :
r i0 1 b a
r i1 o a b
# XNOR Gate
def xnor i0 i1 o :
r i0 1 a b
r i1 o a b
# Half Adder
def halfAdder a b s1 s0 :
and a b s1
xor a b s0
# Full Adder
def fullAdder carryIn a b carryOut sum :
halfAdder a b s1 s0
halfAdder s0 carryIn carry sum
or s1 carry carryOut
# 2-bit Adder
def adder2 carryIn a1 a0 b1 b0 carryOut s1 s0 :
fullAdder carryIn a0 b0 carry s0
fullAdder carry a1 b1 carryOut s1
# 4-bit Adder
def adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carryOut s3 s2 s1 s0 :
adder2 carryIn a1 a0 b1 b0 carry s1 s0
adder2 carry a3 a2 b3 b2 carryOut s3 s2
# 8-bit Adder
def adder8 carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carry s3 s2 s1 s0
adder4 carry a7 a6 a5 a4 b7 b6 b5 b4 carryOut s7 s6 s5 s4
# 57 + 142 = ?
run 100 1 adder8 0
0 0 1 1 1 0 0 1
1 0 0 0 1 1 1 0
? ? ? ? ? ? ? ? ?
+293
View File
@@ -0,0 +1,293 @@
# Four double-pole relay
def r4 coil l3 nd3 nc3 l2 nd2 nc2 l1 nd1 nc1 l0 nd0 nc0 :
r coil l3 nd3 nc3
r coil l2 nd2 nc2
r coil l1 nd1 nc1
r coil l0 nd0 nc0
# Buffer
def buf input output :
r input output 1 0
# Inverter
def inv input output :
r input output 0 1
# AND Gate
def and i1 i0 o :
r i0 z 1 0
r i1 o z 0
# NAND Gate
def nand i0 i1 o :
r i0 1 0 o
r i1 1 0 o
# OR Gate
def or i0 i1 o :
r i0 1 o 0
r i1 1 o 0
# NOR Gate
def nor i0 i1 o :
r i0 1 0 z
r i1 z 0 o
# XOR Gate
def xor i0 i1 o :
r i0 1 b a
r i1 o a b
# XNOR Gate
def xnor i0 i1 o :
r i0 1 a b
r i1 o a b
# Half Adder
def halfAdder a b s1 s0 :
and a b s1
xor a b s0
# Full Adder
def fullAdder carryIn a b carryOut sum :
halfAdder a b s1 s0
halfAdder s0 carryIn carry sum
or s1 carry carryOut
# 2-bit Adder
def adder2 carryIn a1 a0 b1 b0 carryOut s1 s0 :
fullAdder carryIn a0 b0 carry s0
fullAdder carry a1 b1 carryOut s1
# 4-bit Adder
def adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carryOut s3 s2 s1 s0 :
adder2 carryIn a1 a0 b1 b0 carry s1 s0
adder2 carry a3 a2 b3 b2 carryOut s3 s2
# 8-bit Adder
def adder8 carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carry s3 s2 s1 s0
adder4 carry a7 a6 a5 a4 b7 b6 b5 b4 carryOut s7 s6 s5 s4
# Konrad Zuse Dual-Rail-Carry Full Adder
def zuseFullAdder carryInNeg carryIn a b carryOutNeg carryOut sum :
r4 a carryInNeg y z sum w x 1 v y carryIn u v
r4 b carryOutNeg z y carryInNeg x w carryIn w x carryOut v u
# Konrad Zuse Dual-Rail-Carry 2-bit Adder
def zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
zuseFullAdder carryInNeg carryIn a0 b0 cOutNeg cOut s0
zuseFullAdder cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# Konrad Zuse Dual-Rail-Carry 4-bit Adder
def zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
zuseAdder2 cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# Konrad Zuse Dual-Rail-Carry 8-bit Adder
def zuseAdder8 carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0 cOutNeg cOut s3 s2 s1 s0
zuseAdder4 cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 1-bit Partial Adder/Subtractor
def xFullAdder subtract carryInNeg carryIn a b carryOutNeg carryOut sum :
xor subtract b bNeg
zuseFullAdder carryInNeg carryIn a bNeg carryOutNeg carryOut sum
# 2-bit Partial Adder/Subtractor
def xFullAdder2 subtract carryInNeg carryIn
a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
xFullAdder subtract carryInNeg carryIn a0 b0 cOutNeg cOut s0
xFullAdder subtract cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# 4-bit Partial Adder/Subtractor
def xFullAdder4 subtract carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
xFullAdder2 subtract carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
xFullAdder2 subtract cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# 8-bit Partial Adder/Subtractor
def xFullAdder8 subtract carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
xFullAdder4 subtract carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
cOutNeg cOut s3 s2 s1 s0
xFullAdder4 subtract cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 8-bit Adder/Subtractor
def adderSubtractor subtract
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
inv subtract carryInNeg
xFullAdder8 subtract carryInNeg subtract
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg cOut s7 s6 s5 s4 s3 s2 s1 s0
xor cOut subtract carryOut
# 2-to-1 Mux
def mux a i1 i0 o :
r a o i1 i0
# 4-to-1 Mux
def mux4to1 a1 a0 i3 i2 i1 i0 o :
mux a0 i1 i0 x
mux a0 i3 i2 y
mux a1 y x o
# 8-to-1 Mux
def mux8to1 a2 a1 a0 i7 i6 i5 i4 i3 i2 i1 i0 o :
mux4to1 a1 a0 i3 i2 i1 i0 x
mux4to1 a1 a0 i7 i6 i5 i4 y
mux a2 y x o
# 3-to-8 Decoder
def decoder3to8 a2 a1 a0 o7 o6 o5 o4 o3 o2 o1 o0 :
mux8to1 a2 a1 a0 o7 o6 o5 o4 o3 o2 o1 o0 1
def trans enabled a b :
r enabled a b 0
# 2-bit transmission gate
def trans2 enabled a1 a0 b1 b0 :
trans enabled a1 b1
trans enabled a0 b0
# 4-bit transmission gate
def trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0 :
trans2 enabled a3 a2 b3 b2
trans2 enabled a1 a0 b1 b0
# 8-bit transmission gate
def trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0 :
trans4 enabled a7 a6 a5 a4 b7 b6 b5 b4
trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0
# 16-bit transmission gate
def trans16 enabled
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 :
trans8 enabled a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
# Latch, stores when w = 1
def latch w d q :
mux w d q z
buf z q
# Latch, stores when w = 0
def latchNeg w d q :
mux w q d z
buf z q
# Flip flop, stores when w rises to 1, expresses new value when w drops to 0
def flipFlop w d q :
latch w d q2
latchNeg w q2 q
def flipFlopRegister w d7 d6 d5 d4 d3 d2 d1 d0 q7 q6 q5 q4 q3 q2 q1 q0:
flipFlop w d7 q7
flipFlop w d6 q6
flipFlop w d5 q5
flipFlop w d4 q4
flipFlop w d3 q3
flipFlop w d2 q2
flipFlop w d1 q1
flipFlop w d0 q0
def latchRegister w d7 d6 d5 d4 d3 d2 d1 d0 q7 q6 q5 q4 q3 q2 q1 q0:
latch w d7 q7
latch w d6 q6
latch w d5 q5
latch w d4 q4
latch w d3 q3
latch w d2 q2
latch w d1 q1
latch w d0 q0
def tinyLatchRegister writeNeg d7 d6 d5 d4 d3 d2 d1 d0 :
r d7 d7 writeNeg 0
r d6 d6 writeNeg 0
r d5 d5 writeNeg 0
r d4 d4 writeNeg 0
r d3 d3 writeNeg 0
r d2 d2 writeNeg 0
r d1 d1 writeNeg 0
r d0 d0 writeNeg 0
def memoryRegister select load d7 d6 d5 d4 d3 d2 d1 d0 :
inv load writeNeg
inv writeNeg select
trans8 select d7 d6 d5 d4 d3 d2 d1 d0 z7 z6 z5 z4 z3 z2 z1 z0
tinyLatchRegister writeNeg z7 z6 z5 z4 z3 z2 z1 z0
# 2 Bytes of memory
def memory2 address select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux address select1 select0 select
mux address load1 load0 load
memoryRegister select0 load0 d7 d6 d5 d4 d3 d2 d1 d0
memoryRegister select1 load1 d7 d6 d5 d4 d3 d2 d1 d0
# 4 Bytes of memory
def memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a1 select1 select0 select
mux a1 load1 load0 load
memory2 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory2 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 8 Bytes of memory
def memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a2 select1 select0 select
mux a2 load1 load0 load
memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 16 Bytes of memory
def memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a3 select1 select0 select
mux a3 load1 load0 load
memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 32 Bytes of memory
def memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a4 select1 select0 select
mux a4 load1 load0 load
memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 64 Bytes of memory
def memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a5 select1 select0 select
mux a5 load1 load0 load
memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 128 Bytes of memory
def memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a6 select1 select0 select
mux a6 load1 load0 load
memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 256 Bytes of memory
def memory256 a7 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a7 select1 select0 select
mux a7 load1 load0 load
memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
run 100 1 memory256 0 0 0 0 0 0 0 0 1 0 ? ? ? ? ? ? ? ?
+414
View File
@@ -0,0 +1,414 @@
# Four double-pole relay
def r4 coil l3 nd3 nc3 l2 nd2 nc2 l1 nd1 nc1 l0 nd0 nc0 :
r coil l3 nd3 nc3
r coil l2 nd2 nc2
r coil l1 nd1 nc1
r coil l0 nd0 nc0
# Buffer
def buf input output :
r input output 1 0
# Inverter
def inv input output :
r input output 0 1
# AND Gate
def and i1 i0 o :
r i0 z 1 0
r i1 o z 0
# NAND Gate
def nand i0 i1 o :
r i0 1 0 o
r i1 1 0 o
# OR Gate
def or i0 i1 o :
r i0 1 o 0
r i1 1 o 0
# NOR Gate
def nor i0 i1 o :
r i0 1 0 z
r i1 z 0 o
# XOR Gate
def xor i0 i1 o :
r i0 1 b a
r i1 o a b
# XNOR Gate
def xnor i0 i1 o :
r i0 1 a b
r i1 o a b
# Half Adder
def halfAdder a b s1 s0 :
and a b s1
xor a b s0
# Full Adder
def fullAdder carryIn a b carryOut sum :
halfAdder a b s1 s0
halfAdder s0 carryIn carry sum
or s1 carry carryOut
# 2-bit Adder
def adder2 carryIn a1 a0 b1 b0 carryOut s1 s0 :
fullAdder carryIn a0 b0 carry s0
fullAdder carry a1 b1 carryOut s1
# 4-bit Adder
def adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carryOut s3 s2 s1 s0 :
adder2 carryIn a1 a0 b1 b0 carry s1 s0
adder2 carry a3 a2 b3 b2 carryOut s3 s2
# 8-bit Adder
def adder8 carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carry s3 s2 s1 s0
adder4 carry a7 a6 a5 a4 b7 b6 b5 b4 carryOut s7 s6 s5 s4
# Konrad Zuse Dual-Rail-Carry Full Adder
def zuseFullAdder carryInNeg carryIn a b carryOutNeg carryOut sum :
r4 a carryInNeg y z sum w x 1 v y carryIn u v
r4 b carryOutNeg z y carryInNeg x w carryIn w x carryOut v u
# Konrad Zuse Dual-Rail-Carry 2-bit Adder
def zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
zuseFullAdder carryInNeg carryIn a0 b0 cOutNeg cOut s0
zuseFullAdder cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# Konrad Zuse Dual-Rail-Carry 4-bit Adder
def zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
zuseAdder2 cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# Konrad Zuse Dual-Rail-Carry 8-bit Adder
def zuseAdder8 carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0 cOutNeg cOut s3 s2 s1 s0
zuseAdder4 cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 1-bit Partial Adder/Subtractor
def xFullAdder subtract carryInNeg carryIn a b carryOutNeg carryOut sum :
xor subtract b bNeg
zuseFullAdder carryInNeg carryIn a bNeg carryOutNeg carryOut sum
# 2-bit Partial Adder/Subtractor
def xFullAdder2 subtract carryInNeg carryIn
a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
xFullAdder subtract carryInNeg carryIn a0 b0 cOutNeg cOut s0
xFullAdder subtract cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# 4-bit Partial Adder/Subtractor
def xFullAdder4 subtract carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
xFullAdder2 subtract carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
xFullAdder2 subtract cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# 8-bit Partial Adder/Subtractor
def xFullAdder8 subtract carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
xFullAdder4 subtract carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
cOutNeg cOut s3 s2 s1 s0
xFullAdder4 subtract cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 8-bit Adder/Subtractor
def adderSubtractor subtract
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
inv subtract carryInNeg
xFullAdder8 subtract carryInNeg subtract
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg cOut s7 s6 s5 s4 s3 s2 s1 s0
xor cOut subtract carryOut
# 2-to-1 Mux
def mux a i1 i0 o :
r a o i1 i0
# 4-to-1 Mux
def mux4to1 a1 a0 i3 i2 i1 i0 o :
mux a0 i1 i0 x
mux a0 i3 i2 y
mux a1 y x o
# 8-to-1 Mux
def mux8to1 a2 a1 a0 i7 i6 i5 i4 i3 i2 i1 i0 o :
mux4to1 a1 a0 i3 i2 i1 i0 x
mux4to1 a1 a0 i7 i6 i5 i4 y
mux a2 y x o
# 3-to-8 Decoder
def decoder3to8 a2 a1 a0 o7 o6 o5 o4 o3 o2 o1 o0 :
mux8to1 a2 a1 a0 o7 o6 o5 o4 o3 o2 o1 o0 1
def trans enabled a b :
r enabled a b 0
# 2-bit transmission gate
def trans2 enabled a1 a0 b1 b0 :
trans enabled a1 b1
trans enabled a0 b0
# 4-bit transmission gate
def trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0 :
trans2 enabled a3 a2 b3 b2
trans2 enabled a1 a0 b1 b0
# 8-bit transmission gate
def trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0 :
trans4 enabled a7 a6 a5 a4 b7 b6 b5 b4
trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0
# 16-bit transmission gate
def trans16 enabled
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 :
trans8 enabled a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
# Latch, stores when w = 1
def latch w d q :
mux w d q z
buf z q
# Latch, stores when w = 0
def latchNeg w d q :
mux w q d z
buf z q
# Flip flop, stores when w rises to 1, expresses new value when w drops to 0
def flipFlop w d q :
latch w d q2
latchNeg w q2 q
def flipFlopRegister w d7 d6 d5 d4 d3 d2 d1 d0 q7 q6 q5 q4 q3 q2 q1 q0:
flipFlop w d7 q7
flipFlop w d6 q6
flipFlop w d5 q5
flipFlop w d4 q4
flipFlop w d3 q3
flipFlop w d2 q2
flipFlop w d1 q1
flipFlop w d0 q0
def latchRegister w d7 d6 d5 d4 d3 d2 d1 d0 q7 q6 q5 q4 q3 q2 q1 q0:
latch w d7 q7
latch w d6 q6
latch w d5 q5
latch w d4 q4
latch w d3 q3
latch w d2 q2
latch w d1 q1
latch w d0 q0
def tinyLatchRegister writeNeg d7 d6 d5 d4 d3 d2 d1 d0 :
r d7 d7 writeNeg 0
r d6 d6 writeNeg 0
r d5 d5 writeNeg 0
r d4 d4 writeNeg 0
r d3 d3 writeNeg 0
r d2 d2 writeNeg 0
r d1 d1 writeNeg 0
r d0 d0 writeNeg 0
def memoryRegister select load d7 d6 d5 d4 d3 d2 d1 d0 :
inv load writeNeg
inv writeNeg select
trans8 select d7 d6 d5 d4 d3 d2 d1 d0 z7 z6 z5 z4 z3 z2 z1 z0
tinyLatchRegister writeNeg z7 z6 z5 z4 z3 z2 z1 z0
# 2 Bytes of memory
def memory2 address select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux address select1 select0 select
mux address load1 load0 load
memoryRegister select0 load0 d7 d6 d5 d4 d3 d2 d1 d0
memoryRegister select1 load1 d7 d6 d5 d4 d3 d2 d1 d0
# 4 Bytes of memory
def memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a1 select1 select0 select
mux a1 load1 load0 load
memory2 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory2 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 8 Bytes of memory
def memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a2 select1 select0 select
mux a2 load1 load0 load
memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 16 Bytes of memory
def memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a3 select1 select0 select
mux a3 load1 load0 load
memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 32 Bytes of memory
def memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a4 select1 select0 select
mux a4 load1 load0 load
memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 64 Bytes of memory
def memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a5 select1 select0 select
mux a5 load1 load0 load
memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 128 Bytes of memory
def memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a6 select1 select0 select
mux a6 load1 load0 load
memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 256 Bytes of memory
def memory256 a7 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a7 select1 select0 select
mux a7 load1 load0 load
memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
def counterElement andIn andOut value :
xor andIn value data
flipFlop c data value
and andIn value andOut
def counter2 andIn andOut v1 v0 :
counterElement andIn x v0
counterElement x andOut v1
def counter4 andIn andOut v3 v2 v1 v0 :
counter2 andIn x v1 v0
counter2 x andOut v3 v2
def counter8 andIn andOut v7 v6 v5 v4 v3 v2 v1 v0 :
counter4 andIn x v3 v2 v1 v0
counter4 x andOut v7 v6 v5 v4
def shift2 shiftIn q1 q0 :
flipFlop c shiftIn q1
flipFlop c q1 q0
def shift4 shiftIn q3 q2 q1 q0 :
shift2 shiftIn q3 q2
shift2 q2 q1 q0
def shift8 shiftIn q7 q6 q5 q4 q3 q2 q1 q0 :
shift4 shiftIn q7 q6 q5 q4
shift4 q4 q3 q2 q1 q0
def shiftOne q7 q6 q5 q4 q3 q2 q1 q0 :
flipFlop c 1 q
inv q shiftIn
shift8 shiftIn q7 q6 q5 q4 q3 q2 q1 q0
def loop q7 q6 q5 q4 q3 q2 q1 q0 :
flipFlop c 1 q
inv q shiftIn
shift8 shiftIn q7 q6 q5 q4 q3 q2 q1 q0
buf q0 shiftIn
# 1-bit adder
def mAdder add carryInNeg carryIn a b carryOutNeg carryOut sum :
trans add b s
zuseFullAdder carryInNeg carryIn a s carryOutNeg carryOut sum
# 2-bit adder
def mAdder2 add carryInNeg carryIn a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
mAdder add carryInNeg carryIn a0 b0 cOutNeg cOut s0
mAdder add cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# 4-bit adder
def mAdder4 add carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
mAdder2 add carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
mAdder2 add cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# 8-bit adder
def mAdder8 add
carryInNeg carryIn a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
mAdder4 add carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
cOutNeg cOut s3 s2 s1 s0
mAdder4 add cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 16-bit adder
def mAdder16 add
carryInNeg carryIn a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s15 s14 s13 s12 s11 s10 s9 s8 s7 s6 s5 s4 s3 s2 s1 s0 :
mAdder8 add carryInNeg carryIn a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
cOutNeg cOut s7 s6 s5 s4 s3 s2 s1 s0
mAdder8 add cOutNeg cOut
a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
carryOutNeg carryOut s15 s14 s13 s12 s11 s10 s9 s8
def multiplier
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0 :
mAdder16 b0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0
0 0 d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
mAdder16 b1 1 0
d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
0 0 0 0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0
0 0 e15 e14 e13 e12 e11 e10 e9 e8 e7 e6 e5 e4 e3 e2 e1 e0
mAdder16 b2 1 0
e15 e14 e13 e12 e11 e10 e9 e8 e7 e6 e5 e4 e3 e2 e1 e0
0 0 0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0
0 0 f15 f14 f13 f12 f11 f10 f9 f8 f7 f6 f5 f4 f3 f2 f1 f0
mAdder16 b3 1 0
f15 f14 f13 f12 f11 f10 f9 f8 f7 f6 f5 f4 f3 f2 f1 f0
0 0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0
0 0 g15 g14 g13 g12 g11 g10 g9 g8 g7 g6 g5 g4 g3 g2 g1 g0
mAdder16 b4 1 0
g15 g14 g13 g12 g11 g10 g9 g8 g7 g6 g5 g4 g3 g2 g1 g0
0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0 0
0 0 h15 h14 h13 h12 h11 h10 h9 h8 h7 h6 h5 h4 h3 h2 h1 h0
mAdder16 b5 1 0
h15 h14 h13 h12 h11 h10 h9 h8 h7 h6 h5 h4 h3 h2 h1 h0
0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0 0 0
0 0 i15 i14 i13 i12 i11 i10 i9 i8 i7 i6 i5 i4 i3 i2 i1 i0
mAdder16 b6 1 0
i15 i14 i13 i12 i11 i10 i9 i8 i7 i6 i5 i4 i3 i2 i1 i0
0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0 0 0 0
0 0 j15 j14 j13 j12 j11 j10 j9 j8 j7 j6 j5 j4 j3 j2 j1 j0
mAdder16 b7 1 0
j15 j14 j13 j12 j11 j10 j9 j8 j7 j6 j5 j4 j3 j2 j1 j0
0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0 0 0 0 0
0 0 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0
# 100 x 200 = 20,000
run 100 1 multiplier
0 1 1 0 0 1 0 0
1 1 0 0 1 0 0 0
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
+516
View File
@@ -0,0 +1,516 @@
# Four double-pole relay
def r4 coil l3 nd3 nc3 l2 nd2 nc2 l1 nd1 nc1 l0 nd0 nc0 :
r coil l3 nd3 nc3
r coil l2 nd2 nc2
r coil l1 nd1 nc1
r coil l0 nd0 nc0
# Buffer
def buf input output :
r input output 1 0
# Inverter
def inv input output :
r input output 0 1
# AND Gate
def and i1 i0 o :
r i0 z 1 0
r i1 o z 0
# NAND Gate
def nand i0 i1 o :
r i0 1 0 o
r i1 1 0 o
# OR Gate
def or i0 i1 o :
r i0 1 o 0
r i1 1 o 0
# NOR Gate
def nor i0 i1 o :
r i0 1 0 z
r i1 z 0 o
# XOR Gate
def xor i0 i1 o :
r i0 1 b a
r i1 o a b
# XNOR Gate
def xnor i0 i1 o :
r i0 1 a b
r i1 o a b
# Half Adder
def halfAdder a b s1 s0 :
and a b s1
xor a b s0
# Full Adder
def fullAdder carryIn a b carryOut sum :
halfAdder a b s1 s0
halfAdder s0 carryIn carry sum
or s1 carry carryOut
# 2-bit Adder
def adder2 carryIn a1 a0 b1 b0 carryOut s1 s0 :
fullAdder carryIn a0 b0 carry s0
fullAdder carry a1 b1 carryOut s1
# 4-bit Adder
def adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carryOut s3 s2 s1 s0 :
adder2 carryIn a1 a0 b1 b0 carry s1 s0
adder2 carry a3 a2 b3 b2 carryOut s3 s2
# 8-bit Adder
def adder8 carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carry s3 s2 s1 s0
adder4 carry a7 a6 a5 a4 b7 b6 b5 b4 carryOut s7 s6 s5 s4
# Konrad Zuse Dual-Rail-Carry Full Adder
def zuseFullAdder carryInNeg carryIn a b carryOutNeg carryOut sum :
r4 a carryInNeg y z sum w x 1 v y carryIn u v
r4 b carryOutNeg z y carryInNeg x w carryIn w x carryOut v u
# Konrad Zuse Dual-Rail-Carry 2-bit Adder
def zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
zuseFullAdder carryInNeg carryIn a0 b0 cOutNeg cOut s0
zuseFullAdder cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# Konrad Zuse Dual-Rail-Carry 4-bit Adder
def zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
zuseAdder2 cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# Konrad Zuse Dual-Rail-Carry 8-bit Adder
def zuseAdder8 carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0 cOutNeg cOut s3 s2 s1 s0
zuseAdder4 cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 1-bit Partial Adder/Subtractor
def xFullAdder subtract carryInNeg carryIn a b carryOutNeg carryOut sum :
xor subtract b bNeg
zuseFullAdder carryInNeg carryIn a bNeg carryOutNeg carryOut sum
# 2-bit Partial Adder/Subtractor
def xFullAdder2 subtract carryInNeg carryIn
a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
xFullAdder subtract carryInNeg carryIn a0 b0 cOutNeg cOut s0
xFullAdder subtract cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# 4-bit Partial Adder/Subtractor
def xFullAdder4 subtract carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
xFullAdder2 subtract carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
xFullAdder2 subtract cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# 8-bit Partial Adder/Subtractor
def xFullAdder8 subtract carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
xFullAdder4 subtract carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
cOutNeg cOut s3 s2 s1 s0
xFullAdder4 subtract cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 8-bit Adder/Subtractor
def adderSubtractor subtract
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
inv subtract carryInNeg
xFullAdder8 subtract carryInNeg subtract
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg cOut s7 s6 s5 s4 s3 s2 s1 s0
xor cOut subtract carryOut
# 2-to-1 Mux
def mux a i1 i0 o :
r a o i1 i0
# 4-to-1 Mux
def mux4to1 a1 a0 i3 i2 i1 i0 o :
mux a0 i1 i0 x
mux a0 i3 i2 y
mux a1 y x o
# 8-to-1 Mux
def mux8to1 a2 a1 a0 i7 i6 i5 i4 i3 i2 i1 i0 o :
mux4to1 a1 a0 i3 i2 i1 i0 x
mux4to1 a1 a0 i7 i6 i5 i4 y
mux a2 y x o
# 3-to-8 Decoder
def decoder3to8 a2 a1 a0 o7 o6 o5 o4 o3 o2 o1 o0 :
mux8to1 a2 a1 a0 o7 o6 o5 o4 o3 o2 o1 o0 1
def trans enabled a b :
r enabled a b 0
# 2-bit transmission gate
def trans2 enabled a1 a0 b1 b0 :
trans enabled a1 b1
trans enabled a0 b0
# 4-bit transmission gate
def trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0 :
trans2 enabled a3 a2 b3 b2
trans2 enabled a1 a0 b1 b0
# 8-bit transmission gate
def trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0 :
trans4 enabled a7 a6 a5 a4 b7 b6 b5 b4
trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0
# 16-bit transmission gate
def trans16 enabled
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 :
trans8 enabled a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
# Latch, stores when w = 1
def latch w d q :
mux w d q z
buf z q
# Latch, stores when w = 0
def latchNeg w d q :
mux w q d z
buf z q
# Flip flop, stores when w rises to 1, expresses new value when w drops to 0
def flipFlop w d q :
latch w d q2
latchNeg w q2 q
def flipFlopRegister w d7 d6 d5 d4 d3 d2 d1 d0 q7 q6 q5 q4 q3 q2 q1 q0:
flipFlop w d7 q7
flipFlop w d6 q6
flipFlop w d5 q5
flipFlop w d4 q4
flipFlop w d3 q3
flipFlop w d2 q2
flipFlop w d1 q1
flipFlop w d0 q0
def latchRegister w d7 d6 d5 d4 d3 d2 d1 d0 q7 q6 q5 q4 q3 q2 q1 q0:
latch w d7 q7
latch w d6 q6
latch w d5 q5
latch w d4 q4
latch w d3 q3
latch w d2 q2
latch w d1 q1
latch w d0 q0
def tinyLatchRegister writeNeg d7 d6 d5 d4 d3 d2 d1 d0 :
r d7 d7 writeNeg 0
r d6 d6 writeNeg 0
r d5 d5 writeNeg 0
r d4 d4 writeNeg 0
r d3 d3 writeNeg 0
r d2 d2 writeNeg 0
r d1 d1 writeNeg 0
r d0 d0 writeNeg 0
def memoryRegister select load d7 d6 d5 d4 d3 d2 d1 d0 :
inv load writeNeg
inv writeNeg select
trans8 select d7 d6 d5 d4 d3 d2 d1 d0 z7 z6 z5 z4 z3 z2 z1 z0
tinyLatchRegister writeNeg z7 z6 z5 z4 z3 z2 z1 z0
# 2 Bytes of memory
def memory2 address select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux address select1 select0 select
mux address load1 load0 load
memoryRegister select0 load0 d7 d6 d5 d4 d3 d2 d1 d0
memoryRegister select1 load1 d7 d6 d5 d4 d3 d2 d1 d0
# 4 Bytes of memory
def memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a1 select1 select0 select
mux a1 load1 load0 load
memory2 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory2 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 8 Bytes of memory
def memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a2 select1 select0 select
mux a2 load1 load0 load
memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 16 Bytes of memory
def memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a3 select1 select0 select
mux a3 load1 load0 load
memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 32 Bytes of memory
def memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a4 select1 select0 select
mux a4 load1 load0 load
memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 64 Bytes of memory
def memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a5 select1 select0 select
mux a5 load1 load0 load
memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 128 Bytes of memory
def memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a6 select1 select0 select
mux a6 load1 load0 load
memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 256 Bytes of memory
def memory256 a7 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a7 select1 select0 select
mux a7 load1 load0 load
memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
def counterElement andIn andOut value :
xor andIn value data
flipFlop c data value
and andIn value andOut
def counter2 andIn andOut v1 v0 :
counterElement andIn x v0
counterElement x andOut v1
def counter4 andIn andOut v3 v2 v1 v0 :
counter2 andIn x v1 v0
counter2 x andOut v3 v2
def counter8 andIn andOut v7 v6 v5 v4 v3 v2 v1 v0 :
counter4 andIn x v3 v2 v1 v0
counter4 x andOut v7 v6 v5 v4
def shift2 shiftIn q1 q0 :
flipFlop c shiftIn q1
flipFlop c q1 q0
def shift4 shiftIn q3 q2 q1 q0 :
shift2 shiftIn q3 q2
shift2 q2 q1 q0
def shift8 shiftIn q7 q6 q5 q4 q3 q2 q1 q0 :
shift4 shiftIn q7 q6 q5 q4
shift4 q4 q3 q2 q1 q0
def shiftOne q7 q6 q5 q4 q3 q2 q1 q0 :
flipFlop c 1 q
inv q shiftIn
shift8 shiftIn q7 q6 q5 q4 q3 q2 q1 q0
def loop q7 q6 q5 q4 q3 q2 q1 q0 :
flipFlop c 1 q
inv q shiftIn
shift8 shiftIn q7 q6 q5 q4 q3 q2 q1 q0
buf q0 shiftIn
# 1-bit adder
def mAdder add carryInNeg carryIn a b carryOutNeg carryOut sum :
trans add b s
zuseFullAdder carryInNeg carryIn a s carryOutNeg carryOut sum
# 2-bit adder
def mAdder2 add carryInNeg carryIn a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
mAdder add carryInNeg carryIn a0 b0 cOutNeg cOut s0
mAdder add cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# 4-bit adder
def mAdder4 add carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
mAdder2 add carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
mAdder2 add cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# 8-bit adder
def mAdder8 add
carryInNeg carryIn a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
mAdder4 add carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
cOutNeg cOut s3 s2 s1 s0
mAdder4 add cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 16-bit adder
def mAdder16 add
carryInNeg carryIn a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s15 s14 s13 s12 s11 s10 s9 s8 s7 s6 s5 s4 s3 s2 s1 s0 :
mAdder8 add carryInNeg carryIn a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
cOutNeg cOut s7 s6 s5 s4 s3 s2 s1 s0
mAdder8 add cOutNeg cOut
a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
carryOutNeg carryOut s15 s14 s13 s12 s11 s10 s9 s8
def multiplier
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0 :
mAdder16 b0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0
0 0 d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
mAdder16 b1 1 0
d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
0 0 0 0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0
0 0 e15 e14 e13 e12 e11 e10 e9 e8 e7 e6 e5 e4 e3 e2 e1 e0
mAdder16 b2 1 0
e15 e14 e13 e12 e11 e10 e9 e8 e7 e6 e5 e4 e3 e2 e1 e0
0 0 0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0
0 0 f15 f14 f13 f12 f11 f10 f9 f8 f7 f6 f5 f4 f3 f2 f1 f0
mAdder16 b3 1 0
f15 f14 f13 f12 f11 f10 f9 f8 f7 f6 f5 f4 f3 f2 f1 f0
0 0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0
0 0 g15 g14 g13 g12 g11 g10 g9 g8 g7 g6 g5 g4 g3 g2 g1 g0
mAdder16 b4 1 0
g15 g14 g13 g12 g11 g10 g9 g8 g7 g6 g5 g4 g3 g2 g1 g0
0 0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0 0
0 0 h15 h14 h13 h12 h11 h10 h9 h8 h7 h6 h5 h4 h3 h2 h1 h0
mAdder16 b5 1 0
h15 h14 h13 h12 h11 h10 h9 h8 h7 h6 h5 h4 h3 h2 h1 h0
0 0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0 0 0
0 0 i15 i14 i13 i12 i11 i10 i9 i8 i7 i6 i5 i4 i3 i2 i1 i0
mAdder16 b6 1 0
i15 i14 i13 i12 i11 i10 i9 i8 i7 i6 i5 i4 i3 i2 i1 i0
0 0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0 0 0 0
0 0 j15 j14 j13 j12 j11 j10 j9 j8 j7 j6 j5 j4 j3 j2 j1 j0
mAdder16 b7 1 0
j15 j14 j13 j12 j11 j10 j9 j8 j7 j6 j5 j4 j3 j2 j1 j0
0 a7 a6 a5 a4 a3 a2 a1 a0 0 0 0 0 0 0 0
0 0 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0
# 16-bit Partial Adder/Subtractor
def xFullAdder16 subtract carryInNeg carryIn
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s15 s14 s13 s12 s11 s10 s9 s8 s7 s6 s5 s4 s3 s2 s1 s0 :
xFullAdder8 subtract carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
cOutNeg cOut s7 s6 s5 s4 s3 s2 s1 s0
xFullAdder8 subtract cOutNeg cOut
a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
carryOutNeg carryOut s15 s14 s13 s12 s11 s10 s9 s8
# 16-bit Adder/Subtractor
def adderSubtractor16 subtract
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
carryOut s15 s14 s13 s12 s11 s10 s9 s8 s7 s6 s5 s4 s3 s2 s1 s0 :
inv subtract carryInNeg
xFullAdder16 subtract carryInNeg subtract
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg cOut s15 s14 s13 s12 s11 s10 s9 s8 s7 s6 s5 s4 s3 s2 s1 s0
xor cOut subtract carryOut
def signedMultiplier signed
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0 :
and signed a7 negateA
and signed b7 negateB
adderSubtractor negateA 0 0 0 0 0 0 0 0
a7 a6 a5 a4 a3 a2 a1 a0 0 c7 c6 c5 c4 c3 c2 c1 c0
adderSubtractor negateB 0 0 0 0 0 0 0 0
b7 b6 b5 b4 b3 b2 b1 b0 0 d7 d6 d5 d4 d3 d2 d1 d0
multiplier
c7 c6 c5 c4 c3 c2 c1 c0
d7 d6 d5 d4 d3 d2 d1 d0
q15 q14 q13 q12 q11 q10 q9 q8 q7 q6 q5 q4 q3 q2 q1 q0
xor a7 b7 negateProduct
and signed negateProduct negateQ
adderSubtractor16 negateQ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
q15 q14 q13 q12 q11 q10 q9 q8 q7 q6 q5 q4 q3 q2 q1 q0
0 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0
# 4-input OR gate
def or4 i3 i2 i1 i0 o :
or i3 i2 o
or i1 i0 o
# 8-input OR gate
def or8 i7 i6 i5 i4 i3 i2 i1 i0 o :
or4 i7 i6 i5 i4 o
or4 i3 i2 i1 i0 o
def multiplier2
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0 :
# 16-bit register made of flip flops
flipFlop c d15 p15
flipFlop c d14 p14
flipFlop c d13 p13
flipFlop c d12 p12
flipFlop c d11 p11
flipFlop c d10 p10
flipFlop c d9 p9
flipFlop c d8 p8
flipFlop c d7 p7
flipFlop c d6 p6
flipFlop c d5 p5
flipFlop c d4 p4
flipFlop c d3 p3
flipFlop c d2 p2
flipFlop c d1 p1
flipFlop c d0 p0
# Transmission gates and 8-bit adder
trans8 loadB d7 d6 d5 d4 d3 d2 d1 d0 b7 b6 b5 b4 b3 b2 b1 b0
trans8 p0 a7 a6 a5 a4 a3 a2 a1 a0 z7 z6 z5 z4 z3 z2 z1 z0
zuseAdder8 1 0 p15 p14 p13 p12 p11 p10 p9 p8 z7 z6 z5 z4 z3 z2 z1 z0
0 s8 s7 s6 s5 s4 s3 s2 s1 s0
trans16 tallyShift d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
s8 s7 s6 s5 s4 s3 s2 s1 s0 p7 p6 p5 p4 p3 p2 p1
trans16 keepValue d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0
# State machine
flipFlop c 1 boot
inv boot loadB
flipFlop c loadB state1
flipFlop c state1 state2
flipFlop c state2 state3
flipFlop c state3 state4
flipFlop c state4 state5
flipFlop c state5 state6
flipFlop c state6 state7
flipFlop c state7 state8
flipFlop c state8 keepValue
or8 state1 state2 state3 state4 state5 state6 state7 state8 tallyShift
buf keepValue keepValue
# 170 x 105 = 17850
run 1000 3 multiplier2
1 0 1 0 1 0 1 0
0 1 1 0 1 0 0 1
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
+1
View File
@@ -0,0 +1 @@
run 3 1 r 1 1 ? ?
+323
View File
@@ -0,0 +1,323 @@
# Four double-pole relay
def r4 coil l3 nd3 nc3 l2 nd2 nc2 l1 nd1 nc1 l0 nd0 nc0 :
r coil l3 nd3 nc3
r coil l2 nd2 nc2
r coil l1 nd1 nc1
r coil l0 nd0 nc0
# Buffer
def buf input output :
r input output 1 0
# Inverter
def inv input output :
r input output 0 1
# AND Gate
def and i1 i0 o :
r i0 z 1 0
r i1 o z 0
# NAND Gate
def nand i0 i1 o :
r i0 1 0 o
r i1 1 0 o
# OR Gate
def or i0 i1 o :
r i0 1 o 0
r i1 1 o 0
# NOR Gate
def nor i0 i1 o :
r i0 1 0 z
r i1 z 0 o
# XOR Gate
def xor i0 i1 o :
r i0 1 b a
r i1 o a b
# XNOR Gate
def xnor i0 i1 o :
r i0 1 a b
r i1 o a b
# Half Adder
def halfAdder a b s1 s0 :
and a b s1
xor a b s0
# Full Adder
def fullAdder carryIn a b carryOut sum :
halfAdder a b s1 s0
halfAdder s0 carryIn carry sum
or s1 carry carryOut
# 2-bit Adder
def adder2 carryIn a1 a0 b1 b0 carryOut s1 s0 :
fullAdder carryIn a0 b0 carry s0
fullAdder carry a1 b1 carryOut s1
# 4-bit Adder
def adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carryOut s3 s2 s1 s0 :
adder2 carryIn a1 a0 b1 b0 carry s1 s0
adder2 carry a3 a2 b3 b2 carryOut s3 s2
# 8-bit Adder
def adder8 carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carry s3 s2 s1 s0
adder4 carry a7 a6 a5 a4 b7 b6 b5 b4 carryOut s7 s6 s5 s4
# Konrad Zuse Dual-Rail-Carry Full Adder
def zuseFullAdder carryInNeg carryIn a b carryOutNeg carryOut sum :
r4 a carryInNeg y z sum w x 1 v y carryIn u v
r4 b carryOutNeg z y carryInNeg x w carryIn w x carryOut v u
# Konrad Zuse Dual-Rail-Carry 2-bit Adder
def zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
zuseFullAdder carryInNeg carryIn a0 b0 cOutNeg cOut s0
zuseFullAdder cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# Konrad Zuse Dual-Rail-Carry 4-bit Adder
def zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
zuseAdder2 cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# Konrad Zuse Dual-Rail-Carry 8-bit Adder
def zuseAdder8 carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0 cOutNeg cOut s3 s2 s1 s0
zuseAdder4 cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 1-bit Partial Adder/Subtractor
def xFullAdder subtract carryInNeg carryIn a b carryOutNeg carryOut sum :
xor subtract b bNeg
zuseFullAdder carryInNeg carryIn a bNeg carryOutNeg carryOut sum
# 2-bit Partial Adder/Subtractor
def xFullAdder2 subtract carryInNeg carryIn
a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
xFullAdder subtract carryInNeg carryIn a0 b0 cOutNeg cOut s0
xFullAdder subtract cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# 4-bit Partial Adder/Subtractor
def xFullAdder4 subtract carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
xFullAdder2 subtract carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
xFullAdder2 subtract cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# 8-bit Partial Adder/Subtractor
def xFullAdder8 subtract carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
xFullAdder4 subtract carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
cOutNeg cOut s3 s2 s1 s0
xFullAdder4 subtract cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 8-bit Adder/Subtractor
def adderSubtractor subtract
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
inv subtract carryInNeg
xFullAdder8 subtract carryInNeg subtract
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg cOut s7 s6 s5 s4 s3 s2 s1 s0
xor cOut subtract carryOut
# 2-to-1 Mux
def mux a i1 i0 o :
r a o i1 i0
# 4-to-1 Mux
def mux4to1 a1 a0 i3 i2 i1 i0 o :
mux a0 i1 i0 x
mux a0 i3 i2 y
mux a1 y x o
# 8-to-1 Mux
def mux8to1 a2 a1 a0 i7 i6 i5 i4 i3 i2 i1 i0 o :
mux4to1 a1 a0 i3 i2 i1 i0 x
mux4to1 a1 a0 i7 i6 i5 i4 y
mux a2 y x o
# 3-to-8 Decoder
def decoder3to8 a2 a1 a0 o7 o6 o5 o4 o3 o2 o1 o0 :
mux8to1 a2 a1 a0 o7 o6 o5 o4 o3 o2 o1 o0 1
def trans enabled a b :
r enabled a b 0
# 2-bit transmission gate
def trans2 enabled a1 a0 b1 b0 :
trans enabled a1 b1
trans enabled a0 b0
# 4-bit transmission gate
def trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0 :
trans2 enabled a3 a2 b3 b2
trans2 enabled a1 a0 b1 b0
# 8-bit transmission gate
def trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0 :
trans4 enabled a7 a6 a5 a4 b7 b6 b5 b4
trans4 enabled a3 a2 a1 a0 b3 b2 b1 b0
# 16-bit transmission gate
def trans16 enabled
a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0
b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 :
trans8 enabled a15 a14 a13 a12 a11 a10 a9 a8 b15 b14 b13 b12 b11 b10 b9 b8
trans8 enabled a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
# Latch, stores when w = 1
def latch w d q :
mux w d q z
buf z q
# Latch, stores when w = 0
def latchNeg w d q :
mux w q d z
buf z q
# Flip flop, stores when w rises to 1, expresses new value when w drops to 0
def flipFlop w d q :
latch w d q2
latchNeg w q2 q
def flipFlopRegister w d7 d6 d5 d4 d3 d2 d1 d0 q7 q6 q5 q4 q3 q2 q1 q0:
flipFlop w d7 q7
flipFlop w d6 q6
flipFlop w d5 q5
flipFlop w d4 q4
flipFlop w d3 q3
flipFlop w d2 q2
flipFlop w d1 q1
flipFlop w d0 q0
def latchRegister w d7 d6 d5 d4 d3 d2 d1 d0 q7 q6 q5 q4 q3 q2 q1 q0:
latch w d7 q7
latch w d6 q6
latch w d5 q5
latch w d4 q4
latch w d3 q3
latch w d2 q2
latch w d1 q1
latch w d0 q0
def tinyLatchRegister writeNeg d7 d6 d5 d4 d3 d2 d1 d0 :
r d7 d7 writeNeg 0
r d6 d6 writeNeg 0
r d5 d5 writeNeg 0
r d4 d4 writeNeg 0
r d3 d3 writeNeg 0
r d2 d2 writeNeg 0
r d1 d1 writeNeg 0
r d0 d0 writeNeg 0
def memoryRegister select load d7 d6 d5 d4 d3 d2 d1 d0 :
inv load writeNeg
inv writeNeg select
trans8 select d7 d6 d5 d4 d3 d2 d1 d0 z7 z6 z5 z4 z3 z2 z1 z0
tinyLatchRegister writeNeg z7 z6 z5 z4 z3 z2 z1 z0
# 2 Bytes of memory
def memory2 address select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux address select1 select0 select
mux address load1 load0 load
memoryRegister select0 load0 d7 d6 d5 d4 d3 d2 d1 d0
memoryRegister select1 load1 d7 d6 d5 d4 d3 d2 d1 d0
# 4 Bytes of memory
def memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a1 select1 select0 select
mux a1 load1 load0 load
memory2 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory2 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 8 Bytes of memory
def memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a2 select1 select0 select
mux a2 load1 load0 load
memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory4 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 16 Bytes of memory
def memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a3 select1 select0 select
mux a3 load1 load0 load
memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory8 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 32 Bytes of memory
def memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a4 select1 select0 select
mux a4 load1 load0 load
memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory16 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 64 Bytes of memory
def memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a5 select1 select0 select
mux a5 load1 load0 load
memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory32 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 128 Bytes of memory
def memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a6 select1 select0 select
mux a6 load1 load0 load
memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory64 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
# 256 Bytes of memory
def memory256 a7 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0 :
mux a7 select1 select0 select
mux a7 load1 load0 load
memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
memory128 a6 a5 a4 a3 a2 a1 a0 select load d7 d6 d5 d4 d3 d2 d1 d0
def counterElement andIn andOut value :
xor andIn value data
flipFlop c data value
and andIn value andOut
def counter2 andIn andOut v1 v0 :
counterElement andIn x v0
counterElement x andOut v1
def counter4 andIn andOut v3 v2 v1 v0 :
counter2 andIn x v1 v0
counter2 x andOut v3 v2
def counter8 andIn andOut v7 v6 v5 v4 v3 v2 v1 v0 :
counter4 andIn x v3 v2 v1 v0
counter4 x andOut v7 v6 v5 v4
def shift2 shiftIn q1 q0 :
flipFlop c shiftIn q1
flipFlop c q1 q0
def shift4 shiftIn q3 q2 q1 q0 :
shift2 shiftIn q3 q2
shift2 q2 q1 q0
def shift8 shiftIn q7 q6 q5 q4 q3 q2 q1 q0 :
shift4 shiftIn q7 q6 q5 q4
shift4 q4 q3 q2 q1 q0
run 100 5 shift8 1 ? ? ? ? ? ? ? ?
+106
View File
@@ -0,0 +1,106 @@
# Four double-pole relay
def r4 coil l3 nd3 nc3 l2 nd2 nc2 l1 nd1 nc1 l0 nd0 nc0 :
r coil l3 nd3 nc3
r coil l2 nd2 nc2
r coil l1 nd1 nc1
r coil l0 nd0 nc0
# Buffer
def buf input output :
r input output 1 0
# Inverter
def inv input output :
r input output 0 1
# AND Gate
def and i1 i0 o :
r i0 z 1 0
r i1 o z 0
# NAND Gate
def nand i0 i1 o :
r i0 1 0 o
r i1 1 0 o
# OR Gate
def or i0 i1 o :
r i0 1 o 0
r i1 1 o 0
# NOR Gate
def nor i0 i1 o :
r i0 1 0 z
r i1 z 0 o
# XOR Gate
def xor i0 i1 o :
r i0 1 b a
r i1 o a b
# XNOR Gate
def xnor i0 i1 o :
r i0 1 a b
r i1 o a b
# Half Adder
def halfAdder a b s1 s0 :
and a b s1
xor a b s0
# Full Adder
def fullAdder carryIn a b carryOut sum :
halfAdder a b s1 s0
halfAdder s0 carryIn carry sum
or s1 carry carryOut
# 2-bit Adder
def adder2 carryIn a1 a0 b1 b0 carryOut s1 s0 :
fullAdder carryIn a0 b0 carry s0
fullAdder carry a1 b1 carryOut s1
# 4-bit Adder
def adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carryOut s3 s2 s1 s0 :
adder2 carryIn a1 a0 b1 b0 carry s1 s0
adder2 carry a3 a2 b3 b2 carryOut s3 s2
# 8-bit Adder
def adder8 carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carry s3 s2 s1 s0
adder4 carry a7 a6 a5 a4 b7 b6 b5 b4 carryOut s7 s6 s5 s4
# Konrad Zuse Dual-Rail-Carry Full Adder
def zuseFullAdder carryInNeg carryIn a b carryOutNeg carryOut sum :
r4 a carryInNeg y z sum w x 1 v y carryIn u v
r4 b carryOutNeg z y carryInNeg x w carryIn w x carryOut v u
# Konrad Zuse Dual-Rail-Carry 2-bit Adder
def zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
zuseFullAdder carryInNeg carryIn a0 b0 cOutNeg cOut s0
zuseFullAdder cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# Konrad Zuse Dual-Rail-Carry 4-bit Adder
def zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
zuseAdder2 cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# Konrad Zuse Dual-Rail-Carry 8-bit Adder
def zuseAdder8 carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0 cOutNeg cOut s3 s2 s1 s0
zuseAdder4 cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 57 + 142 = ?
run 100 1 zuseAdder8 1 0
0 0 1 1 1 0 0 1
1 0 0 0 1 1 1 0
? ? ? ? ? ? ? ? ? ?
+105
View File
@@ -0,0 +1,105 @@
# Four double-pole relay
def r4 coil l3 nd3 nc3 l2 nd2 nc2 l1 nd1 nc1 l0 nd0 nc0 :
r coil l3 nd3 nc3
r coil l2 nd2 nc2
r coil l1 nd1 nc1
r coil l0 nd0 nc0
# Buffer
def buf input output :
r input output 1 0
# Inverter
def inv input output :
r input output 0 1
# AND Gate
def and i1 i0 o :
r i0 z 1 0
r i1 o z 0
# NAND Gate
def nand i0 i1 o :
r i0 1 0 o
r i1 1 0 o
# OR Gate
def or i0 i1 o :
r i0 1 o 0
r i1 1 o 0
# NOR Gate
def nor i0 i1 o :
r i0 1 0 z
r i1 z 0 o
# XOR Gate
def xor i0 i1 o :
r i0 1 b a
r i1 o a b
# XNOR Gate
def xnor i0 i1 o :
r i0 1 a b
r i1 o a b
# Half Adder
def halfAdder a b s1 s0 :
and a b s1
xor a b s0
# Full Adder
def fullAdder carryIn a b carryOut sum :
halfAdder a b s1 s0
halfAdder s0 carryIn carry sum
or s1 carry carryOut
# 2-bit Adder
def adder2 carryIn a1 a0 b1 b0 carryOut s1 s0 :
fullAdder carryIn a0 b0 carry s0
fullAdder carry a1 b1 carryOut s1
# 4-bit Adder
def adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carryOut s3 s2 s1 s0 :
adder2 carryIn a1 a0 b1 b0 carry s1 s0
adder2 carry a3 a2 b3 b2 carryOut s3 s2
# 8-bit Adder
def adder8 carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
adder4 carryIn a3 a2 a1 a0 b3 b2 b1 b0 carry s3 s2 s1 s0
adder4 carry a7 a6 a5 a4 b7 b6 b5 b4 carryOut s7 s6 s5 s4
# Konrad Zuse Dual-Rail-Carry Full Adder
def zuseFullAdder carryInNeg carryIn a b carryOutNeg carryOut sum :
r4 a carryInNeg y z sum w x 1 v y carryIn u v
r4 b carryOutNeg z y carryInNeg x w carryIn w x carryOut v u
# Konrad Zuse Dual-Rail-Carry 2-bit Adder
def zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 carryOutNeg carryOut s1 s0 :
zuseFullAdder carryInNeg carryIn a0 b0 cOutNeg cOut s0
zuseFullAdder cOutNeg cOut a1 b1 carryOutNeg carryOut s1
# Konrad Zuse Dual-Rail-Carry 4-bit Adder
def zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0
carryOutNeg carryOut s3 s2 s1 s0 :
zuseAdder2 carryInNeg carryIn a1 a0 b1 b0 cOutNeg cOut s1 s0
zuseAdder2 cOutNeg cOut a3 a2 b3 b2 carryOutNeg carryOut s3 s2
# Konrad Zuse Dual-Rail-Carry 8-bit Adder
def zuseAdder8 carryInNeg carryIn
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 b5 b4 b3 b2 b1 b0
carryOutNeg carryOut s7 s6 s5 s4 s3 s2 s1 s0 :
zuseAdder4 carryInNeg carryIn a3 a2 a1 a0 b3 b2 b1 b0 cOutNeg cOut s3 s2 s1 s0
zuseAdder4 cOutNeg cOut a7 a6 a5 a4 b7 b6 b5 b4
carryOutNeg carryOut s7 s6 s5 s4
# 255 + 1 = ?
run 100 1 zuseAdder8 1 0
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 1
? ? ? ? ? ? ? ? ? ?
+31
View File
@@ -0,0 +1,31 @@
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# data files for this entry
#
DATA=
build: ${ENTRY}
clean:
-${RM} ${ENTRY}
clobber: clean
alt:
data:
${ENTRY}: ${ENTRY}.c ${DATA}
${CC} ${CFLAGS} ${ENTRY}.c -o ${ENTRY}
+75
View File
@@ -0,0 +1,75 @@
#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#undef D
#undef E
#undef U
#ifndef C
#define I int n,r;
#define D(N) void*N(void*);
#define C pthread_create
#define E int l;char *ak(char *u){return (*u=(l+=6,*u)=\
='@'?'K':*u=='.'?'P':*u=='-'?'M':tolower(*u))?ak(u+1)-1:u;}
#define U int
#elif ! defined J
#define H "x\0\b\0\200\1\0\0\0\0\377\377\377,\0\0\0\0x\0\b\0\0\3"
#define E tn; char h[30]="GIF87a" H;void *(*fn[25])(void*)={
#define U };
#define D(N) N,
#define L return fwrite("\1\t\0;",1,4,stdout)!=4;
#define K {I for(r=0;r<8;r++)for(n=0,putchar(l);n<l;n++)putchar(B[r][n]|8)
#define J h[6]=h[24]=l=l-3;fwrite(h,1,30,stdout);K
#else
#define T pthread_t
#define E char B[8][256];
#define U int main(int c,char **a) { bdefhklmnprtuvwxyz57(ak(a[1]));J;}L}
#define D(N) void *N(void *y) {\
static I char *x=y;\
T t=0;\
if(!n && (r=tn)<24) C(&t,NULL,fn[++tn],y);\
if(*x&&strchr(# N,*x)) B[2+r/5][2+n*6+r%5]=16;\
n++;\
if(*x) N(x+1);\
if(t) pthread_join(t,&y);\
return y;\
}
#endif
E
D(bdefhklmnprtuvwxyz57)
D(bcdefgiopqrstz23567890K)
D(abcdefgjopqrstz123567890K)
D(cefghkoqstz23457890K)
D(mntuvwxyz7)
D(bcdefghklmnopqrsuvw256890K)
D(aimnxy1)
D(jkt14)
D(abdhmprxyz0)
D(mnoquvw237890K)
D(abcdefghklmnopqruvw560K)
D(befhikprs45689MK)
D(befghjmnqprstwxyz156890MK)
D(dghs234789M)
D(amnoquvw90K)
D(abcdefghjklmnopqruw4680K)
D(aivxz40PK)
D(ajkrtwy1247PK)
D(abdghnqvx456K)
D(amnosuw34890K)
D(abdefhklmnprxz25_)
D(bcdegijloqsuwz12356890_PK)
D(bcdegloqstuvyz123567890_PK)
D(cehklorsuwz1234890_K)
D(amnqxz2_K)
U
#ifndef T
#include __FILE__
#endif
+91
View File
@@ -0,0 +1,91 @@
# Most Useful
Szabolcs Borsanyi
Department of Physics and Astronomy
University of Sussex
Brighton
East Sussex BN1 9QH
United Kingdom
s.borsanyi at sussex dot ac dot uk
## Judges' comments:
### To build:
make borsanyi
### To run:
./borsanyi ioccc@example.com > example.gif
This entry uses a very user-friendly representation of the font
it uses (with a few exceptions). Check out the source and see
yourself! :-)
The resulting GIF file is likely to puzzle optical character
recognition tools. The amount ofimagination necessary to
recognise the @ character will certainly challenge a few
anti-CAPTCHA tools.
## Author's comments:
Email address to gif converter
==============================
Introduction:
-------------
Most spam robots collect email addresses from the web sites of
innocent people, like you. Conference organizers cannot disclose
the participant's address to prevent malicious users from
grabbing them. One solution is to write as my_email _at_ address
_dot_ com. But robots are clever enough to sort that out. A
more sophisticated approach is to create an image file with the
email address and put that on the web page.
This program creates a GIF image file from the address given
in the command line. To avoid complications with patent issues
the LZW compression feature is not used. A typical email address
is stored in less than 1-2 kilobytes.
Usage:
------
$ gcc email.c -lpthread -o email
$ ./email my@email.address.com > email.gif
$ my_favourite_gif_viewer email.gif
The address cannot be longer than 42 characters, and may consist of
the characters: a-z_A-Z0-9@.-
The program is (like email addresses are) case insensitive.
Obfuscation:
------------
Multicore support is a must in present-day applications. This
entry supports up to 25 cores. The odd names in the bottom
part of the program do have a meaning, they are not there just
for obfuscation. The preprocessor is used to keep the program
small, in fact, everything is a macro. Are you familiar with
the GIF format? Studying this program will give you a (very
little) insight.
Questions:
----------
After analyzing the source code, try to answer these questions:
1. How can you add a further supported symbol?
2. Can you alter the look of the output characters?
3. What limits the number of input characters to 42?
Portability:
------------
The program uses posix threads (using the linker flag -lpthread).
The program accepts email addresses not longer than 42 bytes
composed from letters, digits, and the @._- symbols. An address
not obeying these rules will cause undefined behaviour. The
program is not expected to depend on endianness. The standard
output is used for a binary output, which might cause problems.
To avoid most caveats, the program does not output the octet
0x0a. The program assumes the use of ASCII.
+35
View File
@@ -0,0 +1,35 @@
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# Special flags for this entry
#
LOCAL_FLAGS= -I${X11_INCDIR} -L${X11_LIBDIR} -lX11 ${OPT}
# Data files for this entry
#
DATA= arabian.txt olympic.txt twinkle.txt test.txt
build: ${ENTRY}
clean:
-${RM} ${ENTRY}
clobber: clean
alt:
data:
${ENTRY}: ${ENTRY}.c ${DATA}
${CC} ${CFLAGS} ${LOCAL_FLAGS} ${ENTRY}.c -o ${ENTRY}
+1
View File
@@ -0,0 +1 @@
453,54,4569564459,9#95458,8987453 54
+43
View File
@@ -0,0 +1,43 @@
#include<stdio.h>
#include<X11/Xlib.h>
#include<stdlib.h>
#include<sys/time.h>
#include<time.h>
#include<string.h>
static
Display
*b;static
Window d; static GC e;
static int f,g,i;static
double j,k;static void l
(int m){int _=00,__,x;double
y,_x;y=m/j*02.0;_x=k/j*02.0;(void)
XSetForeground(b,e,BlackPixel(b,DefaultScreen
(b)));(void)XFillRectangle(b,d,e,00,00,(unsigned
int)g,(unsigned int)f);if(m==00){for(__=0x0;__<g;__++)
for(x=0;x<f;)(void)XDrawPoint(b,d,e,__,x),x++;return;}(void)XSetForeground
(b,e,WhitePixel(b,DefaultScreen(b)));for(x=00;x<f;x++){__=0x0;if(((int)
(_*y)%2)==0)for(;__<g;__++){if(((int)(_*_x)%2)==1)(void)XDrawPoint(b,
d,e,__,x);_++;}_+=i-__;}}int main(int __x,char* ___[]){if(__x!=4)
fprintf(stderr,"usage:%spixelclockcarrier_freqhorizontal_total"
"\n",___[00]),exit(EXIT_FAILURE);j=atof(___[1]),k=atof(
___[(1+1)]),i=atoi(___[(1+1+1)]),b=XOpenDisplay("");
if(!b)exit(EXIT_FAILURE);{XSetWindowAttributes X;
X.event_mask=ExposureMask|ButtonPressMask,
X.override_redirect=True,
g=WidthOfScreen(ScreenOfDisplay
(b,DefaultScreen(b))),f=HeightOfScreen
(ScreenOfDisplay(b,DefaultScreen(b))),d
=XCreateWindow(b,RootWindow(b,DefaultScreen(b)),
00,00,(unsigned int)g,(unsigned int)f,00,CopyFromParent,
InputOutput,(Visual*)CopyFromParent,(unsigned long int)CWOverrideRedirect
|CWEventMask,&X);}(void)XMapWindow(b,d),(void)XRaiseWindow(b,d),e=
XCreateGC(b,d,0,0);{static int _X_[0377];int _x_;_X_[061]=948,
_X_[0x32]=01763,_X_[043]=0x4b9,52[_X_]=0x3dd,_X_[063]=1082,
_X_[0x36]=02143,_X_[42]=02063,_X_[070]=1094,065[_X_]=0x41d,
_X_[48]=02162,_X_[0x39]=02214,55[_X_]=0x406;while((_x_=
getchar())!=EOF){l(_X_[_x_]);{static struct timespec
_l;_l.tv_nsec=03563262400,nanosleep(&_l,00);}}}
(void)XDestroyWindow(b,d),(void)XCloseDisplay
(b),exit(EXIT_SUCCESS);}
+107
View File
@@ -0,0 +1,107 @@
# Most Obfuscaed Audio
Aaron Grothe
2205 South 51st Street
Omaha, NE 68106
US
## Judges' Comments:
### To build:
make grothe
### To run:
./grothe 65000000 10000000 1344 < twinkle.txt
... and then put on your "electronic ears". You may find using
a tunable scanning electronic ear helps.
Most of the time, interference is annoying. This entry is the
exception that proves the rule. What is a bug to some is a
feature to this entry. :-)
## Selected Author's Comments:
The program draws patterns on the screen that can be picked up by a
shortwave radio. It emulates the frequencies for an old fashion touch
tone phone, so old songs can be played by hitting 0-9,#, and *.
To be able to run the program you need to determine the following
parameters
carrier_freq - base frequency used to host music
pixelclock - refresh rate of the monitor
horizontal_total - total scan along the horizontal axis
If you have xvidtune installed you can get the pixelclock and
horizontal total with the following command
xvidtune -show | head -n 1 |
awk '{ print "pixelclock " $2 * 1000000 " horizontal_total = " $6 }'
example from my laptops
./grothe 65000000 10000000 1344 < twinkle.txt
Even if the user gets a setting off, the sound will usually be able to be
heard on AM at a multiple of the original frequency
The core idea of using a machine to play music on AM radio goes all the
way back to the Altair computers and Timex Sinclair ZX-81s.
### Several example songs
Olympic Fanfare - from antang@phakt.usc.edu - Tony
4-9-91231,2222-321123123-9-91231,2222-32112321
Twinkle Twinkle Little Star - from fsufunkyb@aol.com - Ben Schmidt
1199##9-6633221-9966332-9966332-1199#9-6633221-
Generic Arabian Tune - from rdippold@qualcomm.com -Ron "Asbestos" Dippold
453,54,4569564459,9#95458,8987453 54
Others can be found by doing a search for "touch tone phone songs".
### Obfuscations
- Some numbers expressed in Octal, some in hex and some in decimal
"A foolish consistency is the hobgoblin of little minds" -
Ralph Waldo Emerson
- Funky scoping, looking at the nanosleep section and
XsetWindowAttributes declares local variables
- Algorithm is very weird, uses y dimension to draw carrier frequency
and x dimension to draw audio frequency, based on Erik Thiele's
Tempest for Eliza
- lack of #defines confuses many people :-)
- figuring out your pixelclock and horizontal total and which carrier
frequency to use can be an exercise in obfuscation for the user
- use of commas in various places, confuses most c code beautifiers
sometimes making the beautified code harder to read
- use of static to ensure initilization is EVIL and done in several
places
- uses static declarations & voids function returns we don't care about
making the code harder to read
- does sound using only X11 libs, no other libs required
- demonstrates tempest emissions in a fun/easy way
- follows good programming practices of actually setting exit codes and
giving usage when run with incorrect parameters
### References
Tempest for Eliza - Basis for Algorithms
> <http://www.erikyyy.de/tempest/>
Tempest AM - Another early program in this field
> <http://silcnet.org/priikone/programs.php?lang=en>
Paper by Markus G. Kuhn's and Ross J. Anderson's,
"Soft Tempest: Hidden Data Transmission Using Electromagnetic Emanations"
> <http://www.cl.cam.ac.uk/~mgk25/ih98-tempest.pdf>
+1
View File
@@ -0,0 +1 @@
3-9-91231,2222-321123123-9-91231,2222-32112321
+1
View File
@@ -0,0 +1 @@
123456789#0*123456789#0*123456789#0*123456789#0*
+1
View File
@@ -0,0 +1 @@
1199##9-6633221-9966332-9966332-1199#9-6633221-
+558
View File
@@ -0,0 +1,558 @@
19th International Obfuscated C Code Contest Guidelines, Hints and Comments
Copyright (C) 2006 Leonid A. Broukhis, Simon Cooper, Landon Curt Noll and
Peter Seebach.
All Rights Reserved. Permission for personal, education or non-profit use is
granted provided this this copyright and notice are included in its entirety
and remains unaltered. All other uses must receive prior permission in
writing from the contest judges.
ABOUT THIS FILE:
This file contains guidelines intended to help people who wish to
submit entries to the International Obfuscated C Code Contest (IOCCC
for short).
This is not the IOCCC rules, though it does contain comments about
them. The guidelines should be viewed as hints and suggestions.
Entries that violate the guidelines but remain within the rules are
allowed. Even so, you are safer if you remain within the guidelines.
You should read the current IOCCC rules, prior to submitting entries.
The rules are typically sent out with these guidelines.
| WHAT'S NEW IN 2006:
| The contest runs from 31-Dec-2006 23:59 UTC to 28-Feb-2007 23:59 UTC.
| Only online submissions will be accepted this year.
See the following for details,
| http://www.ioccc.org/2006/submit
| Most of the changes in the rules and guidelines for this year have been
| marked with a "|" character on the left hand side.
HINTS AND SUGGESTIONS:
You are encouraged to examine the winners of previous contests. See
FOR MORE INFORMATION for details on how to get previous winners.
Keep in mind that rules change from year to year, so some winning entries
may not be valid entries this year. What was unique and novel one year
might be 'old' the next year.
An entry is usually examined in a number of ways. We typically apply
a number of tests to an entry:
* look at the original source
* convert ANSI tri-graphs to ASCII
* C pre-process the source ignoring '#include' lines
* C pre-process the source ignoring '#define' and '#include' lines
* run it through a C beautifier
* examine the algorithm
* compile it (with flags to enable all warnings)
* execute it
You should consider how your entry looks in each of the above tests.
You should ask yourself if your entry remains obscure after it has been
'cleaned up' by the C pre-processor and a C beautifier.
Your entry need not pass all of the above tests. In certain
cases, a test is not important. Entries that compete for the
'strangest/most creative source layout' need not do as well as
others in terms of their algorithm. On the other hand, given
two such entries, we are more inclined to pick the entry that
does something interesting when you run it.
We try to avoid limiting creativity in our rules. As such, we leave
the contest open for creative rule interpretation. As in real life
programming, interpreting a requirements document or a customer request
is important. For this reason, we often award 'worst abuse of the
rules' to an entry that illustrates this point in an ironic way.
We do realize that there are holes in the rules, and invite entries
to attempt to exploit them. We will award 'worst abuse of the rules'
and then plug the hole next year. Even so, we will attempt to use
the smallest plug needed, if not smaller. :-)
Check out your program and be sure that it works. We sometimes make
the effort to debug an entry that has a slight problem, particularly
in or near the final round. On the other hand, we have seen some
of the best entries fall down because they didn't work.
We tend to look down on a prime number printer, that claims that
16 is a prime number. If you do have a bug, you are better off
documenting it. Noting "this entry sometimes prints the 4th power
of a prime by mistake" would save the above entry. And sometimes,
a strange bug/feature can even help the entry! Of course, a correctly
working entry is best.
People who are considering to just use some complex mathematical
function or state machine to spell out something such as "hello,
world!" may want to try and be more creative.
Ultra-obfuscated programs are in some cases some cases easier to
deobfuscate than subtly-obfuscated programs. Consider using
misleading or subtle tricks layered on top of or under an
appropriate level of obfuscation.
Programs that use VTxxx/ANSI sequences that are NOT limited to a
specific terminal brand and that can also work in a standard xterm
are considered portable.
OUR LIKES AND DISLIKES:
Doing masses of #defines to obscure the source has become 'old'. We
tend to 'see thru' masses of #defines due to our pre-processor tests
that we apply. Simply abusing #defines or -Dfoo=bar won't go as far
as a program that is more well rounded in confusion.
Many ANSI C compilers dislike the following code, and so do we:
#define d define
#d foo <-- don't expect this to turn into #define foo
When declaring local or global variables, you should declare the type:
int this_is_ok;
this_is_not; <-- don't use such implicit type declarations
We suggest that you compile your entry with an ANSI C compiler. If you
must use non-ANSI C, such as K&R C, you must avoid areas that result in
compile/link errors for ANSI C compilers. For example, using gcc
local function declarations, such as:
int
main() {
void blah() { printf("blah\n"); }
blah();
}
are not allowed even though their existence seems tailor made for
this contest! But for now, since they are not in wide spread use
we cannot accept entries that use them.
If your entry uses functions that have a variable number of
arguments, be careful. Systems implement va_list as a wide variety
of ways. Because of this, a number of operations using va_list are
not portable and must not be used:
* assigning a non-va_list variable to/from a va_list variable
* casting a non-va_list variable into/from a va_list variable
* passing a va_list variable to a function expecting a non-va_list arg
* passing a non-va_list variable to a function expecting a va_list arg
* performing arithmetic on va_list variables
* using va_list as a structure or union
In particular, do not treat va_list variables as if they were a char **'s.
Avoid using <varargs.h>. Use <stdarg.h> instead.
| On 28 January 2007, the Judges recinded the following guidline regarding
| "whitespace" before a preprocessor directive.
| If you use C preprocessor directives (#define, #if, #ifdef, ...),
| the leading '#' must be the first non-whitespace character on a line.
| While some broken C preprocessors do not allow whitespace before a
| '#', most do.
The exit() function returns void. On some broken systems have exit()
return int. Your entry should assume that exit() returns a void.
Small programs are best when they are short, obscure and concise.
While such programs are not as complex as other winners, they do
serve a useful purpose. They are often the only program that people
attempt to completely understand. For this reason, we look for
programs that are compact, and are instructional.
One line programs should be short one line programs, say around 80
bytes long. Getting close to 160 bytes is a bit too long in our opinion.
We tend to dislike programs that:
* are very hardware specific
* are very OS version specific
(index/strchr differences are ok, but socket/streams specific
code is likely not to be)
* dump core or have compiler warnings
(it is ok only if you warn us in the 'remark' header item)
* won't compile or run under a POSIX P1003.1/P1003.2 like systems
* depend on a utility or application not normally found on most
most POSIX P1003.1/P1003.2 like systems
* abuse the build file to get around the size limit
* obfuscate by excessive use of ANSI tri-graphs
* are longer than they need to be
* are similar to previous winners
* are identical to previous losers :-)
Unless you are cramped for space, or unless you are entering the
'best one liner' category, we suggest that you format your program
in a more creative way than simply forming excessively long lines.
The build file should not be used to try and get around the size
limit. It is one thing to make use of a several -D's to help out,
but it is quite another to use 200+ bytes of -D's in order to
try and squeeze the source under the size limit. You should feel
free to make use of the build file space, but you are better off
if you show some amount of restraint.
You should try to restrict commands used on the build file to
POSIX-like or common Un*x-like commands. You can also compile
and use your own programs. If you do, try to build and execute
from the current directory. This restriction is not a hard and
absolute one. The intent is to ensure that the building if your
program is reasonably portable.
Don't forget that the building of your program should be done
***without human intervention***. So don't do:
cat > prog.c
cc prog.c -o prog
However, you can do something cute such as making your program
do something dumb (or cute) when build 'automatically'. However
when it is run with a human involved, do something more clever.
For example, one could use the build instructions:
cc prog.c -DNONHUMAN -o prog
echo "See remarks section about alternate ways to compile"
and then include special notes in the program "remarks" for
alternate / human intervention based building.
We want to get away from source that is simply a compact blob of
characters. To help, we give a break to source that contains
whitespace, and in certain cases ; { or } characters. While the
number of characters excluding whitespace (tab, space, newline),
and excluding any ; { or } followed immediately by either whitespace
or end of file, must be <= 2048, the total size may be less than 4096
bytes. This means that one may use "free of charge" up to 2048
bytes of whitespace, or ; { or } followed by either whitespace
or end of file.
Please do not use things like gzip to get around the size limit.
Given two versions of the same program, one that is a compact blob
of code, and the other that is formatted more like a typical C
program, we tend to favor the second version. Of course, a third
version of the same program that is formatted in an interesting
and/or obfuscated way, would definitely win over the first two!
We suggest that you avoid trying for the 'smallest self-replicating'
source. The smallest, a zero byte entry, won in 1994.
We do not like writable strings. That is, we don't want stuff like:
char *T = "So many primes, so little time!";
...
T[14] = ';';
Please don't make use of this feature, even if your system allows it.
However, initialized char arrays are OK to write over. This is OK:
char b[] = "Is this Ok";
b[9] = 'K';
X client entries should be as portable as possible. Entries that
adapt to a wide collection of environments will be favored. Don't
depend on a particular type of display. For example, don't depend
on color or a given size. Don't require backing store.
X client entries should avoid using X related libraries and
software that is not in wide spread use.
We don't like entries that use proprietary M*tif, Xv*ew, or OpenL*ok
toolkits, since not everyone has them. Use of OpenMotif is permitted
because it is more widely and freely available.
You should avoid depending on a particular window manager.
X client entries should not to depend on particular items on
.Xdefaults. If you must do so, be sure to note the required lines
in the program "remarks".
While we recognize that UN*X is not a universal operating system, the
contest does have a bias towards such systems. In an effort to expand
the scope of the contest, we phrase our bias in terms of POSIX P1003.1
and P1003.2 standards. This will allow certain non-UN*X OS users to
submit entries. On the other hand, this is a guideline and not a rule.
We will not reject an entry based on some POSIX technicality.
When dealing with OS and application environments, we suggest that you
be reasonable with a nod towards vanilla UN*X-like systems. POSIX will
evolve but not as much as the contest, so avoid stuff like POSIX real
time, security, etc.
We like programs that:
* are as concise and small as they need to be
* do something at least quasi-interesting
* are portable
* are unique or novel in their obfuscation style
* MAKE USE OF A NUMBER OF DIFFERENT TYPES OF OBFUSCATION <== HINT!!
* make us laugh and/or throw up :-) (humor helps!)
Some types of programs can't excel (tm) in some areas. Of course, your
program doesn't have to excel in all areas, but doing well in several
areas really does help.
You are better off explaining what your entry does in the program
"remarks" section rather than leaving it obscure for the judges
as we might miss something and/or be too tired to notice.
We freely admit that interesting, creative or humorous comments in
the program "remarks" help your chances of winning. If you had to
read so many twisted entries, you too would enjoy a good laugh or two.
We think the readers of the contest winners do as well. We do read
the program "remarks" during the judging process, so it is worth your
while to write remarkable program "remarks".
We dislike C code with trailing control-M's (\r or \015) that results
in compilation failures. Some non-Un*x/non-Linux tools such as
MS Visual C and MS Visual C++ leave trailing control-M's on lines.
Users of such tools should strip off such control-M's before submitting
their entries. In some cases tools have a "Save As" option that will
prevent such trailing control-M's being added.
We dislike entries that depend on non-portable libcurses features such
as halfdelay(). One should restrict libcurses to portable features
found on BSD and SVR4/System V curses.
The rules disallow source that contains unescaped octets with values
between 128 and 255. You must use \octal or \hex escapes instead:
/* 123456789 123456789 123456789 123456 */
char *foo = "This string is 36 octets in length \263";
/* This octet requires 4 octets of source ^^^^ */
if (strlen(foo) == 36) printf("foo is 36 octets a final NUL\n");
Be creative!
ABUSING THE RULES:
Legal abuse of the rules is somewhat encouraged. Legal rule abuse may
involve, but is not limited to, doing things that are technically
allowed by the rules and yet do not fit the spirit of what we intended
to be submitted.
Legal rule abuse is encouraged to help promote creativity. Rule abuse
entries, regardless of if they receive an award, result in changes to
the next year's rules and guidelines.
Legal abuse of the rules is NOT an invitation to violate the rules.
An entry that violates the rules in the opinion of the judges, WILL be
disqualified. RULE ABUSE CARRIES A CERTAIN LEVEL OF RISK! If you
have an entry that might otherwise be interesting, you might want to
submit two versions; one that does not abuse the rules and one that
does.
If you intend to abuse the rules, indicate so in the program
"remarks". You must try to justify why you consider your rule abuse
to be allowed under the rules. That is, you must plead your case as
to why your entry is valid. Humor and/or creativity help plead a
case.
| Abusing the web submission procedure tends to annoy us more
| than amuse us. Spend your creative energy on content of your
| entry rather than on the submission process itself.
We are often asked why the contest rules and guidelines seem too
strange or contain mistakes, flaws or grammatical errors. One reason
is that we sometimes make genuine mistakes. But in many cases such
problems, flaws or areas of confusion are deliberate. Changes to
rules and guidelines in response to rule abuses, are done in a minimal
fashion. Often we will deliberately leave behind holes (or introduce
new ones) so that future rule abuse may continue.
At the risk of stating the obvious, this contest is a parody of the
software development process. The rules and guidelines are only a
small part of the overall contest. Even so, one may think the contest
rules and guideline process as a parody of the sometimes tragic
mismatch between what a customer (or marketing) wants and what
engineering delivers.
JUDGING PROCESS:
Entries are judged by Leonid A. Broukhis, Simon Cooper, Landon Curt Noll
and Peter Seebach.
Each entry submitted is given an id number and subdirectory. The
"program", "info", "build" and "remarks" portions of a submission are
stored and judged from this directory.
Any "author" and identifiable "entry" information is not read until
the judging process is complete, and then only from entries that have
won an award.
The above process helps keep us biased for/against any one particular
| individual. Therefore you MUST refrain from putting any information
| that reveals your identity in the "program", "info", "build", or "remarks"
| portions of your entry. We are usually kept in the dark as much as you
| are until the final awards are given. We like the surprise of finding
out in the end, who won and where they were from.
We attempt to keep all entries anonymous, unless they win an award.
Because the main 'prize' of winning is being announced, we make all
attempts to send non-winners into oblivion. We remove all non-winning
files, and shred all related paper. By tradition, we do not even
reveal the number of entries that we received. (For the curious,
we do indicate the volume of paper consumed when presenting the IOCCC
winners at talks)
After the initial announcement, we attempt to send EMail to the
authors of the winning entries. One reason we do this is to give
the authors a chance to comment on the way we have presented their
entry. They are given the chance to correct mistakes and typos. We
often accept their suggestions/comments about our remarks as well.
This is done prior to posting the winners to the wide world.
Judging consists of a number of elimination rounds. During a round,
the collection of entries are divided into two roughly equal piles;
the pile that advances on to the next round, and the pile that does
not. We also re-examine the entries that were eliminated in the
previous round. Thus, an entry gets at least two readings.
A reading consists of a number of actions:
* reading the "build" information
* reading the "program"
* reading the program "info", if any
* passing the source thru the C pre-processor
skipping over any #include files
* performing a number of C beautify/cleanup edits on the source
* passing the beautified source thru the C pre-processor
skipping over any #include files
In later rounds, other actions are performed:
* compiling/building the source
* running the program
* performing miscellaneous tests on the source and binary
Until we reduce the stack of entries down to about 25 entries, entries
are judged on an individual basis. An entry is set aside because it
does not, in our opinion, meet the standard established by the round.
When the number of entries thins to about 25 entries, we begin to form
award categories. Entries begin to compete with each other for awards.
An entry will often compete in several categories.
The actual award category list will vary depending on the types of entries
we receive. A typical category list might be:
* best small one line program
* best small program
* strangest/most creative source layout
* most useful obfuscated program
* best game that is obfuscated
* most creatively obfuscated program
* most deceptive C code
* best X client (see OUR LIKES AND DISLIKES)
* best abuse of ANSI C
* worst abuse of the rules
* (anything else so strange that it deserves an award)
We do not limit ourselves to this list. For example, a few entries are so
good/bad that they are declared winners at the start of the final round.
We will invent awards categories for them, if necessary.
In the final round process, we perform the difficult tasks of
reducing the remaining entries (typically about 25) down to 8 or 10
winners. Often we are confident that the entries that make it into
the final round are definitely better than the ones that do not
make it. The selection of the winners out of the final round, is
less clear cut.
Sometimes a final round entry is good enough to win, but is beat out
by a similar, but slightly better entry. For this reason, it is
sometimes worthwhile to re-enter an improved version of an entry
that failed to win in a previous year. This assumes, of course,
that the entry is worth improving in the first place!
More often than not, we select a small entry (usually one line), a
strange/creative layout entry, and an entry that abuses the contest
rules in some way.
In the end, we traditionally pick one entry as 'best'. Sometimes such
an entry simply far exceeds any of the other entries. More often, the
'best' is picked because it does well in a number of categories.
ANNOUNCEMENT OF WINNERS:
The judges will post an initial announcement of who won, the name
of their award, and a very brief description of the winning entry
on the IOCCC web site:
http://www.ioccc.org/whowon.html
We will also submit a brief announcement story to /.:
http://slashdot.org
that, depending on the willingness of the /. editors, may be posted
to their site at the same time.
Note that initial announcement will NOT contain source. This is because
the winning authors are given a chance to review the judges comments,
and test our Makefile. This review process typically takes a few weeks.
Sometime after the initial announcement, and once the the review
by the winners has been completed, the winning source will be
posted to the IOCCC web site:
http://www.ioccc.org/years.html
NOTE: previous winners are available at that URL
We will submit a story announcing the availability of the winners
to /. at the same time.
Finally the winning entries will be posted to the following groups:
comp.lang.c comp.lang.c.moderated alt.sources
In addition, pointers to these postings are posted to the following
comp.sources.misc comp.windows.x comp.programming
misc.misc comp.std.c alt.folklore.computers
Often, winning entries are published in selected magazines from around
the world. Winners have appeared in books ("The New Hackers Dictionary")
and on T-Shirts.
Last, but not least, winners receive international fame and flames! :-)
FOR MORE INFORMATION:
You may contact the judges by sending EMail to the following address:
| q.2006@ioccc.org (do not submit entries to this address)
| You must include the words 'ioccc 2006 question' in the subject of your
EMail message when sending EMail to the judges.
Questions and comments about the contest are welcome. Comments about
confusing rules and guidelines are also welcome.
The rules and the guidelines may (and often do) change from year to
year. You should be sure you have the current rules and guidelines
prior to submitting entries.
Check out the IOCCC Web page:
http://www.ioccc.org
It has rules, guidelines and winners of previous contests (1984 to date).
Leonid A. Broukhis
Simon Cooper
chongo (Landon Curt Noll) /\cc/\
Peter Seebach
+31
View File
@@ -0,0 +1,31 @@
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# data files for this entry
#
DATA=
build: ${ENTRY}
clean:
-${RM} ${ENTRY}
clobber: clean
alt:
data:
${ENTRY}: ${ENTRY}.c ${DATA}
${CC} ${CFLAGS} ${ENTRY}.c -o ${ENTRY}
+26
View File
@@ -0,0 +1,26 @@
#define q [v+a]
#define c b[1]
#define O 1 q
#define o 0 q
#define r(v,a\
)v<0&&( v*=-1, a*=-1);
#define p(v,m, s,w)*c==*#v?2 q\
<m?(c++ ,d=1,3 q=0,5 q=m,main\
(a+3,b) ,o=o*s q,O=O* w q):0:
static d,v[99 ];main (int a,
char**b ){d=7; if(*c?! (p(+,3
,4 q+O* 3,4)p( -,(o?3
:(O=1,6 )),4 q -O*3,4)
p(*,4,3 ,4)p(/ ,5,4,3)
p((),d, 0+3,0+ 04)*c==
')'?2 q <02?(c ++,0):0
:(o=012 *o+*c- '0',c++
,O=1)): 2 q?3- 2:printf(
"%d/%d" "\n",o ,O))return
1;d=a,r (o,d)r (O,d)3 q
=o<O?(4 q=o,O) :(4 q=O,
o);r(d, o)a+=3;O?
1:(O=1,2
q=1);while
(2 q=o%1 q)a++;v[d]/=O;d[
v+1]/=O;return main(d,b);}
+57
View File
@@ -0,0 +1,57 @@
# Most Irrational
Steinar Hamre
Norway
## Judges' Comments:
### To build:
make hamre
### To run:
./hamre '-1+4/3*(2+1/(3/2*(7/2-7/3+1/6)))/2'
An irrationally coded source presents rational things!
A rational person might want to attempt the irrational task
of supporting a new operator by way of an existing macro
in the source. And can you determine which macro this is
and understand the purpose of its arguments?
## Selected Author's Comments:
This is a calculator for rational numbers. Believe it or not, that is
a useful tool to have around, and I haven't found a useful version,
much less an obfuscated one.
It is rather feature complete as rational calculators go. The
supported operators are: +, - (binary and unary), *, / and (). Run it
by supplying an expression as the first argument, and the normalized
result will be written to stdout.
./hamre '-1+4/3*(2+1/(3/2*(7/2-7/3+1/6)))/2'
2/3
If you do not supply an argument, the calculator will crash. Other
arguments are ignored. Supplying more arguments may further limit the
number of nested operators supported.
Remember that 1/0 is not a rational number. You will not get any
answer if you divide by zero.
By default, only 31 nested levels of operators are supported.
The code is well documented, even with an example. In fact this
documentation accounts for 100% of the source. Personally I find
preprocessing or reindenting the program counterproductive when it
comes to understanding the source. The preprocessed source becomes
rather verbose.
IOCCC entries are often loaded with all kinds of hard-coded numbers. I
have restricted myself to mostly use sensible numbers (<= 7) as
smaller numbers are much easier to remember. Also the macros really
help hiding most of the uses of these numbers away. All macros and
variables are easy-to-remember single character abbreviations, from
some language, meaningful to the purpose(s) of the macro, I hope.
+31
View File
@@ -0,0 +1,31 @@
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# data files for this entry
#
DATA=
build: ${ENTRY}
clean:
-${RM} ${ENTRY}
clobber: clean
alt:
data:
${ENTRY}: ${ENTRY}.c ${DATA}
${CC} ${CFLAGS} ${ENTRY}.c -o ${ENTRY}
+103
View File
@@ -0,0 +1,103 @@
# Best Game
Raphael Meyer
US
## Judges' Comments:
### To build:
make meyer
### To run:
./meyer
For your first input try:
a 0 1
This entry turns a newspaper solitare puzzle into a competition
with the computer to be the last one moving. The object of this
source code is to determine the object of this source code! :-)
## Selected Author's Comments:
I wanted submit a fully object-oriented entry to show that
object-orientated code:
1. is ridiculously bloated
2. is unreadable
3. isn't WYWIWID anymore
But I just totally failed. No, I didn't fail in showing any of
the points above. Before I even had the chance to prove any of
these claims, (1) already brought me to my knees. The code got
so much bloated up, that I missed the size limit by a few hundred
bytes. Therefore, I broke the only rule in this contest, I think
you shouldn't break in any case: Rule Nr 2, The size of ...
The degree of claim (2) actually depends on the compiler. As I
_manualy_ compiled it from [a generic object-oriented programming
language] to C, it didn't just end up unreadable, but awfully
messed up, i.e. obfuscated.
As it is already (pre)compiled to C, you could also call it an object-
disoriented progam.
Comparing this progam to a potential object-oriented implementation,
it is obvious, that object-oriented code isn't WYWIWID (what
you write is what it does). It may be tempting to think that
Object o;
might do something similar as
struct not_an_object o;
But this program reveals that it doesn't. Even worse, this program only
reveals the tip of the iceberg, what kind of black magic is involved in
a simple declaration of an object.
A few things you can explore about object-orientation in this program
include:
- constructors (invoked by the new operator)
- new operators (every class gets its own new operator at compile time)
- virtual method tables
(all the virtual method tables have been combined to a single vtable)
- runtime method binding
- inheritance and polymorphism
It is left as an exercise to the reader to find a corresponding
implementation in a popular object-oriented programming language.
### Starting the game
./meyer [SEED]
### Gameplay
It is a sudoku based game. The goal of the game is to be able
to do the last valid 'move'.
On your turn you have to set a free cell to a value between 1 to 9 without breaking the following rule:
any number must be unique in its
1. row
2. column
3. 3x3 block.
Expected input for your move:
row column number
where
row: [a-i]
column: [0-8]
number: [1-9].
The game can be aborted with 'q'.
The one who can do the last move wins the game.
+220
View File
@@ -0,0 +1,220 @@
#include <stdlib.h>
#include <stdio.h>
#define JF 0
#define JG 1
#define JH 2
#define JI 3
#define a(p,q,r,s) s=(p<r)?s:(p=q,s+1)
#define b(p,q,r,s,t,u,v) a(p,q,r,s),a(s,t,u,v)
#define c(p,q,r) for(p=q; p<r; p++)
#define d(p,q,r,s,t,u) for(p=q,s=t; s<u; p++,a(p,q,r,s))
#define e(p,q,r,s,t,u,v,w,x) for(p=q,s=t,v=w; (v<x); p++,b(p,q,r,s,t,u,v))
#define f
#define g(p) ,p
#define h(p) j(p,f,f)
#define i(p,q) j(p,q r,g(r))
#define j(p,q,r) p* N##p(q) { p* s=(p*)malloc(sizeof(p)); s->M=L[J##p]; ((p##0)s->M[0])(s r); U s; }
#define k(p, q) C struct { K* M; q } p
#define l(p) printf(O+p
#define m(p, q) (_->P+(q<<4&0360))[017&p]
#define n void
#define o int
#define A char
#define B const
#define C typedef
#define D C n
#define E C o
#define U return
#define V(p) (p<3)?0:(p<6)?3:6
#define W(p,q,r) ((p)q->M[r])(q)
B A* B O = " %c%s\0\n0 1 2 3 4 5 6 7 8\n\n\0%s\n\0you win\0you: \0%1s\0%d %d\0you lose\0cpu: %c %d %d\n\0 \0";
D (*K)(n);
k(F, o P[00400]; );
k(G, F* Q; B A* R; );
k(H, F* Q; B A* R; );
k(I, F* Q; B A* R; );
D (*F0)(F*);
E (*F1)(F*);
D (*F2)(F*, o, o, o);
E (*F3)(F*, o, o, o);
D (*F4)(F*);
D (*G0)(G*, F*);
E (*G1)(G*);
E (*G2)(G*, o*, o*, o*);
E (*G3)(G*);
D (*H0)(H*, F*);
D (*I0)(I*, F*);
n OOOO(F* _) {
o p;
c(p, 0, 0xFF) _->P[p] = 0;
}
o OOOl(F* _) {
o p, q, r;
e(p, 0, 9, q, 0, 9, r, 1, 10) if(((F3)_->M[3])(_, p, q, r)) U 1;
U 0;
}
n OOlO(F* _, o p, o q, o r) {
m(p,q) = r;
}
o OOll(F* _, o r, o s, o t) {
o u = 0;
if(t > 0 && t < 10 && r >= 0 && r < 9 && s >= 0 && s < 9 && m(r,s) == 0) {
o p, q;
o w = V(r);
o x = V(s);
c(p, 0, 9) if(m(p,s) == t || m(r,p) == t) goto v;
d(p, w, w+3, q, x, x+3) if(m(p,q) == t) goto v;
u = 1;
v: U u;
}
goto v;
}
n OlOO(F* _) {
o p, q;
for(q = 0, l(28)), p = 0; q < 9; p++, q = (p < 9)?q:(p=0,l(0), q+'a', O+((q == 2 || q == 5) ? 27 : 28)),q+1)) {
l(2), m(p,q) == 0 ? '.' : '0' + m(p,q), O+((p == 2 || p==5) ? 82 : 83));
}
l(7));
}
n lOll(G* _, F* p) {
_->Q = p;
_->R = O+6;
}
o OlOl(G* _) {
o p, q, r;
if(((G2)_->M[2])(_, &p, &q, &r)) {
((F2)_->Q->M[2])(_->Q, p, q, r);
U 1;
}
U 0;
}
n OllO(G* _) {
l(30), _->R);
}
n Olll(H* _, F *p) {
lOll((G*)_, p);
_->R = O+34;
}
o lOOO(H* _, o* p, o* q, o* r) {
do {
A s[3];
l(42));
fflush(stdout);
scanf(O+48, s);
if(*s == 'q') U 0; else *q = (*s >= 'a' && *s <= 'i') ? *s - 'a' : 9;
scanf(O+52, p, r);
} while(!((F3)_->Q->M[3])(_->Q, *p, *q, *r));
U 1;
}
n lOOl(I* _, F* p) {
lOll((G*)_, p);
_->R = O+58;
}
o lOlO(I* _, o* p, o* q, o* r) {
o s, t, u;
o v = 0;
o w[01331];
e(s, 0, 9, t, 0, 9, u, 1, 10) if(((F3)_->Q->M[3])(_->Q, s, t, u)) w[v++] = s | (t << 5) | (u << 10);
s = rand() % v;
*p = w[s] & 0x1f;
*q = (w[s] & 0x3e0) >> 5;
*r = (w[s] & 0x7c00) >> 10;
l(67), *q + 'a', *p, *r);
U 1;
}
K M[17] = {
(K)OOOO,
(K)OOOl,
(K)OOlO,
(K)OOll,
(K)OlOO,
(K)0000,
(K)OlOl,
(K)0000,
(K)OllO,
(K)Olll,
(K)OlOl,
(K)lOOO,
(K)OllO,
(K)lOOl,
(K)OlOl,
(K)lOlO,
(K)OllO
} ;
K* L[4] = {
M+0x0,
M+0x5,
M+0x9,
M+0xD
} ;
h(F)
i(G, F*)
i(I, F*)
i(H, F*)
o main(o s, A** t) {
o p = 42;
F* q = 0;
G* r[2] = { 0, 0} ;
if(s-- > 1) {
srand(atoi(t[s]));
U main(s, t);
}
q = NF();
r[0] = (G*)NH(q);
r[1] = (G*)NI(q);
for(p&=1; !(p&4); p&=5) {
W(F4,q,4);
if(W(G1,r[p],1)) {
if(!W(F1,q,1)) {
W(F4,q,4);
W(G3,r[p],3);
p = 4;
}
} else {
p = 4;
}
p++;
}
free((n*)q);
free((n*)r[0]);
free((n*)r[1]);
U 0;
}
+41
View File
@@ -0,0 +1,41 @@
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# Special flags for this entry
#
LOCAL_FLAGS= -O3 `sdl-config --libs --cflags`
# For Mac OS X with Darwin Ports installed
# LOCAL_FLAGS= -O3 `/opt/local/bin/sdl-config --libs --cflags`
# Data files for this entry
#
DATA=
build: ${ENTRY} ${ENTRY}_orig
clean:
-${RM} ${ENTRY} ${ENTRY}_orig
clobber: clean
alt:
data:
${ENTRY}: ${ENTRY}.c ${DATA}
${CC} ${LOCAL_FLAGS} ${ENTRY}.c -o ${ENTRY}
${ENTRY}_orig: ${ENTRY}_orig.c
${CC} ${LOCAL_FLAGS} ${ENTRY}_orig.c -o ${ENTRY}_orig
+185
View File
@@ -0,0 +1,185 @@
# Best Compiled Graphics
Maurizio Monge
Department of Mathematics
University of Pisa
Pisa
Italy
maurizio.monge at gmail dot com
## Judges' comments:
### To build:
echo Make sure you have the SDL development environment installed
make monge
### Try:
./monge "z = 0" "z = z*z*z + c; Abs2(z) < 4"
For those who are familiar with the previous IOCCC winners, this program
is best described as "1994/tvr meets 2001/bellard". Here you have
mouse-manipulated fractals AND generated binary code, all in one package.
A more appropriate award could have been "Best abuse of the
rules", because on a non-x86-based architecture this program
is, quite predictably, a dud.
At the time of judging we were too mesmerized by the graphics
to realize it; and, after all, this entry does take a special
effort to work on both i386 and x86_64. Portable it is! :)
## Author's comments:
### For the impatients
0. Compile using the Makefile, or just run:
gcc monge.c -o monge -O3 `sdl-config --libs --cflags`
1. Run:
./monge "z = 0" "z = z*z + c; Abs2(z) < 4"
2. Keep clicked with left or right button to zoom in or out.
3. Use the numpad '+' and '-' to increase/decrease the iteration
count when needed.
4. Enjoy, unless you're more interested in trying to understand
how it works. :)
### Introduction
This is a fractal generator that supports custom formulas and
real time zoom. The program needs to be run with two arguments,
the first being a semicolon separated list of assignments to
do once per pixel, and the second a semicolon separated list
of assignents and conditions that will be executed (and conditions
checked) for each iteration (up to the maximum). Using the
left and right mouse buttons you will be able to zoom in and
out (a la Xaos), the zooming algorithm is a bit slower than
Xaos's but it should give slightly better results.
Formulas can use all a-z (lowercase) variables, and the special
variables 'c' and 'i' are respectively set by default to the
complex coordinate of the pixel and to the complex imaginary 'i'.
All the constant numbers will be interpreted as real double
values. Each expression must be an assignment ([variable] =
[expr]) or a comparison with < or > ([expr1] < or > [expr2]),
and you can add spaces as you like (as understood by the c
function 'isspace').
Supported operations and functions are:
> Operation | Description
> :-------- | :----------
> +,-,*,/ | Arithmetic operations, priority of *,/ over +,- is respected.
> <,> | Compares the real parts of two complex numbers (the imaginary part is ignored). Any number of conditions is allowed, the iteration will just stop as soon as one of them fails.
> Abs2 | Calculates the squared norm, ie: Abs2(a+b*i) is (a*a+b*b)+0*i
> Re | Extract the real part, ie: Re(a+b*i) is a+0*i
> Im | Extract the imaginary part, ie: Im(a+b*i) is b+0*i
> Exp | Calculates the complex exponential, ie Exp(a+b*i) is e^a*(cos(b)+sin(b)*i)
> Ln | Calculates the principal value of the natural logarithm, ie Ln(a+b*i) is ln(a*a+b*b)/2 + atan(b/a)*i
Here are a few examples of fractals you can draw:
- Mandelbrot:
./program "z=1" "z=z*z+c; Abs2(z)<4"
- Mandelbrot (return time variation):
./program "z=c" "z=z*z+c; Abs2(z-c)>0.0001"
- Julia, for c=0.31+i*0.5:
./program "z=c; c=0.31+i*0.5" "z=z*z+c; Abs2(z)<4"
- Julia (return time variation), for c=0.31+i*0.5:
./program "z=c; c=0.31+i*0.5" "z=z*z+c; Abs2(z-c)>0.0001"
- Newton, for x^3-1:
./program "z=c" "p=z; z=0.6666*z+0.3333/(z*z); Abs2(p-z) > 0.001"
- Newton-Mandelbrot:
./program "z=0" "p=z; z=z-(z*z*z + (c-1)*z - c)/(3*z*z+c-1); Abs2(p-z) > 0.001"
- Phoenix, Mandelbrot version:
./program "z=0; q=0" "t=z; z=z*z+Re(c)+Im(c)*q; q=t; Abs2(z)<4"
- Phoenix, Julia version for c=0.56667-i*0.5
./program "z=c; c=0.56667-i*0.5; q=0" "t=z; z=z*z+Re(c)+Im(c)*q; q=t; Abs2(z)<4"
### Compilation and portability
This program will only work on x86 (with an x87 FPU) or x86_64 machines,
and requires the SDL library.
Another system requirement is the mmap function (as #define'd
at the beginning of the program). If it is not available the
macro M(a) will have to be replaced with a system dependent
function that allocates readable, writable *AND* executable
memory (it will not be possible to make this program run on
paranoid systems (like OpenBSD IIRC) do not allow rwx memory).
However i was able to compile and make work the program under
Linux (Debian/x86 and OpenSuSE/x86_64) and under Cygwin/x86. A
friend of mine was able to make it work under MacOSX too.
If you want you can change the window width and height, or the default
number of iterations (that one can be tweaked at runtime, anyway) by
changing the definitions of W, H and I at the beginnning of the code.
### Caveats (i just a selected few of them!)
- The zooming speed depends on the speed of the computer.
- Incorrect formulas will ungracefully crash the program.
- Many SDL identifiers are hardcoded as number, this is safe up to ABI
incompatibility.
- Better optimization could be done treating known real numbers as just one
double, instead of adding a 0 imaginary part to treat them as complex
numbers.
- There should be some way to switch from Mandelbrot to Julia with choosen
parameter.
### Spoiler
Sure, i don't want to deprive you of the pleasure of digging
into the infernal mess created by my corrupted mind (writing
this remark i noticed that i was ending senteces with ';' instead
that with '.', and i worried for my sanity), but just in case...
I used many obfuscation techniques, including a few ones that
are different from the tricks used in most common IOCCC program
(more 'highlevel', in the sense that they require an understanding
of how all the program works to be worked out).
This program is a formula parser that outputs machine code that
calculates the formula and check the given conditions. The
machine code targets the x87 stack based FPU, and it is almost
identical for x86 and x86_64 (except for the comparison
instructions, that have to be generated differently). The
program keeps track of the FPU stack (the FPU has a cyclic stack
of 8 registers) and will automatically swap to and from the
main memory when required (ie, adds instructions to the generated
machine code to take care of this issue).
The formulas are parsed recursively and machine code for the
inner iteration loop is also generated.
After generating the machine code, a big event loop creates (or
zooms into) the factal executing the generated code when needed,
and then waits for input events.
The zooming algorithm works by remembering for each pixel the
floating point offset to where the value was actually calculated.
When zooming, the best match is searched, and if the offset is
too big (>1) the pixel is recalculated.
+64
View File
@@ -0,0 +1,64 @@
#include <stdlib.h>
#include <SDL.h>
#include <sys/mman.h>
#define M(a) mmap(0, a, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0)
#define W 400
#define H 300
#define I 128
#define L char*
#define _ Sint32
#define h(a,b) for(a=0; a<b; a++)
#define O while(
#define b D[j][i][
#define J(b) a(#b)
SDL_Event
e;
SDL_Surface
*F; float f, m,
n,d,D[H][W][6],
v; L A; L X; L
V,G[H][W]; L
E ; L Q; double
R=2/( W-1. ),T=2/(H-1.),c,g, z=2 ,*
K,*Z,*S; _ B, C, o,i,j,q,k,l,x,y,*u,Y=512; P(
L f){ *(u=V)=f-X-5; V+=4; } a(L e){ O l=*e++)
l-38?l==36?s(2),o--:l-37?*V++=l==35?k=*e++
,k* 16+*e++-81:l^128:o>7?J(Yv]#JJ), P(S++):o++
:s(4); } s(_ n){ O o<n){ J(]#IB); P(--S); J(]);
*V ++=217+o++; } } p(L e,_ q,L *t){ _ x=9; do{ A="%]#IB"
; _ i =*e; 5==q?*K=strtod(e,t),e-*t?e=*t,a(A),P(K++), J(%Yn)
: i<6 ?p ( e+1,4,t),i-5||J(Y`YIY`YI), e=*t:i>96?a(A),P(Z+i-97),a
(A),P (Z+*e++-71) :(p(index( e, 40)+1,1,t), i^82?i^73?i^65?i^69?i^76?1:J
(%YhY`%YmY}]YYB%YBXHYIXH$^A$YqYJ$Ys):J(%Y{YJ%Yj^IY@Y|\\iYIYp%Yh$^AY}$]Y\\J$^I)
: J(XHYIXH^AYn):J(]YYn) : J (]XYn),e= index( *t,41 )+ 1): p ( e , q+ 1, &e); A
= "&%YCXJYLXIYK\\J$^I$^k$^A"; (x -=3)<1?J(&]X]Y),1L <<31<0? J(Zi_`#JO):J(_i]X),x
?J (#HH):J(#HC),J(#AD#IJPC) ,o-=4:--x?--x?--x?x-3?J(&%YA%YAXHYIXH^AYh$^q\\J$^IY`)
, a(A): 1:a(A):J(&$^j$^j):J(&$^B$^B); } O q==(x=*(*t=e++))/2); } main(_ r,L*U){
X =V=(Z =(S=(K=M(Y*32))+Y)+ Y)+Y; J(h#AA#AA#AA#AA#FJ:+-*/); h(q,2){ A =E =Q=U[ q+1]; O * A=*A^B++
[ ";<>+-*/" ]?*A:B,(B%=7)||(isspace(*E=*A)||++E,*A++)); E=V; O B=*Q){ if(Q[1]-61)p(
Q,1,&Q); else{ p(Q+2,1,&Q); h(j,2){ J(]#JJ); P(Z+B-71-j*26); o--; } } *Q&&Q++; }
} J(#PPJ#AP#IF); P (E -V+X +1); J(#IJPC); 0[u =X+7] =I; SDL_Init( 32 ); F=
SDL_SetVideoMode(W,H,8 ,0); A=F->pixels; B=F->pitch; O 1){ C^=3; h(j,H)h(i,
W )b C+2]=9; if(r=(k =SDL_GetMouseState(&x,&y))&5){ f=z/50; f=k&1 ?f:-f ;
c+=(x*T-T/R)*f; g += f*y*T-f; z*=f=1-f/z; v=1/f; h(j,H)h(i,W)h(q,4){ k=
x+(i- x)* f +q/2; l=y+(j-y)*f+q%2; if(k>=0&k<W&l>=0&l<H){ m=x+(k+D[
l][k ][ 3-C]-x)*v-i; n=y+( l+D[l][k][4 -C]-y)*v-j; d= m*m+ n*n;
if ( d<b C+2]){ b C]=m; b C+1]=n; b C+2]=d; G[j][i]=A[l*B+
k ]; } } } } h(j,H)h(i,W)if(q=b C+2]){ Z[2]=(i *T-T /
R)*z+c; Z[28]=z-j *T*z-g; Z[8]= 0; Z[34]=1; q =((_(*
)( ))X)(); A[j* B+i]=q? *u-q:0; h(q,3)b C+q]=0;
} else A[j*B+i]=G[j][i]; SDL_UpdateRect(F,
0,0,W,H); O(r?SDL_PollEvent:SDL_WaitEvent)(&e
)) { k=e.type; l=e.key.keysym.sym; if ( k==
12|k== 2& l ==27)return; if(
e.type-5?k==
2&(l==270|l==
269)?*u=l-270
? *u/2:*u*2:0:1
) break;
}
} }
+64
View File
@@ -0,0 +1,64 @@
#include <stdlib.h>
#include <SDL.h>
#include <sys/mman.h>
#define M(a) mmap(0, a, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0)
#define W 400
#define H 300
#define I 128
#define L char*
#define _ Sint32
#define h(a,b) for(a=0; a<b; a++)
#define O while(
#define b D[j][i][
#define J(b) a(#b)
SDL_Event
e;
SDL_Surface
*F; float f, m,
n,d,D[H][W][6],
v; L A; L X; L
V,G[H][W]; L
E ; L Q; double
R=2/( W-1. ),T=2/(H-1.),c,g, z=2 ,*
K,*Z,*S; _ B, C, o,i,j,q,k,l,x,y,*u,Y=512; P(
L f){ *(u=V)=f-X-5; V+=4; } a(L e){ O l=*e++)
l-38?l==36?s(2),o--:l-37?*V++=l==35?k=*e++
,k* 16+*e++-81:l^128:o>7?J(Yv]#JJ), P(S++):o++
:s(4); } s(_ n){ O o<n){ J(]#IB); P(--S); J(]);
*V ++=217+o++; } } p(L e,_ q,L *t){ _ x=9; do{ A="%]#IB"
; _ i =*e; 5==q?*K=strtod(e,t),e-*t?e=*t,a(A),P(K++), J(%Yn)
: i<6 ?p ( e+1,4,t),i-5||J(Y`YIY`YI), e=*t:i>96?a(A),P(Z+i-97),a
(A),P (Z+*e++-71) :(p(index( e, 40)+1,1,t), i^82?i^73?i^65?i^69?i^76?1:J
(%YhY`%YmY}]YYB%YBXHYIXH$^A$YqYJ$Ys):J(%Y{YJ%Yj^IY@Y|\\iYIYp%Yh$^AY}$]Y\\J$^I)
: J(XHYIXH^AYn):J(]YYn) : J (]XYn),e= index( *t,41 )+ 1): p ( e , q+ 1, &e); A
= "&%YCXJYLXIYK\\J$^I$^k$^A"; (x -=3)<1?J(&]X]Y),1L <<31<0? J(Zi_`#JO):J(_i]X),x
?J (#HH):J(#HC),J(#AD#IJPC) ,o-=4:--x?--x?--x?x-3?J(&%YA%YAXHYIXH^AYh$^q\\J$^IY`)
, a(A): 1:a(A):J(&$^j$^j):J(&$^B$^B); } O q==(x=*(*t=e++))/2); } main(_ r,L*U){
X =V=(Z =(S=(K=M(Y*32))+Y)+ Y)+Y; J(h#AA#AA#AA#AA#FJ:+-*/); h(q,2){ A =E =Q=U[ q+1]; O * A=*A^B++
[ ";<>+-*/" ]?*A:B,(B%=7)||(isspace(*E=*A)||++E,*A++)); E=V; O B=*Q){ if(Q[1]-61)p(
Q,1,&Q); else{ p(Q+2,1,&Q); h(j,2){ J(]#JJ); P(Z+B-71-j*26); o--; } } *Q&&Q++; }
} J(#PPJ#AP#IF); P (E -V+X +1); J(#IJPC); 0[u =X+7] =I; SDL_Init( 32 ); F=
SDL_SetVideoMode(W,H,8 ,0); A=F->pixels; B=F->pitch; O 1){ C^=3; h(j,H)h(i,
W )b C+2]=9; if(r=(k =SDL_GetMouseState(&x,&y))&5){ f=z/50; f=k&1 ?f:-f ;
c+=(x*T-T/R)*f; g += f*y*T-f; z*=f=1-f/z; v=1/f; h(j,H)h(i,W)h(q,4){ k=
x+(i- x)* f +q/2; l=y+(j-y)*f+q%2; if(k>=0&k<W&l>=0&l<H){ m=x+(k+D[
l][k ][ 3-C]-x)*v-i; n=y+( l+D[l][k][4 -C]-y)*v-j; d= m*m+ n*n;
if ( d<b C+2]){ b C]=m; b C+1]=n; b C+2]=d; G[j][i]=A[l*B+
k ]; } } } } h(j,H)h(i,W)if(q=b C+2]){ Z[2]=(i *T-T /
R)*z+c; Z[28]=z-j *T*z-g; Z[8]= 0; Z[34]=1; q =((_(*
)( ))X)(); A[j* B+i]=q? *u-q:0; h(q,3)b C+q]=0;
} else A[j*B+i]=G[j][i]; SDL_UpdateRect(F,
0,0,W,H); O(r?SDL_PollEvent:SDL_WaitEvent)(&e
)) { k=e.type; l=e.key.keysym.sym; if ( k==
12|k== 2& l ==27)return; if(
e.type-5?k==
2&(l==270|l==
269)?*u=l-270
? *u/2:*u*2:0:1
) break;
}
} }
+36
View File
@@ -0,0 +1,36 @@
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# Special flags for this entry
#
LOCAL_FLAGS= -lncurses
# data files for this entry
#
DATA=
build: ${ENTRY}
clean:
-${RM} ${ENTRY} ${ENTRY}_orig
clobber: clean
alt:
data:
${ENTRY}: ${ENTRY}.c ${DATA}
${CC} ${CFLAGS} ${LOCAL_FLAGS} ${ENTRY}.c -o ${ENTRY}
+113
View File
@@ -0,0 +1,113 @@
# Best Abuse of Computation
Christopher Night
Harvard University
Department of Astronomy
Cambrige MA 02238
US
<http://www.people.fas.harvard.edu/~night/>
## Judges' Comments:
### To build:
make night
### To run:
./night
You'd never guess, from looking at the code, that there is a
genetic algorithm involved. Somewhere. But what does it do?
Well, it might take you a while to navigate the results, let
alone the code.
## Selected Author's Comments:
Don't worry; this is not a self-reproducing program, as you might at
first guess from the layout. I would never be so foolhardy as to
submit an entry on an over-used theme!
Oh, wait a second... it is a maze-generating program. Oops!
### What it does:
This program solves an optimization problem, namely, generating a
challenging maze. It uses a very simple genetic algorithm: a maze
layout's DNA is represented as a 32-bit integer, and mutations consist
of flipping three different bits. The algorithm is simple in that it
doesn't employ sexual reproduction, only mutations, and it has a
population size of 1. So much for diversity!
This particular optimization problem, I believe, has a unique maximum:
there is but one maze out of 2^32 that requires 64 moves to solve. The
program will run until finding this global maximum, or if you get
bored, you can accept a sub-optimal solution by pressing any key. On
my system, it takes an average of 15 minutes to find the maximum,
whereas a random search would take an average of 3.5 days.
Should you take my word for it that the maze it generates requires as
many moves as I say it does? The answer is yes. But if you're not
convinced, you can try to solve it yourself. The goal is to traverse
from the upper-left to the upper-right and out the top, where the
number of moves remaining is printed. Use the arrow keys for suckers
(w, a, s, d) to move around. q quits and r restarts. Also, the maze
changes as you move through it, in a predicatable way. It should be
easy enough to figure out the pattern. For best results, use a display
with bold-text capabilities and color.
Finally, in the world of DNA, the medium is truly the message. There's
a short message encoded in here that will only appear when you
complete the optimal maze in the required 64 moves.
### Issues:
These depend on your compiler, and they were all intentionally
added for obfuscation purposes. No, really!
My compiler warns of nulls in a string literal, and the redefinition
of the macro T.
On one compiler, compilation took about two minutes.
`sizeof(unsigned short)` must be 2, and `sizeof(unsigned long)` must be 4.
CLOCKS_PER_SEC is assumed to be 1000000. If it's a lot less than that,
expect delays.
### Algorithmic obfuscation:
The representation of the maze layout in a 32-bit integer type is
pretty opaque. As a hint, the optimum layout's DNA is, in base 4,
2102231031201230. Try getting from there to the maze that appears on
screen.
The recursive function CGAC replaces a nested for loop in a handy way.
The maze-solving function TGA returns no solution both if no solution
exists, and if the search space grows too large, with a single test.
### Stylistic obfuscation:
Four-letter alphabets are confusing. I don't know how ribosomes
manage.
Overloaded symbols, such as G and G().
Who needs != when you've got ^?
Who needs if when you've got while?
For that matter, who needs fixed-iteration-count for and while when
you can just duplicate code with the preprocessor? Duplication by this
macro causes one particular graphics line to be replicated 512
times. On my system the preprocessed code is over 80KB in length,
hindering the preprocessor's ability to deobfuscate.
Keypad support was removed to save space. To restore, modify the
following two macros to:
#define ATG srand(time(0)); initscr(); cbreak(); noecho(); start_color(); keypad(stdscr,1);
#define AGG A&2?KEY_UP:KEY_DOWN:A&1?KEY_RIGHT:KEY_LEFT
Code on!
Binary file not shown.
+152
View File
@@ -0,0 +1,152 @@
19th International Obfuscated C Code Contest Rules
Copyright (C) 2006 Leonid A. Broukhis, Simon Cooper, Landon Curt Noll and
Peter Seebach.
All Rights Reserved. Permission for personal, education or non-profit use is
granted provided this this copyright and notice are included in its entirety
and remains unaltered. All other uses must receive prior permission in
writing from the contest judges.
Obfuscate: tr.v. -cated, -cating, -cates. 1. a. To render obscure.
b. To darken. 2. To confuse: his emotions obfuscated his
judgment. [LLat. obfuscare, to darken : ob(intensive) +
Lat. fuscare, to darken < fuscus, dark.] -obfuscation n.
obfuscatory adj.
GOALS OF THE CONTEST:
* To write the most Obscure/Obfuscated C program under the rules below.
* To show the importance of programming style, in an ironic way.
* To stress C compilers with unusual code.
* To illustrate some of the subtleties of the C language.
* To provide a safe forum for poor C code. :-)
The 19th IOCCC contest window is:
| 31-Dec-2006 23:59 UTC to 28-Feb-2007 23:59 UTC
RULES:
To help us with the volume of entries, we ask that you follow these rules:
1) Your entry must be a complete program.
2) The size of your program source must be <= 4096 bytes in length.
The number of characters excluding whitespace (tab, space,
newline, formfeed, return), and excluding any ; { or } immediately
followed by whitespace or end of file, must be <= 2048.
3) Submissions should be performed using the instructions outlined at,
| http://www.ioccc.org/2006/submit
4) If your entry is selected as a winner, it will be modified as follows:
Your 'build' instructions will be incorporated into a
makefile. If your build instructions *is* a makefile then
it should be portable and usable from within a master
makefile.
Your program source will be renamed using an identifier of
our choice (usually your family name or anonymous) followed
by an optional digit, followed by '.c'
Your entry will be compiled into a file with the above name
minus the '.c'.
If your entry requires that a build file exist, state so in
your entry's remark section. The makefile will be arranged to
execute a build shell script containing the 'build'
information. The name of this build shell script will be your
entry's title, possibly followed by a digit, followed by '.sh'.
If needed, your entry's remarks should indicate how your entry
must be changed in order to deal with the new filenames.
5) The build file, the source and the resulting executable should be
treated as read-only files. If your entry needs to modify these files,
it should make and modify a copy of the appropriate file. If this
occurs, state so in your entry's remarks.
6) Your program source must be able to be compiled cleanly by an ANSI C
compiler, or if there are any compile errors, they must be documented
in the "remarks" section of your submission.
7) The program must be of original work. All submitted programs are
are thereby put in the public domain. All explicitly copyrighted
programs will be rejected.
| 8) Entries must be received prior to 28-Feb-2007 23:59 UTC.
An EMail a confirmation of submission will be sent to the sender
before the close of the contest.
9) Each person may submit up to 8 entries per contest year. Each entry
must be submitted separately.
10) Entries requiring human interaction to be built are not permitted.
11) Programs that require special privileges (setuid, setgid, super-user,
| special owner or group) are highly discouraged.
12) Legal abuse of the rules is somewhat encouraged. An entry that, in
the opinion of the judges, violates the rules will be disqualified.
Entries that attempt to abuse the rules must try to justify why
their rule abuse is legal in the submitted "remarks".
13) Your source may not contain unescaped octets with the high bit set.
I.e., your source may not contain octet values between 128 and 255.
14) Any program that fails to compile because of lines with trailing
control-M's (\r or \015) will be rejected.
15) When you submit your entry you must have a valid email address
that can both send and receive email. The online submission
method is a two phase process that requires the use of an
approval code. This code will be emailed to you as part of
phase 1.
Entries submitted without a working or valid email address will
be disqualified.
The judges are not responsible for delays in email, please plan
enough time for one automated exchange of email as part of your
submission.
16) You are STRONGLY encouraged to submit an original entry.
Submissions that are similar to previous entries are discouraged.
| 17) The total size of your submission: the sum of the size of the program,
| hints, comments, build and info files MUST be less than one megabyte
| in size.
FOR MORE INFORMATION:
The judging will be done by Leonid A. Broukhis, Simon Cooper, Landon
Curt Noll and Peter Seebach. Please send questions or comments
about the contest, to:
| q.2006@ioccc.org (for questions only!)
| You must include the words ``ioccc 2006 question'' in the subject of
your EMail message when sending EMail to the judges.
The rules and the guidelines may (and often do) change from year to
year. You should be sure you have the current rules and guidelines
prior to submitting entries. To obtain them, visit the IOCCC web page:
http://www.ioccc.org
It has rules, guidelines and winners of previous contests (1984 to date).
Details of how to submit your entry are located at,
| http://www.ioccc.org/2006/submit
Leonid A. Broukhis
Simon Cooper
chongo (Landon Curt Noll) /\cc/\
Peter Seebach
+35
View File
@@ -0,0 +1,35 @@
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# Special flags for this entry
#
LOCAL_FLAGS= ${CFLAGS} -lm
# data files for this entry
#
DATA=
build: ${ENTRY}
clean:
-${RM} ${ENTRY} ${ENTRY}_orig
clobber: clean
alt:
data:
${ENTRY}: ${ENTRY}.c ${DATA}
${CC} ${LOCAL_FLAGS} ${ENTRY}.c -o ${ENTRY}
+74
View File
@@ -0,0 +1,74 @@
# Homer's Favorite
Andy Sloane
1041 Seneca St.
Hartford, WI 53027
US
## Judges' Comments:
### To build:
make slone
### To run:
./sloane
Looks almost good enough to eat, dunnit? I suppose you could argue that,
at first blush, this looks like a self-reproducing program.
## Selected Author's Comments:
This program doesn't require any special build options, other than that it
uses sin and cos and hence requires the math library.
You will almost certainly get a compiler warning because I declared a bunch
of global ints without types. The code looks better this way, though, I
think. There are also no #includes, so there may be warnings for
undeclared references to printf, etc. There's a chance that my failure to
include math.h or declare sin or cos will make the donut not render
properly -- it's worked on every system I've tried so far though.
You will need some kind of VT100-ish emulation; so while this compiles and
runs OK in Windows, you will need PuTTYcyg or something like that.
The shape of the source gives a hint about its output: it's a little
animation of a shaded donut rotating over an infinite checkerboard. Like
many IOCCC entries, it is thus self-documenting.
I wanted to create something as "pure" as I could - meaning that the
entire source code is shaped into a work of art, without being prefixed
by any #define hacks, or even #includes, _and_ is portable enough to not
require any special libraries to do the animating. I achieved this with
two standard escape codes for clearing the screen and moving the cursor
back to the top-left.
The donut isn't raytraced. It's much simpler than that.
### How is it obfuscated?
There are three main pieces to this program: the donut, the checkerboard,
and the ASCII logo. The first two are programmed in a straightforward way
(with z-buffering even!), but the mathematics for drawing them is
"optimized". The ASCII logo has been shrunk into the smallest I could make
it by any means necessary.
The logo can actually be compressed much better (ironically, by doing
something simpler), but I didn't discover this until well after submitting.
### Puzzles
In increasing order of difficulty:
- Can you change the shading of the donut and checkerboard?
- Can you change the movement rates of the donut, the checkerboard, and
the scrolling logo?
- Can you change the inner/outer radii of the donut? The height/scaling
of the checkerboard?
- How is the "IOCCC 2006" logo encoded? Can you put something else in its
place? Can you find a smaller encoding?
+32
View File
@@ -0,0 +1,32 @@
_,x,y,o ,N;char b[1920] ;p(n,c)
{for(;n --;x++) c==10?y +=80,x=
o-1:x>= 0?80>x? c !='~'?b
[y+x]=c :0: 0:0;}c(
q,l,r) char*l,*r;{while (q>=0)q
=("E" "?yYrIxC{e^}KhE>[|LXbj}" "dOVsJ"
"@" "idOV{Yab[bW}[bW}\\qFywyv{D" "ma\\A"
"" "Ztq?Lyw>e{|Zq>Y\\gq\\qI[tYBe{w" "yvDZE\
vBA[`_" "Lo>}KcqdYrWqKxzKtW]|DXRwsfcUaT\\\
KXw{Y" "RsFwsFwsFw{zaqyaz|FmMpyaoyI\\]cuUw{J"
[_/6] -62>>_++%6&1?r[q]:l[q])-99;return q;}E(a
){for (o=x=a,y=0,_=0;_ <1006;)a=" /\\\n"
"~|_."[c(6,"b" "cd\\a[g","^`" "_e"
"]fh")+8], p( "#$%" "&'()*+,-.1"[ c(11
,"_ac[]\\YZi" "jkm", "`bd^efghXWlV" )+13
]-34,a);}main (k,Z){ float z[1920] ,A=0
,B=0 ,i,j; puts("" "\x1b" "[2J");for(;;
) { float e=sin(A ), n= sin(B),g=cos(
A),m =cos(B);for(k =0;k< 1840;k++)y=-k
/80- 10,o=41+(k%80- 40)*1.3/y+n,N=
A-100.0/y, b[k]= ".#"[o+N&1],z[k] =0;E(
80-(int)(9*B)%250);for(j=0;6.28>j;j+=0.07 )for(
i=0;6.28>i;i+=0.02) { float c=sin(i),d =cos(j
),f=sin(j),h=d+2,D=15/(c*h*e+f*g+5 ),l=cos
(i),t=c *h*g-f*e;x=40+2*D*(l*h*m-t*n),y= 12
+D*(l*h *n+t*m),o=x+80*y,N=8*((f*e-c *d*
g)*m-c* d*e-f*g-l*d*n);if(D>z[o] )z[o]
=D,b[o] =" ..,,-++=#$@"[ N>0?N:0
] ; } printf(
"\x1b[" "H" );for(k =1;1841
>k;k++) putchar (k%80?b [k]:10)
; A += 0.053;B +=0.037 ; } }
+39
View File
@@ -0,0 +1,39 @@
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# Special flags for this entry
#
#CFLAGS=
# data files for this entry
#
DATA= altar box box2 box3 carpet circles cross cross2 cross3 \
crystal curve diamonds diamonds2 dragon dragon2 dragon3 \
fern gasket gasket_mod gasket_mod2 ioccc maze octagon \
pentagon pentagons rings rings2 spirals spirals2 spirals3 \
spirals4 squares stars stars2 tree tree2 tree3 tree4 triangle
build: ${ENTRY}
clean:
-${RM} ${ENTRY}
clobber: clean
alt:
data:
${ENTRY}: ${ENTRY}.c ${DATA}
${CC} ${CFLAGS} ${ENTRY}.c -o ${ENTRY}
+6
View File
@@ -0,0 +1,6 @@
3 0 0 1 1
-.5 0 0 .5 .5 0 .333
.5 0 0 .5 .5 0 .333
0 -.5 .5 0 .5 .5 .334
+5
View File
@@ -0,0 +1,5 @@
4 0 0 1 1
0 -.5 .5 0 .5 0 .25
.5 0 0 .5 0 .5 .25
-.5 0 0 .5 1 .5 .25
.333 0 0 .333 .33 .33 .25
+7
View File
@@ -0,0 +1,7 @@
5 0 0 1 1
0 -.5 .5 0 .5 0 .1
.5 0 0 .5 0 .5 .1
-.5 0 0 .5 1 .5 .1
-.5 0 0 -.5 1 .5 .1
.333 0 0 .333 .33 .33 .6
+6
View File
@@ -0,0 +1,6 @@
3 0 0 1 1
.5 0 0 .5 0 0 .333
.5 0 0 .5 .5 0 .333
0 -.5 .5 0 1 .5 .334
+3
View File
@@ -0,0 +1,3 @@
#To build
gcc prog.c -o prog
+9
View File
@@ -0,0 +1,9 @@
8 0 0 1 1
.3333333 0 0 .3333333 0 0 .125
.3333333 0 0 .3333333 0 .3333333 .125
.3333333 0 0 .3333333 0 .6666667 .125
.3333333 0 0 .3333333 .3333333 0 .125
.3333333 0 0 .3333333 .3333333 .6666667 .125
.3333333 0 0 .3333333 .6666667 0 .125
.3333333 0 0 .3333333 .6666667 .3333333 .125
.3333333 0 0 .3333333 .6666667 .6666667 .125
+15
View File
@@ -0,0 +1,15 @@
6 -.75 -.75 .75 .75
.1 0 0 .1 .5 0 .1667
.05 0 0 .05 .2 0 .1666
.76604444 .64278761 -.64278761 .76604444 0 0 .1667
.76604444 -.64278761 .64278761 .76604444 0 0 .1667
.01 0 0 .01 0 0 .1666
.30901699 .95105652 -.95105652 .30901699 0 0 .1667
.30901699 .95105652 -.95105652 .30901699 0 0 .25
.30901699 .95105652 -.95105652 .30901699 0 0 .25
-.80901699 .58778525 -.58778525 -.80901699 0 0 .25
-.80901699 -.58778525 .58778525 -.80901699 0 0 .25
+15
View File
@@ -0,0 +1,15 @@
5 -.5 -.5 .5 .5
.5 0 0 .2 .25 0 .4
.25 0 0 -.25 .125 0 .0
0 1 -1 0 0 0 .2
0 -1 1 0 0 0 .2
.70710678 .70710678 -.70710678 .70710678 0 0 .2
-1 0 0 -1 0 0 .0
// rotations
90
180
270
+17
View File
@@ -0,0 +1,17 @@
4 -.75 -.75 .75 .75
.5 0 0 .2 .25 0 .4
.25 0 0 -.25 .125 0 .0
0 1 -1 0 0 0 .2
0 -1 1 0 0 0 .4
.70710678 .70710678 -.70710678 .70710678 0 0 .0
-1 0 0 -1 0 0 .0
// rotations
90
180
270
+17
View File
@@ -0,0 +1,17 @@
4 -.75 -.75 .75 .75
.5 0 0 .2 .25 0 .4
.125 0 0 .125 .125 .125 .1
0 1 -1 0 0 0 .2
0 -1 1 0 0 0 .3
.70710678 .70710678 -.70710678 .70710678 0 0 .0
-1 0 0 -1 0 0 .0
// rotations
90
180
270
+7
View File
@@ -0,0 +1,7 @@
4 0 0 1 1
.255 0 0 .255 .3726 .6714 .25
.255 0 0 .255 .1145 .2232 .25
.255 0 0 .255 .6306 .2232 .25
.370 -.642 .642 .370 .6356 -.0061 .25
+5
View File
@@ -0,0 +1,5 @@
4 0 -.5 1 .5
.3333333 0 0 .3333333 0 0 .25
.1666667 -.289 .289 .1666667 .3333333 0 .25
.1666667 .289 -.289 .1666667 .5 .289 .25
.3333333 0 0 .3333333 .6666667 0 .25
+8
View File
@@ -0,0 +1,8 @@
5 0 0 1 1
.3333 0 0 .3333 .3333 .3333 .2
.3333 0 0 .3333 .3333 0 .2
.3333 0 0 .3333 0 .3333 .2
.3333 0 0 .3333 .6667 .3333 .2
.3333 0 0 .3333 .3333 .6667 .2
+17
View File
@@ -0,0 +1,17 @@
4 -.75 -.75 .75 .75
.5 0 0 .3 .25 0 .4
.25 0 0 -.25 .125 0 .0
0 1 -1 0 0 0 .2
0 -1 1 0 0 0 .4
.70710678 .70710678 -.70710678 .70710678 0 0 .0
-1 0 0 -1 0 0 .0
// rotations
90
180
270
+3
View File
@@ -0,0 +1,3 @@
2 -.5 -1 1.5 1
.5 -.5 .5 .5 0 0 .5
-.5 -.5 .5 -.5 1 0 .5
+3
View File
@@ -0,0 +1,3 @@
2 -.5 -.5 1.5 1.5
.5 -.5 .5 .5 0 0 .5
.5 .5 -.5 .5 .5 .5 .5
+3
View File
@@ -0,0 +1,3 @@
2 -7 -2 7 12
.824074 .281428 -.212346 .864198 -1.882290 -.110607 .8
.088272 .520988 -.463889 -.377778 .785630 8.095795 .2
+5
View File
@@ -0,0 +1,5 @@
4 -5.5 0 5.5 11
0 0 0 .16 0 0 .01
.85 .04 -.04 .85 0 1.6 .85
.2 -.26 .23 .22 0 1.6 .07
-.15 .28 .26 .24 0 .44 .07
+4
View File
@@ -0,0 +1,4 @@
3 0 0 1 1
.5 0 0 .5 0 0 .33
.5 0 0 .5 .5 0 .33
.5 0 0 .5 .25 .433 .34
+5
View File
@@ -0,0 +1,5 @@
4 0 0 1 1
.5 0 0 .5 0 0 .25
.5 0 0 .5 .5 0 .25
.5 0 0 .5 .25 .5 .25
.25 0 0 .25 .375 .25 .25
+8
View File
@@ -0,0 +1,8 @@
4 0 -0.05 1.05 1
.5 0 0 .5 0 0 .25
.5 0 0 .5 .5 0 .25
.5 0 0 .5 .25 .433 .25
.15556349 -.15556349 .15556349 .15556349 .475 .18 .25
// a .22 scale and 25 degrees
.19938771 -.092976018 .092976018 .2265 .43 .21 .25
+159
View File
@@ -0,0 +1,159 @@
# Best Computed Graphics
Thomas Stewart
US
## Judges' Comments:
### To build:
make stewart
### Try:
stewart 640 480 FILE
where FILE is one of:
altar box box2 box3 build carpet circles cross cross2 cross3
crystal curve diamonds diamonds2 dragon dragon2 dragon3
fern gasket gasket_mod gasket_mod2 ioccc maze octagon
pentagon pentagons rings rings2 spirals spirals2 spirals3
spirals4 squares stars stars2 tree tree2 tree3 tree4 triangle
Note the interesting choice of using a #define in the output.
The selection of input files makes this one endlessly fun to play
with. Many image viewers will be able to read the results, as will
a reasonably experienced user who can parse formats in their mind. :-)
## Selected Author's Comments:
### Execution
The program should be run with the following
prog <m> <n> <ifs>
m = The size of the picture (picture will be m X m in size).
n = The number of iterations to run (More will make for a
clearer picture).
ifs = The file to use as input.
The program will spit out a xbm image on standard out.
Minimal checking is done on the arguments mainly that there are 3.
Wrong arguments will cause the program to bomb out.
Ex:
./stewart 1024 1000000 gasket > gasket.xbm
### Compilation/Testing
The program compiles without warning with gcc -ansi -Wall.
lint also seems to like the code. This must be a bug in lint.
The program was tested on Linux on a x86 and NetBSD on an alpha.
Only gcc was tested for compilers (4.0.3 and 3.3.3)
### Entry originality
In looking through past winners. THere seem to be only 2 (92 and 94)
that generated fractals. Both of those were Julia fractals from the
Mandlebrot set. Those do make for some pretty pictures. I figured
it would be nice to add some more fractals to the IOCCC, since one
hasn't won since 1994.
Instead of something that has already won I figured I would go with
another kind of fractal, those from the Iterated Function System (IFS).
### Input File
The format of the input file is as follows:
<num ifs> <x min> <y min> <x max> <y max>
<a> <b> <c> <d> <e> <f> <p>
<a> <b> <c> <d> <e> <f> <p>
<a> <b> <c> <d> <e> <f> <p>
.
.
.
This file describe an IFS.
One of the most well known would be the Sierpinski Gasket:
3 0 0 1 1
.5 0 0 .5 0 0 .33
.5 0 0 .5 .5 0 .33
.5 0 0 .5 .25 .433 .34
or the fern:
4 -5.5 0 5.5 11
0 0 0 .16 0 0 .01
.85 .04 -.04 .85 0 1.6 .85
.2 -.26 .23 .22 0 1.6 .07
-.15 .28 .26 .24 0 .44 .07
etc...
Included in my submission will be a tar ball of some ifs files,
including one that attempts (not very well) to mimic the IOCCC logo
(I figure it can't hurt to attempt to suck up, right?)
I would try to explain how to create an IFS file but I am not smart
enough to condense it down to something that is coherent.
Basically the break down is:
num is the number of equations in the IFS.
x (min, max) and y (min, max) define the ranges that will be displayed
in the xbm.
The a b c d e f are used to iterative find points that lie in the IFS
from the algorithm
x = a * prevx + b * prevy + e;
y = c * prevx + d * prevy + f;
The p is for the probability that the equation will run.
### Obfuscations
The main obfuscation is using a void* as my only variable (aside from
the args for main). This causes me to do much casting and porinter
arithmetic to get the correct location and completely does away with
any meaning the variables could have. This also makes the code more
convientient to read in the current form vs preprocessed. After
preprocessing there will almost be 300 casts in the code and I believe
they are all needed... (I would double check but my brain is kinda
mushy right now from chasing down a segfault in the code.)
The other main obfuscation being that it generates an IFS. Which isn't
all that common for a program to do. I mean google only has something
like 66,000 hits for "Iterated function system" so that means it is
obscure, right?
Some other minor obfuscations:
Since I formatted it as a "normal" program I did inject something that
on first glance will looks like a possible bug. (When you run it through
a c-beautifier this will be removed.)
I decided not to use rand() to generate a pseudo random number. Instead
I use xor and bit shifting.
The input file is used to make the program flexible and to allow it to
generate many different IFSs. This has the added bonus of hiding
information about the algorithm.
The use of many magic numbers. I figured if I get yelled about them in
a review they must be bad, right?
Silly things:
The use of decimal numbers where one would expect hex. Octal numbers
where one would expect decimal. Shifts instead of devides.
Using xbm as the output format. This might confuse someone who doesn't
have an X background. It happens to be easy but is probably a very bad
choice from a filesize standpoint. 1024x1024 image is 641k in size.
+18
View File
@@ -0,0 +1,18 @@
14 -.5 -3.5 10.5 7.5
0 .25 .4 0 0 0 .071428571
.09 0 0 .24 2.25 3 .071428571
.09 0 0 .24 2.25 0 .071428571
0 .25 .2 0 1.5 1 .071428571
0 .25 .2 0 3 1 .071428571
.09 0 0 .24 5 3 .071428571
.09 0 0 .24 5 0 .071428571
0 .25 .2 0 4.5 1 .071428571
.09 0 0 .24 7 3 .071428571
.09 0 0 .24 7 0 .071428571
0 .25 .2 0 6.5 1 .071428571
.09 0 0 .24 9 3 .071428571
.09 0 0 .24 9 0 .071428571
0 .25 .2 0 8.5 1 .071428571
+6
View File
@@ -0,0 +1,6 @@
3 0 0 1 1
.3333333 0 0 .3333333 .3333333 .6666667 .3333333
0 .3333333 1 0 .6666667 0 .3333333
0 -.3333333 1 0 .3333333 0 .3333333
+13
View File
@@ -0,0 +1,13 @@
3 -.75 -.75 .75 .75
.01 0 0 .4 .3 0 .33
.76604444 .64278761 -.64278761 .76604444 0 0 .33
.76604444 -.64278761 .64278761 .76604444 0 0 .34
.30901699 .95105652 -.95105652 .30901699 0 0 .25
.30901699 .95105652 -.95105652 .30901699 0 0 .25
.30901699 .95105652 -.95105652 .30901699 0 0 .25
-.80901699 .58778525 -.58778525 -.80901699 0 0 .25
-.80901699 -.58778525 .58778525 -.80901699 0 0 .25
+6
View File
@@ -0,0 +1,6 @@
5 -.4 -.25 1.6 1.75
.382 0 0 .382 0 0 .2
.382 0 0 .382 .618 0 .2
.382 0 0 .382 .809 .588 .2
.382 0 0 .382 .309 .951 .2
.382 0 0 .382 -.191 .588 .2
+9
View File
@@ -0,0 +1,9 @@
4 -.75 -.75 .75 .75
.5 0 0 .4 .25 0 .25
.30901699 .95105652 -.95105652 .30901699 0 0 .25
-.80901699 .58778525 -.58778525 -.80901699 0 0 .25
-.80901699 -.58778525 .58778525 -.80901699 0 0 .25
+9
View File
@@ -0,0 +1,9 @@
4 -.5 -.5 .5 .5
.5 0 0 -.5 0 -.25 .2
-.5 -.8660254 .8660254 -.5 0 0 .3
.25 0 0 -.25 0 .125 .2
-.5 .8660254 -.8660254 -.5 0 0 .3
+13
View File
@@ -0,0 +1,13 @@
4 -.75 -.75 .75 .75
.1 0 0 .1 .3 0 .25
.76604444 .64278761 -.64278761 .76604444 0 0 .25
.76604444 -.64278761 .64278761 .76604444 0 0 .25
.30901699 .95105652 -.95105652 .30901699 0 0 .25
.30901699 .95105652 -.95105652 .30901699 0 0 .25
.30901699 .95105652 -.95105652 .30901699 0 0 .25
-.80901699 .58778525 -.58778525 -.80901699 0 0 .25
-.80901699 -.58778525 .58778525 -.80901699 0 0 .25
+4
View File
@@ -0,0 +1,4 @@
3 -8 -3 8 13
0.787879 -0.424242 0.242424 0.859848 1.758647 1.408065 0.90
-0.121212 0.257576 0.151515 0.053030 -6.721654 1.377236 0.05
0.181818 -0.136364 0.090909 0.181818 6.086107 1.568035 0.05
+18
View File
@@ -0,0 +1,18 @@
2 -.75 -1 1.25 1
.25 0 0 .25 .75 0 .49
.77942286 .45 -.45 .77942286 0 0 .49
-.45 .77942286 -.77942286 -.45 0 0 .1
.76604444 .64278761 -.64278761 .76604444 0 0 .1
.76604444 -.64278761 .64278761 .76604444 0 0 .1
.01 0 0 .01 0 0 .1
.30901699 .95105652 -.95105652 .30901699 0 0 .1
-.37460659 -.92718385 .92718385 -.37460659 0 0 .1
.99026807 -.1391731 .1391731 .99026807 0 0 .1
.8480481 .52991926 -.52991926 .8480481 0 0 .1
1 0 0 -1 0 0 .1
-.80901699 .58778525 -.58778525 -.80901699 0 0 .25
-.80901699 -.58778525 .58778525 -.80901699 0 0 .25
+21
View File
@@ -0,0 +1,21 @@
5 -1 -1 1 1
.333 0 0 .333 .6 -.6 .25
-.3 0 0 -.3 -.25 -.75 .25
.7517541 .27361611 -.27361611 .7517541 0 0 .5
.77036162 .35922552 -.35922552 .77036162 0 0 .5
.7878462 .13891854 -.13891854 .7878462 0 0 .5
.8 0 0 .8 0 0 .2
.70710678 .70710678 -.70710678 .70710678 0 0 .2
.70710678 -.70710678 .70710678 .70710678 0 0 .2
-.70710678 .70710678 -.70710678 -.70710678 0 0 .2
-.70710678 -.70710678 .70710678 -.70710678 0 0 .2
-1 0 0 -1 0 0 .0
// rotations
20 * .8
25 * .85
10 * .8
270
+23
View File
@@ -0,0 +1,23 @@
5 -1.1 -1.5 1.1 .5
.333 0 0 .333 .6 -.6 .25
-.060776862 -.34468271 .34468271 -.060776862 -.75 -.85 .25
.72504623 .33809461 -.33809461 .72504623 0 0 .5
.77036162 .35922552 -.35922552 .77036162 0 0 .5
.7517541 .27361611 -.27361611 .7517541 0 0 .5
.7878462 .13891854 -.13891854 .7878462 0 0 .5
.8 0 0 .8 0 0 .2
.70710678 .70710678 -.70710678 .70710678 0 0 .2
.70710678 -.70710678 .70710678 .70710678 0 0 .2
-.70710678 .70710678 -.70710678 -.70710678 0 0 .2
-.70710678 -.70710678 .70710678 -.70710678 0 0 .2
-1 0 0 -1 0 0 .0
// rotations
25 * .8
25 * .85
20 * .8
10 * .8
270
full window
+8
View File
@@ -0,0 +1,8 @@
5 0 0 1 1
.4 0 0 .4 0 0 .2
.4 0 0 .4 0 .6 .2
.4 0 0 .4 .6 0 .2
.4 0 0 .4 .6 .6 .2
.2 0 0 .2 .4 .4 .2
+6
View File
@@ -0,0 +1,6 @@
3 0 0 1 1
.5 0 0 .5 .25 .25 .333
0 .35 .75 0 0 .125 .333
0 .35 .75 0 .65 .125 .334
+9
View File
@@ -0,0 +1,9 @@
4 -.75 -.75 .75 .75
.5 0 0 .2 .3 0 .25
.30901699 .95105652 -.95105652 .30901699 0 0 .25
-.80901699 .58778525 -.58778525 -.80901699 0 0 .25
-.80901699 -.58778525 .58778525 -.80901699 0 0 .25
+65
View File
@@ -0,0 +1,65 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define P printf
#define F(x,y) ((FILE*)Z(x,y))
#define U(x,y) ((unsigned char*)Z(x,y))
#define X(x,y,z) ((double*)x+y+7*z)
#define Y(x,y) ((double*)x+y)
#define Z(x,y) *(long*)Y(x,y)
#define R(x,y) (x=y,y^=(y<<11),y^=(y>>15),y^=(y<<3),(x+y)&0x7fffffff)
int main(int c,char**o)
{
void* v=malloc(0170UL);
memset(v,0,0170UL);
if(c!=4)P("bad args\n"),exit(1);
Z(v,2)=atoi(o[1]);
Z(v,1)=atoi(o[2]);
Z(v,0)=Z(v,2)*Z(v,2)>>3;
Z(v,6)=(long)malloc(Z(v,0));
memset((void*)Z(v,6),0,Z(v,0));
Z(v,13)=(long)fopen(o[3],"r");
fscanf(F(v,13),"%ld",(long*)Y(v,3));
Z(v,8)=(long)malloc(050+Z(v,3)*070);
Z(Z(v,8),0)=Z(v,3);
fscanf(F(v,13),"%lf %lf %lf %lf",Y(Z(v,8),1),Y(Z(v,8),2),Y(Z(v,8),3),Y(Z(v,8),4));
for(Z(v,3)=0;Z(v,3)<Z(Z(v,8),0);
fscanf(F(v,13),"%lf %lf %lf %lf %lf %lf %lf",X(Z(v,8),5,Z(v,3)),
X(Z(v,8),6,Z(v,3)),X(Z(v,8),7,Z(v,3)),X(Z(v,8),8,Z(v,3)),
X(Z(v,8),9,Z(v,3)),X(Z(v,8),10,Z(v,3)),X(Z(v,8),11,Z(v,3))),
++Z(v,3));
fclose(F(v,13));
Z(v,14)=8675309;
for(Z(v,3)=0;Z(v,3)<Z(v,1);++Z(v,3))
{
*Y(v,7)=(R(Z(v,4),Z(v,14))/(double)0x7fffffff),Z(v,5)=0;
for(Z(v,4)=0;Z(v,4)<Z(Z(v,8),0);++Z(v,4),++Z(v,5))
if(*Y(v,7)<*X(Z(v,8),11,Z(v,5)))
break;
else
*Y(v,7)-=*X(Z(v,8),11,Z(v,5));
*Y(v,11)=*X(Z(v,8),5,Z(v,5))**Y(v,9)+*X(Z(v,8),6,Z(v,5))**Y(v,10)+*X(Z(v,8),9,Z(v,5));
*Y(v,12)=*X(Z(v,8),7,Z(v,5))**Y(v,9)+*X(Z(v,8),8,Z(v,5))**Y(v,10)+*X(Z(v,8),10,Z(v,5));
*Y(v,9)=*Y(v,11);
*Y(v,10)=*Y(v,12);
if(Z(v,3)>10)
if((*Y(v,9)>=*Y(Z(v,8),1))&&(*Y(v,9)<=*Y(Z(v,8),3))&&(*Y(v,10)>=*Y(Z(v,8),2))&&(*Y(v,10)<=*Y(Z(v,8),4)))
*Y(v,11)=(*Y(v,9)+-*Y(Z(v,8),1))/(*Y(Z(v,8),3)-*Y(Z(v,8),1)),
*Y(v,12)=(*Y(v,10)+-*Y(Z(v,8),2))/(*Y(Z(v,8),4)-*Y(Z(v,8),2)),
*(U(v,6)+((((long)(Z(v,2)-*Y(v,12)*Z(v,2))*Z(v,2))+(long)(*Y(v,11)*Z(v,2)))>>3))|=
1<<((((long)(Z(v,2)-*Y(v,12)*Z(v,2))*Z(v,2))+(long)(*Y(v,11)*Z(v,2)))&7);
}
P("#define x_width %ld\n#define x_height %ld\nstatic char x_bits[] = {\n",Z(v,2),Z(v,2));
for(Z(v,3)=0;Z(v,3)<Z(v,0);++Z(v,3))
{
if(Z(v,3))
P(",");
P("0x%02x",*(U(v,6)+Z(v,3)));
}
P("};\n");
free(Y(Z(v,6),0));
free(Y(Z(v,8),0));
free(v);
return 0;
}
+5
View File
@@ -0,0 +1,5 @@
4 -.25 0 .25 .5
0 0 0 .5 0 0 .05
.42 -.42 .42 .42 0 .2 .4
.42 .42 -.42 .42 0 .2 .4
.1 0 0 .1 0 .2 .15
+8
View File
@@ -0,0 +1,8 @@
7 -1 -1 1 1
0.0500 0.0000 0.0000 0.4000 -0.0600 -0.4700 .14285714
-0.0500 0.0000 0.0000 -0.4000 -0.0600 -0.4700 .14285714
0.0300 -0.1400 0.0000 0.2600 -0.1600 -0.0100 .14285714
-0.0300 0.1400 0.0000 -0.2600 -0.1600 -0.0100 .14285714
0.5600 0.4400 -0.3700 0.5100 0.3000 0.1500 .14285714
0.1900 0.0700 -0.1000 0.1500 -0.2000 0.2800 .14285714
-0.3300 -0.3400 -0.3300 0.3400 -0.5400 0.3900 .14285714
+6
View File
@@ -0,0 +1,6 @@
3 0 0 1 1
0 -.5 .5 0 .5 0 .3333333
0 .5 -.5 0 .5 .5 .3333333
.5 0 0 .5 .25 .5 .3333334
+14
View File
@@ -0,0 +1,14 @@
10 -.75 -.75 .75 .75
.5 0 0 .5 .25 0 .15
.5 0 0 .5 0 0 .15
.25 0 0 .75 .25 0 .2
0 .1 -.8 0 0 0 .2
0 -.1 .8 0 0 0 .1
.5 0 0 1 0 0 .1
.5 0 0 1 0 0 .1
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
+4
View File
@@ -0,0 +1,4 @@
3 0 0 1 1
.5 0 0 .5 0 0 .33
.5 0 0 .5 0 .5 .33
.5 0 0 .5 .5 0 .34
+39
View File
@@ -0,0 +1,39 @@
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# Special flags for this entry
#
LOCAL_FLAGS= -Wall -W -ansi -O3 --unroll-loops
# data files for this entry
#
DATA=
build: ${ENTRY} ${ENTRY}.html
clean:
-${RM} ${ENTRY} ${ENTRY}.html
clobber: clean
alt:
data:
${ENTRY}: ${ENTRY}.c ${DATA}
${CC} ${CFLAGS} ${LOCAL_FLAGS} ${ENTRY}.c -o ${ENTRY}
${ENTRY}.html: ${ENTRY}.c
${RM} ${ENTRY}.html
cp ${ENTRY}.c ${ENTRY}.html
+198
View File
@@ -0,0 +1,198 @@
# Best Assembler
Stephen Sykes
Itäinen koulupolku
Kauniainen
Finland
<http://www.stephensykes.com>
## Judges' Comments:
### To build:
make sykes1
### To run:
./sykes1
next point your browser to the file:
sykes1.html
in the same directory. Next try:
./sykes1 10
and refresh your browser. Now read the sykes1.html page source.
Now then read the C source. Confused? :-)
For extra credit, understand what happens when you give this entry
an negative number argument, and why.
## Selected Author's Comments:
This cube shaped program solves the fiendishly difficult "Bedlam Cube"
If you did not get one for Christmas, there is an article about these
puzzles in wikipedia:
> <http://en.wikipedia.org/wiki/Bedlam_cube>
There is also website dedicated to them - <http://www.bedlampuzzles.com>
And some instructions on how to make your own cube here:
<http://ch.twi.tudelft.nl/~sidney/puzzles/downloads/bedlam-pieces.pdf>
Finally, you can watch it being solved here:
> <http://www.youtube.com/watch?v=eDpC7oKQJIQ>
Actually the cube is very hard to do by hand by just trying to fit it
together. I have not known anyone to solve it in this way - you would
need to be very lucky indeed to stumble across a solution.
### Instructions
Compile the program, then test that it works:
./sykes1
Shortly you should see the first solution pop out on your screen. It
shows you how to build the cube piece by piece, rendered in glorious
3d ascii.
Ascii art is all very well, but you also have a web browser, right?
Well, just open the file sykes1.html. This html file is just a copy
of prog.c, which helpfully contains an html document that should make
the browser display for you a nice animated gif, showing you how to
build the cube. Rendered in glorious 3d color.
Want to see another solution? Try:
./sykes1 some_number
The program will discard solutions up to the number, and output numbered
solution. Refresh your browser window to see the new solution.
Try some more - there are exactly 19186 solutions to choose from.
If you have a fast machine you might try the last solution:
./sykes1 19186
On my machine this takes about half an hour to run.
### Implementation
The implementation is an optimized recursive algorithm that tries to fit
the pieces into the cube one by one. The cube pieces are defined near
the start of the program:
int s[ ] = { 186, 94, 1426, 3098
,1047 , 122 , 1082 , 3083 , 1039
, 569 , 527 , 1054 , 531 } ;
Each piece is a bitmap, and represents a 3x3x3 cube.
For instance the first piece is 186 - this is 010111010 in binary.
Written out like this you can see that it is the cross shaped piece:
010
111
010
The other pieces are defined similarly. Most of the rest require more
than one layer, such as piece 3 (1426):
000
000
010
110
010
010
Imagine the two layers on top of each other, and you should see this
shape:
+---------+
/ +----+ /|
+-/ /| / |
|+----+ |/ +
|| | + /
+| | /
| | /
| | /
| |/
+----+
The program is in fact a general solver - you can change the shape of
the pieces, and provided that a solution is possible, it will be found.
For example, if you modify line 13 of the source like this, the program
will solve for a different piece set:
int s[ ] = { 187, 94, 402, 3098
And of course you can make your own.
After the pieces are defined, the first thing the program does it to
fit them into a 4x4 cube. It collects every possible placing of each
of the pieces.
Once those placings are ready, the program recursively checks each
combination thereof.
In order to complete in a reasonable time, care is take to eliminate
any branches that cannot result in a solution. This is done by checking
after each placing if all the remaining pieces can be placed somewhere,
and that all the free space in the cube can be filled by at least one
viable placing. Also if a piece is found to only have one possible
placing, it is placed immediately without invoking a recursive function
call.
Once the solution is found, the ascii and gif representations are
generated. Care must be taken to render cubes in the right order such
that pieces further back are occluded by those in front.
In the ascii output care must be taken with drawing the edges of each
1/64th cube (edges must be removed within each piece). In the gif
this is taken care of by color, which is graded from the back to the
front to ensure edge visibility.
### Notes
The whole program has just one function - main - which is recursively
called. In fact if you select solution 19186 it will be called exactly
159,260,759 times.
If you pick a number higher than 19186, the program will return a
solution but it will be a rotation of one of the first 19186. This is
because the cross shaped piece fits 48 ways in the 4x4 cube, but only
2 of those ways are unique - you can rotate one of those to make any
of the other 46. The algorithm used always places the cross piece
first, so the first two placings of that piece result in the 19186
unique solutions.
If you pick a number higher than 460464 (24x19186) the program will
return without outputting a solution. If you can wait that long.
I recommend compiling with the most aggressive optimization options
your compiler supports. I find --unroll-loops to be helpful with gcc.
The program relies on long long being 64 bits, but has no other special
requirements.
The program is known to compile and run under gcc and intel cc, as well
as PellesC on Windows.
### Bugs
The program is not at all a valid html document, but fortunately
browsers have good error recovery and amongst other things will ignore
the /* at the beginning, and won't mind the missing html and head tags
and the lack of end tags.
The generated gif is not compressed. This could be argued as an
advantage - at least I don't violate any of those old Unisys patents!
The pieces aren't really those colors. Unless you make your own.
+94
View File
@@ -0,0 +1,94 @@
/* <body bgcolor = 0 >
<img src= cube.gif><!-- */
#define _ ] [ /* ; ; ; ; */
#include <string.h> /* ; ; */
#include <stdio.h> /* ; ; ; */
#define K(o,O) L o=0; o<O ; o++)
#define H unsigned long long
#define /* ; ; ; ; ; ; } */ W ]=
#define /* ; ; ; ; ; ; */ L for(
#define /* ; ; ; ; ; ; */ J if (
#include <stdlib.h> /*; ; ; ; */
#define Z (j*3+j/9*3+2)%10+j/9*9
int s[ ] = { 186, 94, 1426, 3098
,1047 , 122 , 1082 , 3083 , 1039
, 569 , 527 , 1054 , 531 } ;
#define P( o , O ,l) K(C,o)\
fputc ( ( O )[ C ] -l, G);
#define Y strncpy( /* */
int j,k,l,v,c,C,O[64],n[
64],*o,q[13 _ 13],u,d,f,g[
W{ 8,7,6,6,6,6 } ; H p [13 _
#define M memset(E[c]+j*298+v\
*a+88-u*5+586*( u*5+152-i/16*a+C
13 _ 432],r,w,t,b,S[13]; FILE*G;
char E[13 _ 168840],*A="||||||",
*D=" { ; wb; aa; aaaa}a \
0z00Zzz} { z0z} ",Q[64 _ 60
],*F ="+ +",T [43]; int main(
int I,char**V){ int i,h,B,a,m; H
#define R(z){ x=h=0; K(j,27)h|=\
(c>> j&1 )<<z ; ; ; } c=h; ; ; ;
x; J I>1)B=C=atoi(V[1]); J !d)K(
v,13){ h=s[v]; J B<0){ k=h>>18
^h&511; h^= k<<18|k; C=-C; }
K(k,7){ J k==4)R(Z)R(j+(j-
" /@"[j/9]+38)/3*6-6)K(l
,4){ R(Z)K(a,9) x|=((H)c
>>a*3&7)<<a*4 +a/3*4; K(a,
96){ m=a-37; r=m<0?x>>-m:x<<
m; J!(x!=(m<0?r<<-m:r>>m)||r&r
/2&0x888888888888888ULL||r&r>>4&
0xF000F000F000ULL)){ p[0 _ v _ q
[v _ 0]++W r; K(j,q[v _ 0]-1)J p
[0 _ v _ j]==r)q[v _ 0]--; } } }
} } h=d; x=w; m=q[f _ h]; a=f; u
|=1<<a; B=u; K(i,m){ w|=S[a W p[
d _ a _ i]; r: d++; v=*s; t=w; L
j=1; j<13; j++){ J u>>j&1^1){ b=
c=k=0; l=q[j _ h]; L; k<l; k++){
r=p[h _ j _ k]; J!(w&r))b|=p[d _
j _ c++W r; } J!c) goto n; J c
==1){ w|=S[j W b; u|=1<<j; J
d==12){ J--C<1){ K(c,64)O[
c W-1; x=0; K(c,13){ r=~
0; K(j,13)J S[j]<r&&S[j]
>x)r=S[j]; K(i,64){ n[i W-
1; memset(Q[i],32,59); } K(i
,64){ J r>>i&1)O[i W n[i W c ;
K(j,2){ o=j?O:n; k=o[i]; u=i&d ;
v=i&3; a=48; J k+1){ C=k==c; Y T
,"+----+/ /|+----+ || | +\
| |/+----+",43); J!C&&v&&o[i-
1]==k)T[6 W T[21 W T[29 W 32 ; J
u&&o[i-4]==k){ Y T,C?"//////":F,
6); J v==3||o[i-3]<0)T[d W T [20
W C?47:32; } J i&a&&o[i-16]==k){
J u==d||o[i-d]<0)Y T+36,C?A:F,6)
; J!C)J v==3|| o[i-15]<0) T[35 W
32; } J C){ Y T+7,"////",4); T
[19 W T[27 W 47; Y T+22,A,4)
; Y T+30,A,4); } K(C,6)Y Q
[9-i/16*3+u/2+C]+v*5-u/2
+j*30+g[C],T+"06=EMT"[C]
-a,20-g[C]-g[5-C]); K(C,a)
{ M)+28,m=k+33,h=20); M+h)-h
,k+49+u/4*16,a); } K(C,h){ M)-
C,k+17,a); M)+a-C,m,C); M+a)+28,
m,h-C); } } } } K(i,21)puts(Q[i]
); x=r; } G=fopen("cube.gif", D+
11); P(13,"qspbc\213t,J+ **",42)
K(i,8)P(a,D,h+" H Zbjm "[i]+C)P(
19,"F$0sjyxhfujWSU(&%%%",37)K(i,
13){ P(19,"K#.3 ***V****t,J+*1",
42)K(j,1340){ P(2," !",161)P(126
,E[i]+j*126,0)}P(3+i/d,"!\241 ["
,32 ) } exit(0); } goto n; }else
goto r; } J c<v) { f=j; v=c; }
q[j _ d W c; t|=b; } } J!~t)
main(0,0); n:u=B; w=x; d=h
; } u^=1<<a ; } /*--> */
+35
View File
@@ -0,0 +1,35 @@
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# Special flags for this entry
#
#CFLAGS=
# data files for this entry
#
DATA=
build: ${ENTRY}
clean:
-${RM} ${ENTRY} ${ENTRY}.html
clobber: clean
alt:
data:
${ENTRY}: ${ENTRY}.c ${DATA}
${CC} ${CFLAGS} ${ENTRY}.c -o ${ENTRY}
+53
View File
@@ -0,0 +1,53 @@
# Best One Liner
Stephen Sykes
Itäinen koulupolku
Kauniainen
Finland
<http://www.stephensykes.com>
## Judges' Comments:
### To build:
make sykes2
### To run:
./sykes2
Then "Lather, rinse, repeat":
while :; do
clear
rm -f sykes2
make sykes2
./sykes2
sleep 1
done
If you have the time, figure out how this small 1-line entry works!
## Selected Author's Comments:
At 130 characters of C code (without the newline at the end), this
should fit into the "1-liner" category.
The clock numerals are rendered as an old fashioned 7 segment display.
The encodings for which segments light for which number, and for where
each segment appears on screen are hidden in the two strings.
When reading the program, you may want to refer to a table of
operator precedence - careful choices were made to keep the usage of
brackets to a minimum, and to keep the character count as low as
possible.
One interesting bit of obfuscation - the null at the end of the second
string actually forms part of the lookup table.
Intel CC warns about the lack of a declaration for the argument to main.
(gcc does not notice this though, even with -Wall.) But anyway it can
easily be declared as int at the expense of 4 more characters.
I'm not sure of the effects on a hard disk of rewriting the same file
multiple times per second for a long time. Run at your own risk!
+1
View File
@@ -0,0 +1 @@
main(_){_^448&&main(-~_);putchar(--_%64?32|-~7[__TIME__-_/8%8][">'txiZ^(~z?"-48]>>";;;====~$::199"[_*2&8|_/64]/(_&2?1:8)%8&1:10);}
+35
View File
@@ -0,0 +1,35 @@
# 2006 makefile
#
# Copyright (C) 2006-2009, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# Special flags for this entry
#
#CFLAGS=
# data files for this entry
#
DATA=
build: ${ENTRY}
clean:
-${RM} ${ENTRY}
clobber: clean
alt:
data:
${ENTRY}: ${ENTRY}.c ${DATA}
${CC} ${CFLAGS} ${ENTRY}.c -o ${ENTRY}
+43
View File
@@ -0,0 +1,43 @@
# Best Small Program
Oscar Toledo
Av. Santa Cruz del Monte 9-304
Ciudad Satelite. Edo. de Mexico
CP. 53110
Mexico
## Judges' remarks:
### To build:
make toledo1
### Try:
./toledo1 00
./toledo1 30
./toledo1 99
For most of the arguments (e.g. those above) the resulting path
is not circular, but at least one starting point yields a circular path.
Why do some of the "illegal" starting points work more or less as could
be expected, and some dump core?
## Author's comments:
Can you place a knight on a chess board and make it
to visit the 64 squares without repeating them?
If not, this program does it, just run it with an argument
giving initial position.
./toledo1 11 (start is A8)
./toledo1 18 (start is H8)
./toledo1 81 (start is A1)
./toledo1 88 (start is H1)
./toledo1 44 (start is D5)
It will print move order. The algorithm is so simple that you can read
it on the source code, at the first glance it can appear checkered :-)
but don't dismail, jar, jar.
+17
View File
@@ -0,0 +1,17 @@
char *e,t [366 ],*f
,*g, *h,* i;d, m ;
main (c,b) char **b;{
for( ;d[t] =d%3 ?60<d
&300 >d&6 <d % 30?0
:32: d%30 ?32: 10 ,
366> ++d;) ;for (g=3*
atoi (*++ b) + 34+t;
i=f= "\1" "\7" "(d"
"\177" "yX" "\34" ,e=g
; ) for( *e++ =++m/
10 + 48,g =c=0 ,*e =
48+m %10; h=e- 65+*
i,d= *h,* i++; f-=8
,g=d <c?c =d,h: g)for
(; d -=!! h[*f ++-64
],*f ;) ; puts (t);}
Loaded 100 of 1683 files, more files were not shown because too many files have changed in this diff. Show more