ISA & Assembly

In RISC-V, what can happen when the address of a 4-byte lw is not a multiple of 4 (misaligned)?

  1. AThe address is silently rounded to the next multiple of 4 and always read correctly at full speed
  2. BDepending on the implementation, it may raise an exception, be handled in hardware, or be handled in software and run very slowly
  3. 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, be handled in hardware, or be handled in software and run 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 any of these behaviors.
  • C. Ignoring them would read the wrong location.