Added a distinction between constant numbers and what are effectively memory addresses (i.e. strings and labels).
This commit is contained in:
+17
-4
@@ -38,10 +38,13 @@ int ExpectTokenClass(int, ...);
|
||||
const Symbol* GetSymbol(char*);
|
||||
List* SymbolsTable;
|
||||
unsigned int ProgramCounter = 0;
|
||||
char Memory[HIGHMEMORY];
|
||||
|
||||
void ParseTokens(List* tokens) {
|
||||
if (!tokens) return;
|
||||
|
||||
memset(Memory, 0, sizeof(Memory));
|
||||
|
||||
TokensList = tokens;
|
||||
|
||||
SymbolsTable = CreateList();
|
||||
@@ -56,7 +59,7 @@ void ParseTokens(List* tokens) {
|
||||
case Opcode:
|
||||
HandleOperation();
|
||||
break;
|
||||
case Immediate16:
|
||||
case Address:
|
||||
if (t->type == LABEL) {
|
||||
printf("%s: \n", t->lexeme);
|
||||
AddSymbol(t, ProgramCounter);
|
||||
@@ -71,7 +74,12 @@ void ParseTokens(List* tokens) {
|
||||
|
||||
PrintSymbols();
|
||||
DestroyList(SymbolsTable);
|
||||
//printf("Program Counter: %d\n", ProgramCounter);
|
||||
// for(int i = 0; i < 256; i++) {
|
||||
// if (i != 0 && i % 80 == 0) printf("\n");
|
||||
// printf("%02X ", Memory[i] & 0xFF);
|
||||
// }
|
||||
// printf("\n");
|
||||
// printf("Program Counter: %d\n", ProgramCounter);
|
||||
//printf("Heap Top: %#06X\n", HeapTop);
|
||||
}
|
||||
|
||||
@@ -93,6 +101,10 @@ void HandleAssemblerDirective(void) {
|
||||
case STRING:
|
||||
printf("[INFO] %s = '%s' (%#04X)\n", identifier->lexeme, PeekToken()->lexeme, ProgramCounter);
|
||||
|
||||
for(int i = 0; i < strlen(PeekToken()->lexeme); i++) {
|
||||
Memory[ProgramCounter + i] = PeekToken()->lexeme[i];
|
||||
}
|
||||
|
||||
ProgramCounter += strlen(PeekToken()->lexeme);
|
||||
|
||||
AdvanceParser();
|
||||
@@ -106,6 +118,7 @@ void HandleAssemblerDirective(void) {
|
||||
}
|
||||
else {
|
||||
//Add the NULL byte.
|
||||
Memory[ProgramCounter] = '\0';
|
||||
ProgramCounter++;
|
||||
return;
|
||||
}
|
||||
@@ -142,7 +155,7 @@ void HandleOperation(void) {
|
||||
//Encode the register number here.
|
||||
printf("%s ", PeekToken()->lexeme);
|
||||
}
|
||||
else if (inst->parameter_one & Immediate16) {
|
||||
else if (inst->parameter_one & Address || inst->parameter_one & Constant) {
|
||||
if (PeekToken()->type == IDENTIFIER || PeekToken()->type == LABEL) {
|
||||
const Symbol* symbol = GetSymbol(PeekToken()->lexeme);
|
||||
|
||||
@@ -176,7 +189,7 @@ void HandleOperation(void) {
|
||||
|
||||
if (inst->parameter_two && PeekToken()->token_class > 0) {
|
||||
//printf("Matched 2 '%s'\n", PeekToken()->lexeme);
|
||||
if (inst->parameter_two & Immediate16) {
|
||||
if (inst->parameter_two & Address || inst->parameter_two & Constant) {
|
||||
if (PeekToken()->type == IDENTIFIER || PeekToken()->type == LABEL) {
|
||||
const Symbol* symbol = GetSymbol(PeekToken()->lexeme);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user