Added a register ret, a word, which holds the result of any instruction

Allows inspection at runtime of any routines result.
This commit is contained in:
2023-10-15 21:14:56 +01:00
parent 2490966554
commit f0e48a186d

View File

@@ -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