aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-15 21:29:26 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-15 21:29:26 +0100
commit14e9192996749208da8acbad44545dc991dd4ef8 (patch)
tree6322d61102f2795f58a385fd933b3e76c57e72ae /src
parentf73604ba6e141ccb4bd5c9b0783cd6128656ed31 (diff)
downloadovm-14e9192996749208da8acbad44545dc991dd4ef8.tar.gz
ovm-14e9192996749208da8acbad44545dc991dd4ef8.tar.bz2
ovm-14e9192996749208da8acbad44545dc991dd4ef8.zip
Implemented OP_PUSH_*_REGISTER in vm_execute
Diffstat (limited to 'src')
-rw-r--r--src/main.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index e8925f2..9f1e90c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -186,6 +186,13 @@ static const push_f PUSH_ROUTINES[] = {
[OP_PUSH_FLOAT] = vm_push_float,
};
+typedef void (*push_reg_f)(vm_t *, word);
+static const push_reg_f PUSH_REG_ROUTINES[] = {
+ [OP_PUSH_BYTE_REGISTER] = vm_push_byte_register,
+ [OP_PUSH_WORD_REGISTER] = vm_push_word_register,
+ [OP_PUSH_FLOAT_REGISTER] = vm_push_float_register,
+};
+
typedef void (*mov_f)(vm_t *, data_t, word);
static const mov_f MOV_ROUTINES[] = {
[OP_MOV_BYTE] = vm_mov_byte,
@@ -214,9 +221,9 @@ void vm_execute(vm_t *vm)
vm->registers.ret = instruction.operand.as_word;
prog->ptr++;
}
- else if (OPCODE_IS_MOV(instruction.opcode))
+ else if (OPCODE_IS_PUSH_REG(instruction.opcode))
{
- MOV_ROUTINES[instruction.opcode](vm, instruction.operand, instruction.reg);
+ PUSH_REG_ROUTINES[instruction.opcode](vm, instruction.reg);
vm->registers.ret = instruction.operand.as_word;
prog->ptr++;
}
@@ -227,6 +234,12 @@ void vm_execute(vm_t *vm)
vm->registers.ret = d.as_word;
prog->ptr++;
}
+ else if (OPCODE_IS_MOV(instruction.opcode))
+ {
+ MOV_ROUTINES[instruction.opcode](vm, instruction.operand, instruction.reg);
+ vm->registers.ret = instruction.operand.as_word;
+ prog->ptr++;
+ }
else
{
// TODO: Error (Unknown opcode)