AmigaDOS Universal Register Machine

AmigaDOS Script is Turing-complete. The following code simulates a Universal Register Machine. If you actually want to use it (it is extremely slow), the code should be copied to a file with the script attribute set. The environmental variables P and A should be set to the program number and register list respectively (using the standard Gödel encoding).

; $VER: urm.dos 1.0 (09/12/2003)
; urm.dos (c) 2003 Safalra (Stephen Morley)

; environmental variable P stores program number
; envirommental variable A stores register list

SetEnv T 0
SetEnv N 0
SetEnv PC 0
SetEnv C 0
SetEnv R 0
SetEnv S 0
SetEnv temp 0

Lab CopyPToT
  SetEnv T $P
Lab PopTToN
  If val $T eq 0
    SetEnv N 0
    Skip Halt
  Endif
  Lab PopTToN2
    SetEnv temp $T
    SetEnv T 0
    Lab PopTToN3
      If val $temp ge 2
        Eval $temp-2 lformat "%n" to RAM:Env/temp
        Eval $T+1 lformat "%n" to RAM:Env/T
        Skip PopTToN3 back
      Endif
    If val $temp 0
      Eval $N+1 lformat "%n" to RAM:Env/N
      Skip PopTToN2 back
    Endif
Lab PCMinus
  If val $PC ge 0
    Eval $PC-1 lformat "%n" to RAM:Env/PC
    Skip PopTToN back
  Endif
Lab PopNToC
  If val $N eq 0
    SetEnv C 0
    Skip Halt
  Endif
  Lab PopNToC2
    SetEnv temp $N
    SetEnv N 0
    Lab PopNToC3
      If val $temp ge 2
        Eval $temp-2 lformat "%n" to RAM:Env/temp
        Eval $N+1 lformat "%n" to RAM:Env/N
        Skip PopNToC3 back
      Endif
    If val $temp 0
      Eval $C+1 lformat "%n" to RAM:Env/C
      Skip PopNToC2 back
    Endif
Lab PopAToR
  If val $A eq 0
    SetEnv R 0
    Skip CMinus1
  Endif
  Lab PopAToR2
    SetEnv temp $A
    SetEnv A 0
    Lab PopAToR3
      If val $temp ge 2
        Eval $temp-2 lformat "%n" to RAM:Env/temp
        Eval $A+1 lformat "%n" to RAM:Env/A
        Skip PopAToR3 back
      Endif
    If val $temp 0
      Eval $R+1 lformat "%n" to RAM:Env/R
      Skip PopAToR2 back
    Endif
Lab CMinus1
  If val $C eq 0
    Skip RPlus
  Endif
  Eval $C-1 lformat "%n" to RAM:Env/C
Lab CMinus2
  If val $C eq 0
    Skip NPlus
  Endif
  Eval $C-1 lformat "%n" to RAM:Env/C
Lab PushRToS
  Eval $S+1 lformat "%n" to RAM:Env/S
  Lab PushRToS2
  If val $R ge 0
    Eval $R-1 lformat "%n" to RAM:Env/R
    Eval $S+$S lformat "%n" to RAM:Env/S
    Skip PushRToS2 back
  Endif
  Skip PopAToR back
Lab RPlus
  Eval $R+1 lformat "%n" to RAM:Env/R
  Skip CopyNToPC
Lab NPlus
  Eval $N+1 lformat "%n" to RAM:Env/N
Lab PopNToPC
  If val $N eq 0
    SetEnv PC 0
    Skip RMinus
  Endif
  Lab PopNToPC2
    SetEnv temp $N
    SetEnv N 0
    Lab PopNToPC3
      If val $temp ge 2
        Eval $temp-2 lformat "%n" to RAM:Env/temp
        Eval $N+1 lformat "%n" to RAM:Env/N
        Skip PopNToPC3 back
      Endif
    If val $temp 0
      Eval $PC+1 lformat "%n" to RAM:Env/PC
      Skip PopNToPC2 back
    Endif
Lab RMinus
  If val $R ge 0
    Eval $R-1 lformat "%n" to RAM:Env/R
    Skip PushRToA
  Endif
Lab CopyNToPC
  SetEnv PC $N
Lab PushRToA
  Eval $A+1 lformat "%n" to RAM:Env/A
  Lab PushRToA2
  If val $R ge 0
    Eval $R-1 lformat "%n" to RAM:Env/R
    Eval $A+$A lformat "%n" to RAM:Env/A
    Skip PushRToA2 back
  Endif
Lab PopASoR
  If val $S eq 0
    SetEnv R 0
    Skip CopyPToT
  Endif
  Lab PopSToR2
    SetEnv temp $S
    SetEnv S 0
    Lab PopSToR3
      If val $temp ge 2
        Eval $temp-2 lformat "%n" to RAM:Env/temp
        Eval $S+1 lformat "%n" to RAM:Env/S
        Skip PopSToR3 back
      Endif
    If val $temp 0
      Eval $R+1 lformat "%n" to RAM:Env/R
      Skip PopSToR2 back
    Endif
  Skip PushRToA back
Lab Halt
This article was last edited on 15th April 2007. The author can be contacted using the form below.
Back to home page
Bookmark with: