The SEGMENT statement declares a generic segment along with memory class and segment location options. Where | segname | specifies the symbol name to assign to the segment. This symbol is references by subsequent RSEG statements. It may also be used in expressions to represent the base or starting address of the combined segment. | | class | is the memory classification for the segment. The class specifies the memory space where the segment is located. | | relocation | determines what relocation options are available to the linker for this segment. | | alignment | determines what address alignment options are available to the linker for this segment. |
The name of each segment in a source module must be unique. The linker combines segments that have the same type. ClassThe segment class specifies the memory space for the segment and is used by the linker to access all segments that belong to that class. The following table lists the basic classes. | class | Description |
|---|
| BIT | The BIT address space with the valid address range is 20H.0-2FH.7. For example: 21H.5. | | CODE | The CODE address space (from 0000h-0FFFFh). | | CONST1 | The CONST address space. This is the same as the CODE space but is used for constants only. This memory is accessed using the MOVC instruction. | | DATA | The DATA address space (from 00h-7Fh). | | EBIT1 | The Extended BIT space on 80C251-compatible devices. | | ECODE1 | The entire address space (used for code) on 80C51MX devices. | | ECONST1 | The Extended CONST space (same as EDATA) on 80C251-compatible devices. | | EDATA1 | The Extended DATA space on 80C251-compatible devices. | | HCONST1 | The entire address space (used for constants) on 80C51MX devices. | | HDATA1 | The entire address space (used for data) on 80C51MX devices. | | IDATA | The IDATA address space (from 00h-0FFh). | | XDATA | The XDATA address space (from 0000h-0FFFFh). |
Following are a few examples of segments defined using the basic classes.
seg1 SEGMENT XDATA
seg2 SEGMENT HCONST
seg3 SEGMENT DATA
User-Defined ClassesUser-defined classes allow you to access the same address space as basic class names but with greater flexibility and more granular control over program segments. The primary benefit to user-defined segments is the ability to locate only certain segments to specific physical addresses using the linker. User-defined class names are composed of a basic class name and an extension and are enclosed in single-quotes ('). For example:
seg1 SEGMENT 'XDATA_FLASH'
seg2 SEGMENT 'HCONST_IMAGES'
seg3 SEGMENT 'DATA1'
RelocationThe relocation type specifies how the linker may relocate the segment. The following table lists the valid kinds of relocation. | relocation | Description |
|---|
| AT address1 2 | specifies that the segment is absolute and is located at the specified address. | | BITADDRESSABLE | specifies that the segment is located in bit-addressable memory. This relocation type is allowed only for segments in the DATA class whose length does not exceed 16 bytes. | | INBLOCK | specifies that the segment must be located in a single 2048-byte block. This relocation type may be specified only for segments in the CODE class. This is typically used for segments with routines that use ACALL and AJMP instructions. | | INPAGE | specifies that the segment must be located in a single 256-byte page. | | INSEG1 | specifies that the segment must be located in a single 64K byte segment. | | OFFS offset1 2 | specifies that the segment is absolute and is located at offset bytes from the base address of the segment's memory class. The advantage of the OFFS relocation type over the AT relocation type is that segments defined with an offset may be relocated using the LX51 Linker's CLASSES directive. | | OVERLAYABLE 2 | specifies that the segment may be overlaid with and share the memory of other segments. Segments declared with the OVERLAYABLE relocation type may be overlaid with each other. OVERLAYABLE segments must be declared using the naming conventions of the C51 or CX51 Compiler. |
AlignmentThe alignment is optional and specifies how the linker allocates the segment. The following table lists the valid alignment types. | alignment | Description |
|---|
| BIT1 | specifies bit alignment for the segment. This is the default for all segments with the class BIT. | | BYTE | specifies byte alignment for the segment. This is the default for all segments, except for segments with the class BIT. | | WORD1 | specifies word alignment for the segment. This forces the segment to start on an even address. | | DWORD1 | specifies double word alignment for the segment. This forces the segment to start on an address that starts on a 4-byte boundary. | | PAGE | specifies 256-byte page alignment for the segment. The segment start must be on a 256-byte page boundary. | | BLOCK1 | specifies 2048-byte block alignment for the segment. This forces the segment to start on a 2048-byte boundary. | | SEG1 | specifies 64 kbyte alignment for the segment. This forces the segment to start on a 64KB boundary. | | |
|