From a949007c75ee263776ca88226dbf1c0547436853 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Mon, 3 Oct 2022 16:56:39 +0000 Subject: [PATCH] Updated the ISA so the program will correctly see things like 'load', 'inc' and 'dec'. --- includes/opcodes.h | 4 ++-- src/main.c | 4 +--- src/opcodes.c | 16 +++++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/includes/opcodes.h b/includes/opcodes.h index e261a38..805474d 100644 --- a/includes/opcodes.h +++ b/includes/opcodes.h @@ -9,8 +9,8 @@ typedef enum { } Registers; typedef enum { - COPY, ADD, SUB, JZ, INT, YLD, RET, - CMP, NOP, JMP, CALL, IN, OUT, + ADD, SUB, JZ, INT, YLD, RET, + CMP, NOP, JMP, CALL, LOAD, JE, INC, DEC, LOADB } Mnemonic; typedef enum { diff --git a/src/main.c b/src/main.c index 74b63f2..db5afcb 100644 --- a/src/main.c +++ b/src/main.c @@ -22,8 +22,6 @@ int main(int argc, char* args[]) { List* list = GenerateTokenList(source_code); char mnemonic[12]; - printf("PRINTING TOKENS\n"); - for(int i = 0; i < list->size; i++) { Token* t = (Token*) list->content[i]; @@ -80,7 +78,7 @@ int main(int argc, char* args[]) { } } - IRState* image = ParseTokens(list); + //IRState* image = ParseTokens(list); //Disassemble(image); //for(int i = 0; i < image->Opcodes->size; i++) { // printf("%d\n", ((IROpcode*) image->Opcodes->content[i])->Mnemonic); diff --git a/src/opcodes.c b/src/opcodes.c index 234a46e..798b5f1 100644 --- a/src/opcodes.c +++ b/src/opcodes.c @@ -2,7 +2,7 @@ #include #include -#define OPCODECOUNT 13 +#define OPCODECOUNT 15 struct _instruction { char* Name; @@ -10,7 +10,6 @@ struct _instruction { }; struct _instruction instructions[OPCODECOUNT] = { - { "copy", COPY },//, Reg | Address, Reg | Constant | Address }, { "add", ADD },//, Reg, Reg | Constant }, { "sub", SUB },//, Reg, Reg | Constant }, { "jz", JZ },//, Address, None }, @@ -18,11 +17,14 @@ struct _instruction instructions[OPCODECOUNT] = { { "yld", YLD },//, None, None }, { "ret", RET },//, None, None }, { "cmp", CMP },//, Reg, Reg | Constant }, - { "in", IN },//, Constant | Reg, None}, - { "out", OUT },//, None, None}, + { "inc", INC },//, Constant | Reg, None}, + { "dec", DEC },//, None, None}, { "nop", NOP },//, None, None}, { "jmp", JMP },//, Address, None}, { "call", CALL },//, Address, None} + { "load", LOAD }, + { "je", JE }, + { "loadb", LOADB} }; Instruction* CreateInstruction(Mnemonic mnemonic) { @@ -49,7 +51,7 @@ void FreeInstruction(Instruction* instruction) { unsigned char GetInstructionMask(Mnemonic type) { switch (type) { - case COPY: + case LOAD: return 0x20; //0b00100000; ORing 0x80 marks the first parameter as an address case ADD: return 0x40;//0b01000000; @@ -69,9 +71,9 @@ unsigned char GetInstructionMask(Mnemonic type) { return 0x05; case JMP: return 0x06;//0b00000110; - case IN: + case INC: return 0x07;//0b00000111; - case OUT: + case DEC: return 0x08;//0b00001000; default: return 0x00;