From 33aa62634af2bddb64b678c065aa597756feb14d Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 15 Oct 2023 21:00:01 +0100 Subject: Added registers to virtual machine Registers for bytes, words and floats with routines to set them. --- src/main.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 4ccb42a..301a468 100644 --- a/src/main.c +++ b/src/main.c @@ -16,8 +16,17 @@ #include "./base.h" #include "./inst.h" +#define VM_BYTE_REGISTERS 8 +#define VM_WORD_REGISTERS 8 +#define VM_FLOAT_REGISTERS 8 typedef struct { + struct Registers + { + byte b[VM_BYTE_REGISTERS]; + word w[VM_WORD_REGISTERS]; + f64 f[VM_FLOAT_REGISTERS]; + } registers; struct Stack { byte *data; @@ -78,6 +87,30 @@ void vm_push_float(vm_t *vm, data_t f) vm->stack.ptr += FLOAT_SIZE; } +void vm_mov_byte(vm_t *vm, data_t b, word reg) +{ + if (reg >= VM_BYTE_REGISTERS) + // TODO: Error (reg is not a valid byte register) + return; + vm->registers.b[reg] = b.as_byte; +} + +void vm_mov_word(vm_t *vm, data_t w, word reg) +{ + if (reg >= VM_WORD_REGISTERS) + // TODO: Error (reg is not a valid byte register) + return; + vm->registers.w[reg] = w.as_word; +} + +void vm_mov_float(vm_t *vm, data_t f, word reg) +{ + if (reg >= VM_FLOAT_REGISTERS) + // TODO: Error (reg is not a valid byte register) + return; + vm->registers.f[reg] = f.as_float; +} + byte vm_pop_byte(vm_t *vm) { if (vm->stack.ptr == 0) -- cgit v1.2.3-13-gbd6f