Fixed a bug where words weren't being written to 'memory' correctly.
This commit is contained in:
+5
-10
@@ -115,7 +115,9 @@ void WriteByte(unsigned char byte) {
|
||||
}
|
||||
|
||||
void WriteWord(unsigned short word) {
|
||||
mem[PC2] = word;
|
||||
mem[PC2] = (word >> 8) & 0xFF;
|
||||
mem[PC2 + 1] = word & 0xFF;
|
||||
PC2 += 2;
|
||||
}
|
||||
|
||||
unsigned short GetValueFromToken(Token* token) {
|
||||
@@ -124,7 +126,7 @@ unsigned short GetValueFromToken(Token* token) {
|
||||
|
||||
if (TryGetSymbol(token->Lemexe, Symbols, &symbol)) {
|
||||
printf("Returning %d for address of %s.\n", symbol->Address, symbol->Name);
|
||||
return symbol->Address;
|
||||
return 0xABCD;//symbol->Address;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Failed to find symbol %s while assembling.\n", token->Lemexe);
|
||||
@@ -154,7 +156,6 @@ void assemble() {
|
||||
WriteByte(current->Value.Mnemonic | ((Token*) LIST->content[CurrentIndex])->Value.Register);
|
||||
CurrentIndex++;
|
||||
WriteWord(GetValueFromToken(LIST->content[CurrentIndex]));
|
||||
PC2 += 2;
|
||||
break;
|
||||
case COPYRA:
|
||||
case COPYRAB:
|
||||
@@ -173,15 +174,13 @@ void assemble() {
|
||||
WriteByte(current->Value.Mnemonic | ((Token*) LIST->content[CurrentIndex])->Value.Register);
|
||||
CurrentIndex++;
|
||||
WriteWord(GetValueFromToken(LIST->content[CurrentIndex]));
|
||||
PC2 += 2;
|
||||
break;
|
||||
case COPYB:
|
||||
CurrentIndex++;
|
||||
|
||||
WriteByte(current->Value.Mnemonic | ((Token*) LIST->content[CurrentIndex])->Value.Register);
|
||||
CurrentIndex++;
|
||||
WriteWord((unsigned char)GetValueFromToken(LIST->content[CurrentIndex]));
|
||||
PC2 += 1;
|
||||
WriteByte((unsigned char)GetValueFromToken(LIST->content[CurrentIndex]));
|
||||
break;
|
||||
case CMP:
|
||||
CurrentIndex++;
|
||||
@@ -196,7 +195,6 @@ void assemble() {
|
||||
WriteByte(current->Value.Mnemonic | ((Token*) LIST->content[CurrentIndex])->Value.Register);
|
||||
CurrentIndex++;
|
||||
WriteWord(GetValueFromToken(LIST->content[CurrentIndex]));
|
||||
PC2 += 2;
|
||||
break;
|
||||
case ADD:
|
||||
case SUB:
|
||||
@@ -216,7 +214,6 @@ void assemble() {
|
||||
WriteByte(current->Value.Mnemonic | ((Token*) LIST->content[CurrentIndex])->Value.Register);
|
||||
CurrentIndex++;
|
||||
WriteWord(GetValueFromToken(LIST->content[CurrentIndex]));
|
||||
PC2 += 2;
|
||||
break;
|
||||
case INC:
|
||||
case DEC:
|
||||
@@ -234,7 +231,6 @@ void assemble() {
|
||||
WriteByte(current->Value.Mnemonic);
|
||||
CurrentIndex++;
|
||||
WriteWord(GetValueFromToken(LIST->content[CurrentIndex]));
|
||||
PC2 += 2;
|
||||
break;
|
||||
case NOP:
|
||||
case RET:
|
||||
@@ -244,7 +240,6 @@ void assemble() {
|
||||
WriteByte(current->Value.Mnemonic);
|
||||
CurrentIndex++;
|
||||
WriteWord(GetValueFromToken(LIST->content[CurrentIndex]));
|
||||
PC2 += 2;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user