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;
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 {
+1 -3
View File
@@ -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);
+9 -7
View File
@@ -2,7 +2,7 @@
#include <stdlib.h>
#include <string.h>
#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;