Updated the opcode listing and 'fixed' the code to at least compile, but obviously I'll need to rework how the new copy instructions are to be parsed. Fixed some errors in the documentation where I skipped some hex numbers and added a copy immediate op.
This commit is contained in:
+33
-69
@@ -7,65 +7,43 @@
|
||||
struct _instruction {
|
||||
char* Name;
|
||||
Mnemonic Mnemonic;
|
||||
OpcodeParameter ParameterOne;
|
||||
OpcodeParameter ParameterTwo;
|
||||
};
|
||||
|
||||
struct _instruction instructions[OPCODECOUNT] = {
|
||||
{ "add", ADD, RegisterParameter, RegisterParameter },
|
||||
{ "sub", SUB, RegisterParameter, RegisterParameter },//, Reg, Reg | Constant },
|
||||
{ "jz", JZ, AddressParameter, NoParameter },//, Address, None },
|
||||
{ "yld", YLD, NoParameter, NoParameter },//, None, None },
|
||||
{ "cmp", CMP, RegisterParameter, RegisterParameter },//, Reg, Reg | Constant },
|
||||
{ "cmpi", CMPI, RegisterParameter, ConstantParameter },
|
||||
{ "inc", INC, RegisterParameter, NoParameter },//, Constant | Reg, None},
|
||||
{ "dec", DEC, RegisterParameter, NoParameter },//, None, None},
|
||||
{ "nop", NOP, NoParameter, NoParameter },//, None, None},
|
||||
{ "jmp", JMP, AddressParameter, NoParameter },//, Address, None},
|
||||
{ "call", CALL, AddressParameter, NoParameter },//, Address, None}
|
||||
{ "lodwi", LODWI, RegisterParameter, ConstantParameter },
|
||||
{ "je", JE, AddressParameter, NoParameter },
|
||||
{ "stob", STOB, RegisterParameter, AddressParameter },
|
||||
{ "stow", STOW, RegisterParameter, AddressParameter },
|
||||
{ "laa", LAA, RegisterParameter, AddressParameter },
|
||||
{ "lodw", LODW, RegisterParameter, RegisterParameter },
|
||||
{ "jmp", JMP, AddressParameter, NoParameter },
|
||||
{ "jg", JG, AddressParameter, NoParameter },
|
||||
{ "jl", JL, AddressParameter, NoParameter },
|
||||
{ "and", AND, RegisterParameter, RegisterParameter },
|
||||
{ "xor", XOR, RegisterParameter, RegisterParameter },
|
||||
{ "or", OR, RegisterParameter, RegisterParameter },
|
||||
{ "not", NOT, RegisterParameter, NoParameter },
|
||||
{ "shr", SHR, RegisterParameter, ConstantParameter },
|
||||
{ "shl", SHL, RegisterParameter, ConstantParameter },
|
||||
{ "nop", NOP, NoParameter, NoParameter },
|
||||
{ "pop", POP, RegisterParameter, NoParameter },
|
||||
{ "push", PUSH, RegisterParameter, NoParameter },
|
||||
{ "lodb", LODB, RegisterParameter, RegisterParameter},
|
||||
{ "jmpa", JMPA, RegisterParameter, NoParameter},
|
||||
{ "jza", JZA, RegisterParameter, NoParameter},
|
||||
{ "jla", JLA, RegisterParameter, NoParameter},
|
||||
{ "jga", JGA, RegisterParameter, NoParameter},
|
||||
struct _instruction instructions[31] = {
|
||||
{ "copya", COPYA },
|
||||
{ "copyab", COPYAB },
|
||||
{ "copyra", COPYRA },
|
||||
{ "copyrab", COPYRAB },
|
||||
{ "copyrara", COPYRARA },
|
||||
{ "copyrarab", COPYRARAB },
|
||||
{ "copy", COPY },
|
||||
{ "copyi", COPYI },
|
||||
{ "copyb", COPYB },
|
||||
{ "cmp", CMP },
|
||||
{ "cmpi", CMPI },
|
||||
{ "add", ADD },
|
||||
{ "sub", SUB },
|
||||
{ "and", AND },
|
||||
{ "xor", XOR },
|
||||
{ "or", OR },
|
||||
{ "not", NOT },
|
||||
{ "shr", SHR },
|
||||
{ "shl", SHL },
|
||||
{ "inc", INC },
|
||||
{ "dec", DEC },
|
||||
{ "push", PUSH },
|
||||
{ "pop", POP },
|
||||
{ "jmpi", JMPI },
|
||||
{ "jmp", JMP },
|
||||
{ "jz", JZ },
|
||||
{ "jg", JG },
|
||||
{ "jl", JL },
|
||||
{ "nop", NOP },
|
||||
{ "call", CALL },
|
||||
{ "ret", RET }
|
||||
//yld
|
||||
};
|
||||
|
||||
void ExpectParameters(Mnemonic mnemonic, OpcodeParameter* paramOne, OpcodeParameter* paramTwo) {
|
||||
*paramOne = NoParameter;
|
||||
*paramTwo = NoParameter;
|
||||
|
||||
for (int i = 0; i < OPCODECOUNT; i++) {
|
||||
struct _instruction ins = instructions[i];
|
||||
|
||||
if (ins.Mnemonic == mnemonic) {
|
||||
*paramOne = ins.ParameterOne;
|
||||
*paramTwo = ins.ParameterTwo;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "[Warning] Could not find mnemonic (%d) when looking for parameters.\n", mnemonic);
|
||||
}
|
||||
|
||||
Instruction* CreateInstruction(Mnemonic mnemonic) {
|
||||
Instruction* instruction = calloc(1, sizeof(Instruction));
|
||||
|
||||
@@ -80,20 +58,6 @@ Instruction* CreateInstruction(Mnemonic mnemonic) {
|
||||
return instruction;
|
||||
}
|
||||
|
||||
Parameter* CreateParameter(OpcodeParameter parameterType) {
|
||||
Parameter* param = calloc(1, sizeof(Parameter));
|
||||
|
||||
if (!param) {
|
||||
fprintf(stderr, "Failed to calloc room for a Parameter. %s,\n", strerror(errno));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
param->ParameterType = parameterType;
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
void FreeInstruction(Instruction* instruction) {
|
||||
if (!instruction) return;
|
||||
|
||||
|
||||
+34
-31
@@ -130,42 +130,42 @@ void HandleAssemblerDirective() {
|
||||
|
||||
if (PeekToken()->Class == NumberClass) {
|
||||
directive->Class = MnemonicClass;
|
||||
directive->Value.Mnemonic = LODWI;
|
||||
directive->Lemexe = "LODWI";
|
||||
directive->Value.Mnemonic = COPYI;
|
||||
directive->Lemexe = "copyi";
|
||||
AdvanceParser(); //Number, register or identifier
|
||||
}
|
||||
else if (PeekToken()->Class == RegisterClass) {
|
||||
directive->Class = MnemonicClass;
|
||||
directive->Value.Mnemonic = LODW;
|
||||
directive->Lemexe = "LODW";
|
||||
directive->Value.Mnemonic = COPY;
|
||||
directive->Lemexe = "copy";
|
||||
AdvanceParser(); //Number, register or identifier
|
||||
}
|
||||
else {
|
||||
ExpectIdentifier(0, ForwardParser);
|
||||
|
||||
directive->Class = MnemonicClass;
|
||||
directive->Value.Mnemonic = LAA;
|
||||
directive->Lemexe = "LAA";
|
||||
directive->Value.Mnemonic = COPYA;
|
||||
directive->Lemexe = "copya";
|
||||
}
|
||||
}
|
||||
else if (reg->Class == DirectiveClass) {
|
||||
if (reg->Value.Directive != Byte) {
|
||||
fprintf(stderr, "[Line %d] Syntax error, expected keyword 'byte'.\n", reg->LineNumber);
|
||||
exit(3);
|
||||
}
|
||||
// else if (reg->Class == DirectiveClass) {
|
||||
// if (reg->Value.Directive != Byte) {
|
||||
// fprintf(stderr, "[Line %d] Syntax error, expected keyword 'byte'.\n", reg->LineNumber);
|
||||
// exit(3);
|
||||
// }
|
||||
|
||||
RemoveCurrentToken(); //byte
|
||||
// RemoveCurrentToken(); //byte
|
||||
|
||||
ExpectRegister();
|
||||
// ExpectRegister();
|
||||
|
||||
ExpectPuncuation(Comma, ForwardParser);
|
||||
// ExpectPuncuation(Comma, ForwardParser);
|
||||
|
||||
ExpectRegister();
|
||||
// ExpectRegister();
|
||||
|
||||
directive->Class = MnemonicClass;
|
||||
directive->Value.Mnemonic = LODB;
|
||||
directive->Lemexe = "LODB";
|
||||
}
|
||||
// directive->Class = MnemonicClass;
|
||||
// directive->Value.Mnemonic = LODB;
|
||||
// directive->Lemexe = "LODB";
|
||||
// }
|
||||
|
||||
ExpectLineEndOrFileEnd(ForwardParser);
|
||||
}
|
||||
@@ -180,9 +180,9 @@ void HandleAssemblerDirective() {
|
||||
if (next->Class != DirectiveClass) {
|
||||
//If the token after the current one is invalid then the expect function ahead will exit, so we can
|
||||
//go ahead and change the STORE directive into a proper opcode here.
|
||||
directive->Value.Mnemonic = STOW;
|
||||
directive->Value.Mnemonic = COPY;
|
||||
directive->Class = MnemonicClass;
|
||||
directive->Lemexe = "STOW";
|
||||
directive->Lemexe = "copy";
|
||||
}
|
||||
else {
|
||||
if (next->Value.Directive != Byte) {
|
||||
@@ -192,9 +192,9 @@ void HandleAssemblerDirective() {
|
||||
|
||||
RemoveCurrentToken(); //Remove byte modifier token.
|
||||
|
||||
directive->Value.Mnemonic = STOB;
|
||||
directive->Value.Mnemonic = COPYB;
|
||||
directive->Class = MnemonicClass;
|
||||
directive->Lemexe = "STOB";
|
||||
directive->Lemexe = "copyb";
|
||||
}
|
||||
|
||||
ExpectRegister();
|
||||
@@ -272,11 +272,14 @@ void HandleOpcode(void) {
|
||||
{
|
||||
Token* arg = PeekToken();
|
||||
|
||||
opcode->Value.Mnemonic = JMPI;
|
||||
opcode->Lemexe = "jmpi";
|
||||
|
||||
if (arg->Class == IdentifierClass) {
|
||||
ExpectIdentifier(0, ForwardParser);
|
||||
|
||||
opcode->Value.Mnemonic = JMPA;
|
||||
opcode->Lemexe = "JMPA";
|
||||
opcode->Value.Mnemonic = JMP;
|
||||
opcode->Lemexe = "jmp";
|
||||
}
|
||||
else ExpectRegister();
|
||||
}
|
||||
@@ -288,8 +291,8 @@ void HandleOpcode(void) {
|
||||
if (arg->Class == IdentifierClass) {
|
||||
ExpectIdentifier(0, ForwardParser);
|
||||
|
||||
opcode->Value.Mnemonic = JZA;
|
||||
opcode->Lemexe = "JZA";
|
||||
opcode->Value.Mnemonic = JZ;
|
||||
opcode->Lemexe = "jz";
|
||||
}
|
||||
else ExpectRegister();
|
||||
}
|
||||
@@ -301,8 +304,8 @@ void HandleOpcode(void) {
|
||||
if (arg->Class == IdentifierClass) {
|
||||
ExpectIdentifier(0, ForwardParser);
|
||||
|
||||
opcode->Value.Mnemonic = JGA;
|
||||
opcode->Lemexe = "JGA";
|
||||
opcode->Value.Mnemonic = JG;
|
||||
opcode->Lemexe = "jg";
|
||||
}
|
||||
else ExpectRegister();
|
||||
}
|
||||
@@ -314,8 +317,8 @@ void HandleOpcode(void) {
|
||||
if (arg->Class == IdentifierClass) {
|
||||
ExpectIdentifier(0, ForwardParser);
|
||||
|
||||
opcode->Value.Mnemonic = JLA;
|
||||
opcode->Lemexe = "JLA";
|
||||
opcode->Value.Mnemonic = JL;
|
||||
opcode->Lemexe = "jl";
|
||||
}
|
||||
else ExpectRegister();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user