Relocatable sections

The starting address of a relocatable section is evaluated at linking time according to the information stored in the linker parameter file. A relocatable section is defined through the SECTION - Declare Relocatable Section assembler directive. The following listing shows an example using the SECTION directive.

Listing: Example source code using SECTION for relocatable sections
          XDEF  entry
constSec: SECTION     ; Relocatable constant data section.

cst1:     DC.B  $A6

cst2:     DC.B  $BC

dataSec:  SECTION     ; Relocatable data section.

var:      DS.B  1

codeSec:  SECTION     ; Relocatable code section.

entry:

          LDA   cst1  ; Load value into cst1

          ADD   cst2  ; Add value in cst2

          STA   var   ; Store into var

          BRA   entry

In the previous example, two bytes of storage are allocated in the constSec section. The constant cst1 is allocated at the start of the section at address $A00 and another constant cst2 is allocated at an offset of 1 byte from the beginning of the section. All subsequent instructions or data allocation directives will be located in the relocatable constSec section until another section is specified using the ORG or SECTION directives.

When using relocatable sections, the user does not need to care about overlapping sections. The linker will assign a start address to each section according to the input from the linker parameter file.

The user can decide to define only one memory area for the code and constant sections and another one for the variable sections or to split the sections over several memory areas.