From 2918f2964de34d2cc1ec3b46f0f7c11a855f71f2 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Sat, 24 Jun 2023 18:00:13 -0500 Subject: [PATCH] Fixed a bug where words weren't being written to 'memory' correctly. --- src/main.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main.c b/src/main.c index 5022f3a..cf94871 100644 --- a/src/main.c +++ b/src/main.c @@ -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; }