Commit Graph

28 Commits

Author SHA1 Message Date
Aryadev Chavali
ae9bc91713 Added and implemented OP_PRINT*
Here is where we may have differing interpretations of what the bits
in the data pile may actually mean.  This in particular refers to
printing the signed or unsigned versions of the bits given.  Also,
interpreting some byte as a character or just a raw number.
2023-10-23 00:09:12 +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
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
a8d743e76e Added macros for NOOP and HALT 2023-10-22 18:02:30 +01:00
Aryadev Chavali
47c7d6baf7 Store the result of OP_POP in the last register as a word
Instead of making routines to handle data in the `ret` register, just
store the result of POP into the last word register.

This means we are no longer using vm_pop_* or POP_ROUTINES for the
vm_execute script on OP_POP: instead we'll just use vm_mov_* which
automatically pops the datum for us, while moving the datum to the
last register.
2023-10-22 17:34:30 +01:00
Aryadev Chavali
696589b7b6 Introduced opcodes for NOT, OR, AND, XOR and EQ
Does a bit level version of each of these.
2023-10-21 23:42:07 +01:00
Aryadev Chavali
f9b2c8ed77 Cleaned up and used macro magic to shorten the INST_* macros
Instead of having 3 differing macros for each typed version of each
opcode, just supply the type as a symbol to the macro, which will
concatenated the type to all the places necessary.

Relies on D(BYTE|HWORD|WORD) and OP_*_(BYTE|HWORD|WORD) being a
consistent naming style.
2023-10-21 23:40:03 +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
4d9b8a04f2 Fixed error with OP_PUSH where bits weren't in the pattern of data_type_t 2023-10-16 01:20:11 +01:00
Aryadev Chavali
a4c9b85c79 MOV and PUSH_*_REGISTER should only need bytes for their operand
We won't have more than 255 registers, so a byte is all that's
necessary.
2023-10-16 01:20:06 +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
Aryadev Chavali
a24a096e2a Made OP_HALT the only instruction to have the top byte filled 2023-10-16 01:06:02 +01:00
Aryadev Chavali
0f37a59940 MOV now uses the stack, removed register member in inst_t
Instead of taking an operand and a register, mov just uses the stack
for the operand.  Therefore, there's no need for a register member in
inst_t.

As a result, PUSH_*_REGISTER now uses the operand for the register.
2023-10-16 01:05:42 +01:00
Aryadev Chavali
cd19f1e1d3 Better checking of opcode types
Introduced an enum (opcode_type_t) for the masks and values of each
opcode, which allows defining a single enum which checks an opcode by
a opcode_type_t.
2023-10-15 22:16:31 +01:00
Aryadev Chavali
1cb54dc994 Remove parameter for INST_*POP
POP instructions do not require an operand: they're a unary operator.
2023-10-15 22:06:30 +01:00
Aryadev Chavali
15ce778771 Set register parameter for inst_t to be a byte
We at most have 255 registers, so no need to have a word for it.
2023-10-15 22:05:59 +01:00
Aryadev Chavali
744cc7acf7 Renamed opcodes PUSH_*REG to PUSH_*_REGISTER
More precise in naming
2023-10-15 21:27:00 +01:00
Aryadev Chavali
4ae762294d Rearranged opcodes (switched mov with push_reg)
This is so push opcodes are closer together
2023-10-15 21:22:42 +01:00
Aryadev Chavali
54760d446c Added instructions to push register values onto the stack 2023-10-15 21:19:49 +01:00
Aryadev Chavali
00517fddd6 Added instructions for popping differing types
Bit mask is 100.
2023-10-15 21:09:00 +01:00
Aryadev Chavali
56c545e7c9 Added opcodes for MOV and ability for instructions to hold registers
Pretty simple implementation
2023-10-15 21:03:27 +01:00
Aryadev Chavali
7a820290f9 Make push opcodes a specific bit set and add a NOOP opcode
By default, a zero initialised set of instructions are NOOPs, which is
great.

Last two bits of a push opcode is always 01.  Rest of the bits are
used to distinguish between differing types of push.  This makes it
easier to inspect on the byte level what type of opcode we have.
2023-10-15 20:59:26 +01:00
Aryadev Chavali
40dfa5c255 Split off instruction structure to its own file 2023-10-15 17:38:35 +01:00