diff --git a/src/execute.c b/src/execute.c index 8ce5e79..d5e60a6 100644 --- a/src/execute.c +++ b/src/execute.c @@ -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); } } 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 bool isSDT = inst->data.SingleTransferData.SingleTransferOpType == a64inst_SINGLE_TRANSFER_SINGLE_DATA_TRANSFER; diff --git a/src/print.c b/src/print.c index 1d1d4a2..88ed6f9 100644 --- a/src/print.c +++ b/src/print.c @@ -44,6 +44,14 @@ dword readDoubleWord(byte *memory, uint32_t address) { 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 void printMemory(Machine *state, FILE *stream) { fprintf(stream, "\nNon-zero memory:\n"); diff --git a/src/print.h b/src/print.h index 404e947..5a64a4e 100644 --- a/src/print.h +++ b/src/print.h @@ -5,6 +5,7 @@ word readWord(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 printRegisters(Machine *state, FILE *stream); void printMemory(Machine *state, FILE *stream);