diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-21 22:57:43 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-21 22:57:43 +0100 |
commit | dcedb70a5ccead41574cf857b369d264c87dd7e0 (patch) | |
tree | 45f4f9eb7a5258fc7ee1e25fbe4edaa05f82093f /src/inst.h | |
parent | 266b4e4572be015dca986b423896ec6fa14b4318 (diff) | |
download | ovm-dcedb70a5ccead41574cf857b369d264c87dd7e0.tar.gz ovm-dcedb70a5ccead41574cf857b369d264c87dd7e0.tar.bz2 ovm-dcedb70a5ccead41574cf857b369d264c87dd7e0.zip |
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.
Diffstat (limited to 'src/inst.h')
-rw-r--r-- | src/inst.h | 56 |
1 files changed, 22 insertions, 34 deletions
@@ -23,41 +23,29 @@ typedef enum { OP_NOOP = 0, - // 0b0001 - OP_PUSH_BYTE = 0b00000001, - OP_PUSH_WORD = 0b00000011, - OP_PUSH_FLOAT = 0b00000101, - // 0b0010 - OP_PUSH_BYTE_REGISTER = 0b00000010, - OP_PUSH_WORD_REGISTER = 0b00000110, - OP_PUSH_FLOAT_REGISTER = 0b00001010, - // 0b0100 - OP_POP_BYTE = 0b00000100, - OP_POP_WORD = 0b00001100, - OP_POP_FLOAT = 0b00010100, - // 0b1000 - OP_MOV_BYTE = 0b00001000, - OP_MOV_WORD = 0b00011000, - OP_MOV_FLOAT = 0b00101000, - - OP_HALT = 0b10000000, // top of the byte is a HALT -} opcode_t; + OP_PUSH_BYTE, + OP_PUSH_HWORD, + OP_PUSH_WORD, -const char *opcode_as_cstr(opcode_t); + OP_PUSH_REGISTER_BYTE, + OP_PUSH_REGISTER_HWORD, + OP_PUSH_REGISTER_WORD, -// Masks and values to check if an opcode is of a type -typedef enum -{ - OP_TYPE_PUSH = 0b00000001, - OP_TYPE_PUSH_REGISTER = 0b00000010, - OP_TYPE_POP = 0b00000100, - OP_TYPE_MOV = 0b00001000, - OP_TYPE_HALT = 0b10000000, -} opcode_type_t; + OP_POP_BYTE, + OP_POP_HWORD, + OP_POP_WORD, -const char *opcode_type_as_cstr(opcode_type_t); + OP_MOV_BYTE, + OP_MOV_HWORD, + OP_MOV_WORD, + + OP_HALT = 0b11111111, // top of the byte is a HALT +} opcode_t; + +const char *opcode_as_cstr(opcode_t); -#define OPCODE_IS_TYPE(OPCODE, OP_TYPE) (((OPCODE) & (OP_TYPE)) == (OP_TYPE)) +#define OPCODE_IS_TYPE(OPCODE, OP_TYPE) \ + (((OPCODE) >= OP_TYPE##_BYTE) && ((OPCODE) <= OP_TYPE##_WORD)) typedef struct { @@ -96,12 +84,12 @@ inst_t inst_read_bytecode(darr_t *); #define INST_FPOP ((inst_t){.opcode = OP_POP_FLOAT}) #define INST_BPUSH_REG(REG) \ - ((inst_t){.opcode = OP_PUSH_BYTE_REGISTER, .operand = DBYTE(REG)}) + ((inst_t){.opcode = OP_PUSH_REGISTER_BYTE, .operand = DBYTE(REG)}) #define INST_WPUSH_REG(REG) \ - ((inst_t){.opcode = OP_PUSH_WORD_REGISTER, .operand = DBYTE(REG)}) + ((inst_t){.opcode = OP_PUSH_REGISTER_WORD, .operand = DBYTE(REG)}) #define INST_FPUSH_REG(REG) \ - ((inst_t){.opcode = OP_PUSH_FLOAT_REGISTER, .operand = DBYTE(REG)}) + ((inst_t){.opcode = OP_PUSH_REGISTER_FLOAT, .operand = DBYTE(REG)}) #endif |