Updated the ISA so the program will correctly see things like 'load', 'inc' and 'dec'.

This commit is contained in:
2022-10-03 16:56:39 +00:00
parent a0d5d62a34
commit a949007c75
3 changed files with 12 additions and 12 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ typedef enum {
} Registers; } Registers;
typedef enum { typedef enum {
COPY, ADD, SUB, JZ, INT, YLD, RET, ADD, SUB, JZ, INT, YLD, RET,
CMP, NOP, JMP, CALL, IN, OUT, CMP, NOP, JMP, CALL, LOAD, JE, INC, DEC, LOADB
} Mnemonic; } Mnemonic;
typedef enum { typedef enum {
+1 -3
View File
@@ -22,8 +22,6 @@ int main(int argc, char* args[]) {
List* list = GenerateTokenList(source_code); List* list = GenerateTokenList(source_code);
char mnemonic[12]; char mnemonic[12];
printf("PRINTING TOKENS\n");
for(int i = 0; i < list->size; i++) { for(int i = 0; i < list->size; i++) {
Token* t = (Token*) list->content[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); //Disassemble(image);
//for(int i = 0; i < image->Opcodes->size; i++) { //for(int i = 0; i < image->Opcodes->size; i++) {
// printf("%d\n", ((IROpcode*) image->Opcodes->content[i])->Mnemonic); // printf("%d\n", ((IROpcode*) image->Opcodes->content[i])->Mnemonic);
+9 -7
View File
@@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define OPCODECOUNT 13 #define OPCODECOUNT 15
struct _instruction { struct _instruction {
char* Name; char* Name;
@@ -10,7 +10,6 @@ struct _instruction {
}; };
struct _instruction instructions[OPCODECOUNT] = { struct _instruction instructions[OPCODECOUNT] = {
{ "copy", COPY },//, Reg | Address, Reg | Constant | Address },
{ "add", ADD },//, Reg, Reg | Constant }, { "add", ADD },//, Reg, Reg | Constant },
{ "sub", SUB },//, Reg, Reg | Constant }, { "sub", SUB },//, Reg, Reg | Constant },
{ "jz", JZ },//, Address, None }, { "jz", JZ },//, Address, None },
@@ -18,11 +17,14 @@ struct _instruction instructions[OPCODECOUNT] = {
{ "yld", YLD },//, None, None }, { "yld", YLD },//, None, None },
{ "ret", RET },//, None, None }, { "ret", RET },//, None, None },
{ "cmp", CMP },//, Reg, Reg | Constant }, { "cmp", CMP },//, Reg, Reg | Constant },
{ "in", IN },//, Constant | Reg, None}, { "inc", INC },//, Constant | Reg, None},
{ "out", OUT },//, None, None}, { "dec", DEC },//, None, None},
{ "nop", NOP },//, None, None}, { "nop", NOP },//, None, None},
{ "jmp", JMP },//, Address, None}, { "jmp", JMP },//, Address, None},
{ "call", CALL },//, Address, None} { "call", CALL },//, Address, None}
{ "load", LOAD },
{ "je", JE },
{ "loadb", LOADB}
}; };
Instruction* CreateInstruction(Mnemonic mnemonic) { Instruction* CreateInstruction(Mnemonic mnemonic) {
@@ -49,7 +51,7 @@ void FreeInstruction(Instruction* instruction) {
unsigned char GetInstructionMask(Mnemonic type) { unsigned char GetInstructionMask(Mnemonic type) {
switch (type) { switch (type) {
case COPY: case LOAD:
return 0x20; //0b00100000; ORing 0x80 marks the first parameter as an address return 0x20; //0b00100000; ORing 0x80 marks the first parameter as an address
case ADD: case ADD:
return 0x40;//0b01000000; return 0x40;//0b01000000;
@@ -69,9 +71,9 @@ unsigned char GetInstructionMask(Mnemonic type) {
return 0x05; return 0x05;
case JMP: case JMP:
return 0x06;//0b00000110; return 0x06;//0b00000110;
case IN: case INC:
return 0x07;//0b00000111; return 0x07;//0b00000111;
case OUT: case DEC:
return 0x08;//0b00001000; return 0x08;//0b00001000;
default: default:
return 0x00; return 0x00;