aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-21 23:55:29 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-21 23:55:29 +0100
commitc9b23b7b241fa4cb3aab1ca4436193c943ba46e9 (patch)
tree98a2040bf5dee2d7515f1f50716a6cea9b8ec5a2
parent6161a352e020a68775877a2d61af09c8efc62355 (diff)
downloadovm-c9b23b7b241fa4cb3aab1ca4436193c943ba46e9.tar.gz
ovm-c9b23b7b241fa4cb3aab1ca4436193c943ba46e9.tar.bz2
ovm-c9b23b7b241fa4cb3aab1ca4436193c943ba46e9.zip
Implemented vm routines for OP_AND_*
-rw-r--r--src/runtime.c30
-rw-r--r--src/runtime.h10
2 files changed, 40 insertions, 0 deletions
diff --git a/src/runtime.c b/src/runtime.c
index a57dc2f..d07f141 100644
--- a/src/runtime.c
+++ b/src/runtime.c
@@ -396,3 +396,33 @@ void vm_or_word(vm_t *vm)
vm_push_word(vm, DWORD(a | b));
}
+void vm_and_byte(vm_t *vm)
+{
+ if (vm->stack.ptr < 2)
+ // TODO: Error STACK_UNDERFLOW
+ return;
+ byte a = vm_pop_byte(vm).as_byte;
+ byte b = vm_pop_byte(vm).as_byte;
+ vm_push_byte(vm, DBYTE(a & b));
+}
+
+void vm_and_hword(vm_t *vm)
+{
+ if (vm->stack.ptr < (HWORD_SIZE * 2))
+ // TODO: Error STACK_UNDERFLOW
+ return;
+ hword a = vm_pop_hword(vm).as_hword;
+ hword b = vm_pop_hword(vm).as_hword;
+ vm_push_hword(vm, DHWORD(a & b));
+}
+
+void vm_and_word(vm_t *vm)
+{
+ if (vm->stack.ptr < (WORD_SIZE * 2))
+ // TODO: Error STACK_UNDERFLOW
+ return;
+ word a = vm_pop_word(vm).as_word;
+ word b = vm_pop_word(vm).as_word;
+ vm_push_word(vm, DWORD(a & b));
+}
+
diff --git a/src/runtime.h b/src/runtime.h
index d757e36..4ac475b 100644
--- a/src/runtime.h
+++ b/src/runtime.h
@@ -121,4 +121,14 @@ static const or_f OR_ROUTINES[] = {
[OP_OR_WORD] = vm_or_word,
};
+void vm_and_byte(vm_t *);
+void vm_and_hword(vm_t *);
+void vm_and_word(vm_t *);
+typedef void (*and_f)(vm_t *);
+static const and_f AND_ROUTINES[] = {
+ [OP_AND_BYTE] = vm_and_byte,
+ [OP_AND_HWORD] = vm_and_hword,
+ [OP_AND_WORD] = vm_and_word,
+};
+
#endif