Added support for the STORE directive.

This commit is contained in:
2023-03-29 12:57:07 -05:00
parent ee60d14570
commit 2e888913be
3 changed files with 43 additions and 2 deletions
+3 -1
View File
@@ -9,4 +9,6 @@ something_insance:
load r1, unknown_symbol
load byte r1, r3
load r1, 5
load r3, r4
load r3, r4
store byte r3, r5
store r5, r7
+32 -1
View File
@@ -167,7 +167,38 @@ void HandleAssemblerDirective() {
break;
case Store:
{
AdvanceParser();
Token* next = PeekToken();
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->Class = MnemonicClass;
directive->Lemexe = "STOW";
}
else {
if (next->Value.Directive != Byte) {
fprintf(stderr, "[Line %d] Syntax error, expected keyword 'byte'.\n", next->LineNumber);
exit(10);
}
RemoveCurrentToken(); //Remove byte modifier token.
AdvanceParser();
directive->Value.Mnemonic = STOB;
directive->Class = MnemonicClass;
directive->Lemexe = "STOB";
}
ExpectRegister();
ExpectPuncuation(Comma, ForwardParser);
ExpectRegister();
ExpectLineEndOrFileEnd(ForwardParser);
}
break;
default:
+8
View File
@@ -299,6 +299,14 @@ Token* ParseIdentifier(void) {
return token;
}
if (strcmp(lexeme, "store") == 0) {
Token* token = CreateToken(Line, DirectiveClass);
token->Lemexe = lexeme;
token->Value.Directive = Store;
return token;
}
Token* token = CreateToken(Line, IdentifierClass);