diff options
-rw-r--r-- | mnemonics.c | 40 | ||||
-rw-r--r-- | mnemonics.h | 64 |
2 files changed, 104 insertions, 0 deletions
diff --git a/mnemonics.c b/mnemonics.c new file mode 100644 index 0000000..4a21992 --- /dev/null +++ b/mnemonics.c @@ -0,0 +1,40 @@ +#include "mnemonics.h" + +const struct mnemonic mnemonics[] = { + { "add", 0x0000, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* add */ + { "sub", 0x0001, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* subtract */ + { "mul", 0x0002, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* multiply */ + { "div", 0x0003, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* divide */ + { "and", 0x0100, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* bitwise and */ + { "or", 0x0101, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* bitwise or */ + { "xor", 0x0102, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* bitwise exclusive or */ + { "lsl", 0x1000, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* logical shift left */ + { "lsr", 0x1100, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* logical shift right */ + { "asl", 0x1002, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* arithmetic shift left (fills with lsb) */ + { "asr", 0x1102, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* arithmetic shift right (fills with msb) */ + { "rol", 0x1003, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* rotate left */ + { "ror", 0x1103, { {REG, 9}, {REG, 5}, {REG, 2} } }, /* rotate right */ + { "not", 0x2000, { {REG, 9}, {REG, 2} } }, /* bitwise inverse */ + { "neg", 0x2100, { {REG, 9}, {REG, 2} } }, /* negate */ + { "btc", 0x3000, { {REG, 9}, {REG, 2} } }, /* bit clear */ + { "bts", 0x3100, { {REG, 9}, {REG, 2} } }, /* bit set */ + { "mov", 0x4004, { {REG, 9}, {REG, 5} } }, /* register move */ + { "st.b", 0x4100, { {REGPTR, 9}, {REG, 5} } }, /* store byte */ + { "st.w", 0x4104, { {REGPTR, 9}, {REG, 5} } }, /* store word */ + { "ld.bl", 0x4101, { {REG, 9}, {REGPTR, 5} } }, /* load byte into low byte of register */ + { "ld.bh", 0x4111, { {REG, 9}, {REGPTR, 5} } }, /* load byte into high byte of register */ + { "ld.w", 0x4105, { {REG, 9}, {REGPTR, 5} } }, /* load word */ + { "ldi.bl", 0x5000, { {REG, 9}, {IMM, 0} } }, /* load immediate into low byte of register */ + { "ldi.bh", 0x5100, { {REG, 9}, {IMM, 0} } }, /* load immediate into high byte of register */ + { "beq", 0x6000, { {PCOFF, 0}, } }, /* branch if equal */ + { "bne", 0x6200, { {PCOFF, 0}, } }, /* branch if not equal */ + { "bgt", 0x6400, { {PCOFF, 0}, } }, /* branch if greater than */ + { "bge", 0x6600, { {PCOFF, 0}, } }, /* branch if greater than or equal */ + { "blt", 0x6800, { {PCOFF, 0}, } }, /* branch if less than */ + { "ble", 0x6a00, { {PCOFF, 0}, } }, /* branch if less than or equal */ + { "bra", 0x6e00, { {PCOFF, 0}, } }, /* branch always */ + { "jmp", 0x7000, { {REGPTR, 5}, } }, /* branch always */ + { "addpc", 0x8000, { {REG, 9}, {IMM, 0} } }, /* add program counter and immediate */ + { "nop", 0xffff, { } }, /* no operation */ +}; + diff --git a/mnemonics.h b/mnemonics.h new file mode 100644 index 0000000..969926e --- /dev/null +++ b/mnemonics.h @@ -0,0 +1,64 @@ +#ifndef NQ_MNEMONICS_H +#define NQ_MNEMONICS_H + +#include <stdint.h> + +/* operand types */ +#define REG 1 +#define REGPTR 2 +#define IMM 3 +#define PCOFF 4 + +enum { + MNEM_ADD, + MNEM_SUB, + MNEM_MUL, + MNEM_DIV, + MNEM_AND, + MNEM_OR, + MNEM_XOR, + MNEM_LSL, + MNEM_LSR, + MNEM_ASL, + MNEM_ASR, + MNEM_ROL, + MNEM_ROR, + MNEM_NOT, + MNEM_NEG, + MNEM_BTC, + MNEM_BTS, + MNEM_MOV, + MNEM_ST_B, + MNEM_ST_W, + MNEM_LD_BL, + MNEM_LD_BH, + MNEM_LD_W, + MNEM_LDI_BL, + MNEM_LDI_BH, + MNEM_BEQ, + MNEM_BNE, + MNEM_BGT, + MNEM_BGE, + MNEM_BLT, + MNEM_BLE, + MNEM_BRA, + MNEM_JMP, + MNEM_ADDPC, + MNEM_NOP, +}; + +struct operand { + uint8_t type; + uint8_t shift; +}; + +struct mnemonic { + const char *mnem; + uint16_t bits; + struct operand operands[3]; +}; + +extern const struct mnemonic mnemonics[]; + +#endif + |