Implementation of the UM-32 "Universal Machine" as described by the Cult of the Bound Variable
1;
2; cat.asm
3;
4; Read from stdin and echo to stdout.
5;
6main:
7 ; set r2 to 0xffffffff
8 nand r2
9
10 ; setup branches
11 adr r6, output
12 adr r5, loop
13
14loop:
15 ; read stdin, r1 will contain 0xffffffff if we've reached EOF.
16 in r1
17
18 ; set r3 to 0 if r2 == r1
19 nand r3, r2, r1
20
21 ; setup branch
22 adr r4, end
23 ; overwrite r4 with $output iff r3 == 0.
24 mov r4, r6, r3
25 jmp [r0, r4]
26
27output:
28 ; write to stdout
29 out r1
30 jmp [r0, r5]
31
32end:
33 halt