5.5.1 Implicit Alignment in Program Memory

In addition to directives that explicitly align the location counter (such as .align, .palign, .org, .porg, etc.), many statements cause an implicit alignment to occur under certain conditions. Implicit alignment occurs when padding is inserted so that the next statement begins at a valid address. Padding uses the current .fillvalue if specified; otherwise the value zero is used.

In data memory, a valid address is available for each byte. Since no data directives specify memory in quantities of less than one byte, implicit alignment is not required in data memory.

In program memory, a valid address is available for each instruction word (4 bytes). Since data directives can specify individual bytes, implicit alignment to the next valid address is sometimes required.

The following conditions cause implicit alignment in program memory:

  1. Labels must be aligned to a valid address. For example, see the following source code:
       .text
       .byte 0x11
    L1:
       .byte 0x22,0x33

    This generates implicit alignment as shown in this excerpt from the listing file:

       1                 	.text
       2 000000  11 00 00 00    .byte 0x11
       3                 	L1:
       4 000004  22 33          .byte 0x22,0x33
    

    Three bytes of padding were inserted so that label L1 would be aligned to a valid address. Keep in mind that a valid instruction address must be divisible by four, even though the instruction word may contain two 16-bit opcodes.

  2. Instructions must be aligned to a valid address. For example, see the following source code:
       .text
       .byte 0x11
        mov w2,w3

    This generates implicit alignment as shown in this excerpt from the listing file:

       1                 	.text
       2 000000  11 00 00 00    .byte 0x11
       3 000004  32 02          mov w2,w3