Fixed a bug in the parser where the size of the binary was too big.

This commit is contained in:
2022-08-29 18:02:11 +00:00
parent ae1e73e00f
commit e3b4293314
2 changed files with 5 additions and 12 deletions
+1 -4
View File
@@ -27,10 +27,7 @@ void Disassemble(unsigned char image[HIGHMEMORY]) {
unsigned char instruction = image[position]; unsigned char instruction = image[position];
while(end >= position) {//(instruction != 0) { while(end > position) {
// printf("%d\n", position);
// printf("%#04X\n", instruction);
unsigned char masked = instruction & 0xE0; unsigned char masked = instruction & 0xE0;
if (masked) { if (masked) {
+4 -8
View File
@@ -188,8 +188,6 @@ void HandleRegisterBasedOpcode(unsigned char instruction, unsigned char mask) {
Memory[ProgramCounter] = 2 >> symbol->address & 0xFF; Memory[ProgramCounter] = 2 >> symbol->address & 0xFF;
Memory[ProgramCounter + 1] = symbol->address & 0xFF; Memory[ProgramCounter + 1] = symbol->address & 0xFF;
ProgramCounter += 2;
AdvanceParser(); AdvanceParser();
} }
else if (token->type == NUMBER) { else if (token->type == NUMBER) {
@@ -200,13 +198,13 @@ void HandleRegisterBasedOpcode(unsigned char instruction, unsigned char mask) {
Memory[ProgramCounter] = 2 >> *value & 0xFF; Memory[ProgramCounter] = 2 >> *value & 0xFF;
Memory[ProgramCounter + 1] = *value & 0xFF; Memory[ProgramCounter + 1] = *value & 0xFF;
ProgramCounter += 2;
AdvanceParser(); AdvanceParser();
} else { } else {
fprintf(stderr, "[Error] Expected operand, got %s\n", token->lexeme); fprintf(stderr, "[Error] Expected operand, got %s\n", token->lexeme);
exit(1); exit(1);
} }
ProgramCounter += 2;
} }
void HandleOperation(void) { void HandleOperation(void) {
@@ -251,8 +249,6 @@ void HandleOperation(void) {
Memory[ProgramCounter] = 2 >> *value & 0xFF; Memory[ProgramCounter] = 2 >> *value & 0xFF;
Memory[ProgramCounter + 1] = *value & 0xFF; Memory[ProgramCounter + 1] = *value & 0xFF;
ProgramCounter += 2;
} }
else { else {
fprintf(stderr, "[Error] Line: %d: Expected address after jump if zero (JZ) instruction.\n", ((Token*) TokensList->content[CurrentToken - 1])->line); fprintf(stderr, "[Error] Line: %d: Expected address after jump if zero (JZ) instruction.\n", ((Token*) TokensList->content[CurrentToken - 1])->line);
@@ -272,14 +268,14 @@ void HandleOperation(void) {
Memory[ProgramCounter] = 2 >> *value & 0xFF; Memory[ProgramCounter] = 2 >> *value & 0xFF;
Memory[ProgramCounter + 1] = *value & 0xFF; Memory[ProgramCounter + 1] = *value & 0xFF;
ProgramCounter += 2;
} }
else { else {
fprintf(stderr, "[Error] Line %d: Expected Interrupt vector.\n", PeekToken()->line); fprintf(stderr, "[Error] Line %d: Expected Interrupt vector.\n", PeekToken()->line);
exit(1); exit(1);
} }
ProgramCounter += 2;
return; return;
} }