Lamp
Minecraft CarpetMod standalone turing-complete vanilla command-block array-based CPU generator
The generator is written in scarpet using CarpetMod
Assembly is written in JSON so maybe one day, with enough instructions, it would be possible to transpile LUA's bytecode to it. Which would be the ultimate goal of this project
The assembly language is array-based and it provides
- basic stack manipulation instructions (
push
andpop
instructions) - primitive usage of "variables" (
get
andset
instructions) - basic arithmetics (
add
andsub
instructions) - conditional jumps
- subroutines
The ALU (Arithmetic Logic Unit) in action
Sections
Synopsis
The first 10 fibonacci numbers - Video Showcase
jmp main
lbl loop
pop //get 0
add
get 0 //10
push 1
sub
set 0
pop
pop
jnz loop
lbl main
push 10
push 1
push 1
push 69 //dummy for 1st pop in :loop
jmp loop
Instruction Set
number
—[0-9]+
char
—'.'
name
—[_a-zA-Z][_a-zA-Z0-9]*
value
— Eithernumber
,char
orname
(constant)idx
—value
, 0-based index from the bottom of the stack[...]
- optional argument, if not present, taken from the stackA
- top value on the stackB
- second-top value on the stack
Memory manipulation
Instruction | Description |
---|---|
push value |
Push value onto the top of the stack |
pop | Discard the top element of the stack |
get [idx] |
Push element at idx onto the top of the stack |
set [idx] [value] |
Set element at idx to value |
Control flow
Instruction | Description |
---|---|
lbl name |
Define a new label of ID name |
call name |
Call the subroutine at label name |
ret | Return from the current subroutine |
jmp name |
Jump to label name |
je name |
Jump to label name if A == B |
jne name |
Jump to label name if A != B |
jg name |
Jump to label name if A > B |
jge name |
Jump to label name if A >= B |
jl name |
Jump to label name if A < B |
jle name |
Jump to label name if A <= B |
jz name |
Jump to label name if A == 0 |
jnz name |
Jump to label name if A != 0 |
Arithmetic
Instruction | Description |
---|---|
add | Push A + B |
sub | Push A - B |
TO-DO
- Clean up the scarpet code
- Clean up this readme
- Actually handle
char
cuz I don't think it's working - Make conditional jumps pop off their
A
s andB
s - Create a
const
instruction for setting constants - Create an
idx
instruction that pushes the top index - Create
mul
anddiv
instructions for multiplication and division - Perhaps create a
del
instruction that would remove an element at a specified index - Perhaps create a
put
instruction that would place a specified block at the givenx y z
coordinates (good luck with that)