From 2bc20f07d3fcaf95e2e86dd03e44f8437489c352 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 15 Oct 2023 21:05:56 +0100 Subject: Added vm_execute support for mov routines Similar to push routines support. Easy to extend by adding items to the MOV_ROUTINES array. --- src/main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index c6d842e..16059e7 100644 --- a/src/main.c +++ b/src/main.c @@ -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) -- cgit v1.2.3-13-gbd6f