Fixed endian-ness of readWord functions w/ S

This commit is contained in:
Themis Demetriades 2024-06-03 17:29:45 +01:00
parent 8b98a0002f
commit 4c04f44286

View File

@ -31,7 +31,7 @@ word readWord(byte *memory, uint32_t address) {
word result = 0;
int bytesPerWord = WORD_BITS / BYTE_BITS - 1;
for (int i = 0; i <= bytesPerWord; i++)
result |= (word) memory[address + i] << (BYTE_BITS * (bytesPerWord - i));
result |= (word) memory[address + i] << (BYTE_BITS * i);
return result;
}
@ -40,7 +40,7 @@ dword readDoubleWord(byte *memory, uint32_t address) {
dword result = 0;
int bytesPerDword = DWORD_BITS / BYTE_BITS - 1;
for (int i = 0; i <= bytesPerDword; i++)
result |= (dword) memory[address + i] << (BYTE_BITS * (bytesPerDword - i));
result |= (dword) memory[address + i] << (BYTE_BITS * i);
return result;
}
@ -55,5 +55,4 @@ void printMemory(Machine *state, FILE *stream) {
fprintf(stream, "0x%08x: 0x%08x\n", addr, data);
}
}
}