Aryadev Chavali
d8e45fce04
Removed ret register
...
Wasn't useful or necessary.
2023-10-22 20:54: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
bc0e0fce25
Fixed bug in vm_execute_all, if no OP_HALT then program kept going
...
This adds a bound on vm_execute_all to stop program->ptr from going
past program->max.
2023-10-22 20:30:17 +01:00
Aryadev Chavali
9da31398ba
Implemented vm_* routines for OP_DUP and vm_execute code
2023-10-22 20:30:05 +01:00
Aryadev Chavali
073a23152e
Use conversion functions for (h)word to and from bytes instead of bit shifting
...
Wasn't very secure for endianness, and using these helpers abstracts
the details away a bit in case I want to enforce a certain system.
2023-10-22 20:29:02 +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
d5d10480fa
Simple program which assembles instructions then executes them
2023-10-22 19:33:44 +01:00
Aryadev Chavali
33364fddab
Fix bug where accessing byte/hword registers > 8 wouldn't work
...
This is because we were checking them as if they were word registers.
2023-10-22 19:28:45 +01:00
Aryadev Chavali
ed63025927
Added flag to Makefile to set VERBOSE macro in base.h
2023-10-22 18:26:33 +01:00
Aryadev Chavali
cf23a62008
Made a debug and release configuration via flags
...
Also split out the check for whether $(DIST) exists by making it its
own recipe. Removes the repeated checks in each object compilation.
2023-10-22 18:07:41 +01:00
Aryadev Chavali
36bcd90c81
When VEROBSE flag is set greater than 0, print traces in vm_execute_all
...
For each cycle, print the cycle and any changes. We track changes on
the stack by remembering the previous stack pointer. For registers, I
remember the previous array of registers and do a byte level compare
of the current registers and the remembered ones.
Produces pretty log messages and an easy way to track execution.
2023-10-22 18:07:41 +01:00
Aryadev Chavali
936971c1a3
Changed formats for vm_print_(stack|program)
...
Easier to read now
2023-10-22 18:07:41 +01:00
Aryadev Chavali
5eb7b6f431
Fix bug where FILE is closed when passing to darr_(write|read)
2023-10-22 18:07:41 +01:00
Aryadev Chavali
5ee9bfaca8
Added flag in base.h, VERBOSE
...
Will be used to provide traces during program execution or assembly.
2023-10-22 18:07:41 +01:00
Aryadev Chavali
a8d743e76e
Added macros for NOOP and HALT
2023-10-22 18:02:30 +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
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
95723f36d2
Implemented vm routines for OP_EQ_*
2023-10-21 23:55:51 +01:00
Aryadev Chavali
50ce1b35cd
Implemented vm routines for OP_XOR_*
2023-10-21 23:55:41 +01:00
Aryadev Chavali
c9b23b7b24
Implemented vm routines for OP_AND_*
2023-10-21 23:55:29 +01:00
Aryadev Chavali
6161a352e0
Implemented vm routines for OP_OR_*
2023-10-21 23:55:16 +01:00
Aryadev Chavali
ae7f0efc85
Implemented vm routines for OP_NOT_*
2023-10-21 23:54:59 +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
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
d2cdb211b2
Added vm_execute_all which executes an entire program
...
Handles OP_HALT
2023-10-21 23:31:48 +01:00
Aryadev Chavali
1c2de9a926
Wrote a quick tutorial on targeting the virtual machine
2023-10-21 23:27:33 +01:00
Aryadev Chavali
f3a5981fa2
Wrote generalised procedures for interpret and assembly
2023-10-21 23:24:41 +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
903ae3ab04
Helper darr functions to read/write bytes from FILE *
2023-10-21 23:23:13 +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
266b4e4572
Implemented vm_print_* routines
...
Prints each aspect of the vm, and vm_print_all does it all.
2023-10-16 12:55:19 +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
d01b39d1bb
Added helper functions to read and write bytes from files
...
Given a filepath, helper function to write a buffer of bytes to a file
and to read a file completely as a buffer.
2023-10-16 12:03:42 +01:00
Aryadev Chavali
e7616cdeb6
Made a sample program, loaded into VM and executed
...
Seems pretty nice to use, and it works according to GDB.
2023-10-16 11:32:20 +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
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
c24c1d1607
Implemented a dynamically sized byte array
...
Pretty simple, want to ensure amortised constant big O so I use a
REALLOC_MULT, which can be redefined if wished.
2023-10-15 21:50:31 +01:00
Aryadev Chavali
98760ee63b
Added macros for getting the maximum and minimum of two numbers
2023-10-15 21:49:13 +01:00