GOL 8 Documentation
GOL 8 Documentation
xxxxxvvv cccccccc
C = constant value
X = opcode
V = register
xxxxx111 vvv00vvv
X = opcode
V = register
xxxxxvvv
X = opcode
V = register
xxxxx000 cccccccc
X = opcode
C = constant
Stack Operations:
PSH (C/R) 01000 (cat o)
POP (R) 01001 (cat b)
I/O Operations:
OUT (C/R) 01010 (cat o)
Branch Operations:
JMP (A) 01011 (cat j) Regex Verify: ^JMP\s\(@[0-9a-fA-F]{4}\)
JEZ (R, A) (Jump if R = 0) 01100 (cat i)
Memory Operations:
LOD (R, A) 01111 (cat i)
STR (R, A) 01110 (cat i)
Register Codes:
AX 001
BX 010
CX 011
DX 100
Example Programs:
Print perfect squares from 0 to 225:
OUT (%AX)
ADD (%CX, $1E)
;LOOP
SUB (%AX, %CX)
ADD (%AX, $1F)
OUT (%AX)
SUB (%CX, $02)
JEZ (%CX, @0010)
JMP (@0003)
HLT
Quine:
;Init
ADD (%CX, $23)
LOD (%AX, @0000)
;modify LOD
LOD (%BX, @0004)
ADD (%BX, $01)
STR (%BX, @0004)
PSH (%AX)
SUB (%CX, $01)
JEZ (%CX, @0016)
JMP (@0002)
;display code
ADD (%CX, $23)
POP (%DX)
OUT (%DX)
SUB (%CX, $01)
JEZ (%CX, @0022)
JMP (@0018)
HLT
Forward for loop:
ADD (%CX, $FF) ;$FF is the number of loop iterations
PSH (%CX)
XOR (%DX, %DX)
SUB (%DX, %CX)
;OUT (%DX)
;your code here! %DX is the loop counter
POP (%CX)
SUB (%CX, $01)
JEZ (%CX, @0011) ;change this
JMP (@0002)
HLT