SPRAB89A September 2011 – March 2014
The C64+ ISA and some later variants have a feature known as compact instructions, an encoding format that packs pairs of 16-bit instructions into 32-bit words of program memory. In big-endian mode, the instructions are stored in memory in the opposite order from their lexical order in the source program, and opposite from the order in which they execute. This section clarifies the conventions for representing addresses in the face of this discrepancy.
A 16-bit instruction may be considered to have two addresses:
In the little-endian configuration, logical addresses are the same as physical addresses. In big-endian, pairs of 16-bit instructions are swapped in program memory such that if address A represents the physical address of the 32-bit word containing the pair, the first logical instruction is stored A+2 and the second at A.
The code fragment in Figure 5-1 illustrates the distinction between logical and physical addresses. The program is shown in its lexical order. The first column shows the little-endian physical address, which is also the logical address for both little- and big-endian. The second column shows the big-endian physical address. The dashed lines represent 32-bit boundaries in program memory.
The ABI specifies that all program addresses in the object file are represented as logical addresses. This includes branch displacements, symbol values, addresses in unwinding tables, and addresses in debug information.
Referring to Figure 5-1, the value of the label code in the symbol table is 0x0000 even though the instruction it labels (opcode 0x40CE) is stored at 0x0002. Similarly, the value of the label local is 0x000A even though the instruction it labels (opcode 0xA14F) is stored at 0x0008.
For the most part the distinction between logical and physical addresses is transparent to both the programmer and the toolchain. To preserve this transparency, the following conditions are imposed:
Conditions (1) and (2) taken together exclude indirect branches to addresses that are not 32-bit aligned. Note an instance of (2b) does not require a relocation since the offset is an assembly-time constant. This in turn enables condition (3), sidestepping the need to translate between logical and physical addresses to access a relocatable field.