From 1f83e6567dc28b6a6d234a125b4945cf73b33bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Quei=C3=9Fner?= Date: Sat, 21 May 2016 21:36:34 +0200 Subject: [PATCH] Adds stack, base pointer manipulation. --- prototypes/supervm/supervm.md | 5 ++++- prototypes/supervm/vm.c | 30 ++++++++++++++++++++++++++++++ prototypes/supervm/vm.h | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/prototypes/supervm/supervm.md b/prototypes/supervm/supervm.md index e3ba165..d760011 100644 --- a/prototypes/supervm/supervm.md +++ b/prototypes/supervm/supervm.md @@ -80,7 +80,7 @@ An instruction is only executed when all conditions are met. | 4 | SET | output = STACK[BP + input0] = input1 | | 5 | BPGET | output = BP | | 6 | BPSET | output = BP = input0 | -| 7 | RSTSTACK | output = SP = BP | +| 7 | CPGET | output = CP + cmdinfo | | 8 | MATH | output = input0 OP[info] input1 | | 9 | SPGET | output = SP + input0 | | 10 | SPSET | output = SP + input0 = input1 | @@ -134,6 +134,9 @@ by the `cmdinfo`. | seti | no | pop | pop | set | 0 | discard | no | | bpget | no | zero | zero | bpget | 0 | push | no | | bpset | no | pop | zero | bpset | 0 | discard | no | +| spget | no | zero | zero | spget | 0 | push | no | +| spset | no | pop | zero | spset | 0 | discard | no | +| cpget | no | zero | zero | cpget | 1 | push | no | | add | no | pop | pop | math | 0 | push | no | | sub | no | pop | pop | math | 1 | push | no | | cmp | no | pop | pop | math | 1 | discard | yes | diff --git a/prototypes/supervm/vm.c b/prototypes/supervm/vm.c index 0323ef9..1026846 100644 --- a/prototypes/supervm/vm.c +++ b/prototypes/supervm/vm.c @@ -21,6 +21,31 @@ static void cmd_store(Process *p, CommandInfo *info) info->output = info->input1; } +static void cmd_spget(Process *p, CommandInfo *info) +{ + info->output = p->stackPointer; +} + +static void cmd_spset(Process *p, CommandInfo *info) +{ + info->output = p->stackPointer = info->input0; +} + +static void cmd_bpget(Process *p, CommandInfo *info) +{ + info->output = p->basePointer; +} + +static void cmd_bpset(Process *p, CommandInfo *info) +{ + info->output = p->basePointer = info->input0; +} + +static void cmd_cpget(Process *p, CommandInfo *info) +{ + info->output = p->codePointer + info->additional; +} + static void cmd_math(CommandInfo *info) { switch(info->additional) @@ -116,6 +141,11 @@ int vm_step_process(Process *process) case VM_CMD_MATH: cmd_math(&info); break; case VM_CMD_SYSCALL: vm_syscall(process, &info); break; case VM_CMD_HWIO: vm_hwio(process, &info); break; + case VM_CMD_SPGET: cmd_spget(process, &info); break; + case VM_CMD_SPSET: cmd_spset(process, &info); break; + case VM_CMD_BPGET: cmd_bpget(process, &info); break; + case VM_CMD_BPSET: cmd_bpset(process, &info); break; + case VM_CMD_CPGET: cmd_cpget(process, &info); break; default: vm_assert(0, "Invalid instruction: command undefined."); } diff --git a/prototypes/supervm/vm.h b/prototypes/supervm/vm.h index 71452d1..1208c38 100644 --- a/prototypes/supervm/vm.h +++ b/prototypes/supervm/vm.h @@ -28,7 +28,7 @@ extern "C" { #define VM_CMD_SET 4 #define VM_CMD_BPGET 5 #define VM_CMD_BPSET 6 -#define VM_CMD_RSTSTACK 7 +#define VM_CMD_CPGET 7 #define VM_CMD_MATH 8 #define VM_CMD_SPGET 9 #define VM_CMD_SPSET 10