Adds stack, base pointer manipulation.
This commit is contained in:
parent
ad718a930e
commit
1f83e6567d
3 changed files with 35 additions and 2 deletions
|
@ -80,7 +80,7 @@ An instruction is only executed when all conditions are met.
|
||||||
| 4 | SET | output = STACK[BP + input0] = input1 |
|
| 4 | SET | output = STACK[BP + input0] = input1 |
|
||||||
| 5 | BPGET | output = BP |
|
| 5 | BPGET | output = BP |
|
||||||
| 6 | BPSET | output = BP = input0 |
|
| 6 | BPSET | output = BP = input0 |
|
||||||
| 7 | RSTSTACK | output = SP = BP |
|
| 7 | CPGET | output = CP + cmdinfo |
|
||||||
| 8 | MATH | output = input0 OP[info] input1 |
|
| 8 | MATH | output = input0 OP[info] input1 |
|
||||||
| 9 | SPGET | output = SP + input0 |
|
| 9 | SPGET | output = SP + input0 |
|
||||||
| 10 | SPSET | output = SP + input0 = input1 |
|
| 10 | SPSET | output = SP + input0 = input1 |
|
||||||
|
@ -134,6 +134,9 @@ by the `cmdinfo`.
|
||||||
| seti | no | pop | pop | set | 0 | discard | no |
|
| seti | no | pop | pop | set | 0 | discard | no |
|
||||||
| bpget | no | zero | zero | bpget | 0 | push | no |
|
| bpget | no | zero | zero | bpget | 0 | push | no |
|
||||||
| bpset | no | pop | zero | bpset | 0 | discard | 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 |
|
| add | no | pop | pop | math | 0 | push | no |
|
||||||
| sub | no | pop | pop | math | 1 | push | no |
|
| sub | no | pop | pop | math | 1 | push | no |
|
||||||
| cmp | no | pop | pop | math | 1 | discard | yes |
|
| cmp | no | pop | pop | math | 1 | discard | yes |
|
||||||
|
|
|
@ -21,6 +21,31 @@ static void cmd_store(Process *p, CommandInfo *info)
|
||||||
info->output = info->input1;
|
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)
|
static void cmd_math(CommandInfo *info)
|
||||||
{
|
{
|
||||||
switch(info->additional)
|
switch(info->additional)
|
||||||
|
@ -116,6 +141,11 @@ int vm_step_process(Process *process)
|
||||||
case VM_CMD_MATH: cmd_math(&info); break;
|
case VM_CMD_MATH: cmd_math(&info); break;
|
||||||
case VM_CMD_SYSCALL: vm_syscall(process, &info); break;
|
case VM_CMD_SYSCALL: vm_syscall(process, &info); break;
|
||||||
case VM_CMD_HWIO: vm_hwio(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.");
|
default: vm_assert(0, "Invalid instruction: command undefined.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ extern "C" {
|
||||||
#define VM_CMD_SET 4
|
#define VM_CMD_SET 4
|
||||||
#define VM_CMD_BPGET 5
|
#define VM_CMD_BPGET 5
|
||||||
#define VM_CMD_BPSET 6
|
#define VM_CMD_BPSET 6
|
||||||
#define VM_CMD_RSTSTACK 7
|
#define VM_CMD_CPGET 7
|
||||||
#define VM_CMD_MATH 8
|
#define VM_CMD_MATH 8
|
||||||
#define VM_CMD_SPGET 9
|
#define VM_CMD_SPGET 9
|
||||||
#define VM_CMD_SPSET 10
|
#define VM_CMD_SPSET 10
|
||||||
|
|
Loading…
Reference in a new issue