Removed ret register

Wasn't useful or necessary.
This commit is contained in:
2023-10-22 20:54:29 +01:00
parent fffad9aea3
commit d8e45fce04
2 changed files with 4 additions and 27 deletions

View File

@@ -29,85 +29,66 @@ void vm_execute(vm_t *vm)
if (OPCODE_IS_TYPE(instruction.opcode, OP_PUSH)) if (OPCODE_IS_TYPE(instruction.opcode, OP_PUSH))
{ {
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_TYPE(instruction.opcode, OP_PUSH_REGISTER)) else if (OPCODE_IS_TYPE(instruction.opcode, OP_PUSH_REGISTER))
{ {
PUSH_REG_ROUTINES[instruction.opcode](vm, instruction.operand.as_word); PUSH_REG_ROUTINES[instruction.opcode](vm, instruction.operand.as_word);
vm->registers.ret = instruction.operand.as_word;
prog->ptr++; prog->ptr++;
} }
else if (OPCODE_IS_TYPE(instruction.opcode, OP_POP)) else if (OPCODE_IS_TYPE(instruction.opcode, OP_POP))
{ {
// NOTE: We use the first register to hold the result of this pop // NOTE: We use the first register to hold the result of this pop
data_type_t type = OPCODE_DATA_TYPE(instruction.opcode, OP_POP); data_type_t type = OPCODE_DATA_TYPE(instruction.opcode, OP_POP);
data_t datum = vm_peek(vm, type);
switch (type) switch (type)
{ {
case DATA_TYPE_NIL: case DATA_TYPE_NIL:
break; break;
case DATA_TYPE_BYTE: case DATA_TYPE_BYTE:
vm_mov_byte(vm, (VM_REGISTERS * 8) - 1); vm_mov_byte(vm, 0);
break; break;
case DATA_TYPE_HWORD: case DATA_TYPE_HWORD:
vm_mov_hword(vm, (VM_REGISTERS * 4) - 1); vm_mov_hword(vm, 0);
break; break;
case DATA_TYPE_WORD: case DATA_TYPE_WORD:
vm_mov_hword(vm, VM_REGISTERS - 1); vm_mov_word(vm, 0);
break; break;
} }
vm->registers.ret = datum.as_word;
prog->ptr++; prog->ptr++;
} }
else if (OPCODE_IS_TYPE(instruction.opcode, OP_MOV)) else if (OPCODE_IS_TYPE(instruction.opcode, OP_MOV))
{ {
data_t d = MOV_ROUTINES[instruction.opcode](vm, instruction.operand.as_byte);
MOV_ROUTINES[instruction.opcode](vm, instruction.operand.as_byte);
vm->registers.ret = d.as_word;
prog->ptr++; prog->ptr++;
} }
else if (OPCODE_IS_TYPE(instruction.opcode, OP_DUP)) else if (OPCODE_IS_TYPE(instruction.opcode, OP_DUP))
{ {
DUP_ROUTINES[instruction.opcode](vm, instruction.operand.as_word); DUP_ROUTINES[instruction.opcode](vm, instruction.operand.as_word);
data_type_t type = OPCODE_DATA_TYPE(instruction.opcode, OP_DUP);
data_t datum = vm_peek(vm, type);
vm->registers.ret = datum.as_word;
prog->ptr++; prog->ptr++;
} }
else if (OPCODE_IS_TYPE(instruction.opcode, OP_NOT)) else if (OPCODE_IS_TYPE(instruction.opcode, OP_NOT))
{ {
NOT_ROUTINES[instruction.opcode](vm); NOT_ROUTINES[instruction.opcode](vm);
vm->registers.ret =
vm_peek(vm, OPCODE_DATA_TYPE(instruction.opcode, OP_NOT)).as_word;
prog->ptr++; prog->ptr++;
} }
else if (OPCODE_IS_TYPE(instruction.opcode, OP_OR)) else if (OPCODE_IS_TYPE(instruction.opcode, OP_OR))
{ {
OR_ROUTINES[instruction.opcode](vm); OR_ROUTINES[instruction.opcode](vm);
vm->registers.ret =
vm_peek(vm, OPCODE_DATA_TYPE(instruction.opcode, OP_OR)).as_word;
prog->ptr++; prog->ptr++;
} }
else if (OPCODE_IS_TYPE(instruction.opcode, OP_AND)) else if (OPCODE_IS_TYPE(instruction.opcode, OP_AND))
{ {
AND_ROUTINES[instruction.opcode](vm); AND_ROUTINES[instruction.opcode](vm);
vm->registers.ret =
vm_peek(vm, OPCODE_DATA_TYPE(instruction.opcode, OP_AND)).as_word;
prog->ptr++; prog->ptr++;
} }
else if (OPCODE_IS_TYPE(instruction.opcode, OP_XOR)) else if (OPCODE_IS_TYPE(instruction.opcode, OP_XOR))
{ {
XOR_ROUTINES[instruction.opcode](vm); XOR_ROUTINES[instruction.opcode](vm);
vm->registers.ret =
vm_peek(vm, OPCODE_DATA_TYPE(instruction.opcode, OP_XOR)).as_word;
prog->ptr++; prog->ptr++;
} }
else if (OPCODE_IS_TYPE(instruction.opcode, OP_EQ)) else if (OPCODE_IS_TYPE(instruction.opcode, OP_EQ))
{ {
EQ_ROUTINES[instruction.opcode](vm); EQ_ROUTINES[instruction.opcode](vm);
vm->registers.ret =
vm_peek(vm, OPCODE_DATA_TYPE(instruction.opcode, OP_EQ)).as_word;
prog->ptr++; prog->ptr++;
} }
else if (instruction.opcode == OP_JUMP_ABS) else if (instruction.opcode == OP_JUMP_ABS)
@@ -195,7 +176,6 @@ void vm_load_program(vm_t *vm, inst_t *instructions, size_t size)
void vm_print_registers(vm_t *vm, FILE *fp) void vm_print_registers(vm_t *vm, FILE *fp)
{ {
struct Registers reg = vm->registers; struct Registers reg = vm->registers;
fprintf(fp, "Registers.ret = 0x%lX\n", reg.ret);
fprintf(fp, "Registers.reg = ["); fprintf(fp, "Registers.reg = [");
for (size_t i = 0; i < VM_REGISTERS; ++i) for (size_t i = 0; i < VM_REGISTERS; ++i)
{ {

View File

@@ -24,9 +24,6 @@ typedef struct
{ {
struct Registers struct Registers
{ {
// Used for internal
word ret;
// General registers
word reg[VM_REGISTERS]; word reg[VM_REGISTERS];
} registers; } registers;
struct Stack struct Stack