aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-16 11:25:52 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-16 11:25:52 +0100
commit7380dd375a31463bc9f0d78305d7e3fbc6e86020 (patch)
tree08545bb6b1b3e21def1702f8f28183574442bafe /src
parent845d864bc0edb32447e49660b2ddd46066891398 (diff)
downloadovm-7380dd375a31463bc9f0d78305d7e3fbc6e86020.tar.gz
ovm-7380dd375a31463bc9f0d78305d7e3fbc6e86020.tar.bz2
ovm-7380dd375a31463bc9f0d78305d7e3fbc6e86020.zip
Fixed bug with get_opcode_data_type
Pushed the bits one step too far.
Diffstat (limited to 'src')
-rw-r--r--src/inst.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/inst.c b/src/inst.c
index 9d7bf29..445642e 100644
--- a/src/inst.c
+++ b/src/inst.c
@@ -11,6 +11,7 @@
*/
#include <stdbool.h>
+#include <stdio.h>
#include <string.h>
#include "./inst.h"
@@ -19,13 +20,13 @@ data_type_t get_opcode_data_type(opcode_t opcode)
{
data_type_t type = DATA_TYPE_NIL;
if (OPCODE_IS_TYPE(opcode, OP_TYPE_PUSH))
- type = opcode >> 1;
+ type = (data_type_t)opcode;
else if (OPCODE_IS_TYPE(opcode, OP_TYPE_PUSH_REGISTER))
- type = opcode >> 2;
+ type = opcode >> 1;
else if (OPCODE_IS_TYPE(opcode, OP_TYPE_POP))
- type = opcode >> 3;
+ type = opcode >> 2;
else if (OPCODE_IS_TYPE(opcode, OP_TYPE_MOV))
- type = opcode >> 4;
+ type = opcode >> 3;
return type;
}
@@ -137,8 +138,8 @@ inst_t inst_read_bytecode(darr_t *darr)
if (OPCODE_IS_TYPE(opcode, OP_TYPE_PUSH))
inst.operand = read_type_from_darr(darr, get_opcode_data_type(opcode));
// Read register (as a byte)
- if (OPCODE_IS_TYPE(opcode, OP_TYPE_PUSH_REGISTER) ||
- OPCODE_IS_TYPE(opcode, OP_TYPE_MOV))
+ else if (OPCODE_IS_TYPE(opcode, OP_TYPE_PUSH_REGISTER) ||
+ OPCODE_IS_TYPE(opcode, OP_TYPE_MOV))
inst.operand = read_type_from_darr(darr, DATA_TYPE_BYTE);
// Otherwise opcode doesn't take operands