diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-15 21:05:56 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-15 21:05:56 +0100 |
commit | 2bc20f07d3fcaf95e2e86dd03e44f8437489c352 (patch) | |
tree | c390e2bf02e60522e61f5f897a7458e37e3b6905 /src | |
parent | 3f8544485affaf2e701992cdfaedac13e86e050a (diff) | |
download | ovm-2bc20f07d3fcaf95e2e86dd03e44f8437489c352.tar.gz ovm-2bc20f07d3fcaf95e2e86dd03e44f8437489c352.tar.bz2 ovm-2bc20f07d3fcaf95e2e86dd03e44f8437489c352.zip |
Added vm_execute support for mov routines
Similar to push routines support. Easy to extend by adding items to
the MOV_ROUTINES array.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -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) |