Added vm_execute support for mov routines

Similar to push routines support.  Easy to extend by adding items to
the MOV_ROUTINES array.
This commit is contained in:
2023-10-15 21:05:56 +01:00
parent 3f8544485a
commit 2bc20f07d3

View File

@@ -148,6 +148,7 @@ f64 vm_pop_float(vm_t *vm)
}
typedef void (*push_f)(vm_t *, data_t);
typedef void (*mov_f)(vm_t *, data_t, word);
static const push_f PUSH_ROUTINES[] = {
[OP_PUSH_BYTE] = vm_push_byte,
@@ -155,6 +156,12 @@ static const push_f PUSH_ROUTINES[] = {
[OP_PUSH_FLOAT] = vm_push_float,
};
static const mov_f MOV_ROUTINES[] = {
[OP_MOV_BYTE] = vm_mov_byte,
[OP_MOV_WORD] = vm_mov_word,
[OP_MOV_FLOAT] = vm_mov_float,
};
void vm_execute(vm_t *vm)
{
struct Program *prog = &vm->program;
@@ -163,12 +170,16 @@ void vm_execute(vm_t *vm)
return;
inst_t instruction = prog->instructions[prog->ptr];
// Check if opcode is PUSH_LIKE
if (OPCODE_IS_PUSH(instruction.opcode))
{
PUSH_ROUTINES[instruction.opcode](vm, instruction.operand);
prog->ptr++;
}
else if (OPCODE_IS_MOV(instruction.opcode))
{
MOV_ROUTINES[instruction.opcode](vm, instruction.operand, instruction.reg);
prog->ptr++;
}
else
{
// TODO: Error (Unknown opcode)