Msg/MemoryMisaligned
From CPUlator Wiki
< Msg
Memory accesses need to be aligned. The memory address must be a multiple of the size of the access. For example, a 4-byte load must use an address that is a multiple of 4 bytes. This message says that the memory access was not properly aligned.
Attempting a misaligned memory access may throw an exception, or result in a load or store that doesn't behave as you would expect.
Examples
ARMv7
.global _start
_start:
ldr r0, [pc,#1] // Load 4-byte word from a misaligned address
Nios II
.global _start
_start:
ldw r2, 1(r0) # Load 4-byte word from a misaligned address
The above examples try to load from an address that isn't a multiple of 4, but a 4-byte (word-sized) access must be to an address that is a multiple of 4 bytes. The warning message tells you the address the memory access attempted to access.
Debugging
- Start by looking at the address used for the memory access (which base register and what offset). Then look at how the address is calculated and why it became incorrect.
- Also check that you are using the correct size memory access. For example, when iterating over a byte array (also called a "string"), each element is one byte, so a byte-sized load or store needs to be used.
Implementation
The simulator checks alignment for all memory accesses. This warning is generated while executing the load or store.
Disabling this message
This debugging check can be disabled in the Debugging Checks section of the Settings box: Memory access misaligned. If the processor throws an alignment exception, disabling the warning message does not change the behaviour of the processor, and the alignment exception will still be thrown.