diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-15 21:14:56 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-15 21:14:56 +0100 |
commit | f0e48a186d76623017758a96e60174412de78933 (patch) | |
tree | 1a52707ada86385ee6413301e2f2579e9007e828 /src | |
parent | 2490966554a378af4a48b51d5e7eb717a570285a (diff) | |
download | ovm-f0e48a186d76623017758a96e60174412de78933.tar.gz ovm-f0e48a186d76623017758a96e60174412de78933.tar.bz2 ovm-f0e48a186d76623017758a96e60174412de78933.zip |
Added a register `ret`, a word, which holds the result of any instruction
Allows inspection at runtime of any routines result.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -23,6 +23,7 @@ typedef struct { struct Registers { + word ret; byte b[VM_BYTE_REGISTERS]; word w[VM_WORD_REGISTERS]; f64 f[VM_FLOAT_REGISTERS]; @@ -177,18 +178,20 @@ void vm_execute(vm_t *vm) if (OPCODE_IS_PUSH(instruction.opcode)) { PUSH_ROUTINES[instruction.opcode](vm, instruction.operand); + vm->registers.ret = instruction.operand.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 if (OPCODE_IS_POP(instruction.opcode)) { - // TODO: Figure out what should happen to the result of this pop - // routine - POP_ROUTINES[instruction.opcode](vm); + // NOTE: We use the `ret` register for the result of this pop + data_t d = POP_ROUTINES[instruction.opcode](vm); + vm->registers.ret = d.as_word; prog->ptr++; } else |