Add storeMemory utility function and used it to fix a prev bug

This commit is contained in:
sBubshait 2024-06-06 16:38:01 +01:00
parent b16fe2bee3
commit 8893b62a18
3 changed files with 10 additions and 1 deletions

View File

@ -397,7 +397,7 @@ void execute_SDT(Machine *state, a64inst_instruction *inst) {
writeRegister(state, inst->data.SingleTransferData.processOpData.singleDataTransferData.base, inst->data.SingleTransferData.regType, result); writeRegister(state, inst->data.SingleTransferData.processOpData.singleDataTransferData.base, inst->data.SingleTransferData.regType, result);
} }
} else { } else {
*(word *)(state->memory + address) = state->registers[inst->data.SingleTransferData.target]; storeMemory(state->memory, address, state->registers[inst->data.SingleTransferData.target]);
// Update base register if post indexed // Update base register if post indexed
bool isSDT = inst->data.SingleTransferData.SingleTransferOpType == a64inst_SINGLE_TRANSFER_SINGLE_DATA_TRANSFER; bool isSDT = inst->data.SingleTransferData.SingleTransferOpType == a64inst_SINGLE_TRANSFER_SINGLE_DATA_TRANSFER;

View File

@ -44,6 +44,14 @@ dword readDoubleWord(byte *memory, uint32_t address) {
return result; return result;
} }
// Store into memory starting at address the given dword.
void storeMemory(byte *memory, uint32_t address, dword data) {
int bytesPerDword = DWORD_BITS / BYTE_BITS - 1;
for (int i = 0; i <= bytesPerDword; i++) {
memory[address + i] = (byte)((data >> (BYTE_BITS * i)) & 0xFF);
}
}
// Prints all non-zero memory locations into the provided stream // Prints all non-zero memory locations into the provided stream
void printMemory(Machine *state, FILE *stream) { void printMemory(Machine *state, FILE *stream) {
fprintf(stream, "\nNon-zero memory:\n"); fprintf(stream, "\nNon-zero memory:\n");

View File

@ -5,6 +5,7 @@
word readWord(byte *memory, uint32_t address); word readWord(byte *memory, uint32_t address);
dword readDoubleWord(byte *memory, uint32_t address); dword readDoubleWord(byte *memory, uint32_t address);
void storeMemory(byte *memory, uint32_t address, dword data);
void printState(Machine *state, FILE *stream); void printState(Machine *state, FILE *stream);
void printRegisters(Machine *state, FILE *stream); void printRegisters(Machine *state, FILE *stream);
void printMemory(Machine *state, FILE *stream); void printMemory(Machine *state, FILE *stream);