diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-15 21:00:01 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-15 21:01:03 +0100 |
commit | 33aa62634af2bddb64b678c065aa597756feb14d (patch) | |
tree | c6edd2d54fb27e57258f7d796e1d9aa6fc3bbc92 /src/main.c | |
parent | 7a820290f945f94bc38732d989746155883e151a (diff) | |
download | ovm-33aa62634af2bddb64b678c065aa597756feb14d.tar.gz ovm-33aa62634af2bddb64b678c065aa597756feb14d.tar.bz2 ovm-33aa62634af2bddb64b678c065aa597756feb14d.zip |
Added registers to virtual machine
Registers for bytes, words and floats with routines to set them.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -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) |