8ial

From Esolang
Jump to navigation Jump to search

8ial (or 8 instruction assembly language) is basically self explanatory. It's an 8 instruction assembly language created by User:Ractangle.


Specs

8ial has 16 registries that hold integers in 0-255 radius. If it's not in the radius, the integer is wrapped back to the radius

Syntax

The following commands are available:

INC INCrement a registry
END ENDs the program
;A creates label A
OUT OUTput the registry
JMP JuMP to a label unconditionally
PUT inPUT into registry
JIR Jump to a label If Registry is equal to a number
DEC DECrement a registry

An EBNF formulation of the syntax is shown below:

program         := { command } ;

command         := incCommand
                |  decCommand
                |  outCommand
                |  putCommand
                |  labelDefCommand
                |  jmpCommand
                |  jirCommand
                |  endCommand
                ;

incCommand      := "INC" , registerName ;
decCommand      := "DEC" , registerName ;
outCommand      := "OUT" , registerName ;
putCommand      := "PUT" , registerName ;
labelDefCommand := ";"   , labelName ;
jmpCommand      := "JMP" , labelName ;
jirCommand      := "JIR" , labelName
                         , registerName
                         , numericOperand ;
endCommand      := "END" ;

labelName       := labelCharacter , { labelCharacter } ;
labelCharacter  := digit | letter | "-" | "_" ;

numericOperand  := signedInteger | registerName ;
registerName    := "$" , unsignedInteger ;
signedInteger   := [ "+" | "-" ] , unsignedInteger ;
unsignedInteger := digit , { digit } ;
digit           := "0" | "1" | "2" | "3" | "4"
                |  "5" | "6" | "7" | "8" | "9"
                ;
letter          := "a" | ... | "z" | "A" | ... | "Z" ;

Examples

Truth-machine

PUT $1 ;d JIR l $1 0 JIR l $1 1 DEC $1 JMP d ;l OUT $1 JIR l $1 1 END

Cat program

It's more of a numeric cat considering that 8ial only supports numbered inputs

;repeat PUT $1 OUT $1 JIR x $1 0 JMP repeat ;x END

Computational Class

To prove that 8ial is turing complete, here is a compiler from Minsky machine to 8ial as follows:

mm=input("MM:").split(" ");p=x=0;r={}
def MM(x:int)->str:
  a=["0","1","2","3","4","5","6","7","8","9",
     "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
     "Q","R","S","T","U","V","W","X","Y","Z"]
  return (str(a[x%(F:=36)])+str(a[x//F%F])+str(a[x//F//F%F])+str(a[x//F//F//F%F]))[::-1]
while len(mm)!=p:
  print(f";{MM(x)}",end=" ")
  if mm[p][0]=="0":   print(f"INC ${int(mm[p][1:])}",end=" ");x+=1
  elif mm[p][0]=="1":
    try:    print(f"JIR {MM(r[int(mm[p+1])])} ${int(mm[p][1:])} 0 DEC ${int(mm[p][1:])}",end=" ")
    except: r[int(mm[p+1])]=0;print(f"JIR {MM(r[int(mm[p+1])])} ${int(mm[p+1])} 0 DEC ${int(mm[p][1:])}",end=" ")
    p+=1
  p+=1
print("END")

Implementations