diff --git a/README.md b/README.md index 7e99d47..3d149de 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,5 @@ Virtual Machines Just a bunch of immature interpreters. One interprets brainfuck code(nbfi - naive brainfuck interpreter), the other uses an assembler-like dsl(but has -no parser until now). +no parser until now, so you will have to write code within the original +programs code). diff --git a/vvm/README.md b/vvm/README.md new file mode 100644 index 0000000..15df0a1 --- /dev/null +++ b/vvm/README.md @@ -0,0 +1,5 @@ +Veits Virtual Machine +--------------------- + +A virtual machine that executes assembler-like code. + diff --git a/vvm/bin/vvm b/vvm/bin/vvm index 4ddd801..0314d53 100755 Binary files a/vvm/bin/vvm and b/vvm/bin/vvm differ diff --git a/vvm/src/opcode.c b/vvm/src/opcode.c index 2673427..1110ece 100644 --- a/vvm/src/opcode.c +++ b/vvm/src/opcode.c @@ -5,17 +5,17 @@ const char* opcodes[] = {"IADD", "ISUB", "IMULT", "IDIV", "IMOD", "ILT", "IEQ", "IGT", "BR", "BRT", "BRF", "ICONST", "LOAD", "GLOAD", "STORE", "GSTORE", "PRINT", "POP", "HALT", "LEQ", "GEQ", "CALL", "RET", - "IPRINT", "FETCH"}; + "IPRINT", "FETCH", "IINC", "IDEC" }; int nargs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 2, 0, 0, 0 }; + 0, 2, 0, 0, 0, 0, 0 }; instruction* setup_instructions(){ int i; - static instruction ins[FETCH+1]; + static instruction ins[IDEC+1]; ins[0].operands = 0; ins[0].name = NULL; - for(i = 1; i <= FETCH; i++){ + for(i = 1; i <= IDEC; i++){ ins[i].operands = nargs[i-1]; ins[i].name = opcodes[i-1]; } diff --git a/vvm/src/opcode.h b/vvm/src/opcode.h index 85cb319..903c07d 100644 --- a/vvm/src/opcode.h +++ b/vvm/src/opcode.h @@ -25,6 +25,8 @@ #define RET 23 #define IPRINT 24 #define FETCH 25 +#define IINC 26 +#define IDEC 27 typedef struct{ int operands; diff --git a/vvm/src/vm.c b/vvm/src/vm.c index 7211b98..46a4d51 100644 --- a/vvm/src/vm.c +++ b/vvm/src/vm.c @@ -34,6 +34,12 @@ void vm_execute(int code[], int ip, int datasize, int length){ disassemble(sp, fp, ip, opcode, ins, code, stack); } switch(opcode){ + case IINC: + stack[sp]++; + break; + case IDEC: + stack[sp]--; + break; case LOAD: stack[++sp] = stack[code[ip++]+fp]; break;