Commit Graph

17 Commits

Author SHA1 Message Date
Aryadev Chavali
b44eaefabb Remove get_opcode_data_type
Was only used for OP_PUSH data types anyway, so is essentially
useless.  Only OP_PUSH has operands after it that directly relate to
it: the rest either have a fixed type (a byte for registers, for
example) or NIL (because they have no operand).
2023-10-22 22:04:13 +01:00
Aryadev Chavali
1962aabdf5 Added OP_PLUS_*
Takes two operands from the stack then pushes their sum.
2023-10-22 22:00:44 +01:00
Aryadev Chavali
789016a343 Fix bug where negative opcodes lead to invalid bytecode parsing 2023-10-22 21:47:32 +01:00
Aryadev Chavali
7f1994c7aa Added and implemented OP_JUMP_(STACK|REGISTER)
Uses the stack and register, respectively, to jump to an absolute
address.  The stack based jump pops a word off the stack to perform a
jump, while the register based one uses the operand to figure out
which register to use.
2023-10-22 20:57:29 +01:00
Aryadev Chavali
fffad9aea3 Added and implemented OP_JUMP_ABS
Jumps to the operand given, interpreted as a word, an absolute
address.
2023-10-22 20:54:04 +01:00
Aryadev Chavali
aa3d1cb85f Added NUMBER_OF_OPCODES which aids in compilation errors
If I add a new operand I want the build system to be more helpful in
finding the places I need to change to make it work.
2023-10-22 20:28:10 +01:00
Aryadev Chavali
b20ad511a0 Added opcode OP_DUP_*
Duplicates the nth datum off the stack, pushing it to the top.  Useful
for operations such as MOV which eat the stack.
2023-10-22 20:26:17 +01:00
Aryadev Chavali
137a6d3b75 Cleaned up inst.c
Use (H)WORD_SIZE more, added some notes, etc
2023-10-22 20:25:17 +01:00
Aryadev Chavali
d5d37f1264 Functions which convert (h)words to and from bytes
Uses memcpy internally, so we don't need to care about endianness.
2023-10-22 20:23:23 +01:00
Aryadev Chavali
e6339b1036 Changed format of inst_print
Prints the opcode then any operands in the following brackets
2023-10-22 18:02:05 +01:00
Aryadev Chavali
ba57523f3e Implemented opcode_as_cstr for NOT,OR,AND,XOR,EQ 2023-10-21 23:54:35 +01:00
Aryadev Chavali
44a9a3ca46 Helper functions for read/write instructions from darr or FILE* 2023-10-21 23:23:37 +01:00
Aryadev Chavali
dcedb70a5c Switched from floats to halfword
Registers are now just words, with pushing from and moving to
registers with specified subtypes just pushing those types into the
word registers.  That means there are 8 word registers which can act
as 16 half word registers, which themselves can act as 64 byte
registers.
2023-10-21 22:57:43 +01:00
Aryadev Chavali
44f8c81efe Added opcode_as_cstr, opcode_type_as_cstr and inst_print
Pretty self explanatory, helps with logging.
2023-10-16 12:55:15 +01:00
Aryadev Chavali
7380dd375a Fixed bug with get_opcode_data_type
Pushed the bits one step too far.
2023-10-16 11:25:52 +01:00
Aryadev Chavali
845d864bc0 Set opcode after reading parameters in inst_read_byte 2023-10-16 11:04:43 +01:00
Aryadev Chavali
6038363d2f Added functionality to read and write instruction bytecode
Uses some bit hacks to quickly check what data type an opcode may have
by shifting down to units then casting it to a data_type_t.
Not very well tested yet, we'll need to see now.
2023-10-16 01:18:05 +01:00