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:
@@ -23,6 +23,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
struct Registers
|
struct Registers
|
||||||
{
|
{
|
||||||
|
word ret;
|
||||||
byte b[VM_BYTE_REGISTERS];
|
byte b[VM_BYTE_REGISTERS];
|
||||||
word w[VM_WORD_REGISTERS];
|
word w[VM_WORD_REGISTERS];
|
||||||
f64 f[VM_FLOAT_REGISTERS];
|
f64 f[VM_FLOAT_REGISTERS];
|
||||||
@@ -177,18 +178,20 @@ void vm_execute(vm_t *vm)
|
|||||||
if (OPCODE_IS_PUSH(instruction.opcode))
|
if (OPCODE_IS_PUSH(instruction.opcode))
|
||||||
{
|
{
|
||||||
PUSH_ROUTINES[instruction.opcode](vm, instruction.operand);
|
PUSH_ROUTINES[instruction.opcode](vm, instruction.operand);
|
||||||
|
vm->registers.ret = instruction.operand.as_word;
|
||||||
prog->ptr++;
|
prog->ptr++;
|
||||||
}
|
}
|
||||||
else if (OPCODE_IS_MOV(instruction.opcode))
|
else if (OPCODE_IS_MOV(instruction.opcode))
|
||||||
{
|
{
|
||||||
MOV_ROUTINES[instruction.opcode](vm, instruction.operand, instruction.reg);
|
MOV_ROUTINES[instruction.opcode](vm, instruction.operand, instruction.reg);
|
||||||
|
vm->registers.ret = instruction.operand.as_word;
|
||||||
prog->ptr++;
|
prog->ptr++;
|
||||||
}
|
}
|
||||||
else if (OPCODE_IS_POP(instruction.opcode))
|
else if (OPCODE_IS_POP(instruction.opcode))
|
||||||
{
|
{
|
||||||
// TODO: Figure out what should happen to the result of this pop
|
// NOTE: We use the `ret` register for the result of this pop
|
||||||
// routine
|
data_t d = POP_ROUTINES[instruction.opcode](vm);
|
||||||
POP_ROUTINES[instruction.opcode](vm);
|
vm->registers.ret = d.as_word;
|
||||||
prog->ptr++;
|
prog->ptr++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user