Memory Alignment

Since the PIC32MZ memory system is 32-bits wide, a data access that is 32-bit (4-bytes, or WORD), or 16-bit (2-bytes, or HALF WORD) in size can either be aligned or unaligned:

  • (Naturally) Aligned Transfer means that the data's address value is a multiple of the data's type-size (in bytes)
    • WORD size transfers are carried out to addresses that are a multiple of four: 0x00000000, 0x00000004, 0x00000008, …
    • HALF WORD size transfers are carried out to addresses that are a multiple of two: 0x00000000, 0x00000002, 0x00000004, …
  • Unaligned Transfer means that the data's address does not follow the rules above.

All MIPS® architectures prior to Release 5 require "naturally" aligned transfers for normal load/store operations. Unaligned accesses using normal load/store operations will produce exceptions.

In most cases, C-compilers do not generate unaligned data accesses. It can only happen in:

  • Direct manipulation of pointers
  • Accessing data structures with "packed" attributes that contain unaligned data
  • Inline/Embedded Assembly code

Several examples of "naturally" aligned and unaligned data transfers are shown below for a MIPS32® Little-Endian memory system:

memory-alignment.png
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.