31.2 Addressing the Flash During Self-Programming
The Z-pointer (R30 and R31) is used to address the SPM commands.
Since the Flash is organized in pages (Please refer to Page Size section in Memory Programming chapter), the Program Counter can be treated as having two different sections. One section, consisting of the least significant bits, is addressing the words within a page, while the most significant bits are addressing the pages. This is shown in the following figure. Note that the Page Erase and Page Write operations are addressed independently. Therefore it is of major importance that the software addresses the same page in both the Page Erase and Page Write operation.
The Load Program Memory (LPM) instruction uses the Z-pointer to store the address. Since this instruction addresses the Flash byte-by-byte, also the LSB (bit Z0) of the Z-pointer is used.