aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-15 21:00:01 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-15 21:01:03 +0100
commit33aa62634af2bddb64b678c065aa597756feb14d (patch)
treec6edd2d54fb27e57258f7d796e1d9aa6fc3bbc92 /src/main.c
parent7a820290f945f94bc38732d989746155883e151a (diff)
downloadovm-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.c33
1 files changed, 33 insertions, 0 deletions
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)