ISA & Assembly
In RISC-V, what can happen when the address of a 4-byte lw is not a multiple of 4 (misaligned)?
- AThe address is silently rounded to the next multiple of 4 and always read correctly at full speed
- BDepending on the implementation, it may raise an exception or be handled in hardware or software, possibly very slowly
- CThe low two address bits are simply ignored without error
Show answer and explanation
Answer: B. Depending on the implementation, it may raise an exception or be handled in hardware or software, possibly very slowly
A 4-byte item at an address that is a multiple of 4 can be read in one memory access. Crossing a boundary needs two accesses, so RISC-V lets each implementation either handle misaligned accesses in hardware or trap and leave them to software, which can be orders of magnitude slower. This is why compilers insert padding between struct members to keep them aligned.
- A. The address is never silently changed.
- B. Correct. The ISA allows implementations either way.
- C. Ignoring them would read the wrong location.