--- A simple virtual machine based on cpu instruction set.
Includes some DIY instructions,and it is still updating.
by:leviathan
##Building and Running :
###Linux,*nix,Mac OSX:
$ git clone https://github.com/Leviathan1995/lvm.git
$ make
$ ./lvm
##Example :
###Source code: 计算 1+2+3+4...+10=
start : OPCLEAR AL #AL=0
OPCLEAR CL #CL=0
OPLOADVB CL 1 #CL=1
OPLOADVB AL 1 #AL=1 put 1 to AL
add: OPLOAD AL CL #AL=CL
OPADDB AL 10 #AL=AL+[10]
OPSTOREB 10 AL #[10]=AL
OPINC CL #CL=CL+1
OPCMPVB CL 11 #CMP 11
OPJG quit
OPJNG add
quit: OPPRINTR AL
OPHALT
##Syntax
- 注释使用 '#'
- 格式: 操作码 操作数1 操作数2
- 优先级: 寄存器需要在立即数或内存地址前面 例如 OPADDB AL [10]
##Support Instruction:
Instruction | Explanation | Example |
---|---|---|
OPHALT | stop | OPHALT |
OPCLEAR | register=0 | OPCLEAR AL |
OPINIT | id=register | OPINIT i AL |
OPINITLIST | a={1,2,3,4,5} | OPINITLIST a 1,2,3,4,5 |
OPASSIGN | id=reg/num | OPASSIGN i 0 |
OPBINADD | id1=id2+id3 | OPBINADD id1 id2 id3 |
OPBINSUB | id1=id2-id3 | OPBINSUB id1 id2 id3 |
OPBINMUL | id1=id2*id3 | OPBINMUL id1 id2 id3 |
OPBINDIV | id1=id2/id3 | OPBINDIV id1 id2 id3 |
OPADDB | al=al+[10] | OPADDB AL [10] |
OPADDVB | al=al+1 | OPADDVB AL 1 |
OPSUBB | al=al-[10] | OPSUBB AL [10] |
OPSUBVB | al=al-1 | OPSUBVB AL 1 |
OPLOAD | al=cl | OPLOAD AL CL |
OPLOADVB | al=1 | OPLOADVB AL 1 |
OPSTOREB | [10]=al | OPSTOREB 10 AL |
OPINC | al=al+1 | OPINC AL |
OPDEC | al=al-1 | OPDEC AL |
OPCMPVB | cl cmp 5 | OPCMPVB CL 5 |
OPJG | if greatet jump to label | OPJG cmp1 cmp2 label |
OPJNG | if not greater jump to label | OPJNG cmp1 cmp2 label |
OPPRINTR | output al to terminal | OPPRINTR AL |
OPPRINTRLIST | output list to terminal | OPPRINTRLIST list |
OPEND | block end | OPEND block1 |
OPPAUSE | use debug | OPPAUSE |