From 14e9192996749208da8acbad44545dc991dd4ef8 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 15 Oct 2023 21:29:26 +0100 Subject: Implemented OP_PUSH_*_REGISTER in vm_execute --- src/main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') 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) -- cgit v1.2.3-13-gbd6f