WDR paper computer whimsy

Joined
Sep 20, 2022
Messages
317
Reaction score
41
Code:
;slinky0
;Endlessly move register 0 to register 1 and back again.
jmp 3
dec 0
inc 1
isz 0
jmp 1
jmp 8
dec 1
inc 0
isz 1
jmp 6
jmp 0
There was an 8086 assembler called A86 which had a good idea about labels.

There are many jumps in low level programming, and they don't all need unique meaningful names.

>frog refers to the first frog label after the current line, <frog refers to the last frog label before the current line.

This kind of system really pays off when expanding macros that have internal jumps.
Code:
;slinky1
start:
jmp >wend
while:
  dec 0
  inc 1
wend:
isz 0
jmp <while
jmp >wend
while:
  dec 1
  inc 0
wend:
isz 1
jmp <while
jmp start
 
Last edited:
Joined
Sep 20, 2022
Messages
317
Reaction score
41
Code:
;slinky2

MACRO LEFT 0
MACRO RIGHT 1

MACRO {MOVE}
;add reg %0 to reg %1
;clear reg %0
jmp >L01
L02:
dec %0
inc %1
L01:
isz %0
jmp <L02
END

main:
{MOVE}(LEFT,RIGHT)
{MOVE}(RIGHT,LEFT)
jmp <main
The reason I use {} braces inside some macro names is because my macros are just text search and replace.

If I used MOVE and MOVE1, there could be a problem.

{MOVE} and {MOVE1} will never clash.

I got the %0,%1,... idea from MS-DOS batch files.
 
Joined
Sep 20, 2022
Messages
317
Reaction score
41
Since jump arguments can only be constants, implementing nestable CALLs and RETURNs is going to be ugly.

I'm thinking a CALL macro could push the return line onto a register, jump to the subroutine, and the subroutine jumps to a general return routine when finished.

The return routine would pop the line number and jump back to the call. Basically a large IF ELSEIF statement, and needs to be hardcoded to handle every CALL. The preprocessor can do that.

The hardest thing about this language so far, is assigning a large constant to a register.
 
Joined
Sep 20, 2022
Messages
317
Reaction score
41
Its a nice little language. The 5 primitive instructions can build the usual "counter machine" instructions, INC, DEC, CLR, CPY, JE, JZ.

A quine program is possible, my version is over 256^144 lines long, which I can't test, clearly.

Since there's no output instruction, I defined the quine as a program that can load its own Godel number into a register.
 
Joined
Sep 20, 2022
Messages
317
Reaction score
41
Can anyone see a logic error in this pseudocode?
Code:
;Quine pseudocode.
;Godel encoding:
;  1 inc
;  2 dec
;  3 isz
;  4 jmp
;  5 stp
;
;example using base 256:
;  jmp 100
;  stp
;  {4,100,5}
;  4*256^2 + 100*256 + 5
;
;start of phi
line0:
jump to omega
line1:
copy reg0 to reg1
loop reg1 times
  reg0 *= 256
  reg0 += 1 ; "inc"
  reg0 *= 256
  reg0 += 0 ; "0"
reg0 *= 256
reg0 += 4 ; "jmp"
reg0 *= 256
reg0 += 1 ; "1"
stop ; end of phi
omega:
inc 0
inc 0
inc 0
...
jump to line1 ; "jmp 1"
Phi is roughly 72 instructions (I will spare the forum the details). The number of "inc" instructions in omega is equal to the Godel number of phi (This is why the program is so big).

When the program stops, register 0 holds the Godel number of the entire program. I think.

I don't need to use 256, anything over 72 would be fine, but multiplying by a power of 2 is simple.

Not my finest work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,807
Members
48,797
Latest member
PeterSimpson
Top